com.is.jrf
Class SQLServerSybaseDatabasePolicy

java.lang.Object
  |
  +--com.is.jrf.SQLServerSybaseDatabasePolicy
All Implemented Interfaces:
DatabasePolicy

public class SQLServerSybaseDatabasePolicy
extends java.lang.Object
implements DatabasePolicy

Instances of this class perform Sybase/SQLServer-specific logic and return Sybase/SQLServer-specific information.


Constructor Summary
SQLServerSybaseDatabasePolicy()
           
 
Method Summary
 java.lang.String autoIncrementIdentifier()
          SQLServer and Sybase have stored procedures for generating a sequence number, so AUTO INCREMENT is not needed here.
 void createSequence(AbstractDomain domain, JDBCHelper aJDBCHelper)
          This is called when creating a table that has a SEQUENCED_PRIMARY_KEY.
 java.lang.String currentTimestampSQL()
          This should return the the SQL to use to have the database return the current timestamp.
 java.lang.Long findAutoIncrementId(java.lang.String tableName, java.lang.String columnName, JDBCHelper aJDBCHelper)
          This method throws an exception since it should never be called.
 java.lang.String formatDate(java.sql.Date sqlDate)
          The result of this is used in SQL.
 java.lang.String formatTimestamp(java.sql.Timestamp ts)
          The return value should be in the format that the database recognizes for a timestamp.
 java.lang.String outerWhereJoin(java.lang.String mainTableColumn, java.lang.String joinTableColumn)
          Return a string with a name-value pair that represents an SQL outer join in a WHERE clause for SQLServer and Sybase.
 java.lang.String sequenceSQL(java.lang.String tableName)
          When executed, this SQL should return a one column, one row result set with an Integer in it.
 java.lang.String timestampColumnType()
          This method is used when building SQL to create tables.
 java.lang.String timestampFunction()
          This is the string value (function name) to put into the SQL to tell the database to insert the current timestamp.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLServerSybaseDatabasePolicy

public SQLServerSybaseDatabasePolicy()
Method Detail

sequenceSQL

public java.lang.String sequenceSQL(java.lang.String tableName)
When executed, this SQL should return a one column, one row result set with an Integer in it.
Specified by:
sequenceSQL in interface DatabasePolicy
Parameters:
tableName - a value of type 'String'
Returns:
a value of type 'String'

timestampFunction

public java.lang.String timestampFunction()
This is the string value (function name) to put into the SQL to tell the database to insert the current timestamp.
Specified by:
timestampFunction in interface DatabasePolicy
Returns:
a value of type 'String'

formatTimestamp

public java.lang.String formatTimestamp(java.sql.Timestamp ts)
The return value should be in the format that the database recognizes for a timestamp.
Specified by:
formatTimestamp in interface DatabasePolicy
Parameters:
ts - a value of type 'Timestamp'
Returns:
a value of type 'String'

formatDate

public java.lang.String formatDate(java.sql.Date sqlDate)
The result of this is used in SQL. This will return only the date (not the time portion)
Specified by:
formatDate in interface DatabasePolicy
Parameters:
sqlDate - a value of type 'java.sql.Date'
Returns:
a value of type 'String'

currentTimestampSQL

public java.lang.String currentTimestampSQL()
This should return the the SQL to use to have the database return the current timestamp.
Specified by:
currentTimestampSQL in interface DatabasePolicy
Returns:
a value of type 'String'

autoIncrementIdentifier

public java.lang.String autoIncrementIdentifier()
SQLServer and Sybase have stored procedures for generating a sequence number, so AUTO INCREMENT is not needed here.
Specified by:
autoIncrementIdentifier in interface DatabasePolicy
Returns:
null since Sybase doesn't support the auto-increment method

findAutoIncrementId

public java.lang.Long findAutoIncrementId(java.lang.String tableName,
                                          java.lang.String columnName,
                                          JDBCHelper aJDBCHelper)
This method throws an exception since it should never be called.
Specified by:
findAutoIncrementId in interface DatabasePolicy
Parameters:
tableName - a value of type 'String'
columnName - a value of type 'String'
aJDBCHelper - a value of type 'JDBCHelper'
Returns:
a value of type 'Long'

createSequence

public void createSequence(AbstractDomain domain,
                           JDBCHelper aJDBCHelper)
                    throws java.sql.SQLException
This is called when creating a table that has a SEQUENCED_PRIMARY_KEY. This implementation assumes there is already a table called SequenceNumber with columns named SequenceName and CurrentIndex. See the SQLServer-Readme.txt file that should have come with the distribution. When this is called, the Sequence number is set to zero whether a row exists for the table or not.
Specified by:
createSequence in interface DatabasePolicy
Parameters:
domain - a value of type 'AbstractDomain'
aJDBCHelper - a value of type 'JDBCHelper'

outerWhereJoin

public java.lang.String outerWhereJoin(java.lang.String mainTableColumn,
                                       java.lang.String joinTableColumn)
Return a string with a name-value pair that represents an SQL outer join in a WHERE clause for SQLServer and Sybase. Given this operator (*=), it looks like SQLServer always gives preference to the rows in the table on the left whether it is a foreign key in the left table or a foreign key in the right table. This is what we want since we always put the main table on the left.
Specified by:
outerWhereJoin in interface DatabasePolicy
Parameters:
mainTableColumn - a value of type 'String'
joinTableColumn - a value of type 'String'
sqlBuffer - a value of type 'StringBuffer'
Returns:
a value of type 'String'

timestampColumnType

public java.lang.String timestampColumnType()
This method is used when building SQL to create tables.
Specified by:
timestampColumnType in interface DatabasePolicy
Returns:
a value of type 'String'