Search in sources :

Example 1 with SampleGeometry

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

the class PgGeometryMappingTest method testGeometryMapping.

public void testGeometryMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    Point point = new Point("SRID=4326;POINT(10 10)");
    SampleGeometry sampleGeometry;
    SampleGeometry sampleGeometry_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleGeometry = new SampleGeometry(1001, "Geometry (Point)", point);
        pm.makePersistent(sampleGeometry);
        id = JDOHelper.getObjectId(sampleGeometry);
        sampleGeometry = (SampleGeometry) pm.detachCopy(sampleGeometry);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleGeometry_read = (SampleGeometry) pm.getObjectById(id, true);
        assertEquals(sampleGeometry, sampleGeometry_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : SampleGeometry(org.datanucleus.samples.pggeometry.SampleGeometry) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point) SampleMultiPoint(org.datanucleus.samples.pggeometry.SampleMultiPoint)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 SampleGeometry (org.datanucleus.samples.pggeometry.SampleGeometry)1 SampleMultiPoint (org.datanucleus.samples.pggeometry.SampleMultiPoint)1 SamplePoint (org.datanucleus.samples.pggeometry.SamplePoint)1 MultiPoint (org.postgis.MultiPoint)1 Point (org.postgis.Point)1