Search in sources :

Example 6 with SampleGeometry

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

the class JGeometrySpatialTest method testAsText.

public void testAsText() throws SQLException {
    SampleGeometry point1 = getSamplePoint(1);
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Query query = pm.newQuery(SampleGeometry.class, "id > 1000 && id < 2000 && Spatial.asText(geom).startsWith('POINT') && Spatial.asText(geom).endsWith('(10.0 10.0)')");
        List list = (List) query.execute();
        assertEquals("Wrong number of geometries with a given wkt returned", 1, list.size());
        assertTrue("Point 1 should be in the list of geometries with a given wkt", list.contains(point1));
        query = pm.newQuery(SampleGeometry.class, "id == :id");
        query.setResultClass(String.class);
        query.setResult("Spatial.asText(geom)");
        list = (List) query.execute(new Long(point1.getId()));
        assertEquals("Wrong number of geometries with a given id returned", 1, list.size());
        String wkt_read = (String) list.get(0);
        assertTrue("WKT of Point 1 should start with 'POINT'", wkt_read.startsWith("POINT"));
        assertTrue("WKT of Point 1 should end with '(10.0 10.0)'", wkt_read.endsWith("(10.0 10.0)"));
    } finally {
        tx.commit();
    }
}
Also used : SampleGeometry(org.datanucleus.samples.jgeometry.SampleGeometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List)

Example 7 with SampleGeometry

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

the class JGeometryMappingTest method testMultiLineStringMapping.

public void testMultiLineStringMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    JGeometry multiLineString = JGeometry.createLinearMultiLineString(new Object[] { new double[] { 0, 50, 100, 50 }, new double[] { 50, 0, 50, 100 }, new double[] { 100, 25, 120, 25, 110, 10, 110, 45 } }, 2, 4326);
    SampleGeometry sampleMultiLineString;
    SampleGeometry sampleMultiLineString_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleMultiLineString = new SampleGeometry(5001, "MultiLineString", multiLineString);
        pm.makePersistent(sampleMultiLineString);
        id = JDOHelper.getObjectId(sampleMultiLineString);
        sampleMultiLineString = (SampleGeometry) pm.detachCopy(sampleMultiLineString);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleMultiLineString_read = (SampleGeometry) pm.getObjectById(id, true);
        assertEquals(sampleMultiLineString, sampleMultiLineString_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : SampleGeometry(org.datanucleus.samples.jgeometry.SampleGeometry) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) JGeometry(oracle.spatial.geometry.JGeometry)

Example 8 with SampleGeometry

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

the class JGeometryMappingTest method testPointMapping.

public void testPointMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    JGeometry point = new JGeometry(10.0, 10.0, 4326);
    SampleGeometry samplePoint;
    SampleGeometry samplePoint_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        samplePoint = new SampleGeometry(1001, "Point 1", point);
        pm.makePersistent(samplePoint);
        id = JDOHelper.getObjectId(samplePoint);
        samplePoint = (SampleGeometry) pm.detachCopy(samplePoint);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        samplePoint_read = (SampleGeometry) pm.getObjectById(id, true);
        assertEquals(samplePoint, samplePoint_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : SampleGeometry(org.datanucleus.samples.jgeometry.SampleGeometry) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) JGeometry(oracle.spatial.geometry.JGeometry)

Example 9 with SampleGeometry

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

the class JGeometryMappingTest method testGeometryCollectionMapping.

public void testGeometryCollectionMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    int gtype = JGeometry.GTYPE_COLLECTION;
    int srid = 4326;
    // Polygons with holes don't seem to work in GeometryCollections!
    // int[] elemInfo = {1,1,1,3,2,1,7,1003,1,17,2003,1};
    // double[] ordinates = {10,10,0,50,100,50,25,25,75,25,75,75,25,75,25,25,45,45,45,55,55,55,55,45,45,45};
    int[] elemInfo = { 1, 1, 1, 3, 2, 1, 7, 1003, 1 };
    double[] ordinates = { 10, 10, 0, 50, 100, 50, 25, 25, 75, 25, 75, 75, 25, 75, 25, 25 };
    JGeometry geometryCollection = new JGeometry(gtype, srid, elemInfo, ordinates);
    SampleGeometry sampleGeometryCollection;
    SampleGeometry sampleGeometryCollection_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleGeometryCollection = new SampleGeometry(7001, "Collection 1", geometryCollection);
        pm.makePersistent(sampleGeometryCollection);
        id = JDOHelper.getObjectId(sampleGeometryCollection);
        sampleGeometryCollection = (SampleGeometry) pm.detachCopy(sampleGeometryCollection);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleGeometryCollection_read = (SampleGeometry) pm.getObjectById(id, true);
        assertEquals(sampleGeometryCollection, sampleGeometryCollection_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : SampleGeometry(org.datanucleus.samples.jgeometry.SampleGeometry) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) JGeometry(oracle.spatial.geometry.JGeometry)

Aggregations

SampleGeometry (org.datanucleus.samples.jgeometry.SampleGeometry)9 PersistenceManager (javax.jdo.PersistenceManager)8 Transaction (javax.jdo.Transaction)8 JGeometry (oracle.spatial.geometry.JGeometry)8 List (java.util.List)1 Query (javax.jdo.Query)1