Search in sources :

Example 1 with SampleLineString

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

the class JtsGeometryMappingTest method testLineStringMapping.

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

Aggregations

LineString (com.vividsolutions.jts.geom.LineString)1 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)1 PersistenceManager (javax.jdo.PersistenceManager)1 Transaction (javax.jdo.Transaction)1 SampleLineString (org.datanucleus.samples.jtsgeometry.SampleLineString)1 SampleMultiLineString (org.datanucleus.samples.jtsgeometry.SampleMultiLineString)1