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 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() + "'"; }
@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>(); StringBuffer sql = new StringBuffer(); String schema = table.getSchema() == null ? "" : table.getSchema(); String column = dbField.getColumn(); String srid = mapping.getSrid(); // TODO String geometryType = "GEOMETRY"; int dim = 2; sql.append( "SELECT ADDGEOMETRYCOLUMN('" + schema.toLowerCase() + "', '" + table.getTable().toLowerCase() + "','" + column + "','" + srid + "','" + geometryType + "', " + dim + ")" ); ddls.add( sql ); return ddls; }
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; }
@Override protected List<String> getBLOBCreates() { List<String> ddl = new ArrayList<String>(); // create feature_type table TableName ftTable = schema.getBBoxMapping().getTable(); String ftTableSchema = ftTable.getSchema() == null ? "public" : ftTable.getSchema(); ddl.add( "CREATE TABLE " + ftTable + " (id smallint PRIMARY KEY, qname text NOT NULL)" ); ddl.add( "COMMENT ON TABLE " + ftTable + " IS 'Ids and bboxes of concrete feature types'" ); ddl.add( "SELECT ADDGEOMETRYCOLUMN('" + ftTableSchema.toLowerCase() + "', '" + ftTable.getTable().toLowerCase() + "','bbox','" + undefinedSrid + "','GEOMETRY',2)" ); // populate feature_type table for ( short ftId = 0; ftId < schema.getFts(); ftId++ ) { QName ftName = schema.getFtName( ftId ); ddl.add( "INSERT INTO " + ftTable + " (id,qname) VALUES (" + ftId + ",'" + ftName + "')" ); } // create gml_objects table TableName blobTable = schema.getBlobMapping().getTable(); String blobTableSchema = blobTable.getSchema() == null ? "public" : blobTable.getSchema(); ddl.add( "CREATE TABLE " + blobTable + " (id serial PRIMARY KEY, " + "gml_id text UNIQUE NOT NULL, ft_type smallint REFERENCES " + ftTable + " , binary_object bytea)" ); ddl.add( "COMMENT ON TABLE " + blobTable + " IS 'All objects (features and geometries)'" ); ddl.add( "SELECT ADDGEOMETRYCOLUMN('" + blobTableSchema.toLowerCase() + "', '" + blobTable.getTable().toLowerCase() + "','gml_bounded_by','" + undefinedSrid + "','GEOMETRY',2)" ); ddl.add( "ALTER TABLE " + blobTable + " ADD CONSTRAINT gml_objects_geochk CHECK (ST_IsValid(gml_bounded_by))" ); ddl.add( "CREATE INDEX gml_objects_sidx ON " + blobTable + " USING GIST (gml_bounded_by)" ); // ddl.add( "CREATE TABLE gml_names (gml_object_id integer REFERENCES gml_objects," // + "name text NOT NULL,codespace text,prop_idx smallint NOT NULL)" ); return ddl; }
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 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 ); } }
jc = buildJoinTable( table, joinConfig ); TableName toTable = jc.get( jc.size() - 1 ).getToTable(); valueTable = new TableName( toTable.getTable(), toTable.getSchema() );