Search in sources :

Example 21 with RecordDefinition

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

the class OsnReader method skipToFirstRecord.

/**
 * Skip all objects and attributes until the first object in the collection.
 *
 * @return True if an object was found.
 * @throws IOException If an I/O error occurs.
 */
private boolean skipToFirstRecord() throws IOException {
    if (this.osnIterator.next() == OsnIterator.START_DEFINITION) {
        final String typePath = this.osnIterator.getPathValue();
        final RecordDefinitionImpl type = (RecordDefinitionImpl) this.recordDefinitionFactory.getRecordDefinition(typePath);
        final RecordDefinition spatialDataSetType = this.recordDefinitionFactory.getRecordDefinition("/SpatialDataSet");
        if (type != null && type.isInstanceOf(spatialDataSetType)) {
            final String oiName = this.osnIterator.nextFieldName();
            if (oiName != null && oiName.equals("objectIdentifier")) {
                this.osnIterator.nextStringValue();
                final String fieldName = this.osnIterator.nextFieldName();
                if (fieldName != null && (fieldName.equals("geoComponents") || fieldName.equals("annotationComponents"))) {
                    if (this.osnIterator.next() == OsnIterator.START_SET) {
                        return true;
                    } else {
                        this.osnIterator.throwParseError("Expecting a set of objects");
                    }
                } else {
                    this.osnIterator.throwParseError("Excepecting the 'geoComponents' attribute");
                }
            } else {
                this.osnIterator.throwParseError("Expecting the 'objectIdentifier' attribute");
            }
        } else {
            return true;
        }
    } else {
        this.osnIterator.throwParseError("Expecting a start of an object definition");
    }
    return false;
}
Also used : RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 22 with RecordDefinition

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

the class OsnReader method getRecord.

private Object getRecord() {
    final String typePath = this.osnIterator.getPathValue();
    final OsnConverter converter = this.converters.getConverter(typePath);
    if (converter != null) {
        return converter.read(this.osnIterator);
    } else {
        final RecordDefinition type = this.recordDefinitionFactory.getRecordDefinition(typePath);
        final Record record = this.factory.newRecord(type);
        while (this.osnIterator.next() != OsnIterator.END_OBJECT) {
            addField(record);
        }
        return record;
    }
}
Also used : OsnConverter(com.revolsys.record.io.format.saif.util.OsnConverter) Record(com.revolsys.record.Record) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 23 with RecordDefinition

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

the class SaifSchemaReader method getDefinition.

private Object getDefinition(final CsnIterator iterator) throws IOException {
    while (iterator.next() != CsnIterator.END_DEFINITION) {
        switch(iterator.getEventType()) {
            case CsnIterator.CLASS_NAME:
                final String superClassName = iterator.getPathValue();
                if (superClassName.equals("/Enumeration")) {
                    final DataType enumeration = processEnumeration(iterator);
                    nameTypeMap.put(enumeration.getName(), enumeration);
                    return enumeration;
                }
                final RecordDefinition superClass = this.schema.getRecordDefinition(superClassName);
                if (superClass == null) {
                    throw new IllegalStateException("Cannot find super class '" + superClassName + "'");
                }
                this.currentSuperClasses.add(superClass);
                break;
            case CsnIterator.COMPONENT_NAME:
                final String componentName = iterator.getStringValue();
                try {
                    final Method method = getClass().getMethod(componentName, new Class[] { RecordDefinition.class, CsnIterator.class });
                    method.invoke(this, new Object[] { this.currentClass, iterator });
                } catch (final SecurityException e) {
                    throw new IllegalStateException("Unknown component '" + componentName + "'");
                } catch (final NoSuchMethodException e) {
                    throw new IllegalStateException("Unknown component '" + componentName + "'");
                } catch (final IllegalAccessException e) {
                    throw new RuntimeException(e.getMessage(), e);
                } catch (final InvocationTargetException e) {
                    final Throwable cause = e.getCause();
                    if (cause instanceof RuntimeException) {
                        throw (RuntimeException) cause;
                    } else if (cause instanceof Error) {
                        throw (Error) cause;
                    } else if (cause instanceof IOException) {
                        throw (IOException) cause;
                    } else {
                        throw new RuntimeException(cause.getMessage(), cause);
                    }
                }
            default:
                break;
        }
    }
    return this.currentClass;
}
Also used : Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RecordDefinition(com.revolsys.record.schema.RecordDefinition) CollectionDataType(com.revolsys.datatype.CollectionDataType) EnumerationDataType(com.revolsys.datatype.EnumerationDataType) SimpleDataType(com.revolsys.datatype.SimpleDataType) DataType(com.revolsys.datatype.DataType)

Example 24 with RecordDefinition

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

the class Value method setFieldDefinition.

@Override
public void setFieldDefinition(final FieldDefinition field) {
    if (field != null) {
        this.fieldDefinition = field;
        if (field instanceof JdbcFieldDefinition) {
            this.jdbcField = (JdbcFieldDefinition) field;
        } else {
            this.jdbcField = JdbcFieldDefinition.newFieldDefinition(this.queryValue);
        }
        CodeTable codeTable = null;
        if (field != null) {
            final RecordDefinition recordDefinition = field.getRecordDefinition();
            if (recordDefinition != null) {
                final String fieldName = field.getName();
                codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
                if (codeTable instanceof CodeTableProperty) {
                    final CodeTableProperty codeTableProperty = (CodeTableProperty) codeTable;
                    if (codeTableProperty.getRecordDefinition() == recordDefinition) {
                        codeTable = null;
                    }
                }
                if (codeTable != null) {
                    final Identifier id = codeTable.getIdentifier(this.queryValue);
                    if (id == null) {
                        this.displayValue = this.queryValue;
                    } else {
                        setQueryValue(id);
                        final List<Object> values = codeTable.getValues(id);
                        if (values.size() == 1) {
                            this.displayValue = values.get(0);
                        } else {
                            this.displayValue = Strings.toString(":", values);
                        }
                    }
                }
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) TypedIdentifier(com.revolsys.identifier.TypedIdentifier) Identifier(com.revolsys.identifier.Identifier) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) CodeTableProperty(com.revolsys.record.code.CodeTableProperty) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 25 with RecordDefinition

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

the class Query method equal.

public static Query equal(final FieldDefinition field, final Object value) {
    final RecordDefinition recordDefinition = field.getRecordDefinition();
    final Query query = new Query(recordDefinition);
    final Value valueCondition = new Value(field, value);
    final BinaryCondition equal = Q.equal(field, valueCondition);
    query.setWhereCondition(equal);
    return query;
}
Also used : RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

RecordDefinition (com.revolsys.record.schema.RecordDefinition)189 FieldDefinition (com.revolsys.record.schema.FieldDefinition)38 Record (com.revolsys.record.Record)34 Geometry (com.revolsys.geometry.model.Geometry)20 CodeTable (com.revolsys.record.code.CodeTable)19 Query (com.revolsys.record.query.Query)18 LineString (com.revolsys.geometry.model.LineString)17 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)16 PathName (com.revolsys.io.PathName)13 ArrayList (java.util.ArrayList)12 DataType (com.revolsys.datatype.DataType)11 Identifier (com.revolsys.identifier.Identifier)11 RecordReader (com.revolsys.record.io.RecordReader)11 RecordStore (com.revolsys.record.schema.RecordStore)11 HashMap (java.util.HashMap)9 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)8 ArrayRecord (com.revolsys.record.ArrayRecord)8 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)6 Table (com.revolsys.gis.esri.gdb.file.capi.swig.Table)5 RecordWriter (com.revolsys.record.io.RecordWriter)5