Search in sources :

Example 1 with SampleMultiPolygon

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

the class JtsGeometryMappingTest method testMultiPolygonMapping.

public void testMultiPolygonMapping() throws SQLException, ParseException {
    if (!runTestsForDatastore()) {
        return;
    }
    MultiPolygon multiPolygon = (MultiPolygon) wktReader.read("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.jtsgeometry.SampleMultiPolygon) Transaction(javax.jdo.Transaction) SampleMultiPolygon(org.datanucleus.samples.jtsgeometry.SampleMultiPolygon) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) PersistenceManager(javax.jdo.PersistenceManager)

Aggregations

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