Search in sources :

Example 51 with PathName

use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.

the class RecordStoreSchema method refresh.

@Override
public synchronized void refresh() {
    this.initialized = true;
    final AbstractRecordStore recordStore = getRecordStore();
    if (recordStore != null) {
        recordStore.initialize();
        final Collection<RecordStoreExtension> extensions = recordStore.getRecordStoreExtensions();
        for (final RecordStoreExtension extension : extensions) {
            try {
                if (extension.isEnabled(recordStore)) {
                    extension.preProcess(this);
                }
            } catch (final Throwable e) {
                Logs.error(extension, "Unable to pre-process schema: " + this, e);
            }
        }
        try {
            final Map<PathName, ? extends RecordStoreSchemaElement> elementsByPath = recordStore.refreshSchemaElements(this);
            final Set<PathName> removedPaths = new HashSet<>(this.elementsByPath.keySet());
            for (final Entry<PathName, ? extends RecordStoreSchemaElement> entry : elementsByPath.entrySet()) {
                final PathName path = entry.getKey();
                removedPaths.remove(path);
                final RecordStoreSchemaElement newElement = entry.getValue();
                final RecordStoreSchemaElement oldElement = this.elementsByPath.get(path);
                if (oldElement == null) {
                    addElement(newElement);
                } else {
                    replaceElement(path, oldElement, newElement);
                }
            }
            for (final PathName removedPath : removedPaths) {
                removeElement(removedPath);
            }
            for (final RecordDefinition recordDefinition : getRecordDefinitions()) {
                recordStore.initRecordDefinition(recordDefinition);
            }
        } catch (final Throwable e) {
            Logs.error(this, "Unable to refresh schema: " + this, e);
        }
        for (final RecordStoreExtension extension : extensions) {
            try {
                if (extension.isEnabled(recordStore)) {
                    extension.postProcess(this);
                }
            } catch (final Throwable e) {
                Logs.error(extension, "Unable to post-process schema: " + this, e);
            }
        }
    }
}
Also used : RecordStoreExtension(com.revolsys.record.io.RecordStoreExtension) PathName(com.revolsys.io.PathName) HashSet(java.util.HashSet)

Example 52 with PathName

use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.

the class RecordStoreSchema method getElement.

@SuppressWarnings("unchecked")
public <V extends RecordStoreSchemaElement> V getElement(final PathName path) {
    if (isClosed()) {
        throw new IllegalStateException("Record store is closed");
    } else if (path == null) {
        return null;
    } else {
        RecordStoreSchemaElement childElement = this.elementsByPath.get(path);
        if (childElement == null) {
            if (path != null) {
                final PathName schemaPath = getPathName();
                if (schemaPath.equals(path)) {
                    return (V) this;
                } else {
                    if (schemaPath.isParentOf(path)) {
                        childElement = this.elementsByPath.get(path);
                        if (childElement == null) {
                            synchronized (this) {
                                refreshIfNeeded();
                                childElement = this.elementsByPath.get(path);
                                if (childElement == null || childElement instanceof NonExistingSchemaElement) {
                                    return null;
                                } else if (childElement.equalPath(path)) {
                                    return (V) childElement;
                                } else if (childElement instanceof RecordStoreSchema) {
                                    final RecordStoreSchema childSchema = (RecordStoreSchema) childElement;
                                    return childSchema.getElement(path);
                                } else {
                                    return null;
                                }
                            }
                        } else if (childElement instanceof NonExistingSchemaElement) {
                            return null;
                        } else {
                            return (V) childElement;
                        }
                    } else if (schemaPath.isAncestorOf(path)) {
                        final PathName childPath = schemaPath.getChild(path);
                        final RecordStoreSchema schema = getSchema(childPath);
                        if (schema != null) {
                            return schema.getElement(path);
                        }
                    } else {
                        final RecordStoreSchema parent = getSchema();
                        if (parent != null) {
                            return parent.getElement(path);
                        }
                    }
                }
            }
            if (this.recordStore == null) {
                return null;
            } else {
                return (V) this.recordStore.getRootSchema();
            }
        }
        return (V) childElement;
    }
}
Also used : PathName(com.revolsys.io.PathName)

Example 53 with PathName

use of com.revolsys.io.PathName 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 54 with PathName

use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.

the class GeometryTest method doWriteTest.

private void doWriteTest(final DataType geometryType, final int axisCount, final int partCount, final int ringCount) {
    final GeometryFactory sourceGeometryFactory = GeometryFactory.floating(3857, axisCount);
    String typeName = geometryType.getName().toUpperCase();
    typeName = typeName.replace("MULTI", "MULTI_");
    final PathName typePath = PathName.newPathName("/ORACLE_TEST/" + typeName + axisCount);
    Geometry geometry = GeometryTestUtil.geometry(sourceGeometryFactory, geometryType, axisCount, partCount, ringCount);
    if (geometry instanceof Polygonal) {
        geometry = geometry.toCounterClockwise();
    }
    try (Transaction transaction = this.recordStore.newTransaction(Propagation.REQUIRES_NEW)) {
        final RecordDefinition recordDefinition = this.recordStore.getRecordDefinition(typePath);
        final Record record = this.recordStore.newRecord(typePath, Collections.singletonMap("GEOMETRY", geometry));
        try (Writer<Record> writer = this.recordStore.newRecordWriter()) {
            writer.write(record);
        }
        final Identifier identifier = record.getIdentifier();
        final Record savedRecord = this.recordStore.getRecord(typePath, identifier);
        Assert.assertNotNull("Saved record", savedRecord);
        final Geometry savedGeometry = savedRecord.getGeometry();
        final GeometryFactory tableGeometryFactory = recordDefinition.getGeometryFactory();
        final Geometry expectedGeometry = geometry.convertGeometry(tableGeometryFactory);
        com.revolsys.geometry.util.Assert.equals("Saved geometry", savedGeometry.equalsExact(expectedGeometry), expectedGeometry, savedGeometry);
        transaction.setRollbackOnly();
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Identifier(com.revolsys.identifier.Identifier) Transaction(com.revolsys.transaction.Transaction) Polygonal(com.revolsys.geometry.model.Polygonal) Record(com.revolsys.record.Record) PathName(com.revolsys.io.PathName) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 55 with PathName

use of com.revolsys.io.PathName in project com.revolsys.open by revolsys.

the class GeoPackageGeometryFieldAdder method addField.

@Override
public FieldDefinition addField(final AbstractJdbcRecordStore recordStore, final JdbcRecordDefinition recordDefinition, final String dbName, final String name, final String columnDataType, final int sqlType, final int length, final int scale, final boolean required, final String description) {
    final PathName typePath = recordDefinition.getPathName();
    final String tableName = recordDefinition.getDbTableName();
    final String columnName = name.toLowerCase();
    try {
        int srid = 0;
        String type = "geometry";
        int axisCount = 2;
        try {
            final String sql = "select geometry_type_name, srs_id, Z, M from gpkg_geometry_columns where UPPER(TABLE_NAME) = UPPER(?) AND UPPER(COLUMN_NAME) = UPPER(?)";
            final MapEx values = JdbcUtils.selectMap(recordStore, sql, tableName, columnName);
            srid = values.getInteger("srs_id", 0);
            type = values.getString("geometry_type_name", "GEOMETRY");
            if (values.getInteger("z", 0) > 0) {
                axisCount = 3;
            }
            if (values.getInteger("m", 0) > 0) {
                axisCount = 4;
            }
        } catch (final IllegalArgumentException e) {
            Logs.warn(this, "Cannot get geometry column metadata for " + typePath + "." + columnName);
        }
        final DataType dataType = DATA_TYPE_MAP.get(type);
        final GeometryFactory storeGeometryFactory = recordStore.getGeometryFactory();
        final GeometryFactory geometryFactory;
        if (storeGeometryFactory == null) {
            geometryFactory = GeometryFactory.floating(srid, axisCount);
        } else {
            final double[] scales = storeGeometryFactory.newScales(axisCount);
            geometryFactory = GeometryFactory.fixed(srid, axisCount, scales);
        }
        final FieldDefinition field = new GeoPackageGeometryJdbcFieldDefinition(dbName, name, dataType, required, description, null, srid, axisCount, geometryFactory);
        recordDefinition.addField(field);
        field.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
        return field;
    } catch (final Throwable e) {
        Logs.error(this, "Attribute not registered in GEOMETRY_COLUMN table " + tableName + "." + name, e);
        return null;
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) MapEx(com.revolsys.collection.map.MapEx) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) 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