Search in sources :

Example 6 with RecordStoreSchema

use of com.revolsys.record.schema.RecordStoreSchema in project com.revolsys.open by revolsys.

the class FileGdbRecordStore method refreshSchemaElements.

@Override
protected Map<PathName, ? extends RecordStoreSchemaElement> refreshSchemaElements(final RecordStoreSchema schema) {
    synchronized (this.apiSync) {
        synchronized (API_SYNC) {
            final Map<PathName, RecordStoreSchemaElement> elementsByPath = new TreeMap<>();
            final Geodatabase geodatabase = getGeodatabase();
            if (geodatabase != null) {
                try {
                    final PathName schemaPath = schema.getPathName();
                    final String schemaCatalogPath = getCatalogPath(schema);
                    final VectorOfWString childDatasets = getChildDatasets(geodatabase, schemaCatalogPath, "Feature Dataset");
                    if (childDatasets != null) {
                        for (int i = 0; i < childDatasets.size(); i++) {
                            final String childCatalogPath = childDatasets.get(i);
                            final PathName childPath = toPath(childCatalogPath);
                            RecordStoreSchema childSchema = schema.getSchema(childPath);
                            if (childSchema == null) {
                                childSchema = newFeatureDatasetSchema(schema, childPath);
                            } else {
                                if (childSchema.isInitialized()) {
                                    childSchema.refresh();
                                }
                            }
                            elementsByPath.put(childPath, childSchema);
                        }
                    }
                    if (schemaPath.isParentOf(this.defaultSchemaPath) && !elementsByPath.containsKey(this.defaultSchemaPath)) {
                        final SpatialReference spatialReference = getSpatialReference(getGeometryFactory());
                        final RecordStoreSchema childSchema = newSchema(this.defaultSchemaPath, spatialReference);
                        elementsByPath.put(this.defaultSchemaPath, childSchema);
                    }
                    if (schema.equalPath(this.defaultSchemaPath)) {
                        refreshSchemaRecordDefinitions(elementsByPath, schemaPath, "\\", "Feature Class");
                        refreshSchemaRecordDefinitions(elementsByPath, schemaPath, "\\", "Table");
                    }
                    refreshSchemaRecordDefinitions(elementsByPath, schemaPath, schemaCatalogPath, "Feature Class");
                    refreshSchemaRecordDefinitions(elementsByPath, schemaPath, schemaCatalogPath, "Table");
                } finally {
                    releaseGeodatabase();
                }
            }
            return elementsByPath;
        }
    }
}
Also used : Geodatabase(com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) SpatialReference(com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference) PathName(com.revolsys.io.PathName) VectorOfWString(com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString) TreeMap(java.util.TreeMap) RecordStoreSchemaElement(com.revolsys.record.schema.RecordStoreSchemaElement)

Example 7 with RecordStoreSchema

use of com.revolsys.record.schema.RecordStoreSchema 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 8 with RecordStoreSchema

use of com.revolsys.record.schema.RecordStoreSchema 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);
    }
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) PathName(com.revolsys.io.PathName) TreeMap(java.util.TreeMap) RecordStoreSchemaElement(com.revolsys.record.schema.RecordStoreSchemaElement)

Example 9 with RecordStoreSchema

use of com.revolsys.record.schema.RecordStoreSchema in project com.revolsys.open by revolsys.

the class OracleSdoGeometryFieldAdder method newField.

@Override
public JdbcFieldDefinition newField(final AbstractJdbcRecordStore recordStore, final JdbcRecordDefinition recordDefinition, final String dbName, final String name, final String dbDataType, final int sqlType, final int length, final int scale, final boolean required, final String description) {
    final PathName typePath = recordDefinition.getPathName();
    final String columnName = name.toUpperCase();
    final RecordStoreSchema schema = recordDefinition.getSchema();
    GeometryFactory geometryFactory = getColumnProperty(schema, typePath, columnName, GEOMETRY_FACTORY);
    if (geometryFactory == null) {
        geometryFactory = schema.getGeometryFactory();
    }
    if (geometryFactory == null) {
        geometryFactory = GeometryFactory.DEFAULT_2D;
    }
    DataType dataType = getColumnProperty(schema, typePath, columnName, GEOMETRY_TYPE);
    if (dataType == null) {
        dataType = DataTypes.GEOMETRY;
    }
    int axisCount = getIntegerColumnProperty(schema, typePath, columnName, AXIS_COUNT);
    if (axisCount == -1) {
        axisCount = geometryFactory.getAxisCount();
    }
    int oracleSrid = getIntegerColumnProperty(schema, typePath, columnName, ORACLE_SRID);
    if (oracleSrid == -1) {
        oracleSrid = 0;
    }
    final OracleSdoGeometryJdbcFieldDefinition field = new OracleSdoGeometryJdbcFieldDefinition(dbName, name, dataType, sqlType, required, description, null, geometryFactory, axisCount, oracleSrid);
    field.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
    return field;
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) JdbcRecordStoreSchema(com.revolsys.jdbc.io.JdbcRecordStoreSchema) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Example 10 with RecordStoreSchema

use of com.revolsys.record.schema.RecordStoreSchema in project com.revolsys.open by revolsys.

the class AbstractRecordReader method newRecordDefinition.

protected RecordDefinition newRecordDefinition(final String baseName, final List<String> fieldNames) throws IOException {
    this.hasPointFields = Property.hasValue(this.pointXFieldName) && Property.hasValue(this.pointYFieldName);
    if (this.hasPointFields) {
        this.geometryType = DataTypes.POINT;
    } else {
        this.pointXFieldName = null;
        this.pointYFieldName = null;
    }
    final List<FieldDefinition> fields = new ArrayList<>();
    FieldDefinition geometryField = null;
    for (final String fieldName : fieldNames) {
        if (fieldName != null) {
            DataType type;
            int length = 0;
            boolean isGeometryField = false;
            if (fieldName.equalsIgnoreCase(this.geometryColumnName)) {
                type = this.geometryType;
                isGeometryField = true;
            } else if ("GEOMETRY".equalsIgnoreCase(fieldName)) {
                type = DataTypes.GEOMETRY;
                isGeometryField = true;
            } else if ("SHAPE".equalsIgnoreCase(fieldName)) {
                type = DataTypes.GEOMETRY;
                isGeometryField = true;
            } else if ("GEOMETRYCOLLECTION".equalsIgnoreCase(fieldName) || "GEOMETRY_COLLECTION".equalsIgnoreCase(fieldName)) {
                type = DataTypes.GEOMETRY_COLLECTION;
                isGeometryField = true;
            } else if ("POINT".equalsIgnoreCase(fieldName)) {
                type = DataTypes.POINT;
                isGeometryField = true;
            } else if ("MULTI_POINT".equalsIgnoreCase(fieldName) || "MULTIPOINT".equalsIgnoreCase(fieldName)) {
                type = DataTypes.MULTI_POINT;
                isGeometryField = true;
            } else if ("LINE_STRING".equalsIgnoreCase(fieldName) || "LINESTRING".equalsIgnoreCase(fieldName) || "LINE".equalsIgnoreCase(fieldName)) {
                type = DataTypes.LINE_STRING;
                isGeometryField = true;
            } else if ("MULTI_LINESTRING".equalsIgnoreCase(fieldName) || "MULTILINESTRING".equalsIgnoreCase(fieldName) || "MULTILINE".equalsIgnoreCase(fieldName) || "MULTI_LINE".equalsIgnoreCase(fieldName)) {
                type = DataTypes.MULTI_LINE_STRING;
                isGeometryField = true;
            } else if ("POLYGON".equalsIgnoreCase(fieldName)) {
                type = DataTypes.POLYGON;
                isGeometryField = true;
            } else if ("MULTI_POLYGON".equalsIgnoreCase(fieldName) || "MULTIPOLYGON".equalsIgnoreCase(fieldName)) {
                type = DataTypes.MULTI_POLYGON;
                isGeometryField = true;
            } else {
                type = DataTypes.STRING;
                length = 4000;
            }
            final FieldDefinition field;
            if (isGeometryField) {
                field = new GeometryFieldDefinition(this.geometryFactory, fieldName, type, false);
                geometryField = field;
            } else {
                field = new FieldDefinition(fieldName, type, length, false);
            }
            fields.add(field);
        }
    }
    if (this.hasPointFields) {
        if (geometryField == null) {
            geometryField = new FieldDefinition(this.geometryColumnName, this.geometryType, true);
            fields.add(geometryField);
        }
    }
    if (geometryField != null) {
        geometryField.setProperty(FieldProperties.GEOMETRY_FACTORY, this.geometryFactory);
    }
    final RecordStoreSchema schema = getProperty("schema");
    String typePath = getProperty("typePath");
    if (!Property.hasValue(typePath)) {
        typePath = "/" + baseName;
        String schemaPath = getProperty("schemaPath");
        if (Property.hasValue(schemaPath)) {
            if (!schemaPath.startsWith("/")) {
                schemaPath = "/" + schemaPath;
            }
            typePath = schemaPath + typePath;
        }
    }
    final PathName pathName = PathName.newPathName(typePath);
    this.recordDefinition = new RecordDefinitionImpl(schema, pathName, getProperties(), fields);
    return this.recordDefinition;
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) FieldDefinition(com.revolsys.record.schema.FieldDefinition) GeometryFieldDefinition(com.revolsys.record.io.format.csv.GeometryFieldDefinition) ArrayList(java.util.ArrayList) GeometryFieldDefinition(com.revolsys.record.io.format.csv.GeometryFieldDefinition) DataType(com.revolsys.datatype.DataType) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) PathName(com.revolsys.io.PathName)

Aggregations

RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)12 PathName (com.revolsys.io.PathName)11 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)4 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)4 RecordStoreSchemaElement (com.revolsys.record.schema.RecordStoreSchemaElement)4 Geodatabase (com.revolsys.gis.esri.gdb.file.capi.swig.Geodatabase)3 FieldDefinition (com.revolsys.record.schema.FieldDefinition)3 TreeMap (java.util.TreeMap)3 DataType (com.revolsys.datatype.DataType)2 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)2 FileGdbDomainCodeTable (com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable)2 CodeTable (com.revolsys.record.code.CodeTable)2 DEFeatureClass (com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass)2 DETable (com.revolsys.record.io.format.esri.gdb.xml.model.DETable)2 Field (com.revolsys.record.io.format.esri.gdb.xml.model.Field)2 SpatialReference (com.revolsys.record.io.format.esri.gdb.xml.model.SpatialReference)2 RecordDefinition (com.revolsys.record.schema.RecordDefinition)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Table (com.revolsys.gis.esri.gdb.file.capi.swig.Table)1