use of com.revolsys.record.schema.RecordStoreSchema in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method refreshSchemaElements.
@Override
protected Map<PathName, ? extends RecordStoreSchemaElement> refreshSchemaElements(final RecordStoreSchema schema) {
synchronized (this.apiSync) {
synchronized (API_SYNC) {
final Map<PathName, RecordStoreSchemaElement> elementsByPath = new TreeMap<>();
final Geodatabase geodatabase = getGeodatabase();
if (geodatabase != null) {
try {
final PathName schemaPath = schema.getPathName();
final String schemaCatalogPath = getCatalogPath(schema);
final VectorOfWString childDatasets = getChildDatasets(geodatabase, schemaCatalogPath, "Feature Dataset");
if (childDatasets != null) {
for (int i = 0; i < childDatasets.size(); i++) {
final String childCatalogPath = childDatasets.get(i);
final PathName childPath = toPath(childCatalogPath);
RecordStoreSchema childSchema = schema.getSchema(childPath);
if (childSchema == null) {
childSchema = newFeatureDatasetSchema(schema, childPath);
} else {
if (childSchema.isInitialized()) {
childSchema.refresh();
}
}
elementsByPath.put(childPath, childSchema);
}
}
if (schemaPath.isParentOf(this.defaultSchemaPath) && !elementsByPath.containsKey(this.defaultSchemaPath)) {
final SpatialReference spatialReference = getSpatialReference(getGeometryFactory());
final RecordStoreSchema childSchema = newSchema(this.defaultSchemaPath, spatialReference);
elementsByPath.put(this.defaultSchemaPath, childSchema);
}
if (schema.equalPath(this.defaultSchemaPath)) {
refreshSchemaRecordDefinitions(elementsByPath, schemaPath, "\\", "Feature Class");
refreshSchemaRecordDefinitions(elementsByPath, schemaPath, "\\", "Table");
}
refreshSchemaRecordDefinitions(elementsByPath, schemaPath, schemaCatalogPath, "Feature Class");
refreshSchemaRecordDefinitions(elementsByPath, schemaPath, schemaCatalogPath, "Table");
} finally {
releaseGeodatabase();
}
}
return elementsByPath;
}
}
}
use of com.revolsys.record.schema.RecordStoreSchema in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method getRecordDefinition.
public RecordDefinitionImpl getRecordDefinition(final PathName schemaName, final String path, final String tableDefinition) {
synchronized (this.apiSync) {
synchronized (API_SYNC) {
try {
final XmlProcessor parser = new EsriGdbXmlParser();
final DETable deTable = parser.process(tableDefinition);
final String tableName = deTable.getName();
final PathName typePath = PathName.newPathName(schemaName.newChild(tableName));
final RecordStoreSchema schema = getSchema(schemaName);
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(schema, typePath);
recordDefinition.setPolygonRingDirection(ClockDirection.CLOCKWISE);
String lengthFieldName = null;
String areaFieldName = null;
if (deTable instanceof DEFeatureClass) {
final DEFeatureClass featureClass = (DEFeatureClass) deTable;
lengthFieldName = featureClass.getLengthFieldName();
final LengthFieldName lengthFieldNameProperty = new LengthFieldName(lengthFieldName);
lengthFieldNameProperty.setRecordDefinition(recordDefinition);
areaFieldName = featureClass.getAreaFieldName();
final LengthFieldName areaFieldNameProperty = new LengthFieldName(areaFieldName);
areaFieldNameProperty.setRecordDefinition(recordDefinition);
}
for (final Field field : deTable.getFields()) {
final String fieldName = field.getName();
AbstractFileGdbFieldDefinition fieldDefinition = null;
if (fieldName.equals(lengthFieldName)) {
fieldDefinition = new LengthFieldDefinition(field);
} else if (fieldName.equals(areaFieldName)) {
fieldDefinition = new AreaFieldDefinition(field);
} else {
final FieldType type = field.getType();
final Constructor<? extends AbstractFileGdbFieldDefinition> fieldConstructor = ESRI_FIELD_TYPE_FIELD_DEFINITION_MAP.get(type);
if (fieldConstructor != null) {
try {
fieldDefinition = JavaBeanUtil.invokeConstructor(fieldConstructor, field);
} catch (final Throwable e) {
Logs.error(this, tableDefinition);
throw new RuntimeException("Error creating field for " + typePath + "." + field.getName() + " : " + field.getType(), e);
}
} else {
Logs.error(this, "Unsupported field type " + fieldName + ":" + type);
}
}
if (fieldDefinition != null) {
final Domain domain = field.getDomain();
if (domain != null) {
CodeTable codeTable = getCodeTable(domain.getDomainName() + "_ID");
if (codeTable == null) {
codeTable = new FileGdbDomainCodeTable(this, domain);
addCodeTable(codeTable);
}
fieldDefinition.setCodeTable(codeTable);
}
fieldDefinition.setRecordStore(this);
recordDefinition.addField(fieldDefinition);
if (fieldDefinition instanceof GlobalIdFieldDefinition) {
recordDefinition.setIdFieldName(fieldName);
}
}
}
final String oidFieldName = deTable.getOIDFieldName();
recordDefinition.setProperty(EsriGeodatabaseXmlConstants.ESRI_OBJECT_ID_FIELD_NAME, oidFieldName);
if (deTable instanceof DEFeatureClass) {
final DEFeatureClass featureClass = (DEFeatureClass) deTable;
final String shapeFieldName = featureClass.getShapeFieldName();
recordDefinition.setGeometryFieldName(shapeFieldName);
}
for (final Index index : deTable.getIndexes()) {
if (index.getName().endsWith("_PK")) {
for (final Field field : index.getFields()) {
final String fieldName = field.getName();
recordDefinition.setIdFieldName(fieldName);
}
}
}
addRecordDefinitionProperties(recordDefinition);
if (recordDefinition.getIdFieldIndex() == -1) {
recordDefinition.setIdFieldName(deTable.getOIDFieldName());
}
this.catalogPathByPath.put(typePath, deTable.getCatalogPath());
return recordDefinition;
} catch (final RuntimeException e) {
Logs.debug(this, tableDefinition);
throw e;
}
}
}
}
use of com.revolsys.record.schema.RecordStoreSchema in project com.revolsys.open by revolsys.
the class AbstractJdbcRecordStore method refreshSchemaElements.
@Override
protected Map<PathName, ? extends RecordStoreSchemaElement> refreshSchemaElements(final RecordStoreSchema schema) {
final JdbcRecordStoreSchema jdbcSchema = (JdbcRecordStoreSchema) schema;
final JdbcRecordStoreSchema rootSchema = getRootSchema();
final PathName schemaPath = jdbcSchema.getPathName();
if (jdbcSchema == rootSchema) {
if (this.usesSchema) {
final Map<PathName, RecordStoreSchemaElement> schemas = new TreeMap<>();
final Set<String> databaseSchemaNames = getDatabaseSchemaNames();
for (final String dbSchemaName : databaseSchemaNames) {
final PathName childSchemaPath = schemaPath.newChild(dbSchemaName.toUpperCase());
RecordStoreSchema childSchema = schema.getSchema(childSchemaPath);
if (childSchema == null) {
childSchema = new JdbcRecordStoreSchema(rootSchema, childSchemaPath, dbSchemaName);
} else {
if (childSchema.isInitialized()) {
childSchema.refresh();
}
}
schemas.put(childSchemaPath, childSchema);
}
return schemas;
} else {
return refreshSchemaElementsDo(jdbcSchema, schemaPath);
}
} else {
return refreshSchemaElementsDo(jdbcSchema, schemaPath);
}
}
use of com.revolsys.record.schema.RecordStoreSchema in project com.revolsys.open by revolsys.
the class OracleSdoGeometryFieldAdder 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 PathName typePath = recordDefinition.getPathName();
final String columnName = name.toUpperCase();
final RecordStoreSchema schema = recordDefinition.getSchema();
GeometryFactory geometryFactory = getColumnProperty(schema, typePath, columnName, GEOMETRY_FACTORY);
if (geometryFactory == null) {
geometryFactory = schema.getGeometryFactory();
}
if (geometryFactory == null) {
geometryFactory = GeometryFactory.DEFAULT_2D;
}
DataType dataType = getColumnProperty(schema, typePath, columnName, GEOMETRY_TYPE);
if (dataType == null) {
dataType = DataTypes.GEOMETRY;
}
int axisCount = getIntegerColumnProperty(schema, typePath, columnName, AXIS_COUNT);
if (axisCount == -1) {
axisCount = geometryFactory.getAxisCount();
}
int oracleSrid = getIntegerColumnProperty(schema, typePath, columnName, ORACLE_SRID);
if (oracleSrid == -1) {
oracleSrid = 0;
}
final OracleSdoGeometryJdbcFieldDefinition field = new OracleSdoGeometryJdbcFieldDefinition(dbName, name, dataType, sqlType, required, description, null, geometryFactory, axisCount, oracleSrid);
field.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
return field;
}
use of com.revolsys.record.schema.RecordStoreSchema in project com.revolsys.open by revolsys.
the class AbstractRecordReader method newRecordDefinition.
protected RecordDefinition newRecordDefinition(final String baseName, final List<String> fieldNames) throws IOException {
this.hasPointFields = Property.hasValue(this.pointXFieldName) && Property.hasValue(this.pointYFieldName);
if (this.hasPointFields) {
this.geometryType = DataTypes.POINT;
} else {
this.pointXFieldName = null;
this.pointYFieldName = null;
}
final List<FieldDefinition> fields = new ArrayList<>();
FieldDefinition geometryField = null;
for (final String fieldName : fieldNames) {
if (fieldName != null) {
DataType type;
int length = 0;
boolean isGeometryField = false;
if (fieldName.equalsIgnoreCase(this.geometryColumnName)) {
type = this.geometryType;
isGeometryField = true;
} else if ("GEOMETRY".equalsIgnoreCase(fieldName)) {
type = DataTypes.GEOMETRY;
isGeometryField = true;
} else if ("SHAPE".equalsIgnoreCase(fieldName)) {
type = DataTypes.GEOMETRY;
isGeometryField = true;
} else if ("GEOMETRYCOLLECTION".equalsIgnoreCase(fieldName) || "GEOMETRY_COLLECTION".equalsIgnoreCase(fieldName)) {
type = DataTypes.GEOMETRY_COLLECTION;
isGeometryField = true;
} else if ("POINT".equalsIgnoreCase(fieldName)) {
type = DataTypes.POINT;
isGeometryField = true;
} else if ("MULTI_POINT".equalsIgnoreCase(fieldName) || "MULTIPOINT".equalsIgnoreCase(fieldName)) {
type = DataTypes.MULTI_POINT;
isGeometryField = true;
} else if ("LINE_STRING".equalsIgnoreCase(fieldName) || "LINESTRING".equalsIgnoreCase(fieldName) || "LINE".equalsIgnoreCase(fieldName)) {
type = DataTypes.LINE_STRING;
isGeometryField = true;
} else if ("MULTI_LINESTRING".equalsIgnoreCase(fieldName) || "MULTILINESTRING".equalsIgnoreCase(fieldName) || "MULTILINE".equalsIgnoreCase(fieldName) || "MULTI_LINE".equalsIgnoreCase(fieldName)) {
type = DataTypes.MULTI_LINE_STRING;
isGeometryField = true;
} else if ("POLYGON".equalsIgnoreCase(fieldName)) {
type = DataTypes.POLYGON;
isGeometryField = true;
} else if ("MULTI_POLYGON".equalsIgnoreCase(fieldName) || "MULTIPOLYGON".equalsIgnoreCase(fieldName)) {
type = DataTypes.MULTI_POLYGON;
isGeometryField = true;
} else {
type = DataTypes.STRING;
length = 4000;
}
final FieldDefinition field;
if (isGeometryField) {
field = new GeometryFieldDefinition(this.geometryFactory, fieldName, type, false);
geometryField = field;
} else {
field = new FieldDefinition(fieldName, type, length, false);
}
fields.add(field);
}
}
if (this.hasPointFields) {
if (geometryField == null) {
geometryField = new FieldDefinition(this.geometryColumnName, this.geometryType, true);
fields.add(geometryField);
}
}
if (geometryField != null) {
geometryField.setProperty(FieldProperties.GEOMETRY_FACTORY, this.geometryFactory);
}
final RecordStoreSchema schema = getProperty("schema");
String typePath = getProperty("typePath");
if (!Property.hasValue(typePath)) {
typePath = "/" + baseName;
String schemaPath = getProperty("schemaPath");
if (Property.hasValue(schemaPath)) {
if (!schemaPath.startsWith("/")) {
schemaPath = "/" + schemaPath;
}
typePath = schemaPath + typePath;
}
}
final PathName pathName = PathName.newPathName(typePath);
this.recordDefinition = new RecordDefinitionImpl(schema, pathName, getProperties(), fields);
return this.recordDefinition;
}
Aggregations