public BBoxTableMapping( String ftTable, ICRS crs ) { this.ftTable = new TableName( ftTable ); this.crs = crs; }
/** * Returns the name of the table (without schema). * * @return the name of the table, never <code>null</code> */ public String getTable() { return getName(); }
@Override public ResultSet getTableColumnMetadata( DatabaseMetaData md, TableName qTable ) throws SQLException { String schema = qTable.getSchema() != null ? qTable.getSchema() : getDefaultSchema(); String table = qTable.getTable(); return md.getColumns( null, schema.toLowerCase(), table.toLowerCase(), null ); }
private List<StringBuffer> getGeometryCreate( GeometryMapping mapping, DBField dbField, TableName table ) { List<StringBuffer> ddls = new ArrayList<StringBuffer>(); String schema = table.getSchema() == null ? "" : table.getSchema(); String column = dbField.getColumn(); String srid = mapping.getSrid(); double[] dom = mapping.getCRS().getValidDomain(); StringBuffer sql = new StringBuffer(); sql.append( "INSERT INTO user_sdo_geom_metadata(TABLE_NAME,COLUMN_NAME,DIMINFO,SRID) VALUES (" + "'" + table.toString().toUpperCase() + "','" + column.toUpperCase() + "',SDO_DIM_ARRAY(" + "SDO_DIM_ELEMENT('X', " + dom[0] + ", " + dom[2] + ", 0.00000005), SDO_DIM_ELEMENT('Y', " + dom[1] + ", " + dom[3] + ", 0.00000005)), null)" ); ddls.add( sql ); sql = new StringBuffer(); sql.append( "CREATE INDEX " + table.getTable().toUpperCase() + "_" + column.toUpperCase() + " ON " + table.toString().toUpperCase() + "(" + column.toUpperCase() + ") INDEXTYPE IS MDSYS.SPATIAL_INDEX" ); ddls.add( sql ); return ddls; }
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 String getPkConstraintName( TableName ftTable ) { String s = null; String table = ftTable.getTable(); if ( table.endsWith( "\"" ) ) { s = table.substring( 0, table.length() - 1 ) + "_pkey\""; } else { s = table + "_pkey"; } return s; }
@Override public boolean equals( Object obj ) { if ( !( obj instanceof KeyPropagation ) ) { return false; } KeyPropagation that = (KeyPropagation) obj; if ( !this.source.equals( that.source ) || !this.target.equals( that.target ) ) { return false; } for ( int i = 0; i < pkColumns.size(); i++ ) { if ( !this.pkColumns.get( i ).equals( that.pkColumns.get( i ) ) ) { return false; } if ( !this.fkColumns.get( i ).equals( that.fkColumns.get( i ) ) ) { return false; } } return true; }
/** * Returns the name of the schema. * * @return the name of the schema, can be <code>null</code> (default schema) */ public String getSchema() { return getQualifier(); }
protected List<TableJoin> buildJoinTable( TableName from, org.deegree.feature.persistence.sql.jaxb.Join join ) { if ( join != null ) { TableName target = createFromQualifiedName( join.getTable() ); if ( join.getFromColumns().size() != join.getToColumns().size() ) { throw new UnsupportedOperationException( "Joins must use same number of from and to columns." ); } if ( join.getFromColumns().isEmpty() ) { throw new UnsupportedOperationException( "Joins must use at least a single column." ); } boolean isNumbered = join.isNumbered() == null ? false : join.isNumbered(); Map<SQLIdentifier, IDGenerator> keyColumnToGenerator = new HashMap<SQLIdentifier, IDGenerator>(); for ( AutoKeyColumn keyColumn : join.getAutoKeyColumn() ) { SQLIdentifier columnName = new SQLIdentifier( keyColumn.getName() ); IDGenerator idGenerator = buildGenerator( keyColumn.getAbstractIDGenerator() ); keyColumnToGenerator.put( columnName, idGenerator ); } if ( keyColumnToGenerator.isEmpty() ) { // defaulting keyColumnToGenerator.put( new SQLIdentifier( "id" ), new AutoIDGenerator() ); } TableJoin tj = new TableJoin( from, target, join.getFromColumns(), join.getToColumns(), join.getOrderColumns(), isNumbered, keyColumnToGenerator ); return Collections.singletonList( tj ); } return null; }
private void process( FeatureTypeJAXB 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 ( getColumns( 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 AbstractPropertyJAXB>> propDecls = ftDecl.getAbstractProperty(); if ( propDecls != null && !propDecls.isEmpty() ) { process( table, ftName, fidMapping, propDecls ); } else { process( table, ftName, fidMapping ); } }
private JoinRow buildJoinRow( InsertRow row, TableJoin join ) throws FeatureStoreException { JoinRow newRow = new JoinRow( this, join ); delayedRows.add( newRow ); KeyPropagation keyPropagation = tableDeps.findKeyPropagation( join.getFromTable(), join.getFromColumns(), join.getToTable(), join.getToColumns() ); if ( keyPropagation == null ) { String msg = "Internal error: table dependencies don't contain join " + join; throw new FeatureStoreException( msg ); } if ( keyPropagation.getSourceTable().equals( join.getFromTable() ) ) { ParentRowReference ref = new ParentRowReference( row, keyPropagation ); newRow.addParent( ref ); List<InsertRow> children = rowToChildRows.get( row ); if ( children == null ) { children = new ArrayList<InsertRow>(); rowToChildRows.put( row, children ); } children.add( newRow ); } else { ParentRowReference ref = new ParentRowReference( newRow, keyPropagation ); row.addParent( ref ); List<InsertRow> children = new ArrayList<InsertRow>(); rowToChildRows.put( newRow, children ); children.add( row ); } return newRow; }
/** * Creates a new {@link BlobMapping} instance. * * @param table * the name of the table that stores the BLOBs, must not be <code>null</code> * @param storageCRS * crs used for storing geometries / envelopes, must not be <code>null</code> * @param codec * the decoder / encoder used for the BLOBs, must not be <code>null</code> */ public BlobMapping( String table, ICRS storageCRS, BlobCodec codec ) { this.table = new TableName( table ); this.storageCRS = storageCRS; this.codec = codec; }
@Override public String geometryMetadata( TableName qTable, String column, boolean isGeographical ) { String dbSchema = qTable.getSchema() != null ? qTable.getSchema() : getDefaultSchema(); String table = qTable.getTable(); if ( !isGeographical ) { return "SELECT coord_dimension,srid,type FROM public.geometry_columns WHERE f_table_schema='" + dbSchema.toLowerCase() + "' AND f_table_name='" + table.toLowerCase() + "' AND f_geometry_column='" + column.toLowerCase() + "'"; } return "SELECT coord_dimension,srid,type FROM public.geography_columns WHERE f_table_schema='" + dbSchema.toLowerCase() + "' AND f_table_name='" + table.toLowerCase() + "' AND f_geography_column='" + column.toLowerCase() + "'"; }
} else if ( !join.getToTable().getName().equals( "?" ) ) {
private String retrieveTypeOfPrimaryKey( TableName fromTable, SQLIdentifier toColumn, FIDMapping fidMapping ) { if ( fidMapping != null ) { for ( Pair<SQLIdentifier, BaseType> column : fidMapping.getColumns() ) { if ( toColumn.equals( column.getFirst() ) ) { return getDBType( column.getSecond() ); } } } // in joins not connected to the main feature type table 'integer' is used by default if ( !fromTable.equals( currentFtTable ) ) { return "integer"; } return "varchar(2000)"; }
public static TableName createFromQualifiedName( String tableName ) { String table = tableName; String schema = null; if ( table.contains( "." ) ) { String[] splittedQualifiedTableName = table.split( "[.]" ); schema = splittedQualifiedTableName[0]; table = splittedQualifiedTableName[1]; } return new TableName( table, schema ); } }