Search in sources :

Example 11 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class SaifSchemaReader method attributes.

public void attributes(final RecordDefinition type, final CsnIterator iterator) throws IOException {
    while (iterator.getNextEventType() == CsnIterator.ATTRIBUTE_NAME || iterator.getNextEventType() == CsnIterator.OPTIONAL_ATTRIBUTE) {
        boolean required = true;
        switch(iterator.next()) {
            case CsnIterator.OPTIONAL_ATTRIBUTE:
                required = false;
                iterator.next();
            case CsnIterator.ATTRIBUTE_NAME:
                final String fieldName = iterator.getStringValue();
                switch(iterator.next()) {
                    case CsnIterator.ATTRIBUTE_TYPE:
                        final String typePath = iterator.getPathValue();
                        DataType dataType = nameTypeMap.get(typePath);
                        if (typePath.equals(SPATIAL_OBJECT) || typePath.equals(TEXT_OR_SYMBOL_OBJECT)) {
                            dataType = DataTypes.GEOMETRY;
                            this.currentClass.setGeometryFieldIndex(this.currentClass.getFieldCount());
                        } else if (dataType == null) {
                            dataType = new SimpleDataType(typePath, Record.class);
                        }
                        this.currentClass.addField(fieldName, dataType, required);
                        break;
                    case CsnIterator.COLLECTION_ATTRIBUTE:
                        final String collectionType = iterator.getPathValue();
                        if (iterator.next() == CsnIterator.CLASS_NAME) {
                            final String contentTypeName = iterator.getPathValue();
                            final DataType collectionDataType = nameTypeMap.get(collectionType);
                            DataType contentDataType = nameTypeMap.get(contentTypeName);
                            if (contentDataType == null) {
                                contentDataType = DataTypes.RECORD;
                            }
                            this.currentClass.addField(fieldName, new CollectionDataType(collectionDataType.getName(), collectionDataType.getJavaClass(), contentDataType), required);
                        } else {
                            throw new IllegalStateException("Expecting attribute type");
                        }
                        break;
                    case CsnIterator.STRING_ATTRIBUTE:
                        int length = Integer.MAX_VALUE;
                        if (iterator.getEventType() == CsnIterator.STRING_ATTRIBUTE_LENGTH) {
                            length = iterator.getIntegerValue();
                        }
                        this.currentClass.addField(fieldName, DataTypes.STRING, length, required);
                        break;
                    default:
                        throw new IllegalStateException("Unknown event type: " + iterator.getEventType());
                }
                break;
            default:
                break;
        }
    }
}
Also used : SimpleDataType(com.revolsys.datatype.SimpleDataType) CollectionDataType(com.revolsys.datatype.CollectionDataType) CollectionDataType(com.revolsys.datatype.CollectionDataType) EnumerationDataType(com.revolsys.datatype.EnumerationDataType) SimpleDataType(com.revolsys.datatype.SimpleDataType) DataType(com.revolsys.datatype.DataType)

Example 12 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class RecordDefinitionImpl method addField.

public synchronized void addField(final FieldDefinition field) {
    final int index = this.fieldNames.size();
    final String name = field.getName();
    String lowerName;
    if (name == null) {
        lowerName = null;
    } else {
        lowerName = name.toLowerCase();
    }
    this.internalFieldNames.add(name);
    this.fieldNames = Lists.unmodifiable(this.internalFieldNames);
    this.fieldNamesSet = Sets.unmodifiableLinked(this.internalFieldNames);
    this.internalFields.add(field);
    this.fields = Lists.unmodifiable(this.internalFields);
    this.fieldMap.put(lowerName, field);
    this.fieldIdMap.put(lowerName, this.fieldIdMap.size());
    final DataType dataType = field.getDataType();
    if (dataType == null) {
        Logs.debug(this, field.toString());
    } else {
        final Class<?> dataClass = dataType.getJavaClass();
        if (Geometry.class.isAssignableFrom(dataClass)) {
            this.geometryFieldDefinitionIndexes.add(index);
            this.geometryFieldDefinitionNames.add(name);
            if (this.geometryFieldDefinitionIndex == -1) {
                this.geometryFieldDefinitionIndex = index;
                final GeometryFactory geometryFactory = field.getProperty(FieldProperties.GEOMETRY_FACTORY);
                if (geometryFactory == null && this.geometryFactory != null) {
                    field.setProperty(FieldProperties.GEOMETRY_FACTORY, this.geometryFactory);
                }
            }
        }
    }
    field.setIndex(index);
    field.setRecordDefinition(this);
    final CodeTable codeTable = field.getCodeTable();
    addFieldCodeTable(name, codeTable);
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) DataType(com.revolsys.datatype.DataType)

Example 13 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class OracleDdlWriter method writeAddGeometryColumn.

public void writeAddGeometryColumn(final RecordDefinition recordDefinition) {
    final PrintWriter out = getOut();
    final String typePath = recordDefinition.getPath();
    String schemaName = JdbcUtils.getSchemaName(typePath);
    if (schemaName.length() == 0) {
        schemaName = "public";
    }
    final String tableName = PathUtil.getName(typePath);
    final FieldDefinition geometryField = recordDefinition.getGeometryField();
    if (geometryField != null) {
        final GeometryFactory geometryFactory = geometryField.getProperty(FieldProperties.GEOMETRY_FACTORY);
        final String name = geometryField.getName();
        String geometryType = "GEOMETRY";
        final DataType dataType = geometryField.getDataType();
        if (dataType == DataTypes.POINT) {
            geometryType = "POINT";
        } else if (dataType == DataTypes.LINE_STRING) {
            geometryType = "LINESTRING";
        } else if (dataType == DataTypes.POLYGON) {
            geometryType = "POLYGON";
        } else if (dataType == DataTypes.MULTI_POINT) {
            geometryType = "MULTIPOINT";
        } else if (dataType == DataTypes.MULTI_LINE_STRING) {
            geometryType = "MULTILINESTRING";
        } else if (dataType == DataTypes.MULTI_POLYGON) {
            geometryType = "MULTIPOLYGON";
        }
        out.print("select addgeometrycolumn('");
        out.print(schemaName.toLowerCase());
        out.print("', '");
        out.print(tableName.toLowerCase());
        out.print("','");
        out.print(name.toLowerCase());
        out.print("',");
        final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
        out.print(coordinateSystem.getCoordinateSystemId());
        out.print(",'");
        out.print(geometryType);
        out.print("', ");
        out.print(geometryFactory.getAxisCount());
        out.println(");");
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) PrintWriter(java.io.PrintWriter)

Example 14 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class OracleDdlWriter method writeGeometryRecordDefinition.

@Override
public void writeGeometryRecordDefinition(final RecordDefinition recordDefinition) {
    final PrintWriter out = getOut();
    final String typePath = recordDefinition.getPath();
    final String schemaName = JdbcUtils.getSchemaName(typePath);
    final String tableName = PathUtil.getName(typePath);
    final FieldDefinition geometryField = recordDefinition.getGeometryField();
    if (geometryField != null) {
        final GeometryFactory geometryFactory = geometryField.getProperty(FieldProperties.GEOMETRY_FACTORY);
        final String name = geometryField.getName();
        final int axisCount = geometryFactory.getAxisCount();
        final DataType dataType = geometryField.getDataType();
        final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
        final int srid = coordinateSystem.getCoordinateSystemId();
        out.print("INSERT INTO USER_SDO_GEOM_METADATA(TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES('");
        out.print(tableName.toUpperCase());
        out.print("','");
        out.print(name.toUpperCase());
        // TODO get from geometry factory
        out.print("',MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X', 263000, 1876000, 0.001),MDSYS.SDO_DIM_ELEMENT('Y', 356000, 1738000, 0.001)");
        if (axisCount > 2) {
            out.print(",MDSYS.SDO_DIM_ELEMENT('Z',-2500, 5000, 0.001)");
        }
        out.print("),");
        out.println("3005);");
        final int geometryType = OracleSdoGeometryFieldAdder.getGeometryTypeId(dataType, axisCount);
        out.print("INSERT INTO OGIS_GEOMETRY_COLUMNS(F_TABLE_SCHEMA,F_TABLE_NAME,F_GEOMETRY_COLUMN,G_TABLE_SCHEMA,G_TABLE_NAME,GEOMETRY_TYPE,COORD_DIMENSION,SRID) VALUES ('");
        out.print(schemaName.toUpperCase());
        out.print("', '");
        out.print(tableName.toUpperCase());
        out.print("','");
        out.print(name.toUpperCase());
        out.print("', '");
        out.print(schemaName.toUpperCase());
        out.print("', '");
        out.print(tableName.toUpperCase());
        out.print("',");
        out.print(geometryType);
        out.print(",");
        out.print(axisCount);
        out.print(",");
        out.print("100");
        out.print(srid);
        out.println(");");
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) PrintWriter(java.io.PrintWriter)

Example 15 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class ArcSdeStGeometryFieldAdder method newField.

@Override
public ArcSdeStGeometryFieldDefinition 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 JdbcRecordStoreSchema schema = recordDefinition.getSchema();
    final PathName typePath = recordDefinition.getPathName();
    final String owner = schema.getDbName();
    final String tableName = recordDefinition.getDbTableName();
    final String columnName = name.toUpperCase();
    final int esriSrid = JdbcFieldAdder.getIntegerColumnProperty(schema, typePath, columnName, ArcSdeConstants.ESRI_SRID_PROPERTY);
    if (esriSrid == -1) {
        Logs.error(this, "Column not registered in SDE.ST_GEOMETRY table " + owner + "." + tableName + "." + name);
    }
    final int axisCount = JdbcFieldAdder.getIntegerColumnProperty(schema, typePath, columnName, JdbcFieldAdder.AXIS_COUNT);
    if (axisCount == -1) {
        Logs.error(this, "Column not found in SDE.GEOMETRY_COLUMNS table " + owner + "." + tableName + "." + name);
    }
    final DataType dataType = JdbcFieldAdder.getColumnProperty(schema, typePath, columnName, JdbcFieldAdder.GEOMETRY_TYPE);
    if (dataType == null) {
        Logs.error(this, "Column not found in SDE.GEOMETRY_COLUMNS table " + owner + "." + tableName + "." + name);
    }
    final ArcSdeSpatialReference spatialReference = JdbcFieldAdder.getColumnProperty(schema, typePath, columnName, ArcSdeConstants.SPATIAL_REFERENCE);
    final GeometryFactory geometryFactory = JdbcFieldAdder.getColumnProperty(schema, typePath, columnName, JdbcFieldAdder.GEOMETRY_FACTORY);
    final ArcSdeStGeometryFieldDefinition field = new ArcSdeStGeometryFieldDefinition(dbName, name, dataType, required, description, null, spatialReference, axisCount);
    field.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
    return field;
}
Also used : JdbcRecordStoreSchema(com.revolsys.jdbc.io.JdbcRecordStoreSchema) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Aggregations

DataType (com.revolsys.datatype.DataType)85 FieldDefinition (com.revolsys.record.schema.FieldDefinition)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 PathName (com.revolsys.io.PathName)13 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 Geometry (com.revolsys.geometry.model.Geometry)10 Record (com.revolsys.record.Record)10 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)10 ArrayList (java.util.ArrayList)8 ArrayRecord (com.revolsys.record.ArrayRecord)6 PrintWriter (java.io.PrintWriter)6 EsriGeodatabaseXmlFieldType (com.revolsys.record.io.format.esri.gdb.xml.type.EsriGeodatabaseXmlFieldType)5 MapEx (com.revolsys.collection.map.MapEx)4 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 Point (com.revolsys.geometry.model.Point)4 IOException (java.io.IOException)4 Map (java.util.Map)4 CollectionDataType (com.revolsys.datatype.CollectionDataType)3 EnumerationDataType (com.revolsys.datatype.EnumerationDataType)3 CodeTable (com.revolsys.record.code.CodeTable)3