Search in sources :

Example 1 with JdbcRecordStoreSchema

use of com.revolsys.jdbc.io.JdbcRecordStoreSchema in project com.revolsys.open by revolsys.

the class ArcSdeStGeometryFieldAdder method newField.

@Override
public ArcSdeStGeometryFieldDefinition newField(final AbstractJdbcRecordStore recordStore, final JdbcRecordDefinition recordDefinition, final String dbName, final String name, final String dbDataType, final int sqlType, final int length, final int scale, final boolean required, final String description) {
    final JdbcRecordStoreSchema schema = recordDefinition.getSchema();
    final PathName typePath = recordDefinition.getPathName();
    final String owner = schema.getDbName();
    final String tableName = recordDefinition.getDbTableName();
    final String columnName = name.toUpperCase();
    final int esriSrid = JdbcFieldAdder.getIntegerColumnProperty(schema, typePath, columnName, ArcSdeConstants.ESRI_SRID_PROPERTY);
    if (esriSrid == -1) {
        Logs.error(this, "Column not registered in SDE.ST_GEOMETRY table " + owner + "." + tableName + "." + name);
    }
    final int axisCount = JdbcFieldAdder.getIntegerColumnProperty(schema, typePath, columnName, JdbcFieldAdder.AXIS_COUNT);
    if (axisCount == -1) {
        Logs.error(this, "Column not found in SDE.GEOMETRY_COLUMNS table " + owner + "." + tableName + "." + name);
    }
    final DataType dataType = JdbcFieldAdder.getColumnProperty(schema, typePath, columnName, JdbcFieldAdder.GEOMETRY_TYPE);
    if (dataType == null) {
        Logs.error(this, "Column not found in SDE.GEOMETRY_COLUMNS table " + owner + "." + tableName + "." + name);
    }
    final ArcSdeSpatialReference spatialReference = JdbcFieldAdder.getColumnProperty(schema, typePath, columnName, ArcSdeConstants.SPATIAL_REFERENCE);
    final GeometryFactory geometryFactory = JdbcFieldAdder.getColumnProperty(schema, typePath, columnName, JdbcFieldAdder.GEOMETRY_FACTORY);
    final ArcSdeStGeometryFieldDefinition field = new ArcSdeStGeometryFieldDefinition(dbName, name, dataType, required, description, null, spatialReference, axisCount);
    field.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
    return field;
}
Also used : JdbcRecordStoreSchema(com.revolsys.jdbc.io.JdbcRecordStoreSchema) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Example 2 with JdbcRecordStoreSchema

use of com.revolsys.jdbc.io.JdbcRecordStoreSchema in project com.revolsys.open by revolsys.

the class ArcSdeStGeometryRecordStoreExtension method preProcess.

@Override
public void preProcess(final RecordStoreSchema schema) {
    final JdbcRecordStoreSchema jdbcSchema = (JdbcRecordStoreSchema) schema;
    final RecordStore recordStore = schema.getRecordStore();
    final OracleRecordStore oracleRecordStore = (OracleRecordStore) recordStore;
    try {
        try (final Connection connection = oracleRecordStore.getJdbcConnection()) {
            final String schemaName = jdbcSchema.getDbName();
            loadTableProperties(connection, schema, schemaName);
            loadColumnProperties(schema, schemaName, connection);
        }
    } catch (final Throwable e) {
        Logs.error(this, "Unable to get ArcSDE metadata for schema " + schema.getName(), e);
    }
}
Also used : JdbcRecordStoreSchema(com.revolsys.jdbc.io.JdbcRecordStoreSchema) OracleRecordStore(com.revolsys.oracle.recordstore.OracleRecordStore) RecordStore(com.revolsys.record.schema.RecordStore) Connection(java.sql.Connection) OracleRecordStore(com.revolsys.oracle.recordstore.OracleRecordStore)

Example 3 with JdbcRecordStoreSchema

use of com.revolsys.jdbc.io.JdbcRecordStoreSchema in project com.revolsys.open by revolsys.

the class PostgreSQLGeometryFieldAdder method newField.

@Override
public JdbcFieldDefinition newField(final AbstractJdbcRecordStore recordStore, final JdbcRecordDefinition recordDefinition, final String dbName, final String name, final String dbDataType, final int sqlType, final int length, final int scale, final boolean required, final String description) {
    final JdbcRecordStoreSchema schema = recordDefinition.getSchema();
    final PathName typePath = recordDefinition.getPathName();
    String dbSchemaName = schema.getDbName();
    if (!Property.hasValue(dbSchemaName)) {
        dbSchemaName = "public";
    }
    final String tableName = recordDefinition.getDbTableName();
    final String columnName = name.toLowerCase();
    try {
        int srid = 0;
        String type = "geometry";
        int axisCount = 3;
        try {
            final String sql = "select SRID, TYPE, COORD_DIMENSION from GEOMETRY_COLUMNS where UPPER(F_TABLE_SCHEMA) = UPPER(?) AND UPPER(F_TABLE_NAME) = UPPER(?) AND UPPER(F_GEOMETRY_COLUMN) = UPPER(?)";
            final Map<String, Object> values = JdbcUtils.selectMap(this.recordStore, sql, dbSchemaName, tableName, columnName);
            srid = (Integer) values.get("srid");
            type = (String) values.get("type");
            axisCount = (Integer) values.get("coord_dimension");
        } catch (final IllegalArgumentException e) {
            Logs.warn(this, "Cannot get geometry column metadata for " + typePath + "." + columnName);
        }
        final DataType dataType = DATA_TYPE_MAP.get(type);
        final GeometryFactory storeGeometryFactory = this.recordStore.getGeometryFactory();
        final GeometryFactory geometryFactory;
        if (storeGeometryFactory == null) {
            geometryFactory = GeometryFactory.floating(srid, axisCount);
        } else {
            final double[] scales = storeGeometryFactory.newScales(axisCount);
            geometryFactory = GeometryFactory.fixed(srid, axisCount, scales);
        }
        final PostgreSQLGeometryJdbcFieldDefinition field = new PostgreSQLGeometryJdbcFieldDefinition(dbName, name, dataType, sqlType, required, description, null, srid, axisCount, geometryFactory);
        field.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
        return field;
    } catch (final Throwable e) {
        Logs.error(this, "Attribute not registered in GEOMETRY_COLUMN table " + dbSchemaName + "." + tableName + "." + name, e);
        return null;
    }
}
Also used : JdbcRecordStoreSchema(com.revolsys.jdbc.io.JdbcRecordStoreSchema) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Example 4 with JdbcRecordStoreSchema

use of com.revolsys.jdbc.io.JdbcRecordStoreSchema in project com.revolsys.open by revolsys.

the class PostgreSQLRecordStore method getSequenceName.

@Override
protected String getSequenceName(final JdbcRecordDefinition recordDefinition) {
    final JdbcRecordStoreSchema schema = recordDefinition.getSchema();
    final String dbSchemaName = schema.getDbName();
    final String shortName = ShortNameProperty.getShortName(recordDefinition);
    final String sequenceName;
    if (Property.hasValue(shortName)) {
        if (this.useSchemaSequencePrefix) {
            sequenceName = dbSchemaName + "." + shortName.toLowerCase() + "_seq";
        } else {
            sequenceName = shortName.toLowerCase() + "_seq";
        }
    } else {
        final String tableName = recordDefinition.getDbTableName();
        final String idFieldName = recordDefinition.getIdFieldName().toLowerCase();
        if (this.useSchemaSequencePrefix) {
            sequenceName = dbSchemaName + "." + tableName + "_" + idFieldName + "_seq";
        } else {
            sequenceName = tableName + "_" + idFieldName + "_seq";
        }
    }
    return sequenceName;
}
Also used : JdbcRecordStoreSchema(com.revolsys.jdbc.io.JdbcRecordStoreSchema)

Aggregations

JdbcRecordStoreSchema (com.revolsys.jdbc.io.JdbcRecordStoreSchema)4 DataType (com.revolsys.datatype.DataType)2 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)2 PathName (com.revolsys.io.PathName)2 OracleRecordStore (com.revolsys.oracle.recordstore.OracleRecordStore)1 RecordStore (com.revolsys.record.schema.RecordStore)1 Connection (java.sql.Connection)1