use of com.revolsys.record.schema.RecordStoreSchema in project com.revolsys.open by revolsys.
the class OgrRecordStore method newLayerRecordDefinition.
private RecordDefinition newLayerRecordDefinition(final DataSource dataSource, final RecordDefinition sourceRecordDefinition) {
final PathName typePath = sourceRecordDefinition.getPathName();
final String name = typePath.getName();
final PathName parentPath = typePath.getParent();
final RecordStoreSchema schema = getSchema(parentPath);
Layer layer;
if (sourceRecordDefinition.hasGeometryField()) {
final GeometryFactory geometryFactory = sourceRecordDefinition.getGeometryFactory();
final FieldDefinition geometryField = sourceRecordDefinition.getGeometryField();
final int geometryFieldType = getGeometryFieldType(geometryFactory, geometryField);
final SpatialReference spatialReference = Gdal.getSpatialReference(geometryFactory);
layer = dataSource.CreateLayer(typePath.getPath(), spatialReference, geometryFieldType);
} else {
layer = dataSource.CreateLayer(name);
}
if (dataSource.TestCapability(ogrConstants.ODsCCreateLayer) == false) {
System.err.println("CreateLayer not supported by driver.");
}
return newLayerRecordDefinition(schema, layer);
}
use of com.revolsys.record.schema.RecordStoreSchema 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.record.schema.RecordStoreSchema 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.record.schema.RecordStoreSchema 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();
}
}
}
}
}
use of com.revolsys.record.schema.RecordStoreSchema in project com.revolsys.open by revolsys.
the class PathRecordStoreTreeNode method loadChildrenDo.
@Override
protected List<BaseTreeNode> loadChildrenDo() {
final RecordStore recordStore = getRecordStore();
if (recordStore != null) {
final RecordStoreSchema schema = recordStore.getRootSchema();
if (schema != null) {
schema.refresh();
final List<BaseTreeNode> children = new ArrayList<>();
for (final RecordStoreSchemaElement element : schema.getElements()) {
final BaseTreeNode node = BaseTreeNode.newTreeNode(element);
children.add(node);
}
return children;
}
}
return Collections.emptyList();
}
Aggregations