use of com.revolsys.io.PathName 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.io.PathName in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method updateRecord.
void updateRecord(final Table table, final Record record) {
final Object objectId = record.getValue("OBJECTID");
if (objectId == null) {
insertRecord(table, record);
} else {
final RecordDefinition sourceRecordDefinition = record.getRecordDefinition();
final RecordDefinition recordDefinition = getRecordDefinition(sourceRecordDefinition);
validateRequired(record, recordDefinition);
final PathName typePath = sourceRecordDefinition.getPathName();
final String whereClause = "OBJECTID=" + objectId;
try (final FileGdbEnumRowsIterator rows = search(typePath, table, "*", whereClause, false)) {
for (final Row row : rows) {
try {
for (final FieldDefinition field : recordDefinition.getFields()) {
final String name = field.getName();
try {
final Object value = record.getValue(name);
final AbstractFileGdbFieldDefinition esriField = (AbstractFileGdbFieldDefinition) field;
esriField.setUpdateValue(record, row, value);
} catch (final Throwable e) {
throw new ObjectPropertyException(record, name, e);
}
}
updateRow(typePath, table, row);
record.setState(RecordState.PERSISTED);
addStatistic("Update", record);
} catch (final ObjectException e) {
if (e.getObject() == record) {
throw e;
} else {
throw new ObjectException(record, e);
}
} catch (final Throwable e) {
throw new ObjectException(record, e);
}
}
}
}
}
use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method newIterator.
@Override
public AbstractIterator<Record> newIterator(final Query query, final Map<String, Object> properties) {
PathName typePath = query.getTypePath();
RecordDefinition recordDefinition = query.getRecordDefinition();
if (recordDefinition == null) {
recordDefinition = getRecordDefinition(typePath);
if (recordDefinition == null) {
throw new IllegalArgumentException("Type name does not exist " + typePath);
}
} else {
typePath = recordDefinition.getPathName();
}
final String catalogPath = getCatalogPath(typePath);
final BoundingBox boundingBox = QueryValue.getBoundingBox(query);
final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
final StringBuilder whereClause = getWhereClause(query);
StringBuilder sql = new StringBuilder();
if (orderBy.isEmpty() || boundingBox != null) {
if (!orderBy.isEmpty()) {
Logs.error(this, "Unable to sort on " + catalogPath + " " + orderBy.keySet() + " as the ESRI library can't sort with a bounding box query");
}
sql = whereClause;
} else {
sql.append("SELECT ");
final List<String> fieldNames = query.getFieldNames();
if (fieldNames.isEmpty()) {
StringBuilders.append(sql, recordDefinition.getFieldNames());
} else {
StringBuilders.append(sql, fieldNames);
}
sql.append(" FROM ");
sql.append(JdbcUtils.getTableName(catalogPath));
if (whereClause.length() > 0) {
sql.append(" WHERE ");
sql.append(whereClause);
}
boolean first = true;
for (final Entry<? extends CharSequence, Boolean> entry : orderBy.entrySet()) {
final CharSequence fieldName = entry.getKey();
final DataType dataType = recordDefinition.getFieldType(fieldName);
if (dataType != null && !Geometry.class.isAssignableFrom(dataType.getJavaClass())) {
if (first) {
sql.append(" ORDER BY ");
first = false;
} else {
sql.append(", ");
}
if (fieldName instanceof FieldDefinition) {
final FieldDefinition field = (FieldDefinition) fieldName;
field.appendColumnName(sql);
} else {
sql.append(fieldName);
}
final Boolean ascending = entry.getValue();
if (!ascending) {
sql.append(" DESC");
}
} else {
Logs.error(this, "Unable to sort on " + recordDefinition.getPath() + "." + fieldName + " as the ESRI library can't sort on " + dataType + " columns");
}
}
}
final FileGdbQueryIterator iterator = new FileGdbQueryIterator(this, catalogPath, sql.toString(), boundingBox, query, query.getOffset(), query.getLimit());
iterator.setStatistics(query.getStatistics());
return iterator;
}
use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class OgrRecordStore method refreshSchemaElements.
@Override
protected synchronized Map<PathName, ? extends RecordStoreSchemaElement> refreshSchemaElements(final RecordStoreSchema schema) {
final Map<PathName, RecordStoreSchemaElement> elementsByPath = new TreeMap<>();
if (!isClosed()) {
final DataSource dataSource = getDataSource();
if (dataSource != null) {
for (int layerIndex = 0; layerIndex < dataSource.GetLayerCount(); layerIndex++) {
final Layer layer = dataSource.GetLayer(layerIndex);
if (layer != null) {
try {
final RecordDefinitionImpl recordDefinition = newLayerRecordDefinition(schema, layer);
final PathName typePath = recordDefinition.getPathName();
final String layerName = layer.GetName();
this.layerNameToPathMap.put(layerName.toUpperCase(), typePath);
this.pathToLayerNameMap.put(typePath, layerName);
elementsByPath.put(typePath, recordDefinition);
} finally {
layer.delete();
}
}
}
}
}
return elementsByPath;
}
use of com.revolsys.io.PathName 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);
}
}
Aggregations