Search in sources :

Example 1 with SampleLineString

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

the class PgGeometryMappingTest method testLineStringMapping.

public void testLineStringMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    LineString lineString = new LineString("SRID=4326;LINESTRING(0 50,100 50)");
    SampleLineString sampleLineString;
    SampleLineString sampleLineString_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleLineString = new SampleLineString(2001, "LineString 1", lineString);
        pm.makePersistent(sampleLineString);
        id = JDOHelper.getObjectId(sampleLineString);
        sampleLineString = (SampleLineString) pm.detachCopy(sampleLineString);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleLineString_read = (SampleLineString) pm.getObjectById(id, true);
        assertEquals(sampleLineString, sampleLineString_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : SampleLineString(org.datanucleus.samples.pggeometry.SampleLineString) Transaction(javax.jdo.Transaction) SampleMultiLineString(org.datanucleus.samples.pggeometry.SampleMultiLineString) SampleLineString(org.datanucleus.samples.pggeometry.SampleLineString) MultiLineString(org.postgis.MultiLineString) LineString(org.postgis.LineString) PersistenceManager(javax.jdo.PersistenceManager)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 SampleLineString (org.datanucleus.samples.pggeometry.SampleLineString)1 SampleMultiLineString (org.datanucleus.samples.pggeometry.SampleMultiLineString)1 LineString (org.postgis.LineString)1 MultiLineString (org.postgis.MultiLineString)1