use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class OracleSdoGeometryFieldAdder method initialize.
@Override
public void initialize(final JdbcRecordStoreSchema schema) {
try (final JdbcConnection connection = this.recordStore.getJdbcConnection()) {
final String schemaName = schema.getDbName();
final String sridSql = "select M.TABLE_NAME, M.COLUMN_NAME, M.SRID, M.DIMINFO, C.GEOMETRY_TYPE " + "from ALL_SDO_GEOM_METADATA M " + "LEFT OUTER JOIN ALL_GEOMETRY_COLUMNS C ON (M.OWNER = C.F_TABLE_SCHEMA AND M.TABLE_NAME = C.F_TABLE_NAME AND M.COLUMN_NAME = C.F_GEOMETRY_COLUMN) " + "where OWNER = ?";
try (final PreparedStatement statement = connection.prepareStatement(sridSql)) {
statement.setString(1, schemaName);
try (final ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
final String tableName = resultSet.getString(1);
final String columnName = resultSet.getString(2);
final PathName typePath = schema.getPathName().newChild(tableName);
int srid = resultSet.getInt(3);
if (resultSet.wasNull() || srid < 0) {
srid = 0;
}
final Object[] dimInfo = (Object[]) resultSet.getArray("DIMINFO").getArray();
int axisCount = dimInfo.length;
setColumnProperty(schema, typePath, columnName, AXIS_COUNT, axisCount);
if (axisCount < 2) {
axisCount = 2;
} else if (axisCount > 4) {
axisCount = 4;
}
final double[] scales = new double[axisCount];
for (int i = 0; i < scales.length; i++) {
scales[i] = getScale(dimInfo, i);
}
final GeometryFactory geometryFactory = this.recordStore.getGeometryFactory(srid, axisCount, scales);
setColumnProperty(schema, typePath, columnName, GEOMETRY_FACTORY, geometryFactory);
setColumnProperty(schema, typePath, columnName, ORACLE_SRID, srid);
final int geometryType = resultSet.getInt(5);
DataType geometryDataType;
if (resultSet.wasNull()) {
geometryDataType = DataTypes.GEOMETRY;
} else {
geometryDataType = ID_TO_DATA_TYPE.get(geometryType);
if (geometryDataType == null) {
geometryDataType = DataTypes.GEOMETRY;
}
}
setColumnProperty(schema, typePath, columnName, GEOMETRY_TYPE, geometryDataType);
}
}
} catch (final SQLException e) {
Logs.error(this, "Unable to initialize", e);
}
}
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class OgrRecordStore method getGeometryFieldType.
private int getGeometryFieldType(final GeometryFactory geometryFactory, final FieldDefinition field) {
int type;
final DataType dataType = field.getDataType();
if (DataTypes.POINT.equals(dataType)) {
type = 1;
} else if (DataTypes.LINE_STRING.equals(dataType)) {
type = 2;
} else if (DataTypes.POLYGON.equals(dataType)) {
type = 3;
} else if (DataTypes.MULTI_POINT.equals(dataType)) {
type = 4;
} else if (DataTypes.MULTI_LINE_STRING.equals(dataType)) {
type = 5;
} else if (DataTypes.MULTI_POINT.equals(dataType)) {
type = 6;
} else if (DataTypes.GEOMETRY_COLLECTION.equals(dataType)) {
type = 7;
} else if (DataTypes.LINEAR_RING.equals(dataType)) {
type = 101;
} else {
throw new IllegalArgumentException("Unsupported geometry type " + dataType + " for " + field);
}
if (geometryFactory.getAxisCount() > 2) {
type += 0x80000000;
}
return type;
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class OgrRecordStore method newLayerRecordDefinition.
protected RecordDefinitionImpl newLayerRecordDefinition(final RecordStoreSchema schema, final Layer layer) {
final String layerName = layer.GetName();
final PathName typePath = PathName.newPathName(layerName);
/**
* This primes the layer so that the fidColumn is loaded correctly.
*/
layer.GetNextFeature();
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(schema, typePath);
String idFieldName = layer.GetFIDColumn();
if (!Property.hasValue(idFieldName)) {
idFieldName = "rowid";
}
this.idFieldNames.put(typePath.getUpperPath(), idFieldName);
final FeatureDefn layerDefinition = layer.GetLayerDefn();
if (SQLITE.equals(this.driverName) || GEO_PAKCAGE.equals(this.driverName)) {
recordDefinition.addField(idFieldName, DataTypes.LONG, true);
recordDefinition.setIdFieldName(idFieldName);
}
for (int fieldIndex = 0; fieldIndex < layerDefinition.GetFieldCount(); fieldIndex++) {
final FieldDefn fieldDefinition = layerDefinition.GetFieldDefn(fieldIndex);
final String fieldName = fieldDefinition.GetName();
final int fieldType = fieldDefinition.GetFieldType();
final int fieldWidth = fieldDefinition.GetWidth();
final int fieldPrecision = fieldDefinition.GetPrecision();
DataType fieldDataType;
switch(fieldType) {
case 0:
fieldDataType = DataTypes.INT;
break;
case 2:
fieldDataType = DataTypes.DOUBLE;
break;
case 4:
case 6:
fieldDataType = DataTypes.STRING;
break;
case 9:
fieldDataType = DataTypes.DATE;
break;
case 11:
fieldDataType = DataTypes.DATE_TIME;
break;
default:
fieldDataType = DataTypes.STRING;
final String fieldTypeName = fieldDefinition.GetFieldTypeName(fieldType);
Logs.error(this, "Unsupported field type " + this.file + " " + fieldName + ": " + fieldTypeName);
break;
}
final FieldDefinition field = new FieldDefinition(fieldName, fieldDataType, fieldWidth, fieldPrecision, false);
recordDefinition.addField(field);
}
for (int fieldIndex = 0; fieldIndex < layerDefinition.GetGeomFieldCount(); fieldIndex++) {
final GeomFieldDefn fieldDefinition = layerDefinition.GetGeomFieldDefn(fieldIndex);
final String fieldName = fieldDefinition.GetName();
final int geometryFieldType = fieldDefinition.GetFieldType();
DataType geometryFieldDataType;
int axisCount = 2;
switch(geometryFieldType) {
case 1:
geometryFieldDataType = DataTypes.POINT;
break;
case 2:
geometryFieldDataType = DataTypes.LINE_STRING;
break;
case 3:
geometryFieldDataType = DataTypes.POLYGON;
break;
case 4:
geometryFieldDataType = DataTypes.MULTI_POINT;
break;
case 5:
geometryFieldDataType = DataTypes.MULTI_LINE_STRING;
break;
case 6:
geometryFieldDataType = DataTypes.MULTI_POLYGON;
break;
case 7:
geometryFieldDataType = DataTypes.GEOMETRY_COLLECTION;
break;
case 101:
geometryFieldDataType = DataTypes.LINEAR_RING;
break;
case 0x80000000 + 1:
geometryFieldDataType = DataTypes.POINT;
axisCount = 3;
break;
case 0x80000000 + 2:
geometryFieldDataType = DataTypes.LINE_STRING;
axisCount = 3;
break;
case 0x80000000 + 3:
geometryFieldDataType = DataTypes.POLYGON;
axisCount = 3;
break;
case 0x80000000 + 4:
geometryFieldDataType = DataTypes.MULTI_POINT;
axisCount = 3;
break;
case 0x80000000 + 5:
geometryFieldDataType = DataTypes.MULTI_LINE_STRING;
axisCount = 3;
break;
case 0x80000000 + 6:
geometryFieldDataType = DataTypes.MULTI_POLYGON;
axisCount = 3;
break;
case 0x80000000 + 7:
geometryFieldDataType = DataTypes.GEOMETRY_COLLECTION;
axisCount = 3;
break;
default:
geometryFieldDataType = DataTypes.GEOMETRY;
break;
}
final SpatialReference spatialReference = fieldDefinition.GetSpatialRef();
final GeometryFactory geometryFactory = Gdal.getGeometryFactory(spatialReference, axisCount);
final FieldDefinition field = new FieldDefinition(fieldName, geometryFieldDataType, false);
field.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
recordDefinition.addField(field);
}
return recordDefinition;
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class GeometryTest method writeTestFile.
public static void writeTestFile(final GeometryFactory geometryFactory, final String wkt) {
final Geometry geometry = geometryFactory.geometry(wkt);
final DataType geometryDataType = DataTypes.getDataType(geometry);
String name = "/" + geometryDataType.getName();
if (geometryFactory.hasZ()) {
name += "Z";
}
final File file = new File("target/test-data/" + name + ".gdb");
FileUtil.deleteDirectory(file);
final PathName pathName = PathName.newPathName(name);
RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(pathName);
recordDefinition.addField("ID", DataTypes.INT, true);
final FieldDefinition geometryField = recordDefinition.addField("Geometry", geometryDataType, true);
geometryField.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
recordDefinition.setIdFieldName("ID");
final FileGdbRecordStore recordStore = FileGdbRecordStoreFactory.newRecordStore(file);
recordStore.initialize();
recordDefinition = (RecordDefinitionImpl) recordStore.getRecordDefinition(recordDefinition);
final Record object = new ArrayRecord(recordDefinition);
object.setIdentifier(Identifier.newIdentifier(1));
object.setGeometryValue(geometry);
recordStore.insertRecord(object);
final Record object2 = recordStore.getRecord(pathName, Identifier.newIdentifier(1));
if (!DataType.equal(object, object2)) {
System.out.println("Not Equal");
System.out.println(object);
System.out.println(object2);
}
recordStore.close();
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class DatabaseBeanConfigurator method postProcessBeanFactory.
@Override
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
try {
final boolean hasTypeColumnName = Property.hasValue(this.typeColumnName);
String sql = "SELECT " + this.propertyColumnName + ", " + this.valueColumnName;
if (hasTypeColumnName) {
sql += ", " + this.typeColumnName;
}
sql += " FROM " + JdbcUtils.getQualifiedTableName(this.tableName);
if (Property.hasValue(this.whereClause)) {
sql += " WHERE " + this.whereClause;
}
final Connection connection = this.dataSource.getConnection();
try {
final PreparedStatement statement = connection.prepareStatement(sql);
try {
final ResultSet resultSet = statement.executeQuery();
try {
while (resultSet.next()) {
final String property = resultSet.getString(1);
final String valueString = resultSet.getString(2);
String typePath = "string";
if (hasTypeColumnName) {
typePath = resultSet.getString(3);
}
final DataType dataType = DataTypes.getDataType(typePath);
Object value = valueString;
if (dataType != null) {
value = dataType.toObject(valueString);
}
setAttribute(property, value);
}
} finally {
JdbcUtils.close(resultSet);
}
} finally {
JdbcUtils.close(statement);
}
} finally {
JdbcUtils.release(connection, this.dataSource);
}
} catch (final Throwable e) {
Logs.error(this, "Unable to load configuration from database ", e);
} finally {
super.postProcessBeanFactory(beanFactory);
}
}
Aggregations