use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class XbaseSchemaReader method getRecordDefinition.
protected RecordDefinition getRecordDefinition() throws IOException {
if (this.recordDefinition == null) {
this.recordDefinition = new RecordDefinitionImpl(this.typePath);
int b = this.in.read();
while (b != 0x0D) {
final StringBuilder fieldName = new StringBuilder();
boolean endOfName = false;
for (int i = 0; i < 11; i++) {
if (!endOfName && b != 0) {
fieldName.append((char) b);
} else {
endOfName = true;
}
if (i != 10) {
b = this.in.read();
}
}
final char fieldType = (char) this.in.read();
this.in.skipBytes(4);
final int length = this.in.read();
this.in.skipBytes(15);
b = this.in.read();
final XBaseFieldDefinition field = new XBaseFieldDefinition(fieldName.toString(), fieldName.toString(), fieldType, length);
if (this.fieldDefinitions != null) {
this.fieldDefinitions.add(field);
}
this.recordDefinition.addField(fieldName.toString(), field.getDataType(), length, true);
}
}
return this.recordDefinition;
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class XbaseIterator method readRecordDefinition.
private void readRecordDefinition() throws IOException {
this.recordDefinition = new RecordDefinitionImpl(this.typeName);
int b = this.in.read();
while (b != 0x0D) {
final StringBuilder fieldName = new StringBuilder();
boolean endOfName = false;
for (int i = 0; i < 11; i++) {
if (!endOfName && b != 0) {
fieldName.append((char) b);
} else {
endOfName = true;
}
if (i != 10) {
b = this.in.read();
}
}
final char fieldType = (char) this.in.read();
this.in.skipBytes(4);
int length = this.in.read();
final int decimalCount = this.in.read();
this.in.skipBytes(14);
b = this.in.read();
final DataType dataType = DATA_TYPES.get(fieldType);
if (fieldType == MEMO_TYPE) {
length = Integer.MAX_VALUE;
}
this.recordDefinition.addField(fieldName.toString(), dataType, length, decimalCount, false);
}
if (this.mappedFile) {
final EndianMappedByteBuffer file = (EndianMappedByteBuffer) this.in;
this.firstIndex = file.getFilePointer();
}
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class XbaseRecordReader method readRecordDefinition.
private void readRecordDefinition() throws IOException {
this.recordDefinition = new RecordDefinitionImpl(this.typeName);
if (this.exists) {
int readCount = Buffers.readAll(this.in, this.buffer1);
if (readCount == -1) {
throw new RuntimeException("Unexpected end of file: " + this.resource);
}
final ByteBuffer fieldHeaderBuffer = ByteBuffer.allocate(31);
int b = this.buffer1.get();
while (b != 0x0D) {
this.buffer1.clear();
readCount = Buffers.readAll(this.in, fieldHeaderBuffer);
if (readCount != 31) {
throw new RuntimeException("Unexpected end of file: " + this.resource);
}
final StringBuilder fieldName = new StringBuilder();
boolean endOfName = false;
for (int i = 0; i < 11; i++) {
if (!endOfName && b != 0) {
fieldName.append((char) b);
} else {
endOfName = true;
}
if (i != 10) {
b = fieldHeaderBuffer.get();
}
}
final char fieldType = (char) fieldHeaderBuffer.get();
fieldHeaderBuffer.getInt();
int length = fieldHeaderBuffer.get() & 0xFF;
final int decimalCount = fieldHeaderBuffer.get();
fieldHeaderBuffer.clear();
readCount = Buffers.readAll(this.in, this.buffer1);
if (readCount == -1) {
throw new RuntimeException("Unexpected end of file: " + this.resource);
}
b = this.buffer1.get();
final DataType dataType = DATA_TYPES.get(fieldType);
if (fieldType == MEMO_TYPE) {
length = Integer.MAX_VALUE;
}
this.recordDefinition.addField(fieldName.toString(), dataType, length, decimalCount, false);
}
}
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class ShapefileRecordReader method updateRecordDefinition.
private void updateRecordDefinition() {
assert this.recordDefinition == null : "Cannot override recordDefinition when set";
if (this.xbaseRecordReader != null) {
final RecordDefinitionImpl recordDefinition = this.xbaseRecordReader.getRecordDefinition();
recordDefinition.setPolygonRingDirection(ClockDirection.CLOCKWISE);
this.recordDefinition = recordDefinition;
if (recordDefinition.getGeometryFieldIndex() == -1) {
DataType geometryType = DataTypes.GEOMETRY;
switch(this.shapeType) {
case ShapefileConstants.POINT_SHAPE:
case ShapefileConstants.POINT_Z_SHAPE:
case ShapefileConstants.POINT_M_SHAPE:
case ShapefileConstants.POINT_ZM_SHAPE:
geometryType = DataTypes.POINT;
break;
case ShapefileConstants.POLYLINE_SHAPE:
case ShapefileConstants.POLYLINE_Z_SHAPE:
case ShapefileConstants.POLYLINE_M_SHAPE:
case ShapefileConstants.POLYLINE_ZM_SHAPE:
geometryType = DataTypes.MULTI_LINE_STRING;
break;
case ShapefileConstants.POLYGON_SHAPE:
case ShapefileConstants.POLYGON_Z_SHAPE:
case ShapefileConstants.POLYGON_M_SHAPE:
case ShapefileConstants.POLYGON_ZM_SHAPE:
geometryType = DataTypes.MULTI_POLYGON;
break;
case ShapefileConstants.MULTI_POINT_SHAPE:
case ShapefileConstants.MULTI_POINT_Z_SHAPE:
case ShapefileConstants.MULTI_POINT_M_SHAPE:
case ShapefileConstants.MULTI_POINT_ZM_SHAPE:
geometryType = DataTypes.MULTI_POINT;
break;
default:
break;
}
recordDefinition.addField("geometry", geometryType, true);
}
}
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method newTableRecordDefinition.
private RecordDefinitionImpl newTableRecordDefinition(final DETable deTable) {
synchronized (this.apiSync) {
synchronized (API_SYNC) {
final Geodatabase geodatabase = getGeodatabase();
if (geodatabase == null) {
return null;
} else {
try {
String schemaCatalogPath = deTable.getParentCatalogPath();
SpatialReference spatialReference;
if (deTable instanceof DEFeatureClass) {
final DEFeatureClass featureClass = (DEFeatureClass) deTable;
spatialReference = featureClass.getSpatialReference();
} else {
spatialReference = null;
}
PathName schemaPath = toPath(schemaCatalogPath);
final RecordStoreSchema schema = newSchema(schemaPath, spatialReference);
if (schemaPath.equals(this.defaultSchemaPath)) {
if (!(deTable instanceof DEFeatureClass)) {
schemaCatalogPath = "\\";
deTable.setCatalogPath("\\" + deTable.getName());
}
} else if (schemaPath.equals("")) {
schemaPath = this.defaultSchemaPath;
}
for (final Field field : deTable.getFields()) {
final String fieldName = field.getName();
final CodeTable codeTable = getCodeTableByFieldName(fieldName);
if (codeTable instanceof FileGdbDomainCodeTable) {
final FileGdbDomainCodeTable domainCodeTable = (FileGdbDomainCodeTable) codeTable;
field.setDomain(domainCodeTable.getDomain());
}
}
final String tableDefinition = EsriGdbXmlSerializer.toString(deTable);
try {
final Table table = geodatabase.createTable(tableDefinition, schemaCatalogPath);
geodatabase.closeTable(table);
table.delete();
final RecordDefinitionImpl recordDefinition = getRecordDefinition(PathName.newPathName(schemaPath), schemaCatalogPath, tableDefinition);
initRecordDefinition(recordDefinition);
schema.addElement(recordDefinition);
return recordDefinition;
} catch (final Throwable t) {
throw new RuntimeException("Unable to create table " + deTable.getCatalogPath(), t);
}
} finally {
releaseGeodatabase();
}
}
}
}
}
Aggregations