use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class AddDefaultValuesProcess method setDefaultValue.
private void setDefaultValue(final Record record, final String key, final Object value) {
final int dotIndex = key.indexOf('.');
if (dotIndex == -1) {
if (record.getValue(key) == null && !this.excludedFieldNames.contains(key)) {
log.info("Adding attribute " + key + "=" + value);
record.setValue(key, value);
}
} else {
final String fieldName = key.substring(0, dotIndex);
NDC.push(" -> " + fieldName);
try {
final String subKey = key.substring(dotIndex + 1);
final Object attributeValue = record.getValue(fieldName);
if (attributeValue == null) {
final RecordDefinition type = record.getRecordDefinition();
final int attrIndex = type.getFieldIndex(fieldName);
final DataType dataType = type.getFieldType(attrIndex);
final Class<?> typeClass = dataType.getJavaClass();
if (typeClass == Record.class) {
final RecordDefinition subClass = this.recordDefinitionFactory.getRecordDefinition(dataType.getName());
final Record subObject = subClass.newRecord();
setDefaultValue(subObject, subKey, value);
record.setValue(fieldName, subObject);
process(subObject);
}
} else if (attributeValue instanceof Record) {
final Record subObject = (Record) attributeValue;
setDefaultValue(subObject, subKey, value);
} else if (!fieldName.equals(record.getRecordDefinition().getGeometryFieldName())) {
log.error("Attribute '" + fieldName + "' must be a Record");
}
} finally {
NDC.pop();
}
}
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class OracleSdoGeometryFieldAdder method newField.
@Override
public JdbcFieldDefinition newField(final AbstractJdbcRecordStore recordStore, final JdbcRecordDefinition recordDefinition, final String dbName, final String name, final String dbDataType, final int sqlType, final int length, final int scale, final boolean required, final String description) {
final PathName typePath = recordDefinition.getPathName();
final String columnName = name.toUpperCase();
final RecordStoreSchema schema = recordDefinition.getSchema();
GeometryFactory geometryFactory = getColumnProperty(schema, typePath, columnName, GEOMETRY_FACTORY);
if (geometryFactory == null) {
geometryFactory = schema.getGeometryFactory();
}
if (geometryFactory == null) {
geometryFactory = GeometryFactory.DEFAULT_2D;
}
DataType dataType = getColumnProperty(schema, typePath, columnName, GEOMETRY_TYPE);
if (dataType == null) {
dataType = DataTypes.GEOMETRY;
}
int axisCount = getIntegerColumnProperty(schema, typePath, columnName, AXIS_COUNT);
if (axisCount == -1) {
axisCount = geometryFactory.getAxisCount();
}
int oracleSrid = getIntegerColumnProperty(schema, typePath, columnName, ORACLE_SRID);
if (oracleSrid == -1) {
oracleSrid = 0;
}
final OracleSdoGeometryJdbcFieldDefinition field = new OracleSdoGeometryJdbcFieldDefinition(dbName, name, dataType, sqlType, required, description, null, geometryFactory, axisCount, oracleSrid);
field.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
return field;
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class PostgreSQLRecordStore method addField.
@Override
protected JdbcFieldDefinition addField(final JdbcRecordDefinition recordDefinition, final String dbColumnName, final String name, final String dbDataType, final int sqlType, final int length, final int scale, final boolean required, final String description) {
final JdbcFieldDefinition field;
if (dbDataType.charAt(0) == '_') {
final String elementDbDataType = dbDataType.substring(1);
final JdbcFieldAdder fieldAdder = getFieldAdder(elementDbDataType);
final JdbcFieldDefinition elementField = fieldAdder.newField(this, recordDefinition, dbColumnName, name, elementDbDataType, sqlType, length, scale, required, description);
final DataType elementDataType = elementField.getDataType();
final CollectionDataType listDataType = new CollectionDataType("List" + elementDataType.getName(), List.class, elementDataType);
field = new PostgreSQLArrayFieldDefinition(dbColumnName, name, listDataType, sqlType, length, scale, required, description, elementField, getProperties());
recordDefinition.addField(field);
} else {
field = super.addField(recordDefinition, dbColumnName, name, dbDataType, sqlType, length, scale, required, description);
}
if (!dbColumnName.matches("[a-z_]+")) {
field.setQuoteName(true);
}
return field;
}
use of com.revolsys.datatype.DataType 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.datatype.DataType 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