Search in sources :

Example 1 with AbstractFileGdbFieldDefinition

use of com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition 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 2 with AbstractFileGdbFieldDefinition

use of com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition 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;
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) EsriGdbXmlParser(com.revolsys.record.io.format.esri.gdb.xml.model.EsriGdbXmlParser) XmlProcessor(com.revolsys.record.io.format.xml.XmlProcessor) LengthFieldName(com.revolsys.record.property.LengthFieldName) Constructor(java.lang.reflect.Constructor) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DEFeatureClass(com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass) FileGdbDomainCodeTable(com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable) Index(com.revolsys.record.io.format.esri.gdb.xml.model.Index) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) GlobalIdFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.GlobalIdFieldDefinition) AreaFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AreaFieldDefinition) FieldType(com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType) Field(com.revolsys.record.io.format.esri.gdb.xml.model.Field) AbstractFileGdbFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition) LengthFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.LengthFieldDefinition) PathName(com.revolsys.io.PathName) Domain(com.revolsys.record.io.format.esri.gdb.xml.model.Domain) DETable(com.revolsys.record.io.format.esri.gdb.xml.model.DETable)

Example 3 with AbstractFileGdbFieldDefinition

use of com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition 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);
                }
            }
        }
    }
}
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) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) Row(com.revolsys.gis.esri.gdb.file.capi.swig.Row) ObjectException(com.revolsys.beans.ObjectException) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 4 with AbstractFileGdbFieldDefinition

use of com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition in project com.revolsys.open by revolsys.

the class FileGdbQueryIterator method getNext.

@Override
protected synchronized Record getNext() throws NoSuchElementException {
    final FileGdbRecordStore recordStore = this.recordStore;
    final FileGdbEnumRowsIterator rows = this.rows;
    if (rows == null || this.closed) {
        throw new NoSuchElementException();
    } else {
        Row row = null;
        while (this.offset > 0 && this.count < this.offset) {
            row = rows.next();
            this.count++;
            if (this.closed) {
                throw new NoSuchElementException();
            }
        }
        if (this.count - this.offset >= this.limit) {
            throw new NoSuchElementException();
        }
        row = rows.next();
        this.count++;
        try {
            final Record record = this.recordFactory.newRecord(this.recordDefinition);
            if (this.labelCountMap == null) {
                recordStore.addStatistic("query", record);
            } else {
                this.labelCountMap.addCount(record);
            }
            record.setState(RecordState.INITIALIZING);
            for (final FieldDefinition field : this.recordDefinition.getFields()) {
                final String name = field.getName();
                final AbstractFileGdbFieldDefinition esriFieldDefinition = (AbstractFileGdbFieldDefinition) field;
                final Object value = esriFieldDefinition.getValue(row);
                record.setValue(name, value);
                if (this.closed) {
                    throw new NoSuchElementException();
                }
            }
            record.setState(RecordState.PERSISTED);
            if (this.closed) {
                throw new NoSuchElementException();
            }
            return record;
        } catch (final RuntimeException e) {
            if (this.closed) {
                throw new NoSuchElementException();
            } else {
                throw e;
            }
        } finally {
            row.delete();
        }
    }
}
Also used : AbstractFileGdbFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition) FieldDefinition(com.revolsys.record.schema.FieldDefinition) AbstractFileGdbFieldDefinition(com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition) Record(com.revolsys.record.Record) Row(com.revolsys.gis.esri.gdb.file.capi.swig.Row) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

AbstractFileGdbFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.AbstractFileGdbFieldDefinition)4 Row (com.revolsys.gis.esri.gdb.file.capi.swig.Row)3 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)3 AreaFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.AreaFieldDefinition)3 GlobalIdFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.GlobalIdFieldDefinition)3 LengthFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.LengthFieldDefinition)3 PathName (com.revolsys.io.PathName)3 FieldDefinition (com.revolsys.record.schema.FieldDefinition)3 ObjectException (com.revolsys.beans.ObjectException)2 ObjectPropertyException (com.revolsys.beans.ObjectPropertyException)2 BinaryFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.BinaryFieldDefinition)2 DateFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.DateFieldDefinition)2 DoubleFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.DoubleFieldDefinition)2 FloatFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.FloatFieldDefinition)2 GeometryFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.GeometryFieldDefinition)2 GuidFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.GuidFieldDefinition)2 IntegerFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.IntegerFieldDefinition)2 OidFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.OidFieldDefinition)2 ShortFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.ShortFieldDefinition)2 StringFieldDefinition (com.revolsys.gis.esri.gdb.file.capi.type.StringFieldDefinition)2