org.jpox.store.rdbms
Class RDBMSStoreHelper

java.lang.Object
  extended byorg.jpox.store.rdbms.RDBMSStoreHelper

public class RDBMSStoreHelper
extends java.lang.Object

Provides a series of uilities assisting in the datastore management process for RDBMS datastores.

Version:
$Revision: 1.43 $

Field Summary
static int TABLE_IDENTIFIER_COLUMN
           
 
Constructor Summary
RDBMSStoreHelper()
           
 
Method Summary
static AbstractClassMetaData getClassMetaDataManagingTableForClass(AbstractClassMetaData cmd)
          Utility to find the ClassMetaData for the class that manages the table where the supplied class stores its fields.
static java.lang.String getClassNameForIdKeyUsingDiscriminator(PersistenceManager pm, RDBMSManager storeMgr, java.lang.Object id, java.util.List schemaDataOptions)
          Utility that takes an id and a list of possible class RDBMSStoreData and finds which of these classes contains the object with that id.
static java.lang.String getClassNameForIdKeyUsingUnion(PersistenceManager pm, RDBMSManager storeMgr, java.lang.Object id, java.util.List schemaDataOptions)
          Utility that takes an id and a list of possible class RDBMSStoreData and finds which of these classes contains the object with that id.
static ColumnInfo getColumnInfoForColumnName(RDBMSManager storeMgr, Table table, java.sql.Connection conn, DatastoreIdentifier column)
          Returns the column info for a database table.
static java.util.List getColumnInfoForTable(RDBMSManager storeMgr, Table table, java.sql.Connection conn)
          Returns the column info for a database table.
static java.util.List getForeignKeyInfoForTable(RDBMSManager storeMgr, Table table, java.sql.Connection conn)
          Returns the foreign key info for a database table.
static java.lang.String getFullyQualifiedTableName(RDBMSAdapter dba, java.lang.String catalog, java.lang.String schema, java.lang.String table)
          Method to return a name for a table, fully qualified by catalog/schema if the adapter supports it and if specified.
static java.util.List getTableInfo(RDBMSManager storeMgr, java.lang.String catalogName, java.lang.String schemaName, java.sql.Connection conn)
          Returns the table info.
static int getTableType(RDBMSManager storeMgr, Table table, java.sql.Connection conn)
          Returns the type of a database table in the datastore.
static java.lang.String[] splitColumnIdentifierName(java.lang.String separator, java.lang.String name)
          Method to split a fully-qualified database column name into its constituent parts (CATALOG.SCHEMA.TABLE.COLUMN).
static java.lang.String[] splitTableIdentifierName(java.lang.String separator, java.lang.String name)
          Method to split a fully-qualified database table name into its constituent parts (CATALOG.SCHEMA.TABLE).
static java.lang.String stringWithoutIdentifierQuotes(RDBMSAdapter dba, java.lang.String identifier)
          Convenience method to remove any identifier quotes from the passed (SQL) identifier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TABLE_IDENTIFIER_COLUMN

public static final int TABLE_IDENTIFIER_COLUMN
See Also:
Constant Field Values
Constructor Detail

RDBMSStoreHelper

public RDBMSStoreHelper()
Method Detail

getTableType

public static int getTableType(RDBMSManager storeMgr,
                               Table table,
                               java.sql.Connection conn)
                        throws java.sql.SQLException
Returns the type of a database table in the datastore. Uses the DatabaseMetaData to extract this information.

Parameters:
storeMgr - Manager for the store
table - The table/view
conn - Connection to the database.
Returns:
One of the TABLE_TYPE_* values from Table.
Throws:
java.sql.SQLException
See Also:
Table

getColumnInfoForTable

public static java.util.List getColumnInfoForTable(RDBMSManager storeMgr,
                                                   Table table,
                                                   java.sql.Connection conn)
                                            throws java.sql.SQLException
Returns the column info for a database table. Uses the DatabaseMetaData to extract this information.

Parameters:
storeMgr - The RDBMSManager
table - The table/view
conn - Connection to the datastore
Returns:
A list of ColumnInfo objects describing the columns of the table. The list is in the same order as was supplied by getColumns(). If no column info is found for the given table, an empty list is returned.
Throws:
java.sql.SQLException
See Also:
ColumnInfo

getTableInfo

public static java.util.List getTableInfo(RDBMSManager storeMgr,
                                          java.lang.String catalogName,
                                          java.lang.String schemaName,
                                          java.sql.Connection conn)
                                   throws java.sql.SQLException
Returns the table info. Uses the DatabaseMetaData to extract this information.

Parameters:
storeMgr - The RDBMSManager
catalogName - The catalog name
schemaName - The schema name
conn - Connection to the datastore
Returns:
A list of TableInfo objects describing the tables of the schema. The list is in the same order as was supplied by getTables(). If no table, an empty list is returned.
Throws:
java.sql.SQLException
See Also:
TableInfo

getColumnInfoForColumnName

public static ColumnInfo getColumnInfoForColumnName(RDBMSManager storeMgr,
                                                    Table table,
                                                    java.sql.Connection conn,
                                                    DatastoreIdentifier column)
                                             throws java.sql.SQLException
Returns the column info for a database table. Uses the DatabaseMetaData to extract this information.

Parameters:
storeMgr - The RDBMSManager
table - The table/view
conn - Connection to the datastore
column - The column
Returns:
A list of ColumnInfo objects describing the columns of the table. The list is in the same order as was supplied by getColumns(). If no column info is found for the given table, an empty list is returned.
Throws:
java.sql.SQLException
See Also:
ColumnInfo

stringWithoutIdentifierQuotes

public static java.lang.String stringWithoutIdentifierQuotes(RDBMSAdapter dba,
                                                             java.lang.String identifier)
Convenience method to remove any identifier quotes from the passed (SQL) identifier.

Parameters:
dba - Database adapter being used
identifier - The identifier string
Returns:
The identifier without quotes

getForeignKeyInfoForTable

public static java.util.List getForeignKeyInfoForTable(RDBMSManager storeMgr,
                                                       Table table,
                                                       java.sql.Connection conn)
                                                throws java.sql.SQLException
Returns the foreign key info for a database table. Uses the DatabaseMetaData to extract this information.

Parameters:
storeMgr - Manager of the store
table - The table
conn - Connection to the datastore
Returns:
A list of ForeignKeyInfo objects describing the columns of the table's foreign keys. The list is in the same order as was supplied by get??portedKeys(). If no column info is found for the given table, an empty list is returned.
Throws:
java.sql.SQLException
See Also:
ForeignKeyInfo

splitTableIdentifierName

public static java.lang.String[] splitTableIdentifierName(java.lang.String separator,
                                                          java.lang.String name)
Method to split a fully-qualified database table name into its constituent parts (CATALOG.SCHEMA.TABLE). This is typically used where a user has specified a table name as fully qualified in the MetaData.

Parameters:
separator - Separator character
name - The fully qualified name.
Returns:
The separated parts of the name (catalog, schema, table)

splitColumnIdentifierName

public static java.lang.String[] splitColumnIdentifierName(java.lang.String separator,
                                                           java.lang.String name)
Method to split a fully-qualified database column name into its constituent parts (CATALOG.SCHEMA.TABLE.COLUMN). This is typically used where a user has specified a column name as fully qualified in the MetaData.

Parameters:
separator - Separator character
name - The fully qualified name.
Returns:
The separated parts of the name (catalog, schema, table, column)

getFullyQualifiedTableName

public static final java.lang.String getFullyQualifiedTableName(RDBMSAdapter dba,
                                                                java.lang.String catalog,
                                                                java.lang.String schema,
                                                                java.lang.String table)
Method to return a name for a table, fully qualified by catalog/schema if the adapter supports it and if specified.

Parameters:
dba - the RDBMSAdapter
catalog - the catalog identifier
schema - the schema identifier
table - the table identifier
Returns:
String name of the table (catalog.schema.table)

getClassNameForIdKeyUsingUnion

public static java.lang.String getClassNameForIdKeyUsingUnion(PersistenceManager pm,
                                                              RDBMSManager storeMgr,
                                                              java.lang.Object id,
                                                              java.util.List schemaDataOptions)
Utility that takes an id and a list of possible class RDBMSStoreData and finds which of these classes contains the object with that id. Works via a query to the datastore. Operates for all types of identity.

Parameters:
pm - Persistence Manager
storeMgr - Store Manager
id - The id
schemaDataOptions - List of possible RDBMSStoreData
Returns:
Name of the class with this key (or null if none found)

getClassNameForIdKeyUsingDiscriminator

public static java.lang.String getClassNameForIdKeyUsingDiscriminator(PersistenceManager pm,
                                                                      RDBMSManager storeMgr,
                                                                      java.lang.Object id,
                                                                      java.util.List schemaDataOptions)
Utility that takes an id and a list of possible class RDBMSStoreData and finds which of these classes contains the object with that id. Works via a query to the datastore. Operates for all types of identity. TODO The "schemaDataOptions" could be changed to be an array of class names.

Parameters:
pm - Persistence Manager
storeMgr - Store Manager
id - The id
schemaDataOptions - List of possible RDBMSStoreData
Returns:
Name of the class with this key (or null if none found)

getClassMetaDataManagingTableForClass

public static AbstractClassMetaData getClassMetaDataManagingTableForClass(AbstractClassMetaData cmd)
Utility to find the ClassMetaData for the class that manages the table where the supplied class stores its fields. This is for use where the current class uses an inheritance strategy of "superclass-table" and we want to find the table where we should add our fields.

Parameters:
cmd - The meta data for this class.
Returns:
The metadata for the class that manages the table


Copyright © -2007 . All Rights Reserved.