Search in sources :

Example 61 with DataType

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

the class AddDefaultValuesProcess method setDefaultValue.

private void setDefaultValue(final Record record, final String key, final Object value) {
    final int dotIndex = key.indexOf('.');
    if (dotIndex == -1) {
        if (record.getValue(key) == null && !this.excludedFieldNames.contains(key)) {
            log.info("Adding attribute " + key + "=" + value);
            record.setValue(key, value);
        }
    } else {
        final String fieldName = key.substring(0, dotIndex);
        NDC.push(" -> " + fieldName);
        try {
            final String subKey = key.substring(dotIndex + 1);
            final Object attributeValue = record.getValue(fieldName);
            if (attributeValue == null) {
                final RecordDefinition type = record.getRecordDefinition();
                final int attrIndex = type.getFieldIndex(fieldName);
                final DataType dataType = type.getFieldType(attrIndex);
                final Class<?> typeClass = dataType.getJavaClass();
                if (typeClass == Record.class) {
                    final RecordDefinition subClass = this.recordDefinitionFactory.getRecordDefinition(dataType.getName());
                    final Record subObject = subClass.newRecord();
                    setDefaultValue(subObject, subKey, value);
                    record.setValue(fieldName, subObject);
                    process(subObject);
                }
            } else if (attributeValue instanceof Record) {
                final Record subObject = (Record) attributeValue;
                setDefaultValue(subObject, subKey, value);
            } else if (!fieldName.equals(record.getRecordDefinition().getGeometryFieldName())) {
                log.error("Attribute '" + fieldName + "' must be a Record");
            }
        } finally {
            NDC.pop();
        }
    }
}
Also used : DataType(com.revolsys.datatype.DataType) Record(com.revolsys.record.Record) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 62 with DataType

use of com.revolsys.datatype.DataType 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 63 with DataType

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

the class PostgreSQLRecordStore method addField.

@Override
protected JdbcFieldDefinition addField(final JdbcRecordDefinition recordDefinition, final String dbColumnName, final String name, final String dbDataType, final int sqlType, final int length, final int scale, final boolean required, final String description) {
    final JdbcFieldDefinition field;
    if (dbDataType.charAt(0) == '_') {
        final String elementDbDataType = dbDataType.substring(1);
        final JdbcFieldAdder fieldAdder = getFieldAdder(elementDbDataType);
        final JdbcFieldDefinition elementField = fieldAdder.newField(this, recordDefinition, dbColumnName, name, elementDbDataType, sqlType, length, scale, required, description);
        final DataType elementDataType = elementField.getDataType();
        final CollectionDataType listDataType = new CollectionDataType("List" + elementDataType.getName(), List.class, elementDataType);
        field = new PostgreSQLArrayFieldDefinition(dbColumnName, name, listDataType, sqlType, length, scale, required, description, elementField, getProperties());
        recordDefinition.addField(field);
    } else {
        field = super.addField(recordDefinition, dbColumnName, name, dbDataType, sqlType, length, scale, required, description);
    }
    if (!dbColumnName.matches("[a-z_]+")) {
        field.setQuoteName(true);
    }
    return field;
}
Also used : JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) CollectionDataType(com.revolsys.datatype.CollectionDataType) PostgreSQLArrayFieldDefinition(com.revolsys.gis.postgresql.type.PostgreSQLArrayFieldDefinition) CollectionDataType(com.revolsys.datatype.CollectionDataType) DataType(com.revolsys.datatype.DataType) JdbcFieldAdder(com.revolsys.jdbc.field.JdbcFieldAdder)

Example 64 with DataType

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

the class OracleDdlUtil method writeCreateTable.

public static void writeCreateTable(final PrintWriter out, final RecordDefinition recordDefinition) {
    final String typePath = recordDefinition.getPath();
    out.println();
    out.print("CREATE TABLE ");
    final String tableName = JdbcUtils.getQualifiedTableName(typePath);
    out.print(tableName);
    out.println(" (");
    for (int i = 0; i < recordDefinition.getFieldCount(); i++) {
        if (i > 1) {
            out.println(",");
        }
        final FieldDefinition attribute = recordDefinition.getField(i);
        final String name = attribute.getName();
        out.print("  ");
        out.print(name);
        for (int j = name.length(); j < 32; j++) {
            out.print(' ');
        }
        out.print(" : ");
        final DataType dataType = attribute.getDataType();
        if (dataType == DataTypes.BOOLEAN) {
            out.print("NUMBER(1)");
        } else if (dataType == DataTypes.BYTE) {
            out.print("NUMBER(3)");
        } else if (dataType == DataTypes.SHORT) {
            out.print("NUMBER(5)");
        } else if (dataType == DataTypes.INT) {
            out.print("NUMBER(9)");
        } else if (dataType == DataTypes.LONG) {
            out.print("NUMBER(19)");
        } else if (dataType == DataTypes.FLOAT) {
            out.print("NUMBER");
        } else if (dataType == DataTypes.DOUBLE) {
            out.print("NUMBER");
        } else if (dataType == DataTypes.STRING) {
            out.print("VARCHAR2(");
            out.print(attribute.getLength());
            out.print(")");
        } else if (dataType == DataTypes.GEOMETRY) {
            out.print("MDSYS.SDO_GEOMETRY");
        }
        if (attribute.isRequired()) {
            out.print(" NOT NULL");
        }
    }
    out.println();
    out.println(");");
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType)

Example 65 with DataType

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

the class PostgreSQLDdlWriter 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)

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