use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class PostgreSQLDdlWriter method writeGeometryRecordDefinition.
@Override
public void writeGeometryRecordDefinition(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("INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, \"type\") VALUES ('','");
out.print(schemaName.toLowerCase());
out.print("', '");
out.print(tableName.toLowerCase());
out.print("','");
out.print(name.toLowerCase());
out.print("', ");
out.print(geometryFactory.getAxisCount());
out.print(",");
final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
out.print(coordinateSystem.getCoordinateSystemId());
out.print(",'");
out.print(geometryType);
out.println("');");
}
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class PostgreSQLGeometryJdbcFieldDefinition method getInsertUpdateValue.
public Object getInsertUpdateValue(final Object value) throws SQLException {
if (value == null) {
return null;
} else if (value instanceof Geometry) {
final Geometry geometry = (Geometry) value;
final DataType dataType = getDataType();
return new PostgreSQLGeometryWrapper(dataType, this.geometryFactory, geometry);
} else if (value instanceof BoundingBox) {
BoundingBox boundingBox = (BoundingBox) value;
boundingBox = boundingBox.convert(this.geometryFactory);
return new PostgreSQLBoundingBoxWrapper(boundingBox);
} else if (Property.hasValue(value)) {
return value;
} else {
return null;
}
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class OracleDdlWriter method writeColumnDataType.
@Override
public void writeColumnDataType(final FieldDefinition attribute) {
final PrintWriter out = getOut();
final DataType dataType = attribute.getDataType();
if (dataType == DataTypes.BOOLEAN) {
out.print("NUMBER(1,0)");
} 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(10)");
} else if (dataType == DataTypes.LONG) {
out.print("NUMBER(19)");
} else if (dataType == DataTypes.FLOAT) {
out.print("float");
} else if (dataType == DataTypes.DOUBLE) {
out.print("double precision");
} else if (dataType == DataTypes.DATE) {
out.print("DATE");
} else if (dataType == DataTypes.DATE_TIME) {
out.print("TIMESTAMP");
} else if (dataType == DataTypes.STRING) {
out.print("VARCHAR2(");
out.print(attribute.getLength());
out.print(")");
} else if (dataType == DataTypes.BIG_INTEGER) {
out.print("NUMBER(");
out.print(attribute.getLength());
out.print(')');
} else if (dataType == DataTypes.DECIMAL) {
out.print("NUMBER(");
out.print(attribute.getLength());
final int scale = attribute.getScale();
if (scale >= 0) {
out.print(',');
out.print(scale);
}
out.print(')');
} else if (Geometry.class.isAssignableFrom(dataType.getJavaClass())) {
out.print("MDSYS.SDO_GEOMETRY");
} else {
throw new IllegalArgumentException("Unknown data type" + dataType);
}
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class ArcSdeConstants method getStGeometryType.
public static Integer getStGeometryType(final Geometry geometry) {
final DataType dataType = geometry.getDataType();
final Integer type = GEOMETRY_DATA_TYPE_ST_TYPE.get(dataType);
if (type == null) {
throw new IllegalArgumentException("Unsupported geometry type " + dataType);
} else {
return type;
}
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class GeoPackageGeometryFieldAdder method addField.
@Override
public FieldDefinition addField(final AbstractJdbcRecordStore recordStore, final JdbcRecordDefinition recordDefinition, final String dbName, final String name, final String columnDataType, final int sqlType, final int length, final int scale, final boolean required, final String description) {
final PathName typePath = recordDefinition.getPathName();
final String tableName = recordDefinition.getDbTableName();
final String columnName = name.toLowerCase();
try {
int srid = 0;
String type = "geometry";
int axisCount = 2;
try {
final String sql = "select geometry_type_name, srs_id, Z, M from gpkg_geometry_columns where UPPER(TABLE_NAME) = UPPER(?) AND UPPER(COLUMN_NAME) = UPPER(?)";
final MapEx values = JdbcUtils.selectMap(recordStore, sql, tableName, columnName);
srid = values.getInteger("srs_id", 0);
type = values.getString("geometry_type_name", "GEOMETRY");
if (values.getInteger("z", 0) > 0) {
axisCount = 3;
}
if (values.getInteger("m", 0) > 0) {
axisCount = 4;
}
} catch (final IllegalArgumentException e) {
Logs.warn(this, "Cannot get geometry column metadata for " + typePath + "." + columnName);
}
final DataType dataType = DATA_TYPE_MAP.get(type);
final GeometryFactory storeGeometryFactory = recordStore.getGeometryFactory();
final GeometryFactory geometryFactory;
if (storeGeometryFactory == null) {
geometryFactory = GeometryFactory.floating(srid, axisCount);
} else {
final double[] scales = storeGeometryFactory.newScales(axisCount);
geometryFactory = GeometryFactory.fixed(srid, axisCount, scales);
}
final FieldDefinition field = new GeoPackageGeometryJdbcFieldDefinition(dbName, name, dataType, required, description, null, srid, axisCount, geometryFactory);
recordDefinition.addField(field);
field.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
return field;
} catch (final Throwable e) {
Logs.error(this, "Attribute not registered in GEOMETRY_COLUMN table " + tableName + "." + name, e);
return null;
}
}
Aggregations