org.jpox.store.rdbms.sqlidentifier
Class AbstractRDBMSIdentifierFactory

java.lang.Object
  extended by org.jpox.store.AbstractIdentifierFactory
      extended by org.jpox.store.rdbms.sqlidentifier.AbstractRDBMSIdentifierFactory
All Implemented Interfaces:
IdentifierFactory, RDBMSIdentifierFactory
Direct Known Subclasses:
JPAIdentifierFactory, JPOXIdentifierFactory

public abstract class AbstractRDBMSIdentifierFactory
extends AbstractIdentifierFactory
implements RDBMSIdentifierFactory

Abstract representation of an identifier factory for RDBMS datastores. To be extended to generate the identifiers.

Version:
$Revision: 1.21.2.1 $

Field Summary
protected  java.util.Map candidates
           
protected  java.util.Map columns
           
protected  java.lang.String defaultCatalogName
          Default catalog name for any created identifiers.
protected  java.lang.String defaultSchemaName
          Default schema name for any created identifiers.
protected  java.util.Map foreignkeys
           
protected  java.util.Map indexes
           
protected  java.util.Map primarykeys
           
protected  RDBMSAdapter rdba
          Convenience RDBMSAdapter variable to save casting.
protected  java.util.Map references
           
protected  java.util.Map sequences
           
protected  java.util.Map tables
           
protected  java.lang.String wordSeparator
          Separator to use for words in the identifiers.
 
Fields inherited from class org.jpox.store.AbstractIdentifierFactory
CASE_LOWER, CASE_PRESERVE, CASE_UPPER, dba, identifierCase, LOCALISER
 
Fields inherited from interface org.jpox.store.IdentifierFactory
CANDIDATE_KEY, COLUMN, FOREIGN_KEY, IDENTIFIER_LOWER_CASE, IDENTIFIER_LOWER_CASE_QUOTED, IDENTIFIER_MIXED_CASE, IDENTIFIER_MIXED_CASE_QUOTED, IDENTIFIER_UPPER_CASE, IDENTIFIER_UPPER_CASE_QUOTED, INDEX, PRIMARY_KEY, SEQUENCE, TABLE
 
Constructor Summary
AbstractRDBMSIdentifierFactory(DatastoreAdapter dba, java.lang.String requiredCase, java.lang.String defaultCatalog, java.lang.String defaultSchema)
          Constructor.
 
Method Summary
protected abstract  java.lang.String generateIdentifierNameForJavaName(java.lang.String javaName)
          Generate a datastore identifier from a Java identifier.
protected abstract  java.lang.String getColumnIdentifierSuffix(int role, boolean embedded)
          Accessor for the suffix to add to any column identifier, based on the role type.
 java.lang.String getIdentifierInAdapterCase(java.lang.String identifier)
          Convenience method to convert the passed identifier into an identifier in the correct case, and with any required quoting for the datastore adapter.
protected  java.lang.String[] getIdentifierNamePartsFromName(java.lang.String name)
          Convenience method to split a fully-specified identifier name (inc catalog/schema) into its constituent parts.
protected  int getMaxLengthForIdentifierType(int identifierType)
          Method to return the maximum permitted length of an identifier of the specified type.
 java.lang.String getWordSeparator()
          Accessor for the word separator for identifiers.
 DatastoreIdentifier newCandidateKeyIdentifier(DatastoreContainerObject table, int seq)
          Method to generate an identifier for a candidate key in the supplied table.
 DatastoreIdentifier newDatastoreContainerIdentifier(java.lang.String identifierName)
          Method to use to generate an identifier for a datastore field.
 DatastoreIdentifier newDatastoreFieldIdentifier(java.lang.String identifierName)
          Method to use to generate an identifier for a datastore field.
 DatastoreIdentifier newDatastoreFieldIdentifier(java.lang.String javaName, boolean embedded, int fieldRole)
          Method to create an identifier for a datastore field where we want the name based on the supplied java name, and the field has a particular role (and so could have its naming set according to the role).
 DatastoreIdentifier newForeignKeyIdentifier(DatastoreContainerObject table, int seq)
          Method to create a new identifier for a foreign key in the supplied table.
 DatastoreIdentifier newIdentifier(DatastoreIdentifier identifier, java.lang.String suffix)
          Method to return a new Identifier based on the passed identifier, but adding on the passed suffix
 DatastoreIdentifier newIdentifier(int identifierType, java.lang.String name)
          Method to generate an identifier based on the supplied name for the requested type of identifier.
 DatastoreIdentifier newIndexIdentifier(DatastoreContainerObject table, boolean isUnique, int seq)
          Method to create an identifier for an Index in the supplied table.
 DatastoreIdentifier newPrimaryKeyIdentifier(DatastoreContainerObject table)
          Method to generate an identifier for a primary key for the supplied table.
 DatastoreIdentifier newSequenceIdentifier(java.lang.String sequenceName)
          Method to generate an identifier for a sequence using the passed name.
protected  void setCatalogSchemaForTable(org.jpox.store.rdbms.sqlidentifier.TableIdentifier identifier)
          Convenience method to set the catalog/schema on the passed TableIdentifier.
 
Methods inherited from class org.jpox.store.AbstractIdentifierFactory
getDatastoreAdapter, getIdentifierCase, getNameOfIdentifierCase, truncate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jpox.store.rdbms.sqlidentifier.RDBMSIdentifierFactory
newAdapterIndexFieldIdentifier, newForeignKeyFieldIdentifier, newIndexFieldIdentifier, newJoinTableFieldIdentifier
 
Methods inherited from interface org.jpox.store.IdentifierFactory
getDatastoreAdapter, getIdentifierCase, getNameOfIdentifierCase, newDatastoreContainerIdentifier, newDatastoreContainerIdentifier, newDiscriminatorFieldIdentifier, newReferenceFieldIdentifier, newVersionFieldIdentifier
 

Field Detail

tables

protected java.util.Map tables

columns

protected java.util.Map columns

foreignkeys

protected java.util.Map foreignkeys

indexes

protected java.util.Map indexes

candidates

protected java.util.Map candidates

primarykeys

protected java.util.Map primarykeys

sequences

protected java.util.Map sequences

references

protected java.util.Map references

wordSeparator

protected java.lang.String wordSeparator
Separator to use for words in the identifiers.


rdba

protected RDBMSAdapter rdba
Convenience RDBMSAdapter variable to save casting.


defaultCatalogName

protected java.lang.String defaultCatalogName
Default catalog name for any created identifiers.


defaultSchemaName

protected java.lang.String defaultSchemaName
Default schema name for any created identifiers.

Constructor Detail

AbstractRDBMSIdentifierFactory

public AbstractRDBMSIdentifierFactory(DatastoreAdapter dba,
                                      java.lang.String requiredCase,
                                      java.lang.String defaultCatalog,
                                      java.lang.String defaultSchema)
Constructor.

Parameters:
dba - Database adapter
requiredCase - The case the user requires
defaultCatalog - Name of the default catalog (if any)
defaultSchema - Name of the default schema (if any)
Method Detail

getWordSeparator

public java.lang.String getWordSeparator()
Accessor for the word separator for identifiers.

Returns:
The word separator

getIdentifierInAdapterCase

public java.lang.String getIdentifierInAdapterCase(java.lang.String identifier)
Convenience method to convert the passed identifier into an identifier in the correct case, and with any required quoting for the datastore adapter. If the identifier is already quoted and needs quotes then none are added.

Specified by:
getIdentifierInAdapterCase in interface IdentifierFactory
Parameters:
identifier - The identifier
Returns:
The updated identifier in the correct case

newIdentifier

public DatastoreIdentifier newIdentifier(int identifierType,
                                         java.lang.String name)
Method to generate an identifier based on the supplied name for the requested type of identifier.

Specified by:
newIdentifier in interface IdentifierFactory
Parameters:
identifierType - the type of identifier to be created
name - The Java or SQL identifier name
Returns:
The DatastoreIdentifier

newIdentifier

public DatastoreIdentifier newIdentifier(DatastoreIdentifier identifier,
                                         java.lang.String suffix)
Method to return a new Identifier based on the passed identifier, but adding on the passed suffix

Specified by:
newIdentifier in interface IdentifierFactory
Parameters:
identifier - The current identifier
suffix - The suffix
Returns:
The new identifier

newDatastoreContainerIdentifier

public DatastoreIdentifier newDatastoreContainerIdentifier(java.lang.String identifierName)
Method to use to generate an identifier for a datastore field. The passed name will not be changed (other than in its case) although it may be truncated to fit the maximum length permitted for a datastore field identifier.

Specified by:
newDatastoreContainerIdentifier in interface IdentifierFactory
Parameters:
identifierName - The identifier name
Returns:
The DatastoreIdentifier for the table

newDatastoreFieldIdentifier

public DatastoreIdentifier newDatastoreFieldIdentifier(java.lang.String identifierName)
Method to use to generate an identifier for a datastore field. The passed name will not be changed (other than in its case) although it may be truncated to fit the maximum length permitted for a datastore field identifier.

Specified by:
newDatastoreFieldIdentifier in interface IdentifierFactory
Parameters:
identifierName - The identifier name
Returns:
The DatastoreIdentifier

newDatastoreFieldIdentifier

public DatastoreIdentifier newDatastoreFieldIdentifier(java.lang.String javaName,
                                                       boolean embedded,
                                                       int fieldRole)
Method to create an identifier for a datastore field where we want the name based on the supplied java name, and the field has a particular role (and so could have its naming set according to the role).

Specified by:
newDatastoreFieldIdentifier in interface IdentifierFactory
Parameters:
javaName - The java field name
embedded - Whether the identifier is for a field embedded
fieldRole - The role to be performed by this column e.g FK, Index ?
Returns:
The DatastoreIdentifier

newSequenceIdentifier

public DatastoreIdentifier newSequenceIdentifier(java.lang.String sequenceName)
Method to generate an identifier for a sequence using the passed name.

Specified by:
newSequenceIdentifier in interface RDBMSIdentifierFactory
Parameters:
sequenceName - the name of the sequence to use
Returns:
The DatastoreIdentifier

newPrimaryKeyIdentifier

public DatastoreIdentifier newPrimaryKeyIdentifier(DatastoreContainerObject table)
Method to generate an identifier for a primary key for the supplied table.

Specified by:
newPrimaryKeyIdentifier in interface RDBMSIdentifierFactory
Parameters:
table - the table
Returns:
The DatastoreIdentifier

newCandidateKeyIdentifier

public DatastoreIdentifier newCandidateKeyIdentifier(DatastoreContainerObject table,
                                                     int seq)
Method to generate an identifier for a candidate key in the supplied table.

Specified by:
newCandidateKeyIdentifier in interface RDBMSIdentifierFactory
Parameters:
table - the table
seq - the sequential number
Returns:
The DatastoreIdentifier

newForeignKeyIdentifier

public DatastoreIdentifier newForeignKeyIdentifier(DatastoreContainerObject table,
                                                   int seq)
Method to create a new identifier for a foreign key in the supplied table.

Specified by:
newForeignKeyIdentifier in interface RDBMSIdentifierFactory
Parameters:
table - the table
seq - the sequential number
Returns:
The DatastoreIdentifier

newIndexIdentifier

public DatastoreIdentifier newIndexIdentifier(DatastoreContainerObject table,
                                              boolean isUnique,
                                              int seq)
Method to create an identifier for an Index in the supplied table.

Specified by:
newIndexIdentifier in interface RDBMSIdentifierFactory
Parameters:
table - the table
isUnique - if the index is unique
seq - the sequential number
Returns:
The DatastoreIdentifier

getColumnIdentifierSuffix

protected abstract java.lang.String getColumnIdentifierSuffix(int role,
                                                              boolean embedded)
Accessor for the suffix to add to any column identifier, based on the role type.

Parameters:
role - Datastore field role
embedded - Whether the DatastoreField is stored embedded
Returns:
The suffix (e.g _ID for id columns).

generateIdentifierNameForJavaName

protected abstract java.lang.String generateIdentifierNameForJavaName(java.lang.String javaName)
Generate a datastore identifier from a Java identifier. Embodies the naming rules for the factory.

Parameters:
javaName - the Java identifier.
Returns:
The datastore identifier

setCatalogSchemaForTable

protected void setCatalogSchemaForTable(org.jpox.store.rdbms.sqlidentifier.TableIdentifier identifier)
Convenience method to set the catalog/schema on the passed TableIdentifier.

Parameters:
identifier - The TableIdentifier

getIdentifierNamePartsFromName

protected java.lang.String[] getIdentifierNamePartsFromName(java.lang.String name)
Convenience method to split a fully-specified identifier name (inc catalog/schema) into its constituent parts. Returns a String array with 3 elements. The first is the catalog, second the schema, and third the identifier.

Parameters:
name - Name
Returns:
The parts

getMaxLengthForIdentifierType

protected int getMaxLengthForIdentifierType(int identifierType)
Method to return the maximum permitted length of an identifier of the specified type. Returns -1 if the identifier type is not supported.

Specified by:
getMaxLengthForIdentifierType in class AbstractIdentifierFactory
Parameters:
identifierType - Type of identifier
Returns:
The maximum length


Copyright © -2008 . All Rights Reserved.