private void process( FeatureTypeMappingJAXB ftDecl ) throws SQLException, FeatureStoreException { if ( ftDecl.getTable() == null || ftDecl.getTable().isEmpty() ) { String msg = "Feature type element without or with empty table attribute."; throw new FeatureStoreException( msg ); } TableName table = new TableName( ftDecl.getTable() ); LOG.debug( "Processing feature type mapping for table '" + table + "'." ); if ( getColumnMetadataFromDb( table ).isEmpty() ) { throw new FeatureStoreException( "No table with name '" + table + "' exists (or no columns defined)." ); } QName ftName = ftDecl.getName(); if ( ftName == null ) { LOG.debug( "Using table name for feature type." ); ftName = new QName( table.getTable() ); } ftName = makeFullyQualified( ftName, "app", "http://www.deegree.org/app" ); LOG.debug( "Feature type name: '" + ftName + "'." ); FIDMapping fidMapping = buildFIDMapping( table, ftName, ftDecl.getFIDMapping() ); List<JAXBElement<? extends AbstractParticleJAXB>> propDecls = ftDecl.getAbstractParticle(); if ( propDecls != null && !propDecls.isEmpty() ) { buildFeatureTypeAndMapping( table, ftName, fidMapping, propDecls ); } else { buildFeatureTypeAndMapping( table, ftName, fidMapping ); } }
private void buildFeatureTypeAndMapping( TableName table, QName ftName, FIDMapping fidMapping, List<JAXBElement<? extends AbstractParticleJAXB>> propDecls ) throws FeatureStoreException, SQLException { List<PropertyType> pts = new ArrayList<PropertyType>(); List<Mapping> mappings = new ArrayList<Mapping>(); for ( JAXBElement<? extends AbstractParticleJAXB> propDeclEl : propDecls ) { AbstractParticleJAXB propDecl = propDeclEl.getValue(); Pair<PropertyType, Mapping> pt = buildPropertyAndMapping( table, propDecl, ftName.getPrefix(), ftName.getNamespaceURI() ); pts.add( pt.first ); mappings.add( pt.second ); } FeatureType ft = new GenericFeatureType( ftName, pts, false ); ftNameToFt.put( ftName, ft ); FeatureTypeMapping ftMapping = new FeatureTypeMapping( ftName, table, fidMapping, mappings ); ftNameToMapping.put( ftName, ftMapping ); }
private ColumnMetadata getColumn( TableName qTable, SQLIdentifier columnName ) throws SQLException, FeatureStoreException { ColumnMetadata md = getColumnMetadataFromDb( qTable ).get( columnName ); if ( md == null ) md = getUnescapedColumnMetadata( qTable, columnName ); if ( md == null ) { throw new FeatureStoreException( "Table '" + qTable + "' does not have a column with name '" + columnName + "'" ); } return md; }
int colonIdx = xpath.indexOf( ":" ); if ( colonIdx == -1 ) { propName = makeFullyQualified( new QName( xpath ), ftPrefix, ftNs ); } else { String prefix = xpath.substring( 0, colonIdx ); propName = makeFullyQualified( new QName( null, localPart, prefix ), ftPrefix, ftNs ); MappingExpression mapping = parseMappingExpression( me ); if ( !( mapping instanceof DBField ) ) { throw new FeatureStoreException( "Unhandled mapping type '" + mapping.getClass() LOG.debug( "Using column name for property name." ); propName = new QName( columnName ); propName = makeFullyQualified( propName, "app", "http://www.deegree.org/app" ); TableName valueTable = table; if ( joinConfig != null ) { jc = buildJoinTable( table, joinConfig ); TableName toTable = jc.get( jc.size() - 1 ).getToTable(); valueTable = new TableName( toTable.getTable(), toTable.getSchema() ); ColumnMetadata md = getColumn( valueTable, new SQLIdentifier( columnName ) ); int minOccurs = joinConfig != null ? 0 : md.isNullable ? 0 : 1; BaseType primType = null; if ( simpleDecl.getType() != null ) { primType = getPrimitiveType( simpleDecl.getType() ); } else {
for ( ColumnJAXB configColumn : config.getColumn() ) { SQLIdentifier columnName = new SQLIdentifier( configColumn.getName() ); BaseType columnType = configColumn.getType() != null ? getPrimitiveType( configColumn.getType() ) : null; if ( columnType == null ) { ColumnMetadata md = getColumn( table, columnName ); columnType = BaseType.valueOf( md.sqlType ); IDGenerator generator = buildGenerator( config == null ? null : config.getAbstractIDGenerator() ); if ( generator instanceof AutoIDGenerator ) { if ( columns.isEmpty() ) { for ( ColumnMetadata md : getColumnMetadataFromDb( table ).values() ) { if ( md.isAutoincrement ) { BaseType columnType = BaseType.valueOf( md.sqlType );
for ( ColumnMetadata md : getColumnMetadataFromDb( table ).values() ) { if ( fidColumnNames.contains( new SQLIdentifier( md.column.toLowerCase() ) ) ) { LOG.debug( "Omitting column '" + md.column + "' from properties. Used in FIDMapping." ); QName ptName = makeFullyQualified( new QName( md.column.toLowerCase() ), ftName.getPrefix(), ftName.getNamespaceURI() ); if ( md.geomType == null ) { pts.add( pt ); ValueReference path = new ValueReference( ptName ); ICRS crs = deriveCrs( md.srid ); GeometryStorageParams geomStorageParams = new GeometryStorageParams( crs, md.srid, md.dim ); GeometryMapping mapping = new GeometryMapping( path, true, dbField, md.geomType, geomStorageParams,
DatabaseMetaData md = getDbMetadata(); columnNameToMD = new LinkedHashMap<SQLIdentifier, ColumnMetadata>(); ResultSet rs = null; dim = DIM_3; geomType = getGeometryType( rs2.getString( 3 ) ); LOG.debug( "Derived geometry type: " + geomType + ", srid: " + srid + ", dim: " + dim + "" ); dim = DIM_3; geomType = getGeometryType( rs2.getString( 3 ).toUpperCase() ); LOG.debug( "Derived geometry type (geography): " + geomType + ", srid: " + srid + ", dim: " + dim + "" );
private ColumnMetadata getUnescapedColumnMetadata( TableName qTable, SQLIdentifier columnName ) throws SQLException { String name = columnName.getName(); char leadingEscapeChar = dialect.getLeadingEscapeChar(); char tailingEscapeChar = dialect.getTailingEscapeChar(); if ( leadingEscapeChar == name.charAt( 0 ) && tailingEscapeChar == name.charAt( name.length() - 1 ) ) { SQLIdentifier unescapedColumnName = new SQLIdentifier( name.substring( 1, name.length() - 1 ) ); return getColumnMetadataFromDb( qTable ).get( unescapedColumnName ); } return null; }
public static MappedAppSchema build( String configURL, SQLFeatureStoreJAXB config, SQLDialect dialect, Workspace workspace ) throws SQLException, FeatureStoreException { boolean deleteCascadingByDB = true; if ( config.getJoinTableDeletePropagation() != null ) { deleteCascadingByDB = config.getJoinTableDeletePropagation().equals( "db" ); } AbstractMappedSchemaBuilder builder = null; if ( config.getGMLSchema() == null || config.getGMLSchema().isEmpty() ) { LOG.debug( "Table-driven mode configuration" ); if ( config.getFeatureType() != null && !config.getFeatureType().isEmpty() ) { builder = new MappedSchemaBuilderTableOld( config.getJDBCConnId().getValue(), config.getFeatureType(), dialect, deleteCascadingByDB, workspace ); } else { builder = new MappedSchemaBuilderTable( config.getJDBCConnId().getValue(), config.getFeatureTypeMapping(), dialect, deleteCascadingByDB, workspace ); } } else { LOG.debug( "Schema-driven mode configuration" ); List<String> gmlSchemas = config.getGMLSchema(); StorageCRS storageCRS = config.getStorageCRS(); List<NamespaceHint> nsHints = config.getNamespaceHint(); BLOBMapping blobConf = config.getBLOBMapping(); List<FeatureTypeMappingJAXB> ftMappingConfs = config.getFeatureTypeMapping(); builder = new MappedSchemaBuilderGML( configURL, gmlSchemas, storageCRS, nsHints, blobConf, ftMappingConfs, deleteCascadingByDB ); } return builder.getMappedSchema(); }