use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class OracleDdlWriter method writeGeometryRecordDefinition.
@Override
public void writeGeometryRecordDefinition(final RecordDefinition recordDefinition) {
final PrintWriter out = getOut();
final String typePath = recordDefinition.getPath();
final String schemaName = JdbcUtils.getSchemaName(typePath);
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();
final int axisCount = geometryFactory.getAxisCount();
final DataType dataType = geometryField.getDataType();
final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
final int srid = coordinateSystem.getCoordinateSystemId();
out.print("INSERT INTO USER_SDO_GEOM_METADATA(TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES('");
out.print(tableName.toUpperCase());
out.print("','");
out.print(name.toUpperCase());
// TODO get from geometry factory
out.print("',MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X', 263000, 1876000, 0.001),MDSYS.SDO_DIM_ELEMENT('Y', 356000, 1738000, 0.001)");
if (axisCount > 2) {
out.print(",MDSYS.SDO_DIM_ELEMENT('Z',-2500, 5000, 0.001)");
}
out.print("),");
out.println("3005);");
final int geometryType = OracleSdoGeometryFieldAdder.getGeometryTypeId(dataType, axisCount);
out.print("INSERT INTO OGIS_GEOMETRY_COLUMNS(F_TABLE_SCHEMA,F_TABLE_NAME,F_GEOMETRY_COLUMN,G_TABLE_SCHEMA,G_TABLE_NAME,GEOMETRY_TYPE,COORD_DIMENSION,SRID) VALUES ('");
out.print(schemaName.toUpperCase());
out.print("', '");
out.print(tableName.toUpperCase());
out.print("','");
out.print(name.toUpperCase());
out.print("', '");
out.print(schemaName.toUpperCase());
out.print("', '");
out.print(tableName.toUpperCase());
out.print("',");
out.print(geometryType);
out.print(",");
out.print(axisCount);
out.print(",");
out.print("100");
out.print(srid);
out.println(");");
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class OracleJdbcQueryResultPager method updateResults.
/**
* Update the cached results for the current page.
*/
@Override
protected void updateResults() {
synchronized (this) {
final JdbcRecordStore recordStore = getRecordStore();
final Query query = getQuery();
setNumResults(recordStore.getRecordCount(query));
updateNumPages();
final ArrayList<Record> results = new ArrayList<>();
final int pageSize = getPageSize();
final int pageNumber = getPageNumber();
if (pageNumber != -1) {
String sql = getSql();
final int startRowNum = (pageNumber - 1) * pageSize + 1;
final int endRowNum = startRowNum + pageSize - 1;
sql = "SELECT * FROM ( SELECT T2.*, ROWNUM TROWNUM FROM ( " + sql + ") T2 ) WHERE TROWNUM BETWEEN " + startRowNum + " AND " + endRowNum;
try (final JdbcConnection connection = getRecordStore().getJdbcConnection()) {
final RecordFactory<Record> recordFactory = getRecordFactory();
final RecordDefinition recordDefinition = getRecordDefinition();
final List<FieldDefinition> attributes = new ArrayList<>();
final List<String> fieldNames = query.getFieldNames();
if (fieldNames.isEmpty()) {
attributes.addAll(recordDefinition.getFields());
} else {
for (final String fieldName : fieldNames) {
if (fieldName.equals("*")) {
attributes.addAll(recordDefinition.getFields());
} else {
final FieldDefinition attribute = recordDefinition.getField(fieldName);
if (attribute != null) {
attributes.add(attribute);
}
}
}
}
try (final PreparedStatement statement = connection.prepareStatement(sql);
final ResultSet resultSet = JdbcQueryIterator.getResultSet(statement, getQuery())) {
if (resultSet.next()) {
int i = 0;
do {
final Record record = JdbcQueryIterator.getNextRecord(recordStore, recordDefinition, attributes, recordFactory, resultSet, this.internStrings);
results.add(record);
i++;
} while (resultSet.next() && i < pageSize);
}
} catch (final SQLException e) {
throw connection.getException("updateResults", sql, e);
}
}
setResults(results);
}
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class PostgreSQLRecordStore method insertStatementPrepareRowId.
@Override
public PreparedStatement insertStatementPrepareRowId(final JdbcConnection connection, final RecordDefinition recordDefinition, final String sql) throws SQLException {
final List<FieldDefinition> idFields = recordDefinition.getIdFields();
final String[] idColumnNames = new String[idFields.size()];
for (int i = 0; i < idFields.size(); i++) {
final FieldDefinition idField = idFields.get(0);
final String columnName = ((JdbcFieldDefinition) idField).getDbName();
idColumnNames[i] = columnName;
}
return connection.prepareStatement(sql, idColumnNames);
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class OgrRecordStore method getSql.
protected String getSql(final Query query) {
final RecordDefinition recordDefinition = query.getRecordDefinition();
final String typePath = recordDefinition.getPath();
final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
final StringBuilder sql = new StringBuilder();
sql.append("SELECT ");
List<String> fieldNames = query.getFieldNames();
if (fieldNames.isEmpty()) {
fieldNames = recordDefinition.getFieldNames();
}
fieldNames.remove("ROWID");
StringBuilders.append(sql, fieldNames);
sql.append(" FROM ");
final String layerName = getLayerName(typePath);
sql.append(layerName);
final StringBuilder whereClause = getWhereClause(query);
if (whereClause.length() > 0) {
sql.append(" WHERE ");
sql.append(whereClause);
}
boolean first = true;
for (final Entry<? extends CharSequence, Boolean> entry : orderBy.entrySet()) {
final CharSequence fieldName = entry.getKey();
if (first) {
sql.append(" ORDER BY ");
first = false;
} else {
sql.append(", ");
}
if (fieldName instanceof FieldDefinition) {
final FieldDefinition field = (FieldDefinition) fieldName;
field.appendColumnName(sql);
} else {
sql.append(fieldName);
}
final Boolean ascending = entry.getValue();
if (!ascending) {
sql.append(" DESC");
}
}
return sql.toString();
}
use of com.revolsys.record.schema.FieldDefinition 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;
}
Aggregations