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;
}
}
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;
}
}
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(");");
}
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());
}
}
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(");");
}
}
Aggregations