use of com.revolsys.record.Record in project com.revolsys.open by revolsys.
the class RecordStore method newRecordWithIdentifier.
default Record newRecordWithIdentifier(final RecordDefinition recordDefinition) {
final Record record = newRecord(recordDefinition);
if (record != null) {
final String idFieldName = recordDefinition.getIdFieldName();
if (Property.hasValue(idFieldName)) {
final PathName typePath = recordDefinition.getPathName();
final Identifier id = newPrimaryIdentifier(typePath);
record.setIdentifier(id);
}
}
return record;
}
use of com.revolsys.record.Record in project com.revolsys.open by revolsys.
the class TestUtil method doTestGeometry.
public static void doTestGeometry(final Class<?> clazz, final String file) {
boolean valid = true;
final Resource resource = new ClassPathResource(file, clazz);
try (Reader<Record> reader = RecordReader.newRecordReader(resource)) {
int i = 0;
for (final Record object : reader) {
final int srid = object.getInteger("srid");
final int axisCount = object.getInteger("axisCount");
final double scaleXy = object.getInteger("scaleXy");
final double scaleZ = object.getInteger("scaleZ");
final double[] scales = { scaleXy, scaleXy, scaleZ };
final GeometryFactory geometryFactory = GeometryFactory.fixed(srid, axisCount, scales);
final String wkt = object.getValue("wkt");
final Geometry geometry = geometryFactory.geometry(wkt);
valid &= equalsExpectedWkt(i, object, geometry);
final CoordinateSystem coordinateSystem = geometry.getCoordinateSystem();
GeometryFactory otherGeometryFactory;
if (coordinateSystem instanceof ProjectedCoordinateSystem) {
final ProjectedCoordinateSystem projectedCoordinateSystem = (ProjectedCoordinateSystem) coordinateSystem;
otherGeometryFactory = GeometryFactory.fixed(projectedCoordinateSystem.getCoordinateSystemId(), axisCount, scales);
} else {
otherGeometryFactory = GeometryFactory.fixed(3005, axisCount, scales);
}
final Geometry convertedGeometry = geometry.convertGeometry(otherGeometryFactory);
final Geometry convertedBackGeometry = convertedGeometry.convertGeometry(geometryFactory);
valid &= equalsExpectedGeometry(i, convertedBackGeometry, geometry);
i++;
}
}
if (!valid) {
Assert.fail("Has Errors");
}
}
use of com.revolsys.record.Record in project com.revolsys.open by revolsys.
the class OracleJdbcQueryResultPager method updateResults.
/**
* Update the cached results for the current page.
*/
@Override
protected void updateResults() {
synchronized (this) {
final JdbcRecordStore recordStore = getRecordStore();
final Query query = getQuery();
setNumResults(recordStore.getRecordCount(query));
updateNumPages();
final ArrayList<Record> results = new ArrayList<>();
final int pageSize = getPageSize();
final int pageNumber = getPageNumber();
if (pageNumber != -1) {
String sql = getSql();
final int startRowNum = (pageNumber - 1) * pageSize + 1;
final int endRowNum = startRowNum + pageSize - 1;
sql = "SELECT * FROM ( SELECT T2.*, ROWNUM TROWNUM FROM ( " + sql + ") T2 ) WHERE TROWNUM BETWEEN " + startRowNum + " AND " + endRowNum;
try (final JdbcConnection connection = getRecordStore().getJdbcConnection()) {
final RecordFactory<Record> recordFactory = getRecordFactory();
final RecordDefinition recordDefinition = getRecordDefinition();
final List<FieldDefinition> attributes = new ArrayList<>();
final List<String> fieldNames = query.getFieldNames();
if (fieldNames.isEmpty()) {
attributes.addAll(recordDefinition.getFields());
} else {
for (final String fieldName : fieldNames) {
if (fieldName.equals("*")) {
attributes.addAll(recordDefinition.getFields());
} else {
final FieldDefinition attribute = recordDefinition.getField(fieldName);
if (attribute != null) {
attributes.add(attribute);
}
}
}
}
try (final PreparedStatement statement = connection.prepareStatement(sql);
final ResultSet resultSet = JdbcQueryIterator.getResultSet(statement, getQuery())) {
if (resultSet.next()) {
int i = 0;
do {
final Record record = JdbcQueryIterator.getNextRecord(recordStore, recordDefinition, attributes, recordFactory, resultSet, this.internStrings);
results.add(record);
i++;
} while (resultSet.next() && i < pageSize);
}
} catch (final SQLException e) {
throw connection.getException("updateResults", sql, e);
}
}
setResults(results);
}
}
}
use of com.revolsys.record.Record in project com.revolsys.open by revolsys.
the class FileGdbIoTest method doWriteReadTest.
public static void doWriteReadTest(GeometryFactory geometryFactory, final DataType dataType, Geometry geometry) {
final int axisCount = geometryFactory.getAxisCount();
if (geometry.isEmpty() || axisCount == 4) {
return;
}
geometryFactory = GeometryFactory.fixed(geometryFactory.getCoordinateSystemId(), axisCount, GeometryFactory.newScalesFixed(axisCount, 10000000.0));
geometry = geometry.convertGeometry(geometryFactory);
final String geometryTypeString = dataType.toString();
String name = "/tmp/revolsystest/io/gdb/" + geometryTypeString + "_" + axisCount;
if (geometry.isGeometryCollection()) {
name += "_" + geometry.getGeometryCount();
}
if (geometry instanceof Polygonal) {
name += "_" + geometry.getGeometryComponents(LinearRing.class).size();
}
final File file = new File(name + "_" + geometry.getVertexCount() + ".gdb");
FileUtil.deleteDirectory(file);
file.getParentFile().mkdirs();
try (final FileGdbRecordStore recordStore = FileGdbRecordStoreFactory.newRecordStore(file)) {
recordStore.setCreateMissingTables(true);
recordStore.setCreateMissingRecordStore(true);
recordStore.initialize();
final PathName typePath = PathName.newPathName("/" + geometryTypeString);
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(typePath);
recordDefinition.addField("ID", DataTypes.INT, true);
recordDefinition.addField("NAME", DataTypes.STRING, 50, false);
recordDefinition.addField("GEOMETRY", dataType, true);
recordDefinition.setGeometryFactory(geometryFactory);
recordStore.getRecordDefinition(recordDefinition);
try (Writer<Record> writer = recordStore.newRecordWriter()) {
writer.setProperty(IoConstants.GEOMETRY_FACTORY, geometryFactory);
writer.setProperty(IoConstants.GEOMETRY_TYPE, dataType);
final Record record = recordStore.newRecord(typePath);
record.setValue("ID", 1);
record.setGeometryValue(geometry);
writer.write(record);
}
try (Reader<Record> reader = recordStore.getRecords(typePath)) {
final List<Record> objects = reader.toList();
Assert.assertEquals("Geometry Count", 1, objects.size());
final Geometry actual = objects.get(0).getGeometry();
Assert.assertEquals("Empty", geometry.isEmpty(), actual.isEmpty());
if (!geometry.isEmpty()) {
final int geometryAxisCount = geometry.getAxisCount();
Assert.assertEquals("Axis Count", geometryAxisCount, actual.getAxisCount());
if (!actual.equals(geometryAxisCount, geometry)) {
// Allow for conversion of multi part to single part
if (geometry.getGeometryCount() != 1 || !actual.equals(geometryAxisCount, geometry.getGeometry(0))) {
TestUtil.failNotEquals("Geometry Equal Exact", geometry, actual);
}
}
}
}
}
}
use of com.revolsys.record.Record in project com.revolsys.open by revolsys.
the class GeometryTest method writeTestFile.
public static void writeTestFile(final GeometryFactory geometryFactory, final String wkt) {
final Geometry geometry = geometryFactory.geometry(wkt);
final DataType geometryDataType = DataTypes.getDataType(geometry);
String name = "/" + geometryDataType.getName();
if (geometryFactory.hasZ()) {
name += "Z";
}
final File file = new File("target/test-data/" + name + ".gdb");
FileUtil.deleteDirectory(file);
final PathName pathName = PathName.newPathName(name);
RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(pathName);
recordDefinition.addField("ID", DataTypes.INT, true);
final FieldDefinition geometryField = recordDefinition.addField("Geometry", geometryDataType, true);
geometryField.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
recordDefinition.setIdFieldName("ID");
final FileGdbRecordStore recordStore = FileGdbRecordStoreFactory.newRecordStore(file);
recordStore.initialize();
recordDefinition = (RecordDefinitionImpl) recordStore.getRecordDefinition(recordDefinition);
final Record object = new ArrayRecord(recordDefinition);
object.setIdentifier(Identifier.newIdentifier(1));
object.setGeometryValue(geometry);
recordStore.insertRecord(object);
final Record object2 = recordStore.getRecord(pathName, Identifier.newIdentifier(1));
if (!DataType.equal(object, object2)) {
System.out.println("Not Equal");
System.out.println(object);
System.out.println(object2);
}
recordStore.close();
}
Aggregations