org.datanucleus.jdo.spatial.PgSpatialHelper Maven / Gradle / Ivy
/**********************************************************************
Copyright (c) 2006 Thomas Marti, Stefan Schmid and others. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Contributors:
...
**********************************************************************/
package org.datanucleus.jdo.spatial;
import javax.jdo.PersistenceManager;
import org.datanucleus.api.jdo.JDOPersistenceManagerFactory;
import org.postgis.Geometry;
/**
* Helper class to read Spatial MetaData from the datastore, specialized for the geometry classes of
* the PostGIS JDBC driver. The methods assumes that users know what they're doing and will
* automatically downcast query results to org.postgis.Geometry
.
*/
public class PgSpatialHelper extends SpatialHelper
{
/**
* Creates a new PgSpatialHelper
instance for the given PMF.
*
* @param pmf The PMF, can't be null
or closed.
*/
public PgSpatialHelper(JDOPersistenceManagerFactory pmf)
{
super(pmf);
}
/**
* Returns the srid of the first datastore entry for the given geometry field.
* Will return null
, if there are no entries or if the geometry
* field of the first entry is null
. Creates a new
* PersistenceManager
to execute the query on the datastore.
*
* @param pc The PersistenceCapapable class
* @param fieldName Name of the geometry field
* @return The srid or null
*/
public Integer getSridFromDatastoreEntry(Class pc, String fieldName)
{
return getSridFromDatastoreEntry(pc, fieldName, pmf.getPersistenceManager());
}
/**
* Returns the srid of the first datastore entry for the given geometry field.
* Will return null
, if there are no entries or if the geometry
* field of the first entry is null
.
*
* @param pc The PersistenceCapapable class
* @param fieldName Name of the geometry field
* @param pm PersistenceManager
instance that should be used
* to access the datastore
* @return The srid or null
*/
public Integer getSridFromDatastoreEntry(final Class pc, final String fieldName, final PersistenceManager pm)
{
checkValid(pc, fieldName);
Integer srid = null;
Geometry geom = (Geometry)readFirstValueForField(pc, fieldName, pm);
if (geom != null)
{
srid = Integer.valueOf(geom.getSrid());
}
return srid;
}
}