use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class Query method addFilter.
private static void addFilter(final Query query, final RecordDefinition recordDefinition, final Map<String, ?> filter, final AbstractMultiCondition multipleCondition) {
if (filter != null && !filter.isEmpty()) {
for (final Entry<String, ?> entry : filter.entrySet()) {
final String name = entry.getKey();
final FieldDefinition fieldDefinition = recordDefinition.getField(name);
if (fieldDefinition == null) {
final Object value = entry.getValue();
if (value == null) {
multipleCondition.addCondition(Q.isNull(name));
} else if (value instanceof Collection) {
final Collection<?> values = (Collection<?>) value;
multipleCondition.addCondition(new In(name, values));
} else {
multipleCondition.addCondition(Q.equal(name, value));
}
} else {
final Object value = entry.getValue();
if (value == null) {
multipleCondition.addCondition(Q.isNull(name));
} else if (value instanceof Collection) {
final Collection<?> values = (Collection<?>) value;
multipleCondition.addCondition(new In(fieldDefinition, values));
} else {
multipleCondition.addCondition(Q.equal(fieldDefinition, value));
}
}
}
query.setWhereCondition(multipleCondition);
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class GeoPackageRecordStore method refreshSchemaElementsDo.
@Override
protected Map<PathName, ? extends RecordStoreSchemaElement> refreshSchemaElementsDo(final JdbcRecordStoreSchema schema, final PathName schemaPath) {
final String schemaName = schema.getPath();
final Map<String, String> tableDescriptionMap = new HashMap<>();
final Map<String, List<String>> tablePermissionsMap = new TreeMap<>();
final Map<PathName, JdbcRecordDefinition> recordDefinitionMap = loadRecordDefinitionsPermissions(schema);
final Map<PathName, RecordStoreSchemaElement> elementsByPath = new TreeMap<>();
try {
try (final Connection connection = getJdbcConnection()) {
for (final JdbcRecordDefinition recordDefinition : recordDefinitionMap.values()) {
final PathName typePath = recordDefinition.getPathName();
elementsByPath.put(typePath, recordDefinition);
}
for (final JdbcRecordDefinition recordDefinition : recordDefinitionMap.values()) {
final String tableName = recordDefinition.getDbTableName();
final List<String> idFieldNames = new ArrayList<>();
try (PreparedStatement columnStatement = connection.prepareStatement("PRAGMA table_info(" + tableName + ")")) {
try (final ResultSet columnsRs = columnStatement.executeQuery()) {
while (columnsRs.next()) {
final String dbColumnName = columnsRs.getString("name");
final String fieldName = dbColumnName.toUpperCase();
final int sqlType = Types.OTHER;
String dataType = columnsRs.getString("type");
int length = -1;
final int scale = -1;
if (dataType.startsWith("TEXT(")) {
length = Integer.parseInt(dataType.substring(5, dataType.length() - 1));
dataType = "TEXT";
}
final boolean required = columnsRs.getString("notnull").equals("1");
final boolean primaryKey = columnsRs.getString("pk").equals("1");
if (primaryKey) {
idFieldNames.add(fieldName);
}
final Object defaultValue = columnsRs.getString("dflt_value");
final FieldDefinition field = addField(recordDefinition, dbColumnName, fieldName, dataType, sqlType, length, scale, required, null);
field.setDefaultValue(defaultValue);
}
}
}
recordDefinition.setIdFieldNames(idFieldNames);
}
}
} catch (final Throwable e) {
throw new IllegalArgumentException("Unable to load metadata for schema " + schemaName, e);
}
return elementsByPath;
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class OracleRecordStore method appendEnvelopeIntersects.
private void appendEnvelopeIntersects(final Query query, final StringBuilder sql, final EnvelopeIntersects envelopeIntersects) {
final FieldDefinition geometryField = query.getGeometryField();
if (geometryField instanceof OracleSdoGeometryJdbcFieldDefinition) {
sql.append("SDO_RELATE(");
final QueryValue boundingBox1Value = envelopeIntersects.getBoundingBox1Value();
if (boundingBox1Value == null) {
sql.append("NULL");
} else {
boundingBox1Value.appendSql(query, this, sql);
}
sql.append(",");
final QueryValue boundingBox2Value = envelopeIntersects.getBoundingBox2Value();
if (boundingBox2Value == null) {
sql.append("NULL");
} else {
boundingBox2Value.appendSql(query, this, sql);
}
sql.append(",'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'");
} else if (geometryField instanceof ArcSdeStGeometryFieldDefinition) {
sql.append("SDE.ST_ENVINTERSECTS(");
final QueryValue boundingBox1Value = envelopeIntersects.getBoundingBox1Value();
if (boundingBox1Value == null) {
sql.append("NULL");
} else {
boundingBox1Value.appendSql(query, this, sql);
}
sql.append(",");
final QueryValue boundingBox2Value = envelopeIntersects.getBoundingBox2Value();
if (boundingBox2Value == null) {
sql.append("NULL");
} else {
boundingBox2Value.appendSql(query, this, sql);
}
sql.append(") = 1");
} 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 OracleRecordStore method appendGeometryEqual2d.
private void appendGeometryEqual2d(final Query query, final StringBuilder sql, final GeometryEqual2d equals) {
final FieldDefinition geometryField = query.getGeometryField();
if (geometryField instanceof OracleSdoGeometryJdbcFieldDefinition) {
sql.append("MDSYS.SDO_EQUAL(");
final QueryValue geometry1Value = equals.getGeometry1Value();
if (geometry1Value == null) {
sql.append("NULL");
} else {
geometry1Value.appendSql(query, this, sql);
}
sql.append(",");
final QueryValue geometry2Value = equals.getGeometry2Value();
if (geometry2Value == null) {
sql.append("NULL");
} else {
geometry2Value.appendSql(query, this, sql);
}
sql.append(") = 'TRUE'");
} else if (geometryField instanceof ArcSdeStGeometryFieldDefinition) {
sql.append("SDE.ST_EQUALS(");
final QueryValue geometry1Value = equals.getGeometry1Value();
if (geometry1Value == null) {
sql.append("NULL");
} else {
geometry1Value.appendSql(query, this, sql);
}
sql.append(",");
final QueryValue geometry2Value = equals.getGeometry2Value();
if (geometry2Value == null) {
sql.append("NULL");
} else {
geometry2Value.appendSql(query, this, sql);
}
sql.append(") = 1");
} 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 OracleDdlWriter 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