Search in sources :

Example 1 with SampleLinearRing

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

the class PgGeometryMappingTest method testLinearRingMapping.

public void testLinearRingMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    LinearRing linearRing = new LinearRing(new Point[] { new Point(0, 0), new Point(10, 0), new Point(10, 10), new Point(0, 10), new Point(0, 0) });
    linearRing.setSrid(4326);
    SampleLinearRing sampleLinearRing;
    SampleLinearRing sampleLinearRing_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleLinearRing = new SampleLinearRing(2101, "LinearRing", linearRing);
        pm.makePersistent(sampleLinearRing);
        id = JDOHelper.getObjectId(sampleLinearRing);
        sampleLinearRing = (SampleLinearRing) pm.detachCopy(sampleLinearRing);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleLinearRing_read = (SampleLinearRing) pm.getObjectById(id, true);
        assertEquals(sampleLinearRing, sampleLinearRing_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) SampleLinearRing(org.datanucleus.samples.pggeometry.SampleLinearRing) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point) SampleMultiPoint(org.datanucleus.samples.pggeometry.SampleMultiPoint) SampleLinearRing(org.datanucleus.samples.pggeometry.SampleLinearRing) LinearRing(org.postgis.LinearRing)

Aggregations

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