Search in sources :

Example 1 with SampleGeometryCollection

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

the class PgGeometryMappingTest method testGeometryCollectionMapping.

public void testGeometryCollectionMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    GeometryCollection geometryCollection = new GeometryCollection("SRID=4326;GEOMETRYCOLLECTION(POINT(10 10),LINESTRING(0 50, 100 50),POLYGON((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45)))");
    SampleGeometryCollection sampleGeometryCollection;
    SampleGeometryCollection sampleGeometryCollection_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleGeometryCollection = new SampleGeometryCollection(7001, "Collection 1", geometryCollection);
        pm.makePersistent(sampleGeometryCollection);
        id = JDOHelper.getObjectId(sampleGeometryCollection);
        sampleGeometryCollection = (SampleGeometryCollection) pm.detachCopy(sampleGeometryCollection);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleGeometryCollection_read = (SampleGeometryCollection) pm.getObjectById(id, true);
        assertEquals(sampleGeometryCollection, sampleGeometryCollection_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : SampleGeometryCollection(org.datanucleus.samples.pggeometry.SampleGeometryCollection) GeometryCollection(org.postgis.GeometryCollection) SampleGeometryCollection(org.datanucleus.samples.pggeometry.SampleGeometryCollection) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 SampleGeometryCollection (org.datanucleus.samples.pggeometry.SampleGeometryCollection)1 GeometryCollection (org.postgis.GeometryCollection)1