use of com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType in project com.revolsys.open by revolsys.
the class EsriXmlRecordDefinitionUtil method addField.
private static void addField(final RecordDefinitionImpl recordDefinition, final DETable deTable, final String tableName, final Field field, final String fieldName) {
final FieldType fieldType = field.getType();
final int precision = field.getPrecision();
final DataType dataType;
if (fieldType == FieldType.esriFieldTypeGeometry && deTable instanceof DEFeatureClass) {
final DEFeatureClass featureClass = (DEFeatureClass) deTable;
final GeometryType shapeType = featureClass.getShapeType();
switch(shapeType) {
case esriGeometryPoint:
dataType = DataTypes.POINT;
break;
case esriGeometryMultipoint:
dataType = DataTypes.MULTI_POINT;
break;
case esriGeometryPolyline:
dataType = DataTypes.MULTI_LINE_STRING;
break;
case esriGeometryPolygon:
dataType = DataTypes.POLYGON;
break;
default:
throw new RuntimeException("Unknown geometry type" + shapeType + " for " + tableName + "." + fieldName);
}
} else if (precision > 0 && (fieldType.equals(FieldType.esriFieldTypeSingle) || fieldType.equals(FieldType.esriFieldTypeDouble))) {
dataType = DataTypes.DECIMAL;
} else {
dataType = EsriGeodatabaseXmlFieldTypeRegistry.INSTANCE.getDataType(fieldType);
}
final int scale = field.getScale();
int length = field.getLength();
if (precision != 0) {
length = precision;
}
final Boolean required = !field.isIsNullable() || Booleans.getBoolean(field.getRequired());
final FieldDefinition attribute = new FieldDefinition(fieldName, dataType, length, scale, required);
recordDefinition.addField(attribute);
if (fieldName.equals(tableName + "_ID")) {
recordDefinition.setIdFieldName(fieldName);
}
}
use of com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType in project com.revolsys.open by revolsys.
the class EsriXmlRecordDefinitionUtil method getRecordDefinition.
public static RecordDefinition getRecordDefinition(final String schemaName, final Domain domain, final boolean appendIdToName) {
final String tableName;
if (appendIdToName) {
tableName = domain.getName() + "_ID";
} else {
tableName = domain.getName();
}
final PathName typePath = PathName.newPathName(PathUtil.toPath(schemaName, tableName));
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(typePath);
final FieldType fieldType = domain.getFieldType();
final DataType dataType = EsriGeodatabaseXmlFieldTypeRegistry.INSTANCE.getDataType(fieldType);
int length = 0;
for (final CodedValue codedValue : domain.getCodedValues()) {
length = Math.max(length, codedValue.getCode().toString().length());
}
recordDefinition.addField(tableName, dataType, length, true);
recordDefinition.addField("DESCRIPTION", DataTypes.STRING, 255, true);
recordDefinition.setIdFieldIndex(0);
return recordDefinition;
}
use of com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType in project com.revolsys.open by revolsys.
the class FeatureLayer method addField.
private void addField(final RecordDefinitionImpl recordDefinition, final String geometryType, final MapEx field) {
final String fieldName = field.getString("name");
final String fieldTitle = field.getString("string");
final String fieldType = field.getString("type");
final FieldType esriFieldType = FieldType.valueOf(fieldType);
final DataType dataType;
if (esriFieldType == FieldType.esriFieldTypeGeometry) {
final DataType geometryDataType = getGeometryDataType(geometryType);
if (geometryDataType == null) {
throw new IllegalArgumentException("No geometryType specified for " + getServiceUrl());
}
dataType = geometryDataType;
} else {
dataType = esriFieldType.getDataType();
}
if (dataType == null) {
throw new IllegalArgumentException("Unsupported field=" + fieldName + " type=" + dataType + " for " + getServiceUrl());
}
final int length = field.getInteger("length", 0);
final FieldDefinition fieldDefinition = recordDefinition.addField(fieldName, dataType, length, false);
fieldDefinition.setTitle(fieldTitle);
setCodeTable(fieldDefinition, field);
if (esriFieldType == FieldType.esriFieldTypeOID) {
recordDefinition.setIdFieldName(fieldName);
fieldDefinition.setRequired(true);
}
}
use of com.revolsys.record.io.format.esri.gdb.xml.model.enums.FieldType in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method getRecordDefinition.
public RecordDefinitionImpl getRecordDefinition(final PathName schemaName, final String path, final String tableDefinition) {
synchronized (this.apiSync) {
synchronized (API_SYNC) {
try {
final XmlProcessor parser = new EsriGdbXmlParser();
final DETable deTable = parser.process(tableDefinition);
final String tableName = deTable.getName();
final PathName typePath = PathName.newPathName(schemaName.newChild(tableName));
final RecordStoreSchema schema = getSchema(schemaName);
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(schema, typePath);
recordDefinition.setPolygonRingDirection(ClockDirection.CLOCKWISE);
String lengthFieldName = null;
String areaFieldName = null;
if (deTable instanceof DEFeatureClass) {
final DEFeatureClass featureClass = (DEFeatureClass) deTable;
lengthFieldName = featureClass.getLengthFieldName();
final LengthFieldName lengthFieldNameProperty = new LengthFieldName(lengthFieldName);
lengthFieldNameProperty.setRecordDefinition(recordDefinition);
areaFieldName = featureClass.getAreaFieldName();
final LengthFieldName areaFieldNameProperty = new LengthFieldName(areaFieldName);
areaFieldNameProperty.setRecordDefinition(recordDefinition);
}
for (final Field field : deTable.getFields()) {
final String fieldName = field.getName();
AbstractFileGdbFieldDefinition fieldDefinition = null;
if (fieldName.equals(lengthFieldName)) {
fieldDefinition = new LengthFieldDefinition(field);
} else if (fieldName.equals(areaFieldName)) {
fieldDefinition = new AreaFieldDefinition(field);
} else {
final FieldType type = field.getType();
final Constructor<? extends AbstractFileGdbFieldDefinition> fieldConstructor = ESRI_FIELD_TYPE_FIELD_DEFINITION_MAP.get(type);
if (fieldConstructor != null) {
try {
fieldDefinition = JavaBeanUtil.invokeConstructor(fieldConstructor, field);
} catch (final Throwable e) {
Logs.error(this, tableDefinition);
throw new RuntimeException("Error creating field for " + typePath + "." + field.getName() + " : " + field.getType(), e);
}
} else {
Logs.error(this, "Unsupported field type " + fieldName + ":" + type);
}
}
if (fieldDefinition != null) {
final Domain domain = field.getDomain();
if (domain != null) {
CodeTable codeTable = getCodeTable(domain.getDomainName() + "_ID");
if (codeTable == null) {
codeTable = new FileGdbDomainCodeTable(this, domain);
addCodeTable(codeTable);
}
fieldDefinition.setCodeTable(codeTable);
}
fieldDefinition.setRecordStore(this);
recordDefinition.addField(fieldDefinition);
if (fieldDefinition instanceof GlobalIdFieldDefinition) {
recordDefinition.setIdFieldName(fieldName);
}
}
}
final String oidFieldName = deTable.getOIDFieldName();
recordDefinition.setProperty(EsriGeodatabaseXmlConstants.ESRI_OBJECT_ID_FIELD_NAME, oidFieldName);
if (deTable instanceof DEFeatureClass) {
final DEFeatureClass featureClass = (DEFeatureClass) deTable;
final String shapeFieldName = featureClass.getShapeFieldName();
recordDefinition.setGeometryFieldName(shapeFieldName);
}
for (final Index index : deTable.getIndexes()) {
if (index.getName().endsWith("_PK")) {
for (final Field field : index.getFields()) {
final String fieldName = field.getName();
recordDefinition.setIdFieldName(fieldName);
}
}
}
addRecordDefinitionProperties(recordDefinition);
if (recordDefinition.getIdFieldIndex() == -1) {
recordDefinition.setIdFieldName(deTable.getOIDFieldName());
}
this.catalogPathByPath.put(typePath, deTable.getCatalogPath());
return recordDefinition;
} catch (final RuntimeException e) {
Logs.debug(this, tableDefinition);
throw e;
}
}
}
}
Aggregations