Search in sources :

Example 61 with PathName

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

the class RecordLog method getLogRecordDefinition.

public RecordDefinition getLogRecordDefinition(final RecordDefinition recordDefinition) {
    RecordDefinitionImpl logRecordDefinition = this.logRecordDefinitionMap.get(recordDefinition);
    if (logRecordDefinition == null) {
        final String path = recordDefinition.getPath();
        final String parentPath = PathUtil.getPath(path);
        final String tableName = PathUtil.getName(path);
        final String logTableName;
        if (tableName.toUpperCase().equals(tableName)) {
            logTableName = tableName + "_LOG";
        } else {
            logTableName = tableName + "_log";
        }
        final PathName logTypeName = PathName.newPathName(PathUtil.toPath(parentPath, logTableName));
        logRecordDefinition = new RecordDefinitionImpl(logTypeName);
        if (this.usesLocality) {
            logRecordDefinition.addField(LOG_LOCALITY, DataTypes.STRING, 255, false);
        }
        logRecordDefinition.addField(LOG_MESSAGE, DataTypes.STRING, 255, true);
        for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
            final FieldDefinition logFieldDefinition = new FieldDefinition(fieldDefinition);
            final DataType dataType = logFieldDefinition.getDataType();
            if (recordDefinition.getGeometryField() == fieldDefinition) {
                logRecordDefinition.addField("GEOMETRY", dataType);
            } else {
                logRecordDefinition.addField(new FieldDefinition(fieldDefinition));
            }
        }
        logRecordDefinition.setGeometryFactory(recordDefinition.getGeometryFactory());
        this.logRecordDefinitionMap.put(recordDefinition, logRecordDefinition);
    }
    return logRecordDefinition;
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Example 62 with PathName

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

the class DirectoryRecordStore method getRecordDefinition.

@Override
public RecordDefinition getRecordDefinition(final RecordDefinition recordDefinition) {
    final RecordDefinition storeRecordDefinition = super.getRecordDefinition(recordDefinition);
    if (storeRecordDefinition == null && this.createMissingTables) {
        final PathName typePath = recordDefinition.getPathName();
        final PathName schemaPath = typePath.getParent();
        RecordStoreSchema schema = getSchema(schemaPath);
        if (schema == null && this.createMissingTables) {
            final RecordStoreSchema rootSchema = getRootSchema();
            schema = rootSchema.newSchema(schemaPath);
        }
        final File schemaDirectory = new File(this.directory, schemaPath.getPath());
        if (!schemaDirectory.exists()) {
            schemaDirectory.mkdirs();
        }
        final RecordDefinitionImpl newRecordDefinition = new RecordDefinitionImpl(schema, typePath);
        for (final FieldDefinition field : recordDefinition.getFields()) {
            final FieldDefinition newField = new FieldDefinition(field);
            newRecordDefinition.addField(newField);
        }
        schema.addElement(newRecordDefinition);
        return newRecordDefinition;
    }
    return storeRecordDefinition;
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) FieldDefinition(com.revolsys.record.schema.FieldDefinition) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) PathName(com.revolsys.io.PathName) File(java.io.File) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 63 with PathName

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

the class DirectoryRecordStore method refreshSchemaElements.

@Override
protected Map<PathName, RecordStoreSchemaElement> refreshSchemaElements(final RecordStoreSchema schema) {
    final Map<PathName, RecordStoreSchemaElement> elements = new TreeMap<>();
    final String schemaPath = schema.getPath();
    final PathName schemaPathName = schema.getPathName();
    final File subDirectory;
    if (schemaPath.equals("/")) {
        subDirectory = this.directory;
    } else {
        subDirectory = new File(this.directory, schemaPath);
    }
    final FileFilter filter = new ExtensionFilenameFilter(this.fileExtensions);
    final File[] files = subDirectory.listFiles();
    if (files != null) {
        for (final File file : files) {
            if (filter.accept(file)) {
                final PathResource resource = new PathResource(file);
                final RecordDefinition recordDefinition = loadRecordDefinition(schema, schemaPath, resource);
                if (recordDefinition != null) {
                    final PathName path = recordDefinition.getPathName();
                    elements.put(path, recordDefinition);
                }
            } else if (file.isDirectory()) {
                final String name = file.getName();
                final PathName childSchemaPath = schemaPathName.newChild(name);
                RecordStoreSchema childSchema = schema.getSchema(childSchemaPath);
                if (childSchema == null) {
                    childSchema = new RecordStoreSchema(schema, childSchemaPath);
                } else {
                    if (!childSchema.isInitialized()) {
                        childSchema.refresh();
                    }
                }
                elements.put(childSchemaPath, childSchema);
            }
        }
    }
    return elements;
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) PathResource(com.revolsys.spring.resource.PathResource) ExtensionFilenameFilter(com.revolsys.io.filter.ExtensionFilenameFilter) PathName(com.revolsys.io.PathName) TreeMap(java.util.TreeMap) FileFilter(java.io.FileFilter) File(java.io.File) RecordStoreSchemaElement(com.revolsys.record.schema.RecordStoreSchemaElement) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 64 with PathName

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

the class RecordStoreQueryField method clone.

@Override
public Field clone() {
    final String fieldName = getFieldName();
    final PathName typePath = getTypePath();
    final String displayFieldName = getDisplayFieldName();
    return new RecordStoreQueryField(fieldName, this.recordStore, typePath, displayFieldName);
}
Also used : 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