Search in sources :

Example 26 with PathName

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();
                }
            }
        }
    }
}
Also used : Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) DEFeatureDataset(com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureDataset) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) PathName(com.revolsys.io.PathName)

Example 27 with PathName

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);
        }
    }
}
Also used : ObjectPropertyException(com.revolsys.beans.ObjectPropertyException) AbstractFileGdbFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition) OidFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.OidFieldDefinition) DoubleFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.DoubleFieldDefinition) FloatFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.FloatFieldDefinition) AreaFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AreaFieldDefinition) StringFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.StringFieldDefinition) AbstractFileGdbFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition) FieldDefinition(com.revolsys.record.schema.FieldDefinition) GlobalIdFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GlobalIdFieldDefinition) IntegerFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.IntegerFieldDefinition) GuidFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GuidFieldDefinition) XmlFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.XmlFieldDefinition) ShortFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.ShortFieldDefinition) LengthFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.LengthFieldDefinition) BinaryFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.BinaryFieldDefinition) DateFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.DateFieldDefinition) GeometryFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GeometryFieldDefinition) PathName(com.revolsys.io.PathName) Row(com.revolsys.gis.esri.gdb.file.capi.swig.Row) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) ObjectException(com.revolsys.beans.ObjectException) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 28 with PathName

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();
                }
            }
        }
    }
}
Also used : Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) PathName(com.revolsys.io.PathName) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 29 with PathName

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;
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) PathName(com.revolsys.io.PathName)

Example 30 with PathName

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();
                }
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) CodeTable(com.revolsys.record.code.CodeTable) DETable(com.revolsys.record.io.format.esri.gdb.xml.model.DETable) Table(com.revolsys.gis.esri.gdb.file.capi.swig.Table) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) DEFeatureClass(com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) Field(com.revolsys.record.io.format.esri.gdb.xml.model.Field) SpatialReference(com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference) PathName(com.revolsys.io.PathName)

Aggregations

PathName (com.revolsys.io.PathName)64 FieldDefinition (com.revolsys.record.schema.FieldDefinition)15 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)14 DataType (com.revolsys.datatype.DataType)13 RecordDefinition (com.revolsys.record.schema.RecordDefinition)13 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)12 RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)11 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)9 RecordStoreSchemaElement (com.revolsys.record.schema.RecordStoreSchemaElement)7 ArrayList (java.util.ArrayList)7 TreeMap (java.util.TreeMap)7 MapEx (com.revolsys.collection.map.MapEx)5 ResultSet (java.sql.ResultSet)5 Geodatabase (com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase)4 Identifier (com.revolsys.identifier.Identifier)4 JdbcConnection (com.revolsys.jdbc.JdbcConnection)4 Record (com.revolsys.record.Record)4 File (java.io.File)4 PreparedStatement (java.sql.PreparedStatement)4 Geometry (com.revolsys.geometry.model.Geometry)3