Search in sources :

Example 96 with FieldDefinition

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

the class Query method equal.

public static Query equal(final RecordDefinitionProxy recordDefinition, final String name, final Object value) {
    final FieldDefinition fieldDefinition = recordDefinition.getFieldDefinition(name);
    if (fieldDefinition == null) {
        return null;
    } else {
        final Query query = new Query(recordDefinition);
        final Value valueCondition = new Value(fieldDefinition, value);
        final BinaryCondition equal = Q.equal(name, valueCondition);
        query.setWhereCondition(equal);
        return query;
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition)

Example 97 with FieldDefinition

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

the class Query method intersects.

public static Query intersects(final RecordStore recordStore, final PathName path, final BoundingBox boundingBox) {
    final RecordDefinition recordDefinition = recordStore.getRecordDefinition(path);
    final FieldDefinition geometryField = recordDefinition.getGeometryField();
    if (geometryField == null) {
        return null;
    } else {
        final EnvelopeIntersects intersects = F.envelopeIntersects(geometryField, boundingBox);
        final Query query = new Query(recordDefinition, intersects);
        return query;
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) EnvelopeIntersects(com.revolsys.record.query.functions.EnvelopeIntersects) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 98 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition 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 99 with FieldDefinition

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

the class OracleRecordStore method appendWithinDistance.

private void appendWithinDistance(final Query query, final StringBuilder sql, final WithinDistance withinDistance) {
    final FieldDefinition geometryField = query.getGeometryField();
    if (geometryField instanceof OracleSdoGeometryJdbcFieldDefinition) {
        sql.append("MDSYS.SDO_WITHIN_DISTANCE(");
        final QueryValue geometry1Value = withinDistance.getGeometry1Value();
        if (geometry1Value == null) {
            sql.append("NULL");
        } else {
            geometry1Value.appendSql(query, this, sql);
        }
        sql.append(", ");
        final QueryValue geometry2Value = withinDistance.getGeometry2Value();
        if (geometry2Value == null) {
            sql.append("NULL");
        } else {
            geometry2Value.appendSql(query, this, sql);
        }
        sql.append(",'distance = ' || ");
        final QueryValue distanceValue = withinDistance.getDistanceValue();
        if (distanceValue == null) {
            sql.append("0");
        } else {
            distanceValue.appendSql(query, this, sql);
        }
        sql.append(") = 'TRUE'");
    } else if (geometryField instanceof ArcSdeStGeometryFieldDefinition) {
        final Column column = (Column) withinDistance.getGeometry1Value();
        final GeometryFactory geometryFactory = column.getFieldDefinition().getRecordDefinition().getGeometryFactory();
        final Value geometry2Value = (Value) withinDistance.getGeometry2Value();
        final Value distanceValue = (Value) withinDistance.getDistanceValue();
        final Number distance = (Number) distanceValue.getValue();
        final Object geometryObject = geometry2Value.getValue();
        BoundingBox boundingBox;
        if (geometryObject instanceof BoundingBox) {
            boundingBox = (BoundingBox) geometryObject;
        } else if (geometryObject instanceof Geometry) {
            final Geometry geometry = (Geometry) geometryObject;
            boundingBox = geometry.getBoundingBox();
        } else {
            boundingBox = geometryFactory.newBoundingBoxEmpty();
        }
        boundingBox = boundingBox.expand(distance.doubleValue());
        boundingBox = boundingBox.convert(geometryFactory);
        sql.append("(SDE.ST_ENVINTERSECTS(");
        column.appendSql(query, this, sql);
        sql.append(",");
        sql.append(boundingBox.getMinX());
        sql.append(",");
        sql.append(boundingBox.getMinY());
        sql.append(",");
        sql.append(boundingBox.getMaxX());
        sql.append(",");
        sql.append(boundingBox.getMaxY());
        sql.append(") = 1 AND SDE.ST_DISTANCE(");
        column.appendSql(query, this, sql);
        sql.append(", ");
        geometry2Value.appendSql(query, this, sql);
        sql.append(") <= ");
        distanceValue.appendSql(query, this, sql);
        sql.append(")");
    } else {
        throw new IllegalArgumentException("Unknown geometry attribute type " + geometryField.getClass());
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) OracleSdoGeometryJdbcFieldDefinition(com.revolsys.oracle.recordstore.field.OracleSdoGeometryJdbcFieldDefinition) Column(com.revolsys.record.query.Column) FieldDefinition(com.revolsys.record.schema.FieldDefinition) OracleJdbcRowIdFieldDefinition(com.revolsys.oracle.recordstore.field.OracleJdbcRowIdFieldDefinition) ArcSdeStGeometryFieldDefinition(com.revolsys.oracle.recordstore.esri.ArcSdeStGeometryFieldDefinition) JdbcFieldDefinition(com.revolsys.jdbc.field.JdbcFieldDefinition) OracleSdoGeometryJdbcFieldDefinition(com.revolsys.oracle.recordstore.field.OracleSdoGeometryJdbcFieldDefinition) BoundingBox(com.revolsys.geometry.model.BoundingBox) QueryValue(com.revolsys.record.query.QueryValue) Value(com.revolsys.record.query.Value) ArcSdeStGeometryFieldDefinition(com.revolsys.oracle.recordstore.esri.ArcSdeStGeometryFieldDefinition) QueryValue(com.revolsys.record.query.QueryValue)

Example 100 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition 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

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