com.scooterframework.orm.sqldataexpress.vendor
Class DBAdapter

java.lang.Object
  extended by com.scooterframework.orm.sqldataexpress.vendor.DBAdapter
Direct Known Subclasses:
H2DBAdapter, HsqlDBAdapter, MySQLDBAdapter, OracleDBAdapter, PostgreSQLDBAdapter, SQLServerDBAdapter

public abstract class DBAdapter
extends java.lang.Object

DBAdapter class. Subclass should implement all abstract methods listed in this class.


Field Summary
protected static java.lang.String IGNORE
           
protected static java.lang.String USE_LOGIN_USER_ID_AS_SCHEMA
           
 
Constructor Summary
protected DBAdapter()
           
 
Method Summary
 boolean canChangeTableNameCase()
          Checks if table name case can be changed.
Some databases such as Oracle must use uppercase of a table name in order to get meta info of the table.
protected static int dotCount(java.lang.String s)
          Counts how many dots in a string.
protected  java.lang.Object getBlobData(java.sql.Blob blob)
           
abstract  java.lang.String[] getCatalogAndSchema(java.lang.String connName)
          Returns both catalog and schema of a connection.
protected  java.lang.Object getClobData(java.sql.Clob clob)
           
 java.lang.String getExpandedTableName(java.lang.String connName, java.lang.String tableName)
          Returns a full table name which may include catalog and schema.
 java.lang.String getExpandedTableName(java.lang.String catalog, java.lang.String schema, java.lang.String tableName)
          Returns a full-qualified table name which may include catalog and schema.
 java.lang.String getExpandedTableName(java.lang.String connName, java.lang.String catalog, java.lang.String schema, java.lang.String tableName)
          Returns a full-qualified table name which may include catalog and schema.
protected  java.io.InputStream getInputStream(java.lang.Object data)
           
protected static java.lang.String getLoginPassword()
          Returns login user id.
protected static java.lang.String getLoginUserId()
          Returns login user id.
 java.lang.Object getObjectFromResultSetByType(java.sql.ResultSet rs, java.lang.String javaClassType, int sqlDataType, int index)
           
 java.lang.Object getObjectFromStatementByType(java.sql.CallableStatement cstmt, java.lang.String javaClassType, int sqlDataType, int index)
           
 java.lang.String getOneRowSelectSQL(java.lang.String connName, java.lang.String tableName)
          Returns a SQL SELECT query which retrieves only one record from a table.
abstract  java.lang.String getOneRowSelectSQL(java.lang.String catalog, java.lang.String schema, java.lang.String tableName)
          Returns a SQL SELECT query which retrieves only one record from a table.
 java.lang.String getRetrieveAllSQL(java.lang.String connName, java.lang.String tableName)
          Returns a SQL query statement which is used to retrieve all records of a table, such as SELECT * total FROM users.
 java.lang.String getRetrieveAllSQL(java.lang.String catalog, java.lang.String schema, java.lang.String tableName)
          Returns a SQL query statement which is used to retrieve all records of a table, such as SELECT * total FROM users.
 java.lang.String getTotalCountSQL(java.lang.String connName, java.lang.String tableName)
          Returns a SQL query statement which is used to count all records of a table, such as SELECT count(*) total FROM users.
 java.lang.String getTotalCountSQL(java.lang.String catalog, java.lang.String schema, java.lang.String tableName)
          Returns a SQL query statement which is used to count all records of a table, such as SELECT count(*) total FROM users.
 java.lang.String getType()
          Returns type which is the class name of this adapter.
protected static boolean isEmpty(java.lang.String s)
          Checks if a string is empty.
abstract  java.lang.String preparePaginationSql(java.lang.String selectSql, java.util.Map<java.lang.String,java.lang.Object> inputs, java.util.Map<java.lang.String,java.lang.String> outputFilters)
          Returns a SQL query for pagination.
 java.lang.String[] resolveCatalogAndSchemaAndTable(java.lang.String connName, java.lang.String tableName)
          Returns catalog, schema and table of a connection.
 java.lang.String[] resolveCatalogAndSchemaAndTable(java.lang.String catalog, java.lang.String schema, java.lang.String tableName)
          Returns atomic catalog, schema and table based on tableName.
 java.lang.String[] resolveCatalogAndSchemaAndTable(java.lang.String connName, java.lang.String catalog, java.lang.String schema, java.lang.String tableName)
          Returns atomic catalog, schema and table based on connName, and tableName.
 java.lang.String[] resolveCatalogAndSchemaAndTableFromTableName(java.lang.String tableName)
          Returns atomic catalog, schema and table based on tableName.
protected static boolean useLoginAsSchema(java.lang.String connName)
          Checks if using login user id as schema.
 boolean vendorSpecificSetObject(java.sql.PreparedStatement pstmt, java.lang.Object obj, Parameter p, java.util.Map<java.lang.String,java.lang.Object> inputs)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IGNORE

protected static final java.lang.String IGNORE
See Also:
Constant Field Values

USE_LOGIN_USER_ID_AS_SCHEMA

protected static final java.lang.String USE_LOGIN_USER_ID_AS_SCHEMA
See Also:
Constant Field Values
Constructor Detail

DBAdapter

protected DBAdapter()
Method Detail

useLoginAsSchema

protected static boolean useLoginAsSchema(java.lang.String connName)
Checks if using login user id as schema. When the value of use_login_as_schema as defined in database.properties file for a database connection definition is true, this method should return true.

Parameters:
connName - the database connection name
Returns:
true if using login user id as schema

getLoginUserId

protected static java.lang.String getLoginUserId()
Returns login user id.


getLoginPassword

protected static java.lang.String getLoginPassword()
Returns login user id.


isEmpty

protected static boolean isEmpty(java.lang.String s)
Checks if a string is empty. A string containing all white spaces is treated as an empty string.


dotCount

protected static int dotCount(java.lang.String s)
Counts how many dots in a string.


getType

public java.lang.String getType()
Returns type which is the class name of this adapter.

Returns:
class name of this adapter

canChangeTableNameCase

public boolean canChangeTableNameCase()
Checks if table name case can be changed.
Some databases such as Oracle must use uppercase of a table name in order to get meta info of the table. Others, like MySQL in Linux platform, would not work properly if table name's case is changed.

Returns:
true if table name case can be changed.

getCatalogAndSchema

public abstract java.lang.String[] getCatalogAndSchema(java.lang.String connName)
Returns both catalog and schema of a connection.

Parameters:
connName - database connection name
Returns:
a string array containing catalog and schema

resolveCatalogAndSchemaAndTable

public java.lang.String[] resolveCatalogAndSchemaAndTable(java.lang.String connName,
                                                          java.lang.String tableName)
Returns catalog, schema and table of a connection.

Parameters:
connName - database connection name
tableName - table name
Returns:
a string array containing catalog, schema and table

resolveCatalogAndSchemaAndTable

public java.lang.String[] resolveCatalogAndSchemaAndTable(java.lang.String catalog,
                                                          java.lang.String schema,
                                                          java.lang.String tableName)
Returns atomic catalog, schema and table based on tableName.

This method assumes that value of the tableName may take one of the following three cases:

   {catalog}.{schema}.{table}
   {schema}.{table}
   {table}
 

If the catalog or schema is different from those defined with the tableName, an IllegalArgumentException will be thrown.

Parameters:
catalog - catalog name
schema - schema name
tableName - table name
Returns:
a string array containing catalog, schema and table

resolveCatalogAndSchemaAndTable

public java.lang.String[] resolveCatalogAndSchemaAndTable(java.lang.String connName,
                                                          java.lang.String catalog,
                                                          java.lang.String schema,
                                                          java.lang.String tableName)
Returns atomic catalog, schema and table based on connName, and tableName.

This method assumes that value of the tableName may take one of the following three cases:

   {catalog}.{schema}.{table}
   {schema}.{table}
   {table}
 

If the catalog or schema is different from those defined with the connName, an IllegalArgumentException will be thrown.

Parameters:
connName - database connection name
catalog - catalog name
schema - schema name
tableName - table name
Returns:
a string array containing catalog, schema and table

resolveCatalogAndSchemaAndTableFromTableName

public java.lang.String[] resolveCatalogAndSchemaAndTableFromTableName(java.lang.String tableName)
Returns atomic catalog, schema and table based on tableName.

This method assumes that value of the tableName may take one of the following three cases:

   {catalog}.{schema}.{table}
   {schema}.{table}
   {table}
 

This method should be overridden for those databases that do not use schema, such as MySQL database.

Parameters:
tableName -
Returns:
a string array containing catalog, schema and table

getExpandedTableName

public java.lang.String getExpandedTableName(java.lang.String connName,
                                             java.lang.String tableName)
Returns a full table name which may include catalog and schema.

The result table name may take one of the following cases:

   {catalog}.{schema}.{table}
   {catalog}.{table} //for MySQL
   {schema}.{table}  //for Oracle
   {table}
 

Parameters:
connName - connection name
tableName - table name
Returns:
an expanded table name

getExpandedTableName

public java.lang.String getExpandedTableName(java.lang.String catalog,
                                             java.lang.String schema,
                                             java.lang.String tableName)
Returns a full-qualified table name which may include catalog and schema.

The result table name may take one of the following cases:

   {catalog}.{schema}.{table}
   {catalog}.{table} //for MySQL
   {schema}.{table}  //for Oracle
   {table}
 

Parameters:
catalog - catalog name
schema - schema name
tableName - table name
Returns:
an expanded table name

getExpandedTableName

public java.lang.String getExpandedTableName(java.lang.String connName,
                                             java.lang.String catalog,
                                             java.lang.String schema,
                                             java.lang.String tableName)
Returns a full-qualified table name which may include catalog and schema.

The result table name may take one of the following cases:

   {catalog}.{schema}.{table}
   {catalog}.{table} //for MySQL
   {schema}.{table}  //for Oracle
   {table}
 

Parameters:
connName - database connection name
catalog - catalog name
schema - schema name
tableName - table name
Returns:
an expanded table name

getOneRowSelectSQL

public abstract java.lang.String getOneRowSelectSQL(java.lang.String catalog,
                                                    java.lang.String schema,
                                                    java.lang.String tableName)
Returns a SQL SELECT query which retrieves only one record from a table. This query is used for retrieving meta data of the underlining table.

Parameters:
catalog - catalog name
schema - schema name
tableName - table name
Returns:
a SELECT query string

getOneRowSelectSQL

public java.lang.String getOneRowSelectSQL(java.lang.String connName,
                                           java.lang.String tableName)
Returns a SQL SELECT query which retrieves only one record from a table. This query is used for retrieving meta data of the underlying table.

Parameters:
connName - database connection name
tableName - table name
Returns:
a SELECT query string

getTotalCountSQL

public java.lang.String getTotalCountSQL(java.lang.String catalog,
                                         java.lang.String schema,
                                         java.lang.String tableName)
Returns a SQL query statement which is used to count all records of a table, such as SELECT count(*) total FROM users.

Parameters:
catalog - catalog name
schema - schema name
tableName - table name
Returns:
a SQL query string for counting total

getTotalCountSQL

public java.lang.String getTotalCountSQL(java.lang.String connName,
                                         java.lang.String tableName)
Returns a SQL query statement which is used to count all records of a table, such as SELECT count(*) total FROM users.

Parameters:
connName - database connection name
tableName - table name
Returns:
a SQL query string for counting total

getRetrieveAllSQL

public java.lang.String getRetrieveAllSQL(java.lang.String connName,
                                          java.lang.String tableName)
Returns a SQL query statement which is used to retrieve all records of a table, such as SELECT * total FROM users.

Parameters:
connName - database connection name
tableName - table name
Returns:
a retrieve all SQL query string

getRetrieveAllSQL

public java.lang.String getRetrieveAllSQL(java.lang.String catalog,
                                          java.lang.String schema,
                                          java.lang.String tableName)
Returns a SQL query statement which is used to retrieve all records of a table, such as SELECT * total FROM users.

Parameters:
catalog - catalog name
schema - schema name
tableName - table name
Returns:
a retrieve all SQL query string

preparePaginationSql

public abstract java.lang.String preparePaginationSql(java.lang.String selectSql,
                                                      java.util.Map<java.lang.String,java.lang.Object> inputs,
                                                      java.util.Map<java.lang.String,java.lang.String> outputFilters)
Returns a SQL query for pagination. This method converts a generic SQL query statement to a SQL query for pagination.

Parameters:
selectSql - the original SQL statement
inputs - inputs
outputFilters - outputFilters
Returns:
a SQL query for pagination

getObjectFromResultSetByType

public java.lang.Object getObjectFromResultSetByType(java.sql.ResultSet rs,
                                                     java.lang.String javaClassType,
                                                     int sqlDataType,
                                                     int index)
                                              throws java.sql.SQLException
Throws:
java.sql.SQLException

getObjectFromStatementByType

public java.lang.Object getObjectFromStatementByType(java.sql.CallableStatement cstmt,
                                                     java.lang.String javaClassType,
                                                     int sqlDataType,
                                                     int index)
                                              throws java.sql.SQLException
Throws:
java.sql.SQLException

getBlobData

protected java.lang.Object getBlobData(java.sql.Blob blob)
                                throws java.sql.SQLException,
                                       java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

getClobData

protected java.lang.Object getClobData(java.sql.Clob clob)
                                throws java.sql.SQLException,
                                       java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

vendorSpecificSetObject

public boolean vendorSpecificSetObject(java.sql.PreparedStatement pstmt,
                                       java.lang.Object obj,
                                       Parameter p,
                                       java.util.Map<java.lang.String,java.lang.Object> inputs)
                                throws java.lang.Exception
Throws:
java.lang.Exception

getInputStream

protected java.io.InputStream getInputStream(java.lang.Object data)
                                      throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException