org.dbmaintain.database
Class IdentifierProcessor

java.lang.Object
  extended by org.dbmaintain.database.IdentifierProcessor

public class IdentifierProcessor
extends Object

Author:
Tim Ducheyne, Filip Neven

Field Summary
protected  String defaultSchemaName
           
protected  String identifierQuoteString
           
protected  StoredIdentifierCase storedIdentifierCase
           
 
Constructor Summary
IdentifierProcessor(StoredIdentifierCase storedIdentifierCase, String identifierQuoteString, String defaultSchemaName)
           
 
Method Summary
 String getDefaultSchemaName()
           
 String getIdentifierQuoteString()
          Gets the identifier quote string.
 String getSchemaName(String qualifiedTableName)
           
 StoredIdentifierCase getStoredIdentifierCase()
          Gets the stored identifier case.
 String getTableName(String qualifiedTableName)
           
 boolean isQuoted(String identifier)
           
 String qualified(String databaseObjectName)
          Qualifies the given database object name with the name of the default schema.
 String qualified(String schemaName, String databaseObjectName)
          Qualifies the given database object name with the name of the given schema.
 String quoted(String databaseObjectName)
          Put quotes around the given databaseObjectName, if the underlying DBMS supports quoted database object names.
 String removeIdentifierQuotes(String identifier)
           
 String toCorrectCaseIdentifier(String identifier)
          Converts the given identifier to uppercase/lowercase depending on the DBMS.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

storedIdentifierCase

protected StoredIdentifierCase storedIdentifierCase

identifierQuoteString

protected String identifierQuoteString

defaultSchemaName

protected String defaultSchemaName
Constructor Detail

IdentifierProcessor

public IdentifierProcessor(StoredIdentifierCase storedIdentifierCase,
                           String identifierQuoteString,
                           String defaultSchemaName)
Method Detail

getDefaultSchemaName

public String getDefaultSchemaName()

quoted

public String quoted(String databaseObjectName)
Put quotes around the given databaseObjectName, if the underlying DBMS supports quoted database object names. If not, the databaseObjectName is returned unchanged.

Parameters:
databaseObjectName - The name, not null
Returns:
Quoted version of the given databaseObjectName, if supported by the underlying DBMS

isQuoted

public boolean isQuoted(String identifier)
Parameters:
identifier - The identifier, not null
Returns:
True if the identifier starts and ends with identifier quotes

removeIdentifierQuotes

public String removeIdentifierQuotes(String identifier)
Parameters:
identifier - The identifier, not null
Returns:
The identifier, removing identifier quotes if necessary, not null

qualified

public String qualified(String databaseObjectName)
Qualifies the given database object name with the name of the default schema. Quotes are put around both schemaname and object name. If the schemaName is not supplied, the database object is returned surrounded with quotes. If the DBMS doesn't support quoted database object names, no quotes are put around neither schema name nor database object name.

Parameters:
databaseObjectName - The database object name to be qualified
Returns:
The qualified database object name

qualified

public String qualified(String schemaName,
                        String databaseObjectName)
Qualifies the given database object name with the name of the given schema. Quotes are put around both schemaname and object name. If the schemaName is not supplied, the database object is returned surrounded with quotes. If the DBMS doesn't support quoted database object names, no quotes are put around neither schema name nor database object name.

Parameters:
schemaName - The schema, not null
databaseObjectName - The database object name to be qualified
Returns:
The qualified database object name

toCorrectCaseIdentifier

public String toCorrectCaseIdentifier(String identifier)
Converts the given identifier to uppercase/lowercase depending on the DBMS. If a value is surrounded with double quotes (") and the DBMS supports quoted database object names, the case is left untouched and the double quotes are stripped. These values are treated as case sensitive names.

Identifiers can be prefixed with schema names. These schema names will be converted in the same way as described above. Quoting the schema name will make it case sensitive. Examples:

mySchema.myTable -> MYSCHEMA.MYTABLE "mySchema".myTable -> mySchema.MYTABLE "mySchema"."myTable" -> mySchema.myTable

Parameters:
identifier - The identifier, not null
Returns:
The name converted to correct case if needed, not null

getSchemaName

public String getSchemaName(String qualifiedTableName)

getTableName

public String getTableName(String qualifiedTableName)

getIdentifierQuoteString

public String getIdentifierQuoteString()
Gets the identifier quote string.

Returns:
the quote string, null if not supported

getStoredIdentifierCase

public StoredIdentifierCase getStoredIdentifierCase()
Gets the stored identifier case.

Returns:
the case, not null


Copyright © 2011. All Rights Reserved.