use of org.datanucleus.samples.pggeometry.SamplePoint in project tests by datanucleus.
the class PgGeometryMappingTest method testPointMapping.
public void testPointMapping() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
Point point = new Point("SRID=4326;POINT(10 10)");
SamplePoint samplePoint;
SamplePoint samplePoint_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
samplePoint = new SamplePoint(1001, "Point 1", point);
pm.makePersistent(samplePoint);
id = JDOHelper.getObjectId(samplePoint);
samplePoint = (SamplePoint) pm.detachCopy(samplePoint);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
samplePoint_read = (SamplePoint) pm.getObjectById(id, true);
assertEquals(samplePoint, samplePoint_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.datanucleus.samples.pggeometry.SamplePoint in project tests by datanucleus.
the class PgGeometrySpatialTest method testAsText.
public void testAsText() throws SQLException {
SamplePoint point1 = getSamplePoint(1);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
String wkt = "POINT(10 10)";
Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.asText(geom) == :wkt");
List list = (List) query.execute(wkt);
assertEquals("Wrong number of geometries with a given wkt returned", 1, list.size());
assertTrue("Point 1 should be in the list of geometries with a given wkt", list.contains(point1));
query = pm.newQuery(SamplePoint.class, "id == :id");
query.setResultClass(String.class);
query.setResult("Spatial.asText(geom)");
list = (List) query.execute(new Long(point1.getId()));
assertEquals("Wrong number of geometries with a given id returned", 1, list.size());
String wkt_read = (String) list.get(0);
assertEquals("WKT of Point 1 should be equal to a given point's wkt", wkt, wkt_read);
} finally {
tx.commit();
}
}
Aggregations