Search in sources :

Example 1 with SamplePolygon

use of org.datanucleus.samples.jtsgeometry.SamplePolygon in project tests by datanucleus.

the class JtsGeometryMappingTest method testPolygonMapping.

public void testPolygonMapping() throws SQLException, ParseException {
    if (!runTestsForDatastore()) {
        return;
    }
    Polygon polygon = (Polygon) wktReader.read("POLYGON((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45))");
    SamplePolygon samplePolygon;
    SamplePolygon samplePolygon_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        samplePolygon = new SamplePolygon(3001, "Polygon 1", polygon);
        pm.makePersistent(samplePolygon);
        id = JDOHelper.getObjectId(samplePolygon);
        samplePolygon = (SamplePolygon) pm.detachCopy(samplePolygon);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        samplePolygon_read = (SamplePolygon) pm.getObjectById(id, true);
        assertEquals(samplePolygon, samplePolygon_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) SampleMultiPolygon(org.datanucleus.samples.jtsgeometry.SampleMultiPolygon) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Aggregations

MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)1 Polygon (com.vividsolutions.jts.geom.Polygon)1 PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 SampleMultiPolygon (org.datanucleus.samples.jtsgeometry.SampleMultiPolygon)1 SamplePolygon (org.datanucleus.samples.jtsgeometry.SamplePolygon)1