use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class RecordStoreSchema method getTypeNames.
public List<String> getTypeNames() {
refreshIfNeeded();
final List<String> names = new ArrayList<>();
for (final PathName typeName : getTypePaths()) {
names.add(typeName.getParentPath());
}
return names;
}
use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class RecordStoreSchema method addElement.
public void addElement(final RecordStoreSchemaElement element) {
refreshIfNeeded();
final PathName path = getPathName();
final PathName childPath = element.getPathName();
if (path.isParentOf(childPath)) {
this.elementsByPath.put(childPath, element);
if (element instanceof RecordDefinition) {
final RecordDefinition recordDefinition = (RecordDefinition) element;
this.recordDefinitionsByPath.put(childPath, recordDefinition);
final AbstractRecordStore recordStore = getRecordStore();
recordStore.addRecordDefinitionProperties((RecordDefinitionImpl) recordDefinition);
}
if (element instanceof RecordStoreSchema) {
final RecordStoreSchema schema = (RecordStoreSchema) element;
this.schemasByPath.put(childPath, schema);
}
} else {
throw new IllegalArgumentException(path + " is not a parent of " + childPath);
}
}
use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class GeoPackageRecordStore method refreshSchemaElementsDo.
@Override
protected Map<PathName, ? extends RecordStoreSchemaElement> refreshSchemaElementsDo(final JdbcRecordStoreSchema schema, final PathName schemaPath) {
final String schemaName = schema.getPath();
final Map<String, String> tableDescriptionMap = new HashMap<>();
final Map<String, List<String>> tablePermissionsMap = new TreeMap<>();
final Map<PathName, JdbcRecordDefinition> recordDefinitionMap = loadRecordDefinitionsPermissions(schema);
final Map<PathName, RecordStoreSchemaElement> elementsByPath = new TreeMap<>();
try {
try (final Connection connection = getJdbcConnection()) {
for (final JdbcRecordDefinition recordDefinition : recordDefinitionMap.values()) {
final PathName typePath = recordDefinition.getPathName();
elementsByPath.put(typePath, recordDefinition);
}
for (final JdbcRecordDefinition recordDefinition : recordDefinitionMap.values()) {
final String tableName = recordDefinition.getDbTableName();
final List<String> idFieldNames = new ArrayList<>();
try (PreparedStatement columnStatement = connection.prepareStatement("PRAGMA table_info(" + tableName + ")")) {
try (final ResultSet columnsRs = columnStatement.executeQuery()) {
while (columnsRs.next()) {
final String dbColumnName = columnsRs.getString("name");
final String fieldName = dbColumnName.toUpperCase();
final int sqlType = Types.OTHER;
String dataType = columnsRs.getString("type");
int length = -1;
final int scale = -1;
if (dataType.startsWith("TEXT(")) {
length = Integer.parseInt(dataType.substring(5, dataType.length() - 1));
dataType = "TEXT";
}
final boolean required = columnsRs.getString("notnull").equals("1");
final boolean primaryKey = columnsRs.getString("pk").equals("1");
if (primaryKey) {
idFieldNames.add(fieldName);
}
final Object defaultValue = columnsRs.getString("dflt_value");
final FieldDefinition field = addField(recordDefinition, dbColumnName, fieldName, dataType, sqlType, length, scale, required, null);
field.setDefaultValue(defaultValue);
}
}
}
recordDefinition.setIdFieldNames(idFieldNames);
}
}
} catch (final Throwable e) {
throw new IllegalArgumentException("Unable to load metadata for schema " + schemaName, e);
}
return elementsByPath;
}
use of com.revolsys.io.PathName 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;
}
use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class ArcSdeStGeometryRecordStoreExtension method loadColumnProperties.
private void loadColumnProperties(final RecordStoreSchema schema, final String schemaName, final Connection connection) throws SQLException {
final String sql = "SELECT GC.F_TABLE_NAME, GC.F_GEOMETRY_COLUMN, GC.SRID, GC.GEOMETRY_TYPE, GC.COORD_DIMENSION, SG.GEOMETRY_TYPE GEOMETRY_DATA_TYPE FROM SDE.GEOMETRY_COLUMNS GC LEFT OUTER JOIN SDE.ST_GEOMETRY_COLUMNS SG ON GC.F_TABLE_SCHEMA = SG.OWNER AND GC.F_TABLE_NAME = SG.TABLE_NAME WHERE GC.F_TABLE_SCHEMA = ?";
final PreparedStatement statement = connection.prepareStatement(sql);
try {
statement.setString(1, schemaName);
final ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
final String tableName = resultSet.getString(1);
final String columnName = resultSet.getString(2);
final PathName typePath = PathName.newPathName(PathUtil.toPath(schemaName, tableName));
final int esriSrid = resultSet.getInt(3);
JdbcFieldAdder.setColumnProperty(schema, typePath, columnName, ArcSdeConstants.ESRI_SRID_PROPERTY, esriSrid);
int axisCount = resultSet.getInt(5);
axisCount = Math.max(axisCount, 2);
JdbcFieldAdder.setColumnProperty(schema, typePath, columnName, JdbcFieldAdder.AXIS_COUNT, axisCount);
final ArcSdeSpatialReference spatialReference = ArcSdeSpatialReferenceCache.getSpatialReference(connection, schema, esriSrid);
JdbcFieldAdder.setColumnProperty(schema, typePath, columnName, ArcSdeConstants.SPATIAL_REFERENCE, spatialReference);
GeometryFactory geometryFactory = JdbcFieldAdder.getColumnProperty(schema, typePath, columnName, JdbcFieldAdder.GEOMETRY_FACTORY);
int srid = spatialReference.getCoordinateSystemId();
if (srid <= 0) {
srid = geometryFactory.getCoordinateSystemId();
}
axisCount = Math.min(axisCount, 3);
final double[] scales = spatialReference.getGeometryFactory().newScales(axisCount);
geometryFactory = GeometryFactory.fixed(srid, axisCount, scales);
JdbcFieldAdder.setColumnProperty(schema, typePath, columnName, JdbcFieldAdder.GEOMETRY_FACTORY, geometryFactory);
final int geometryType = resultSet.getInt(4);
JdbcFieldAdder.setColumnProperty(schema, typePath, columnName, JdbcFieldAdder.GEOMETRY_TYPE, ArcSdeConstants.getGeometryDataType(geometryType));
String geometryColumnType = resultSet.getString(6);
if (!Property.hasValue(geometryColumnType)) {
geometryColumnType = ArcSdeConstants.SDEBINARY;
}
JdbcFieldAdder.setColumnProperty(schema, typePath, columnName, ArcSdeConstants.GEOMETRY_COLUMN_TYPE, geometryColumnType);
}
} finally {
JdbcUtils.close(resultSet);
}
} finally {
JdbcUtils.close(statement);
}
}
Aggregations