Search in sources :

Example 1 with SamplePolygon

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

the class PgGeometryMappingTest method testPolygonMapping.

public void testPolygonMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    Polygon polygon = new Polygon("SRID=4326;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.pggeometry.SamplePolygon) MultiPolygon(org.postgis.MultiPolygon) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) Polygon(org.postgis.Polygon) SampleMultiPolygon(org.datanucleus.samples.pggeometry.SampleMultiPolygon)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 SampleMultiPolygon (org.datanucleus.samples.pggeometry.SampleMultiPolygon)1 SamplePolygon (org.datanucleus.samples.pggeometry.SamplePolygon)1 MultiPolygon (org.postgis.MultiPolygon)1 Polygon (org.postgis.Polygon)1