use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class AbstractRecordReader method newRecordDefinition.
protected RecordDefinition newRecordDefinition(final String baseName, final List<String> fieldNames) throws IOException {
this.hasPointFields = Property.hasValue(this.pointXFieldName) && Property.hasValue(this.pointYFieldName);
if (this.hasPointFields) {
this.geometryType = DataTypes.POINT;
} else {
this.pointXFieldName = null;
this.pointYFieldName = null;
}
final List<FieldDefinition> fields = new ArrayList<>();
FieldDefinition geometryField = null;
for (final String fieldName : fieldNames) {
if (fieldName != null) {
DataType type;
int length = 0;
boolean isGeometryField = false;
if (fieldName.equalsIgnoreCase(this.geometryColumnName)) {
type = this.geometryType;
isGeometryField = true;
} else if ("GEOMETRY".equalsIgnoreCase(fieldName)) {
type = DataTypes.GEOMETRY;
isGeometryField = true;
} else if ("SHAPE".equalsIgnoreCase(fieldName)) {
type = DataTypes.GEOMETRY;
isGeometryField = true;
} else if ("GEOMETRYCOLLECTION".equalsIgnoreCase(fieldName) || "GEOMETRY_COLLECTION".equalsIgnoreCase(fieldName)) {
type = DataTypes.GEOMETRY_COLLECTION;
isGeometryField = true;
} else if ("POINT".equalsIgnoreCase(fieldName)) {
type = DataTypes.POINT;
isGeometryField = true;
} else if ("MULTI_POINT".equalsIgnoreCase(fieldName) || "MULTIPOINT".equalsIgnoreCase(fieldName)) {
type = DataTypes.MULTI_POINT;
isGeometryField = true;
} else if ("LINE_STRING".equalsIgnoreCase(fieldName) || "LINESTRING".equalsIgnoreCase(fieldName) || "LINE".equalsIgnoreCase(fieldName)) {
type = DataTypes.LINE_STRING;
isGeometryField = true;
} else if ("MULTI_LINESTRING".equalsIgnoreCase(fieldName) || "MULTILINESTRING".equalsIgnoreCase(fieldName) || "MULTILINE".equalsIgnoreCase(fieldName) || "MULTI_LINE".equalsIgnoreCase(fieldName)) {
type = DataTypes.MULTI_LINE_STRING;
isGeometryField = true;
} else if ("POLYGON".equalsIgnoreCase(fieldName)) {
type = DataTypes.POLYGON;
isGeometryField = true;
} else if ("MULTI_POLYGON".equalsIgnoreCase(fieldName) || "MULTIPOLYGON".equalsIgnoreCase(fieldName)) {
type = DataTypes.MULTI_POLYGON;
isGeometryField = true;
} else {
type = DataTypes.STRING;
length = 4000;
}
final FieldDefinition field;
if (isGeometryField) {
field = new GeometryFieldDefinition(this.geometryFactory, fieldName, type, false);
geometryField = field;
} else {
field = new FieldDefinition(fieldName, type, length, false);
}
fields.add(field);
}
}
if (this.hasPointFields) {
if (geometryField == null) {
geometryField = new FieldDefinition(this.geometryColumnName, this.geometryType, true);
fields.add(geometryField);
}
}
if (geometryField != null) {
geometryField.setProperty(FieldProperties.GEOMETRY_FACTORY, this.geometryFactory);
}
final RecordStoreSchema schema = getProperty("schema");
String typePath = getProperty("typePath");
if (!Property.hasValue(typePath)) {
typePath = "/" + baseName;
String schemaPath = getProperty("schemaPath");
if (Property.hasValue(schemaPath)) {
if (!schemaPath.startsWith("/")) {
schemaPath = "/" + schemaPath;
}
typePath = schemaPath + typePath;
}
}
final PathName pathName = PathName.newPathName(typePath);
this.recordDefinition = new RecordDefinitionImpl(schema, pathName, getProperties(), fields);
return this.recordDefinition;
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class EsriXmlRecordDefinitionUtil method getRecordDefinition.
public static RecordDefinition getRecordDefinition(final String schemaName, final DETable deTable, final boolean ignoreEsriFields) {
final String tableName = deTable.getName();
final PathName typePath = PathName.newPathName(PathUtil.toPath(schemaName, tableName));
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(typePath);
final List<String> ignoreFieldNames = new ArrayList<>();
if (ignoreEsriFields) {
ignoreFieldNames.add(deTable.getOIDFieldName());
if (deTable instanceof DEFeatureClass) {
final DEFeatureClass featureClass = (DEFeatureClass) deTable;
ignoreFieldNames.add(featureClass.getLengthFieldName());
ignoreFieldNames.add(featureClass.getAreaFieldName());
}
}
for (final Field field : deTable.getFields()) {
final String fieldName = field.getName();
if (!ignoreFieldNames.contains(fieldName)) {
addField(recordDefinition, deTable, tableName, field, fieldName);
}
}
for (final Index index : deTable.getIndexes()) {
final String indexName = index.getName();
if (indexName.endsWith("_PK")) {
final List<Field> indexFields = index.getFields();
final Field indexField = CollectionUtil.get(indexFields, 0);
final String idName = indexField.getName();
recordDefinition.setIdFieldName(idName);
}
}
if (deTable instanceof DEFeatureClass) {
final DEFeatureClass featureClass = (DEFeatureClass) deTable;
final String shapeFieldName = featureClass.getShapeFieldName();
recordDefinition.setGeometryFieldName(shapeFieldName);
final SpatialReference spatialReference = featureClass.getSpatialReference();
GeometryFactory geometryFactory = spatialReference.getGeometryFactory();
int axisCount = 2;
if (featureClass.isHasM()) {
axisCount = 4;
} else if (featureClass.isHasZ()) {
axisCount = 3;
}
final double[] scales = geometryFactory.newScales(axisCount);
geometryFactory = GeometryFactory.fixed(geometryFactory.getCoordinateSystemId(), axisCount, scales);
final FieldDefinition geometryField = recordDefinition.getGeometryField();
geometryField.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
}
return recordDefinition;
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class ListRecordLayer method newRecordDefinition.
public static RecordDefinitionImpl newRecordDefinition(final String name, final GeometryFactory geometryFactory, final DataType geometryType) {
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(PathName.newPathName(name));
recordDefinition.addField("GEOMETRY", geometryType, true);
recordDefinition.setGeometryFactory(geometryFactory);
return recordDefinition;
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class RecordLog method getLogRecordDefinition.
public RecordDefinition getLogRecordDefinition(final RecordDefinition recordDefinition) {
RecordDefinitionImpl logRecordDefinition = this.logRecordDefinitionMap.get(recordDefinition);
if (logRecordDefinition == null) {
final String path = recordDefinition.getPath();
final String parentPath = PathUtil.getPath(path);
final String tableName = PathUtil.getName(path);
final String logTableName;
if (tableName.toUpperCase().equals(tableName)) {
logTableName = tableName + "_LOG";
} else {
logTableName = tableName + "_log";
}
final PathName logTypeName = PathName.newPathName(PathUtil.toPath(parentPath, logTableName));
logRecordDefinition = new RecordDefinitionImpl(logTypeName);
if (this.usesLocality) {
logRecordDefinition.addField(LOG_LOCALITY, DataTypes.STRING, 255, false);
}
logRecordDefinition.addField(LOG_MESSAGE, DataTypes.STRING, 255, true);
for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
final FieldDefinition logFieldDefinition = new FieldDefinition(fieldDefinition);
final DataType dataType = logFieldDefinition.getDataType();
if (recordDefinition.getGeometryField() == fieldDefinition) {
logRecordDefinition.addField("GEOMETRY", dataType);
} else {
logRecordDefinition.addField(new FieldDefinition(fieldDefinition));
}
}
logRecordDefinition.setGeometryFactory(recordDefinition.getGeometryFactory());
this.logRecordDefinitionMap.put(recordDefinition, logRecordDefinition);
}
return logRecordDefinition;
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class DirectoryRecordStore method getRecordDefinition.
@Override
public RecordDefinition getRecordDefinition(final RecordDefinition recordDefinition) {
final RecordDefinition storeRecordDefinition = super.getRecordDefinition(recordDefinition);
if (storeRecordDefinition == null && this.createMissingTables) {
final PathName typePath = recordDefinition.getPathName();
final PathName schemaPath = typePath.getParent();
RecordStoreSchema schema = getSchema(schemaPath);
if (schema == null && this.createMissingTables) {
final RecordStoreSchema rootSchema = getRootSchema();
schema = rootSchema.newSchema(schemaPath);
}
final File schemaDirectory = new File(this.directory, schemaPath.getPath());
if (!schemaDirectory.exists()) {
schemaDirectory.mkdirs();
}
final RecordDefinitionImpl newRecordDefinition = new RecordDefinitionImpl(schema, typePath);
for (final FieldDefinition field : recordDefinition.getFields()) {
final FieldDefinition newField = new FieldDefinition(field);
newRecordDefinition.addField(newField);
}
schema.addElement(newRecordDefinition);
return newRecordDefinition;
}
return storeRecordDefinition;
}
Aggregations