deegree 2.5 (2011/06/29 09:44 build-8-official)

org.deegree.io.quadtree
Class DBQuadtreeManager<T>

java.lang.Object
  extended by org.deegree.io.quadtree.DBQuadtreeManager<T>
Type Parameters:
T - the type of the quadtree. If unsure use the determineQuattreType() method to determine the type. Be carefull though, if you use a wrong generic here (e.g. not Integer or String) while supplying another types.Type to the constructor there is no way to check find the correct instance.

public class DBQuadtreeManager<T>
extends java.lang.Object

Access control to a quadtree for managing spatial indizes stored in a usual database.

Version:
$Revision: 21181 $, $Date: 2009-12-02 16:47:53 +0100 (Mi, 02 Dez 2009) $
Author:
Andreas Poth, last edited by: $Author: aschmitz $

Field Summary
protected  java.lang.String backend
           
protected  java.lang.String column
           
protected  Envelope envelope
           
protected  java.lang.String indexName
           
protected  JDBCConnection jdbc
           
protected  int maxDepth
           
protected  java.lang.String owner
           
protected  java.lang.String table
           
 
Constructor Summary
DBQuadtreeManager(JDBCConnection jdbc, java.lang.String table, java.lang.String column, java.lang.String owner, int type)
          initializes a QuadtreeManager to access an alread existing Quadtree
DBQuadtreeManager(JDBCConnection jdbc, java.lang.String owner, java.lang.String indexName, java.lang.String table, java.lang.String column, int maxDepth, int type)
           
DBQuadtreeManager(java.lang.String driver, java.lang.String logon, java.lang.String user, java.lang.String password, java.lang.String encoding, java.lang.String table, java.lang.String column, java.lang.String owner, int type)
          initializes a QuadtreeManager to access an alread existing Quadtree
DBQuadtreeManager(java.lang.String driver, java.lang.String logon, java.lang.String user, java.lang.String password, java.lang.String encoding, java.lang.String indexName, java.lang.String table, java.lang.String column, java.lang.String owner, int maxDepth, int type)
           
 
Method Summary
 void appendShape(java.lang.String fileName)
          appends the features of a shape to an existing datatable and inserts references into the assigned quadtree table.
protected  void createDataTable(java.lang.String fileName, java.lang.String idType)
          creates table the shape data shall be stored
protected  void createIndexTable(java.lang.String indexTable, java.lang.String idType)
          Creates actually two tables, an indextable, which will hold the actual quadtree and an index_item table which is a join-table between the dbNodes and the feature_ids.
 java.lang.Object determineQuattreeType()
           
(package private)  java.lang.String getDatabaseType(int dataTypeCode)
          returns the type name for a generic type code as used by SQLServer
 DBQuadtree<T> getQuadtree()
          returns the current Quadtree
 void importShape(java.lang.String fileName)
          imports a shape into the database and builds a quadtree on it
protected  int initQuadtree(java.lang.String fileName)
          initializes a new Quadtree by adding a row into table TAB_QUADTREE and into TAB_QTNODE (-> root node)
protected  void initRootNode(java.lang.String fileName)
          initializes the root node of the quadtree
 void insertIndexMetadata(int fk_indexTree)
          Inserts a row into the quadtree meta data structure 'TAB_DEEGREE_IDX', containing information on the table, geometry, indexname, owner and the foreign_key to the index table.
protected  int loadIndexMetadata()
          loads the metadata of a Index from the TAB_DEEGREE_IDX table
 void release()
          Releases the db connection.
 void setRootEnvelope(Envelope envelope)
          before importing a shape a user may set an envelope for the quadtree to bee created that is different from the one of the shape by calling this method.
protected  void storeFeature(Feature feature, T id, JDBCConnection jdbc)
          stores one feature into the defined table
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jdbc

protected JDBCConnection jdbc

table

protected java.lang.String table

column

protected java.lang.String column

owner

protected java.lang.String owner

indexName

protected java.lang.String indexName

maxDepth

protected int maxDepth

envelope

protected Envelope envelope

backend

protected java.lang.String backend
Constructor Detail

DBQuadtreeManager

public DBQuadtreeManager(JDBCConnection jdbc,
                         java.lang.String owner,
                         java.lang.String indexName,
                         java.lang.String table,
                         java.lang.String column,
                         int maxDepth,
                         int type)
Parameters:
jdbc - database connection info
owner - owner of the table (optional, database user will be used if set to null )
indexName - this name will be used to create the table that stores the nodes of a specific quadtree
table - name of table the index shall be created for
column - name of column the index shall be created for
maxDepth - max depth of the generated quadtree (default = 6 if a value < 2 will be passed)
type - the type of the id of the quadtree, valid are Types.INTEGER and Types.VARCHAR. if unsure use Intger.MIN_VALUE and call determineQuattreeType(), to get an instance of the Type.

DBQuadtreeManager

public DBQuadtreeManager(java.lang.String driver,
                         java.lang.String logon,
                         java.lang.String user,
                         java.lang.String password,
                         java.lang.String encoding,
                         java.lang.String indexName,
                         java.lang.String table,
                         java.lang.String column,
                         java.lang.String owner,
                         int maxDepth,
                         int type)
Parameters:
driver - database connection driver
logon - database connection logon
user - database user
password - database user's password
encoding - character encoding to be used (if possible)
indexName - this name will be used to create the table that stores the nodes of a specific quadtree
table - name of table the index shall be created for
column - name of column the index shall be created for
owner - owner of the table (optional, database user will be used if set to null )
maxDepth - max depth of the generated quadtree (default = 6 if a value < 2 will be passed)
type - the type of the id of the quadtree, valid are Types.INTEGER and Types.VARCHAR. if unsure use Intger.MIN_VALUE and call determineQuattreeType(), to get an instance of the Type.

DBQuadtreeManager

public DBQuadtreeManager(JDBCConnection jdbc,
                         java.lang.String table,
                         java.lang.String column,
                         java.lang.String owner,
                         int type)
initializes a QuadtreeManager to access an alread existing Quadtree

Parameters:
jdbc - database connection info
table - name of table the index shall be created for
column - name of column the index shall be created for
owner - owner of the table (optional, database user will be used if set to null )
type - the type of the id of the quadtree, valid are Types.INTEGER and Types.VARCHAR. if unsure use Intger.MIN_VALUE and call determineQuattreeType(), to get an instance of the Type.

DBQuadtreeManager

public DBQuadtreeManager(java.lang.String driver,
                         java.lang.String logon,
                         java.lang.String user,
                         java.lang.String password,
                         java.lang.String encoding,
                         java.lang.String table,
                         java.lang.String column,
                         java.lang.String owner,
                         int type)
initializes a QuadtreeManager to access an alread existing Quadtree

Parameters:
driver - database connection driver
logon - database connection logon
user - database user
password - database user's password
encoding - character encoding to be used (if possible)
table - name of table the index shall be created for
column - name of column the index shall be created for
owner - owner of the table (optional, database user will be used if set to null )
type - the type of the id of the quadtree, valid are Types.INTEGER and Types.VARCHAR. if unsure use Intger.MIN_VALUE and call determineQuattreeType(), to get an instance of the Type.
Method Detail

loadIndexMetadata

protected int loadIndexMetadata()
                         throws IndexException
loads the metadata of a Index from the TAB_DEEGREE_IDX table

Returns:
FK to the index
Throws:
IndexException

getQuadtree

public DBQuadtree<T> getQuadtree()
                          throws IndexException
returns the current Quadtree

Returns:
the current Quadtree
Throws:
IndexException

determineQuattreeType

public java.lang.Object determineQuattreeType()
                                       throws IndexException
Returns:
an instance of the type of the feature id's stored in the db. Possible instances are String, Integer or null if the type could not be determined.
Throws:
IndexException - if the type information could not be retrieved either because no connection was acquired or an error occurred while executing the select statement.

storeFeature

protected void storeFeature(Feature feature,
                            T id,
                            JDBCConnection jdbc)
                     throws IndexException
stores one feature into the defined table

Parameters:
feature - the feature to insert into the 'table'
id - of the feature to store in the database, currently String and Integer are supported. If it is neither, the Object is saved as an object, which may result in inconsitencies.
jdbc - the connection to the database.
Throws:
IndexException - if the feature can not be inserted or a connection error occurrs.

initRootNode

protected void initRootNode(java.lang.String fileName)
                     throws IndexException,
                            java.io.IOException
initializes the root node of the quadtree

Parameters:
fileName -
Throws:
IndexException
java.io.IOException

setRootEnvelope

public void setRootEnvelope(Envelope envelope)
before importing a shape a user may set an envelope for the quadtree to bee created that is different from the one of the shape by calling this method. Notice: calling this method does not have any effect when calling

Parameters:
envelope -
See Also:
method.

initQuadtree

protected int initQuadtree(java.lang.String fileName)
                    throws IndexException,
                           java.io.IOException
initializes a new Quadtree by adding a row into table TAB_QUADTREE and into TAB_QTNODE (-> root node)

Parameters:
fileName -
Returns:
the id of the inserted node
Throws:
IndexException
java.io.IOException - if the shape file could not be read.

insertIndexMetadata

public void insertIndexMetadata(int fk_indexTree)
                         throws IndexException
Inserts a row into the quadtree meta data structure 'TAB_DEEGREE_IDX', containing information on the table, geometry, indexname, owner and the foreign_key to the index table.

Parameters:
fk_indexTree -
Throws:
IndexException

createDataTable

protected void createDataTable(java.lang.String fileName,
                               java.lang.String idType)
                        throws IndexException,
                               java.io.IOException
creates table the shape data shall be stored

Parameters:
fileName -
idType - the type of the feature_id column, for example VARCHAR(50) or NUMBER.
Throws:
IndexException
java.io.IOException

getDatabaseType

java.lang.String getDatabaseType(int dataTypeCode)
returns the type name for a generic type code as used by SQLServer

Parameters:
dataTypeCode -
Returns:
the type name for a generic type code as used by SQLServer

importShape

public void importShape(java.lang.String fileName)
                 throws java.io.IOException,
                        IndexException,
                        HasNoDBaseFileException,
                        DBaseException
imports a shape into the database and builds a quadtree on it

Parameters:
fileName - of the shapefile.
Throws:
java.io.IOException - if the shapefile could not be opened.
IndexException - if an error occurred while talking to the jdbc database.
DBaseException - if the connection to the shapefile could not be opened.
HasNoDBaseFileException - if the feature could not be read from shape file's database file.

appendShape

public void appendShape(java.lang.String fileName)
                 throws java.io.IOException,
                        IndexException
appends the features of a shape to an existing datatable and inserts references into the assigned quadtree table.

you have to consider that the quadtree is just valid for a defined area. if the features to append exceeds this area the quadtree has to be rebuilded.

Parameters:
fileName -
Throws:
java.io.IOException - if the shape file cannot be read.
IndexException - if the quatree could not be read.

createIndexTable

protected void createIndexTable(java.lang.String indexTable,
                                java.lang.String idType)
                         throws IndexException
Creates actually two tables, an indextable, which will hold the actual quadtree and an index_item table which is a join-table between the dbNodes and the feature_ids.

Parameters:
indexTable - name of the index table.
idType - the type of the feature_id column, for example VARCHAR(50) or NUMBER.
Throws:
IndexException - if the table could not be created.

release

public void release()
Releases the db connection.


deegree 2.5 (2011/06/29 09:44 build-8-official)

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org