use of org.datanucleus.samples.jtsgeometry.SamplePoint in project tests by datanucleus.
the class JtsGeometryMappingTest method testUserDataMappingWithString.
public void testUserDataMappingWithString() throws SQLException, ParseException {
if (!runTestsForDatastore()) {
return;
}
Point point = (Point) wktReader.read("POINT(10 10)");
point.setSRID(-1);
Object userData = "UserDataString";
point.setUserData(userData);
SamplePoint samplePoint;
SamplePoint samplePoint_read;
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
samplePoint = new SamplePoint(12001, "UserDataWithString", point);
em.persist(samplePoint);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
em = emf.createEntityManager();
tx = em.getTransaction();
try {
tx.begin();
samplePoint_read = (SamplePoint) em.find(SamplePoint.class, new Long(12001));
assertEquals(samplePoint, samplePoint_read);
assertNotNull(samplePoint_read.getGeom().getUserData());
assertEquals(String.class, samplePoint_read.getGeom().getUserData().getClass());
assertEquals(userData, samplePoint_read.getGeom().getUserData());
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
}
use of org.datanucleus.samples.jtsgeometry.SamplePoint in project tests by datanucleus.
the class JtsGeometryMappingTest method testPointMapping.
public void testPointMapping() throws SQLException, ParseException {
if (!runTestsForDatastore()) {
return;
}
Point point = (Point) wktReader.read("POINT(10 10)");
point.setSRID(-1);
SamplePoint samplePoint;
SamplePoint samplePoint_read;
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
samplePoint = new SamplePoint(1001, "Point 1", point);
em.persist(samplePoint);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
em = emf.createEntityManager();
tx = em.getTransaction();
try {
tx.begin();
samplePoint_read = (SamplePoint) em.find(SamplePoint.class, new Long(1001));
assertEquals(samplePoint, samplePoint_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
}
use of org.datanucleus.samples.jtsgeometry.SamplePoint in project tests by datanucleus.
the class JtsGeometryMappingTest method testUserDataMappingWithObject.
public void testUserDataMappingWithObject() throws SQLException, ParseException {
if (!runTestsForDatastore()) {
return;
}
Point point = (Point) wktReader.read("POINT(10 10)");
point.setSRID(-1);
Object userData = new Object();
point.setUserData(userData);
SamplePoint samplePoint;
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
samplePoint = new SamplePoint(11001, "UserDataWithObject", point);
em.persist(samplePoint);
tx.commit();
fail("Persisted spatial field with non-serializable user-data but should have failed");
} catch (Exception e) {
// Expected : should fail since Object is not Serializable
} finally {
if (tx.isActive()) {
tx.rollback();
}
em.close();
}
}
use of org.datanucleus.samples.jtsgeometry.SamplePoint in project tests by datanucleus.
the class JtsGeometrySpatialTest method testAsText.
public void testAsText() throws SQLException, ParseException {
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 && geom.toText() == :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("geom.toText()");
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