org.datanucleus.jdo.spatial
Class SpatialHelper

java.lang.Object
  extended by org.datanucleus.jdo.spatial.SpatialHelper
Direct Known Subclasses:
AoSpatialHelper, JgeomSpatialHelper, JtsSpatialHelper, PgSpatialHelper

public class SpatialHelper
extends java.lang.Object

Helper class to search and access Spatial MetaData. This class wraps some of the spatial functions that JPOX-Spatial offers via JDOQL in "real" Java methods and also adds extended functionality, like reading values from JDO-Metadata and getting CRS (Coordinate Reference System) information from the database.

The datatypes and terminology used in this class is (like most of JPOX-Spatial) heavily based on OGC's Simple Feature specification. See http://www.opengeospatial.org/standards/sfa for details.


Nested Class Summary
protected  class SpatialHelper.QueryExecutor
          Abstract helper class to execute queries.
 
Field Summary
protected  org.datanucleus.jdo.JDOPersistenceManagerFactory pmf
           
protected  org.datanucleus.store.mapped.MappedStoreManager storeMgr
           
 
Constructor Summary
SpatialHelper(org.datanucleus.jdo.JDOPersistenceManagerFactory pmf)
          Creates a new SpatialHelper instance for the given PMF.
 
Method Summary
 java.awt.geom.Rectangle2D calculateBoundsInDatastore(java.lang.Class pc, java.lang.String fieldName)
           
 java.awt.geom.Rectangle2D calculateBoundsInDatastore(java.lang.Class pc, java.lang.String fieldName, javax.jdo.PersistenceManager pm)
           
protected  void checkValid(java.lang.Class pc, java.lang.String fieldName)
           
 java.awt.geom.Rectangle2D estimateBoundsFromDatastoreMetadata(java.lang.Class pc, java.lang.String fieldName)
          Returns the (estimated) spatial extent, also called bounding box from datastore metadata for the given geometry field.
 java.awt.geom.Rectangle2D estimateBoundsFromDatastoreMetadata(java.lang.Class pc, java.lang.String fieldName, javax.jdo.PersistenceManager pm)
          Returns the (estimated) spatial extent, also called bounding box from datastore metadata for the given geometry field.
protected  SpatialRDBMSAdapter getAdapter()
           
protected  org.datanucleus.store.rdbms.table.Column getColumn(java.lang.Class pc, org.datanucleus.metadata.AbstractMemberMetaData mmd)
           
protected  org.datanucleus.store.rdbms.table.Column getColumn(java.lang.Class pc, java.lang.String fieldName)
           
 java.lang.String getCrsNameForSrid(java.lang.Class pc, int srid)
          Returns the name of the Coordinate Reference System (CRS) for the given srid.
 java.lang.String getCrsNameForSrid(java.lang.Class pc, int srid, javax.jdo.PersistenceManager pm)
          Returns the name of the Coordinate Reference System (CRS) for the given srid.
 java.lang.String getCrsWktForSrid(java.lang.Class pc, int srid)
          Returns a description of the Coordinate Reference System (CRS) for the given srid in WKT (Well-Known Text).
 java.lang.String getCrsWktForSrid(java.lang.Class pc, int srid, javax.jdo.PersistenceManager pm)
          Returns the description of the Coordinate Reference System (CRS) for the given srid in WKT (Well-Known Text).
 java.lang.Integer getDimensionFromJdoMetadata(java.lang.Class pc, java.lang.String fieldName)
          Returns the dimension from JDO-Metadata for the given geometry field.
 java.lang.String[] getGeometryColumnBackedFields(java.lang.Class pc)
          Return all field names of the given class that are backed by a geometry column in the database.
protected  java.lang.Integer getIntegerFromJdoMetadata(java.lang.Class pc, java.lang.String fieldName, java.lang.String extensionKey)
           
protected  org.datanucleus.metadata.MetaDataManager getMetaDataManager()
           
 java.lang.Integer getSridFromDatastoreMetadata(java.lang.Class pc, java.lang.String fieldName)
          Returns the srid from datastore metadata for the given geometry field.
 java.lang.Integer getSridFromDatastoreMetadata(java.lang.Class pc, java.lang.String fieldName, javax.jdo.PersistenceManager pm)
          Returns the srid from datastore metadata for the given geometry field.
 java.lang.Integer getSridFromJdoMetadata(java.lang.Class pc, java.lang.String fieldName)
          Returns the srid from JDO-Metadata for the given geometry field.
protected  org.datanucleus.store.rdbms.table.Table getTable(java.lang.Class pc)
           
protected  java.lang.String getValueFromJdoMetadata(java.lang.Class pc, java.lang.String memberName, java.lang.String extensionKey)
           
 boolean isGeometryColumnBackedField(java.lang.Class pc, java.lang.String fieldName)
          Checks whether the given field name for the given class is backed by a geometry column in the database.
protected  boolean isGeometryColumnBackedField(org.datanucleus.store.rdbms.table.Column c)
           
protected  java.lang.Object readFirstValueForField(java.lang.Class pc, java.lang.String fieldName, javax.jdo.PersistenceManager pm)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pmf

protected org.datanucleus.jdo.JDOPersistenceManagerFactory pmf

storeMgr

protected org.datanucleus.store.mapped.MappedStoreManager storeMgr
Constructor Detail

SpatialHelper

public SpatialHelper(org.datanucleus.jdo.JDOPersistenceManagerFactory pmf)
Creates a new SpatialHelper instance for the given PMF.

Parameters:
pmf - The PMF, can't be null or closed.
Method Detail

getSridFromJdoMetadata

public java.lang.Integer getSridFromJdoMetadata(java.lang.Class pc,
                                                java.lang.String fieldName)
Returns the srid from JDO-Metadata for the given geometry field. Will return null, if the user has not specified a value in his metadata.

Parameters:
pc - The PersistenceCapapable class
fieldName - Name of the geometry field
Returns:
The srid or null.
See Also:
SpatialRDBMSAdapter.SRID_EXTENSION_KEY

getDimensionFromJdoMetadata

public java.lang.Integer getDimensionFromJdoMetadata(java.lang.Class pc,
                                                     java.lang.String fieldName)
Returns the dimension from JDO-Metadata for the given geometry field. Will return null, if the user has not specified a value in his metadata.

Parameters:
pc - The PersistenceCapapable class
fieldName - Name of the geometry field
Returns:
The dimension or null.
See Also:
SpatialRDBMSAdapter.DIMENSION_EXTENSION_KEY

getSridFromDatastoreMetadata

public java.lang.Integer getSridFromDatastoreMetadata(java.lang.Class pc,
                                                      java.lang.String fieldName)
Returns the srid from datastore metadata for the given geometry field. Will return null, if the datastore doesn't support such an operation (e.g. MySQL) or if there is no metadata in the datastore available for the given class and field name. Creates a new PersistenceManager to execute the query on the datastore.

Parameters:
pc - The PersistenceCapable class
fieldName - Name of the geometry field
Returns:
The srid or null.

getSridFromDatastoreMetadata

public java.lang.Integer getSridFromDatastoreMetadata(java.lang.Class pc,
                                                      java.lang.String fieldName,
                                                      javax.jdo.PersistenceManager pm)
Returns the srid from datastore metadata for the given geometry field. Will return null, if the datastore doesn't support such an operation (e.g. MySQL) or if there is no metadata in the datastore available for the given class and field name.

Parameters:
pc - The PersistenceCapable class
fieldName - Name of the geometry field
pm - PersistenceManager instance that should be used to access the datastore
Returns:
The srid or null.

estimateBoundsFromDatastoreMetadata

public java.awt.geom.Rectangle2D estimateBoundsFromDatastoreMetadata(java.lang.Class pc,
                                                                     java.lang.String fieldName)
Returns the (estimated) spatial extent, also called bounding box from datastore metadata for the given geometry field. Will return null, if the datastore doesn't support such an operation (e.g. MySQL) or if there is no metadata in the datastore available for the given class and field name. Creates a new PersistenceManager to execute the query on the datastore.

Parameters:
pc - The PersistenceCapable class
fieldName - Name of the geometry field
Returns:
The bbox or null.

estimateBoundsFromDatastoreMetadata

public java.awt.geom.Rectangle2D estimateBoundsFromDatastoreMetadata(java.lang.Class pc,
                                                                     java.lang.String fieldName,
                                                                     javax.jdo.PersistenceManager pm)

Returns the (estimated) spatial extent, also called bounding box from datastore metadata for the given geometry field. Will return null, if the datastore doesn't support such an operation (e.g. MySQL) or if there is no metadata in the datastore available for the given class and field name.

Parameters:
pc - The PersistenceCapable class
fieldName - Name of the geometry field
pm - PersistenceManager instance that should be used to access the datastore
Returns:
The bbox or null.

calculateBoundsInDatastore

public java.awt.geom.Rectangle2D calculateBoundsInDatastore(java.lang.Class pc,
                                                            java.lang.String fieldName)

calculateBoundsInDatastore

public java.awt.geom.Rectangle2D calculateBoundsInDatastore(java.lang.Class pc,
                                                            java.lang.String fieldName,
                                                            javax.jdo.PersistenceManager pm)

getCrsWktForSrid

public java.lang.String getCrsWktForSrid(java.lang.Class pc,
                                         int srid)
                                  throws java.sql.SQLException
Returns a description of the Coordinate Reference System (CRS) for the given srid in WKT (Well-Known Text). Will return null, if the datastore doesn't support such an operation (e.g. MySQL) or if there is no metadata in the datastore available for the given class and srid. Creates a new PersistenceManager to execute the query on the datastore.

Parameters:
pc - The PersistenceCapable class
srid - The srid
Returns:
Description of the CRS in WKT or null.
Throws:
java.sql.SQLException

getCrsWktForSrid

public java.lang.String getCrsWktForSrid(java.lang.Class pc,
                                         int srid,
                                         javax.jdo.PersistenceManager pm)
Returns the description of the Coordinate Reference System (CRS) for the given srid in WKT (Well-Known Text). Will return null, if the datastore doesn't support such an operation (e.g. MySQL) or if there is no metadata in the datastore available for the given class and srid.

Parameters:
pc - The PersistenceCapable class
srid - The srid
pm - PersistenceManager instance that should be used to access the datastore
Returns:
Description of the CRS in WKT or null.

getCrsNameForSrid

public java.lang.String getCrsNameForSrid(java.lang.Class pc,
                                          int srid)
                                   throws java.sql.SQLException
Returns the name of the Coordinate Reference System (CRS) for the given srid. Will return null, if the datastore doesn't support such an operation (e.g. MySQL) or if there is no metadata in the datastore available for the given class and srid. Creates a new PersistenceManager to execute the query on the datastore.

Parameters:
pc - The PersistenceCapable class
srid - The srid
Returns:
Name the CRS or null.
Throws:
java.sql.SQLException

getCrsNameForSrid

public java.lang.String getCrsNameForSrid(java.lang.Class pc,
                                          int srid,
                                          javax.jdo.PersistenceManager pm)
Returns the name of the Coordinate Reference System (CRS) for the given srid. Will return null, if the datastore doesn't support such an operation (e.g. MySQL) or if there is no metadata in the datastore available for the given class and srid.

Parameters:
pc - The PersistenceCapable class
srid - The srid
pm - PersistenceManager instance that should be used to access the datastore
Returns:
Name the CRS or null.

getIntegerFromJdoMetadata

protected java.lang.Integer getIntegerFromJdoMetadata(java.lang.Class pc,
                                                      java.lang.String fieldName,
                                                      java.lang.String extensionKey)

getValueFromJdoMetadata

protected java.lang.String getValueFromJdoMetadata(java.lang.Class pc,
                                                   java.lang.String memberName,
                                                   java.lang.String extensionKey)

getGeometryColumnBackedFields

public java.lang.String[] getGeometryColumnBackedFields(java.lang.Class pc)
Return all field names of the given class that are backed by a geometry column in the database.

Parameters:
pc - The PersistenceCapable class
Returns:
Array of names, may be empty, but never null.

isGeometryColumnBackedField

public boolean isGeometryColumnBackedField(java.lang.Class pc,
                                           java.lang.String fieldName)
Checks whether the given field name for the given class is backed by a geometry column in the database.

Parameters:
pc - The PersistenceCapable class
fieldName - Name of the field
Returns:
true, if the field is backed by a geometry column, false otherwise.

isGeometryColumnBackedField

protected boolean isGeometryColumnBackedField(org.datanucleus.store.rdbms.table.Column c)

getTable

protected org.datanucleus.store.rdbms.table.Table getTable(java.lang.Class pc)

getColumn

protected org.datanucleus.store.rdbms.table.Column getColumn(java.lang.Class pc,
                                                             java.lang.String fieldName)

getColumn

protected org.datanucleus.store.rdbms.table.Column getColumn(java.lang.Class pc,
                                                             org.datanucleus.metadata.AbstractMemberMetaData mmd)

getAdapter

protected SpatialRDBMSAdapter getAdapter()
                                  throws java.lang.ClassCastException
Throws:
java.lang.ClassCastException

getMetaDataManager

protected org.datanucleus.metadata.MetaDataManager getMetaDataManager()

checkValid

protected void checkValid(java.lang.Class pc,
                          java.lang.String fieldName)
                   throws java.lang.IllegalArgumentException,
                          java.lang.NullPointerException
Throws:
java.lang.IllegalArgumentException
java.lang.NullPointerException

readFirstValueForField

protected java.lang.Object readFirstValueForField(java.lang.Class pc,
                                                  java.lang.String fieldName,
                                                  javax.jdo.PersistenceManager pm)


Copyright © 2009. All Rights Reserved.