use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method newSchema.
private RecordStoreSchema newSchema(final PathName schemaPath, final SpatialReference spatialReference) {
synchronized (this.apiSync) {
synchronized (API_SYNC) {
final Geodatabase geodatabase = getGeodatabase();
if (geodatabase == null) {
return null;
} else {
try {
String parentCatalogPath = "\\";
RecordStoreSchema schema = getRootSchema();
for (final PathName childSchemaPath : schemaPath.getPaths()) {
if (childSchemaPath.length() > 1) {
RecordStoreSchema childSchema = schema.getSchema(childSchemaPath);
final String childCatalogPath = toCatalogPath(childSchemaPath);
if (!hasChildDataset(getGeodatabase(), parentCatalogPath, "Feature Dataset", childCatalogPath)) {
if (spatialReference != null) {
final DEFeatureDataset dataset = EsriXmlRecordDefinitionUtil.newDEFeatureDataset(childCatalogPath, spatialReference);
final String datasetDefinition = EsriGdbXmlSerializer.toString(dataset);
try {
geodatabase.createFeatureDataset(datasetDefinition);
} catch (final Throwable t) {
Logs.debug(this, datasetDefinition);
throw new RuntimeException("Unable to create feature dataset " + childCatalogPath, t);
}
}
}
if (childSchema == null) {
childSchema = newFeatureDatasetSchema(schema, childSchemaPath);
schema.addElement(childSchema);
}
schema = childSchema;
parentCatalogPath = childCatalogPath;
}
}
return schema;
} finally {
releaseGeodatabase();
}
}
}
}
}
use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method insertRecord.
void insertRecord(final Table table, final Record record) {
final RecordDefinition sourceRecordDefinition = record.getRecordDefinition();
final RecordDefinition recordDefinition = getRecordDefinition(sourceRecordDefinition);
validateRequired(record, recordDefinition);
final PathName typePath = recordDefinition.getPathName();
if (table == null) {
throw new ObjectException(record, "Cannot find table: " + typePath);
} else {
try {
final Row row = newRowObject(table);
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.setInsertValue(record, row, value);
} catch (final Throwable e) {
throw new ObjectPropertyException(record, name, e);
}
}
insertRow(table, row);
if (sourceRecordDefinition == recordDefinition) {
for (final FieldDefinition field : recordDefinition.getFields()) {
final AbstractFileGdbFieldDefinition esriField = (AbstractFileGdbFieldDefinition) field;
try {
esriField.setPostInsertValue(record, row);
} catch (final Throwable e) {
throw new ObjectPropertyException(record, field.getName(), e);
}
}
record.setState(RecordState.PERSISTED);
}
} finally {
row.delete();
addStatistic("Insert", 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 refreshSchemaRecordDefinitions.
private void refreshSchemaRecordDefinitions(final Map<PathName, RecordStoreSchemaElement> elementsByPath, final PathName schemaPath, final String catalogPath, final String datasetType) {
synchronized (this.apiSync) {
synchronized (API_SYNC) {
final Geodatabase geodatabase = getGeodatabase();
if (geodatabase != null) {
try {
final boolean pathExists = isPathExists(geodatabase, catalogPath);
if (pathExists) {
final VectorOfWString childFeatureClasses = getChildDatasets(geodatabase, catalogPath, datasetType);
if (childFeatureClasses != null) {
for (int i = 0; i < childFeatureClasses.size(); i++) {
final String childCatalogPath = childFeatureClasses.get(i);
final String tableDefinition = geodatabase.getTableDefinition(childCatalogPath);
final RecordDefinition recordDefinition = getRecordDefinition(schemaPath, childCatalogPath, tableDefinition);
initRecordDefinition(recordDefinition);
final PathName childPath = recordDefinition.getPathName();
elementsByPath.put(childPath, recordDefinition);
}
}
}
} finally {
releaseGeodatabase();
}
}
}
}
}
use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method newFeatureDatasetSchema.
private RecordStoreSchema newFeatureDatasetSchema(final RecordStoreSchema parentSchema, final PathName schemaPath) {
final PathName childSchemaPath = schemaPath;
final RecordStoreSchema schema = new RecordStoreSchema(parentSchema, childSchemaPath);
this.catalogPathByPath.put(childSchemaPath, toCatalogPath(schemaPath));
return schema;
}
use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method newTableRecordDefinition.
private RecordDefinitionImpl newTableRecordDefinition(final DETable deTable) {
synchronized (this.apiSync) {
synchronized (API_SYNC) {
final Geodatabase geodatabase = getGeodatabase();
if (geodatabase == null) {
return null;
} else {
try {
String schemaCatalogPath = deTable.getParentCatalogPath();
SpatialReference spatialReference;
if (deTable instanceof DEFeatureClass) {
final DEFeatureClass featureClass = (DEFeatureClass) deTable;
spatialReference = featureClass.getSpatialReference();
} else {
spatialReference = null;
}
PathName schemaPath = toPath(schemaCatalogPath);
final RecordStoreSchema schema = newSchema(schemaPath, spatialReference);
if (schemaPath.equals(this.defaultSchemaPath)) {
if (!(deTable instanceof DEFeatureClass)) {
schemaCatalogPath = "\\";
deTable.setCatalogPath("\\" + deTable.getName());
}
} else if (schemaPath.equals("")) {
schemaPath = this.defaultSchemaPath;
}
for (final Field field : deTable.getFields()) {
final String fieldName = field.getName();
final CodeTable codeTable = getCodeTableByFieldName(fieldName);
if (codeTable instanceof FileGdbDomainCodeTable) {
final FileGdbDomainCodeTable domainCodeTable = (FileGdbDomainCodeTable) codeTable;
field.setDomain(domainCodeTable.getDomain());
}
}
final String tableDefinition = EsriGdbXmlSerializer.toString(deTable);
try {
final Table table = geodatabase.createTable(tableDefinition, schemaCatalogPath);
geodatabase.closeTable(table);
table.delete();
final RecordDefinitionImpl recordDefinition = getRecordDefinition(PathName.newPathName(schemaPath), schemaCatalogPath, tableDefinition);
initRecordDefinition(recordDefinition);
schema.addElement(recordDefinition);
return recordDefinition;
} catch (final Throwable t) {
throw new RuntimeException("Unable to create table " + deTable.getCatalogPath(), t);
}
} finally {
releaseGeodatabase();
}
}
}
}
}
Aggregations