Search in sources :

Example 16 with FieldDefinition

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

the class MapReaderRecordReader method next.

@Override
public Record next() {
    if (hasNext()) {
        final MapEx source = this.mapIterator.next();
        final Record target = new ArrayRecord(this.recordDefinition);
        for (final FieldDefinition field : this.recordDefinition.getFields()) {
            final String name = field.getName();
            final Object value = source.get(name);
            if (value != null) {
                final DataType dataType = this.recordDefinition.getFieldType(name);
                final Object convertedValue;
                try {
                    convertedValue = dataType.toObject(value);
                } catch (final Throwable e) {
                    throw new FieldValueInvalidException(name, value, e);
                }
                target.setValue(name, convertedValue);
            }
        }
        return target;
    } else {
        throw new NoSuchElementException();
    }
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) FieldValueInvalidException(com.revolsys.record.FieldValueInvalidException) MapEx(com.revolsys.collection.map.MapEx) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) NoSuchElementException(java.util.NoSuchElementException)

Example 17 with FieldDefinition

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

the class SaifReader method open.

/**
 * Open a SAIF archive, extracting compressed archives to a temporary
 * directory.
 */
@Override
public void open() {
    if (!this.opened) {
        this.opened = true;
        try {
            if (log.isDebugEnabled()) {
                log.debug("Opening SAIF archive '" + this.file.getCanonicalPath() + "'");
            }
            if (this.file.isDirectory()) {
                this.saifArchiveDirectory = this.file;
            } else if (!this.file.exists()) {
                throw new IllegalArgumentException("SAIF file " + this.file + " does not exist");
            } else {
                this.zipFile = new ZipFile(this.file);
            }
            if (log.isDebugEnabled()) {
                log.debug("  Finished opening archive");
            }
            loadSchema();
            loadExportedObjects();
            loadSrid();
            final GeometryFactory geometryFactory = GeometryFactory.fixed3d(this.srid, 1.0, 1.0, 1.0);
            for (final RecordDefinition recordDefinition : ((RecordDefinitionFactoryImpl) this.recordDefinitionFactory).getRecordDefinitions()) {
                final FieldDefinition geometryField = recordDefinition.getGeometryField();
                if (geometryField != null) {
                    geometryField.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
                }
            }
        } catch (final IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}
Also used : RecordDefinitionFactoryImpl(com.revolsys.record.schema.RecordDefinitionFactoryImpl) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) ZipFile(java.util.zip.ZipFile) FieldDefinition(com.revolsys.record.schema.FieldDefinition) IOException(java.io.IOException) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 18 with FieldDefinition

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

the class SaifSchemaReader method restricted.

public void restricted(final RecordDefinition type, final CsnIterator iterator) throws IOException {
    while (iterator.getNextEventType() == CsnIterator.ATTRIBUTE_PATH) {
        iterator.next();
        String fieldName = iterator.getStringValue();
        boolean hasMore = true;
        final List<String> typePaths = new ArrayList<>();
        final List<Object> values = new ArrayList<>();
        while (hasMore) {
            switch(iterator.getNextEventType()) {
                case CsnIterator.CLASS_NAME:
                    iterator.next();
                    final String typePath = iterator.getPathValue();
                    typePaths.add(typePath);
                    break;
                case CsnIterator.FORCE_TYPE:
                    iterator.next();
                    if (iterator.next() == CsnIterator.CLASS_NAME) {
                        typePaths.add(iterator.getPathValue());
                    } else {
                        throw new IllegalStateException("Expecting a class name");
                    }
                    break;
                case CsnIterator.EXCLUDE_TYPE:
                    iterator.next();
                    if (iterator.next() == CsnIterator.CLASS_NAME) {
                        typePaths.add(iterator.getPathValue());
                    } else {
                        throw new IllegalStateException("Expecting a class name");
                    }
                    break;
                case CsnIterator.VALUE:
                    iterator.next();
                    values.add(iterator.getValue());
                    break;
                default:
                    hasMore = false;
                    break;
            }
        }
        fieldName = fieldName.replaceFirst("position.geometry", "position");
        final int dotIndex = fieldName.indexOf('.');
        if (dotIndex == -1) {
            final FieldDefinition attribute = type.getField(fieldName);
            if (attribute != null) {
                if (!typePaths.isEmpty()) {
                    attribute.setProperty(FieldProperties.ALLOWED_TYPE_NAMES, typePaths);
                }
                if (!values.isEmpty()) {
                    attribute.setProperty(FieldProperties.ALLOWED_VALUES, values);
                }
            }
        } else {
            final String key = fieldName.substring(0, dotIndex);
            final String subKey = fieldName.substring(dotIndex + 1);
            final FieldDefinition attribute = type.getField(key);
            if (attribute != null) {
                if (!typePaths.isEmpty()) {
                    Map<String, List<String>> allowedValues = attribute.getProperty(FieldProperties.FIELD_ALLOWED_TYPE_NAMES);
                    if (allowedValues == null) {
                        allowedValues = new HashMap<>();
                        attribute.setProperty(FieldProperties.FIELD_ALLOWED_TYPE_NAMES, allowedValues);
                    }
                    allowedValues.put(subKey, typePaths);
                }
                if (!values.isEmpty()) {
                    Map<String, List<Object>> allowedValues = attribute.getProperty(FieldProperties.FIELD_ALLOWED_VALUES);
                    if (allowedValues == null) {
                        allowedValues = new HashMap<>();
                        attribute.setProperty(FieldProperties.FIELD_ALLOWED_VALUES, allowedValues);
                    }
                    allowedValues.put(subKey, values);
                }
            }
        }
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with FieldDefinition

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

the class SaifSchemaReader method addSuperClass.

public void addSuperClass(final RecordDefinitionImpl currentClass, final RecordDefinition superClass) {
    currentClass.addSuperClass(superClass);
    for (final String name : superClass.getFieldNames()) {
        final FieldDefinition attribute = superClass.getField(name);
        currentClass.addField(attribute.clone());
    }
    for (final Entry<String, Object> defaultValue : superClass.getDefaultValues().entrySet()) {
        final String name = defaultValue.getKey();
        final Object value = defaultValue.getValue();
        if (!currentClass.hasField(name)) {
            currentClass.addDefaultValue(name, value);
        }
    }
    final String idFieldName = superClass.getIdFieldName();
    if (idFieldName != null) {
        currentClass.setIdFieldName(idFieldName);
    }
    String geometryFieldName = superClass.getGeometryFieldName();
    final String path = currentClass.getPath();
    if (path.equals("/TRIM/TrimText")) {
        geometryFieldName = "textOrSymbol";
    }
    if (geometryFieldName != null) {
        currentClass.setGeometryFieldName(geometryFieldName);
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition)

Example 20 with FieldDefinition

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

the class Value method setRecordDefinition.

@Override
public void setRecordDefinition(final RecordDefinition recordDefinition) {
    final String fieldName = this.fieldDefinition.getName();
    if (Property.hasValue(fieldName)) {
        final FieldDefinition field = recordDefinition.getField(fieldName);
        setFieldDefinition(field);
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition)

Aggregations

FieldDefinition (com.revolsys.record.schema.FieldDefinition)133 RecordDefinition (com.revolsys.record.schema.RecordDefinition)38 DataType (com.revolsys.datatype.DataType)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 JdbcFieldDefinition (com.revolsys.jdbc.field.JdbcFieldDefinition)19 PathName (com.revolsys.io.PathName)15 Record (com.revolsys.record.Record)15 ArrayList (java.util.ArrayList)15 Geometry (com.revolsys.geometry.model.Geometry)13 CodeTable (com.revolsys.record.code.CodeTable)9 Query (com.revolsys.record.query.Query)8 LineString (com.revolsys.geometry.model.LineString)7 ArrayRecord (com.revolsys.record.ArrayRecord)7 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)7 SQLException (java.sql.SQLException)7 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 IOException (java.io.IOException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 BadLocationException (javax.swing.text.BadLocationException)4