Search in sources :

Example 1 with SampleMultiPolygon

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

the class PgGeometryMappingTest method testMultiPolygonMapping.

public void testMultiPolygonMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    MultiPolygon multiPolygon = new MultiPolygon("SRID=4326;MULTIPOLYGON(((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45)),((75 75,100 75,100 100,75 75)))");
    SampleMultiPolygon sampleMultiPolygon;
    SampleMultiPolygon sampleMultiPolygon_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleMultiPolygon = new SampleMultiPolygon(6001, "MultiPolygon", multiPolygon);
        pm.makePersistent(sampleMultiPolygon);
        id = JDOHelper.getObjectId(sampleMultiPolygon);
        sampleMultiPolygon = (SampleMultiPolygon) pm.detachCopy(sampleMultiPolygon);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleMultiPolygon_read = (SampleMultiPolygon) pm.getObjectById(id, true);
        assertEquals(sampleMultiPolygon, sampleMultiPolygon_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : SampleMultiPolygon(org.datanucleus.samples.pggeometry.SampleMultiPolygon) Transaction(javax.jdo.Transaction) MultiPolygon(org.postgis.MultiPolygon) SampleMultiPolygon(org.datanucleus.samples.pggeometry.SampleMultiPolygon) PersistenceManager(javax.jdo.PersistenceManager)

Aggregations

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