/** * Recursively scans a SimpleFeature for SimpleFeature attributes in order to build a * "flattened" list of attributes * * @param attributeDescriptors A List of attribute descriptors, populated recursively * @param featuretype The feature type to scan * @param attrAlias An alias for adding as a prefix to the simple attribute names */ private static void scanAttributeDescriptors( List<AttributeDescriptor> attributeDescriptors, SimpleFeatureType featureType, String attrAlias) { List<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors(); for (int i = 0; i < descriptors.size(); i++) { AttributeDescriptor ad = descriptors.get(i); SimpleFeatureType joinedSchema = (SimpleFeatureType) ad.getUserData().get(ContentDataStore.JOINED_FEATURE_TYPE); String name = (attrAlias != null ? attrAlias + "." : "") + ad.getLocalName(); if (joinedSchema != null) { // go forth and harvest feature attribute types scanAttributeDescriptors(attributeDescriptors, joinedSchema, name); } else { // this is a common (non-feature) attribute type AttributeTypeBuilder build = new AttributeTypeBuilder(); build.init(ad); AttributeDescriptor descriptor = build.buildDescriptor(name); attributeDescriptors.add(descriptor); } } }
/** * Extracts the eventual native SRID user property from the descriptor, returns -1 if not found * * @param descriptor */ protected int getDescriptorSRID(AttributeDescriptor descriptor) { int srid = -1; // check if we have stored the native srid in the descriptor (we should) if (descriptor.getUserData().get(JDBCDataStore.JDBC_NATIVE_SRID) != null) srid = (Integer) descriptor.getUserData().get(JDBCDataStore.JDBC_NATIVE_SRID); return srid; }
/** * Extracts the eventual native dimension user property from the descriptor, returns -1 if not * found * * @param descriptor */ protected int getDescriptorDimension(AttributeDescriptor descriptor) { int dimension = -1; // check if we have stored the native srid in the descriptor (we should) if (descriptor.getUserData().get(JDBCDataStore.JDBC_NATIVE_SRID) != null) { dimension = (Integer) descriptor.getUserData().get(Hints.COORDINATE_DIMENSION); } return dimension; }
/** * Returns true if the attribute descriptor matches a native SQL array (as recorded in its user * data via {@link #JDBC_NATIVE_TYPE} * * @return */ private boolean isArray(AttributeDescriptor att) { Integer nativeType = (Integer) att.getUserData().get(JDBC_NATIVE_TYPE); return Objects.equals(Types.ARRAY, nativeType); }
@Override public String getPropertyPath(String property) { AttributeDescriptor descriptor = schema.getDescriptor(property); return descriptor == null ? null : (String) descriptor.getUserData().get(MongoDataStore.KEY_mapping); }
@Override public void postCreateAttribute( AttributeDescriptor att, String tableName, String schemaName, Connection cx) throws SQLException { super.postCreateAttribute(att, tableName, schemaName, cx); if (att instanceof GeometryDescriptor) { Integer srid = (Integer) att.getUserData().get(JDBCDataStore.JDBC_NATIVE_SRID); boolean geodetic = isGeodeticSrid(srid, cx); att.getUserData().put(GEODETIC, geodetic); } }
@Override public String getPropertyPath(String property) { AttributeDescriptor descriptor = schema.getDescriptor(property); return descriptor == null ? null : (String) descriptor.getUserData().get(MongoDataStore.KEY_mapping); }
@Override protected String getArrayComponentTypeName(AttributeDescriptor att) throws SQLException { if (att == null) { return null; } String name = (String) att.getUserData().get(JDBCDataStore.JDBC_NATIVE_TYPENAME); // in postgresql jdbc the database metadata TYPE_NAME column contains the // array "base type" name, prefixed with an underscore if (name != null && name.startsWith("_")) { return name.substring(1); } return super.getArrayComponentTypeName(att); }
boolean isCurrentGeography() { AttributeDescriptor geom = null; if (delegate instanceof PostgisPSFilterToSql) { geom = ((PostgisPSFilterToSql) delegate).getCurrentGeometry(); } else if (delegate instanceof PostgisFilterToSQL) { geom = ((PostgisFilterToSQL) delegate).getCurrentGeometry(); } return geom != null && "geography".equals(geom.getUserData().get(JDBCDataStore.JDBC_NATIVE_TYPENAME)); }
/** * Returns the type cast needed to match this property * * @param pn * @return */ String getArrayTypeCast(PropertyName pn) { AttributeDescriptor at = pn.evaluate(delegate.getFeatureType(), AttributeDescriptor.class); if (at != null) { Object value = at.getUserData().get(JDBCDataStore.JDBC_NATIVE_TYPENAME); if (value instanceof String) { String typeName = (String) value; if (typeName.startsWith("_")) { return "::" + typeName.substring(1) + "[]"; } } } return ""; }
@Override public String getGeometryPath() { String gdName = schema.getGeometryDescriptor().getLocalName(); return (String) schema.getDescriptor(gdName).getUserData().get(MongoDataStore.KEY_mapping); }
@Override public String getGeometryPath() { String gdName = schema.getGeometryDescriptor().getLocalName(); return (String) schema.getDescriptor(gdName).getUserData().get(MongoDataStore.KEY_mapping); }
@Override public void postCreateAttribute( AttributeDescriptor att, String tableName, String schemaName, Connection cx) throws SQLException { if (att instanceof GeometryDescriptor) { // look up tessellation info TessellationInfo tinfo = lookupTessellationInfo(cx, schemaName, tableName, att.getLocalName()); if (tinfo != null) { att.getUserData().put(TessellationInfo.KEY, tinfo); } else { LOGGER.fine( String.format( "%s.%s.(%s) does not have tessellation entry.", schemaName, tableName, att.getLocalName())); } } }
private int getPrimaryKeyOffset( JDBCFeatureSource featureSource, PrimaryKey pk, SimpleFeatureType featureType) { // if we are not exposing them, they are all extras int pkSize = pk.getColumns().size(); if (!featureSource.isExposePrimaryKeyColumns()) { return pkSize; } // otherwise, we have to check if they are requested or not, as we are going to // have them anyways as part of the sql query, but not necessarily in the requested ft int requestedPkColumns = 0; for (AttributeDescriptor ad : featureType.getAttributeDescriptors()) { if (ad.getUserData().get(JDBCDataStore.JDBC_PRIMARY_KEY_COLUMN) == Boolean.TRUE) { requestedPkColumns++; } } return pkSize - requestedPkColumns; }
static boolean equals(AttributeDescriptor a, AttributeDescriptor b, boolean compareUserMaps) { if (a == b) return true; if (a == null) return true; if (!a.equals(b)) return false; if (compareUserMaps) { if (!equals(a.getUserData(), b.getUserData())) return false; if (!equals(a.getType().getUserData(), b.getType().getUserData())) return false; } return true; }
public AttributeDescriptor buildDescriptor(Name name, AttributeType type) { // build the descriptor AttributeDescriptor descriptor = factory.createAttributeDescriptor( type, name, minOccurs(), maxOccurs(), isNillable, defaultValue()); // set the user data descriptor.getUserData().putAll(userData); resetDescriptorState(); return descriptor; }
private AttributeDescriptor reprojectAttribute(AttributeDescriptor descr) { if (reprojection != null && descr.getType() instanceof FeatureType) { AttributeDescriptor ad = ftf.createAttributeDescriptor( reprojectType((FeatureType) descr.getType()), descr.getName(), descr.getMinOccurs(), descr.getMaxOccurs(), descr.isNillable(), descr.getDefaultValue()); ad.getUserData().putAll(descr.getUserData()); return ad; } else { return descr; } }
/** Initializes builder state from another attribute descriptor. */ public void init(AttributeDescriptor descriptor) { init(descriptor.getType()); minOccurs = descriptor.getMinOccurs(); maxOccurs = descriptor.getMaxOccurs(); isNillable = descriptor.isNillable(); userData = descriptor.getUserData(); }
private AttributeDescriptor createAttributeDescriptor( final XSDElementDeclaration elemDecl, int minOccurs, int maxOccurs, CoordinateReferenceSystem crs) { String targetNamespace = elemDecl.getTargetNamespace(); String name = elemDecl.getName(); Name elemName = Types.typeName(targetNamespace, name); AttributeType type = getTypeOf(elemDecl, crs); boolean nillable = elemDecl.isNillable(); Object defaultValue = null; AttributeDescriptor descriptor = createAttributeDescriptor( type, crs, elemName, minOccurs, maxOccurs, nillable, defaultValue); descriptor.getUserData().put(XSDElementDeclaration.class, elemDecl); return descriptor; }
public void testJoinSchema() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); Query q = new Query(tname("ft1")); Join join = new Join( tname("ftjoin"), ff.equal( ff.property(aname("stringProperty")), ff.property(aname("name")), true)); join.setAlias("b"); q.getJoins().add(join); SimpleFeatureCollection features = dataStore.getFeatureSource(tname("ft1")).getFeatures(q); SimpleFeatureType schema = features.getSchema(); AttributeDescriptor ad = schema.getDescriptor("b"); assertNotNull(ad); assertEquals(SimpleFeature.class, ad.getType().getBinding()); SimpleFeatureType joinedSchema = (SimpleFeatureType) ad.getUserData().get(ContentDataStore.JOINED_FEATURE_TYPE); assertEquals(dataStore.getSchema(tname("ftjoin")), joinedSchema); }