com.scooterframework.orm.sqldataexpress.util
Class SqlExpressUtil

java.lang.Object
  extended by com.scooterframework.orm.sqldataexpress.util.SqlExpressUtil

public class SqlExpressUtil
extends java.lang.Object

SqlExpressUtil class holds utility methods for meta data lookup.


Constructor Summary
SqlExpressUtil()
           
 
Method Summary
static java.lang.String checkSpecialCharacterInTableName(java.lang.String table)
           
static java.lang.Object countTotalRecords(java.lang.String connName, java.lang.String table)
          Returns total number of records in a table.
static JdbcStatement createJdbcStatement(java.lang.String name)
           
static JdbcStatement createJdbcStatementDirect(java.lang.String jdbcStatementString)
           
static java.lang.String[] getCatalogAndSchema(java.lang.String connName)
          Returns both catalog and schema of a connection.
static java.sql.Connection getConnection()
          Returns a database connection.
static java.sql.Connection getConnection(DatabaseConnectionContext dcc)
          Returns a database connection.
static java.sql.Connection getConnection(java.lang.String connName)
          Returns a database connection.
static java.util.List<java.lang.String> getConnectionNames()
           
static java.util.Properties getConnectionProperties(java.lang.String connName)
          Returns properties associated with a database connection name.
static java.lang.String getConnectionUser(java.lang.String connName)
          Returns username of a database connection.
static java.util.List<TableInfo> getDatabaseTables(java.lang.String connName)
          Returns a list of TableInfo instances for a database connection name.
static java.util.List<TableInfo> getDatabaseTables(java.lang.String connName, java.lang.String catalog, java.lang.String schema, java.lang.String tableName, java.lang.String[] types)
          Returns a list of TableInfo instances for a database connection name.
static java.lang.String getDatabaseVendor(java.sql.DatabaseMetaData dbmd)
          Returns database vendor name.
static java.util.Properties getDefaultConnectionProperties()
          Returns properties associated with a default database connection name.
static java.lang.String getExpandedTableName(java.lang.String connName, java.lang.String table)
          Returns expanded table name which includes catalog and schema.
static java.lang.String getExtendedTableName(java.lang.String connName, java.lang.String catalog, java.lang.String schema, java.lang.String tableName)
          Returns the extended table name.
static java.lang.String getExtendedTableName(java.lang.String connName, TableInfo ti)
           
static java.lang.String getFinderSQL(java.lang.String connName, java.lang.String table)
          Returns finder SQL query statement.
static java.sql.Connection getReadonlyConnection()
          Returns a real-only database connection.
static java.sql.Connection getReadonlyConnection(DatabaseConnectionContext dcc)
          Returns a real-only database connection.
static java.sql.Connection getReadonlyConnection(java.lang.String connName)
          Returns a real-only database connection.
static java.lang.String getSafeTableName(java.lang.String connName, java.lang.String tableName)
           
static java.util.Map<java.lang.String,java.lang.String> getTableKeyMapForRestfulId(RowInfo ri, java.lang.String restfulId)
          Returns a map of primary key fields with values from restfuId.
static UserDatabaseConnection getUserDatabaseConnection()
          Returns a UserDatabaseConnection instance for default database connection name.
static UserDatabaseConnection getUserDatabaseConnection(DatabaseConnectionContext dcc)
          Returns a UserDatabaseConnection instance for a specific database connection context.
static UserDatabaseConnection getUserDatabaseConnection(java.lang.String connName)
          Returns a UserDatabaseConnection instance for a specific database connection name.
static boolean isBuiltinVendor(java.lang.String vendor, java.lang.String connName)
          Checks if a vendor is a built-in vendor supported.
static boolean isNiceDBString(java.lang.String s)
          Verifies that if the input string contains some special characters that are not friendly in database table names or column names.
static boolean isOracle(java.lang.String connName)
          Checks if the underlying connection is for Oracle database.
static Function lookupAndRegisterFunction(java.lang.String function)
           
static StoredProcedure lookupAndRegisterStoredProcedure(java.lang.String storedProcedure)
           
static Function lookupFunction(UserDatabaseConnection udc, java.lang.String name)
           
static PrimaryKey lookupPrimaryKey(java.lang.String connName, java.lang.String tableName)
          Looks up PrimaryKey.
static StoredProcedure lookupStoredProcedure(UserDatabaseConnection udc, java.lang.String name)
           
static TableInfo lookupTableInfo(java.lang.String connName, java.lang.String tableName)
          Looks up TableInfo.
static TableInfo lookupTableInfo(UserDatabaseConnection udc, java.lang.String tableName)
          Looks up TableInfo.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlExpressUtil

public SqlExpressUtil()
Method Detail

getConnectionNames

public static java.util.List<java.lang.String> getConnectionNames()

getDefaultConnectionProperties

public static java.util.Properties getDefaultConnectionProperties()
Returns properties associated with a default database connection name.

Returns:
properties of the connection name

getConnectionProperties

public static java.util.Properties getConnectionProperties(java.lang.String connName)
Returns properties associated with a database connection name.

Parameters:
connName - database connection name
Returns:
properties of the connection name

getConnectionUser

public static java.lang.String getConnectionUser(java.lang.String connName)
Returns username of a database connection.

Parameters:
connName - database connection name
Returns:
connection username

getExtendedTableName

public static java.lang.String getExtendedTableName(java.lang.String connName,
                                                    TableInfo ti)

getExtendedTableName

public static java.lang.String getExtendedTableName(java.lang.String connName,
                                                    java.lang.String catalog,
                                                    java.lang.String schema,
                                                    java.lang.String tableName)
Returns the extended table name.

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

isOracle

public static boolean isOracle(java.lang.String connName)
Checks if the underlying connection is for Oracle database.

Parameters:
connName - database connection name
Returns:
true if it is Oracle

isBuiltinVendor

public static boolean isBuiltinVendor(java.lang.String vendor,
                                      java.lang.String connName)
Checks if a vendor is a built-in vendor supported.

Parameters:
vendor - vendor name supported
connName - database connection name
Returns:
true if it is built-in vendor

getCatalogAndSchema

public static 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

checkSpecialCharacterInTableName

public static java.lang.String checkSpecialCharacterInTableName(java.lang.String table)

isNiceDBString

public static boolean isNiceDBString(java.lang.String s)

Verifies that if the input string contains some special characters that are not friendly in database table names or column names.

Only the following are treated as nice characters:

Parameters:
s - a string to check
Returns:
true if the string contains no special chars

getSafeTableName

public static java.lang.String getSafeTableName(java.lang.String connName,
                                                java.lang.String tableName)

getUserDatabaseConnection

public static UserDatabaseConnection getUserDatabaseConnection()
Returns a UserDatabaseConnection instance for default database connection name.


getUserDatabaseConnection

public static UserDatabaseConnection getUserDatabaseConnection(DatabaseConnectionContext dcc)
Returns a UserDatabaseConnection instance for a specific database connection context.

Parameters:
dcc - a DatabaseConnectionContext instance

getUserDatabaseConnection

public static UserDatabaseConnection getUserDatabaseConnection(java.lang.String connName)
Returns a UserDatabaseConnection instance for a specific database connection name.

Parameters:
connName - name of a connection

getConnection

public static java.sql.Connection getConnection()
                                         throws java.sql.SQLException
Returns a database connection.

Returns:
a database connection
Throws:
java.sql.SQLException

getConnection

public static java.sql.Connection getConnection(java.lang.String connName)
                                         throws java.sql.SQLException
Returns a database connection.

Parameters:
connName - name of a connection
Returns:
a database connection
Throws:
java.sql.SQLException

getConnection

public static java.sql.Connection getConnection(DatabaseConnectionContext dcc)
                                         throws java.sql.SQLException
Returns a database connection.

Parameters:
dcc - a DatabaseConnectionContext instance
Returns:
a database connection
Throws:
java.sql.SQLException

getReadonlyConnection

public static java.sql.Connection getReadonlyConnection()
                                                 throws java.sql.SQLException
Returns a real-only database connection.

Returns:
a read-only database connection
Throws:
java.sql.SQLException

getReadonlyConnection

public static java.sql.Connection getReadonlyConnection(java.lang.String connName)
                                                 throws java.sql.SQLException
Returns a real-only database connection.

Parameters:
connName - name of a connection
Returns:
a read-only database connection
Throws:
java.sql.SQLException

getReadonlyConnection

public static java.sql.Connection getReadonlyConnection(DatabaseConnectionContext dcc)
                                                 throws java.sql.SQLException
Returns a real-only database connection.

Parameters:
dcc - a DatabaseConnectionContext instance
Returns:
a read-only database connection
Throws:
java.sql.SQLException

getDatabaseTables

public static java.util.List<TableInfo> getDatabaseTables(java.lang.String connName,
                                                          java.lang.String catalog,
                                                          java.lang.String schema,
                                                          java.lang.String tableName,
                                                          java.lang.String[] types)
                                                   throws java.sql.SQLException
Returns a list of TableInfo instances for a database connection name.

Parameters:
connName - the database connection name
catalog - a catalog name; must match the catalog name as it is stored in the database; "" retrieves those without a catalog; null means that the catalog name should not be used to narrow the search
schema - a schema name; must match the schema name as it is stored in the database; "" retrieves those without a schema; null means that the schema name should not be used to narrow the search
tableName - a table name; must match the table name as it is stored in the database
types - a list of table types to include; null returns all types
Returns:
a list of TableInfo instances
Throws:
java.sql.SQLException

getDatabaseTables

public static java.util.List<TableInfo> getDatabaseTables(java.lang.String connName)
                                                   throws java.sql.SQLException
Returns a list of TableInfo instances for a database connection name.

Parameters:
connName - the database connection name
Returns:
a list of TableInfo instances
Throws:
java.sql.SQLException

getDatabaseVendor

public static java.lang.String getDatabaseVendor(java.sql.DatabaseMetaData dbmd)
Returns database vendor name.

Parameters:
dbmd - a DatabaseMetaData instance
Returns:
vendor name

lookupAndRegisterFunction

public static Function lookupAndRegisterFunction(java.lang.String function)

lookupFunction

public static Function lookupFunction(UserDatabaseConnection udc,
                                      java.lang.String name)

lookupAndRegisterStoredProcedure

public static StoredProcedure lookupAndRegisterStoredProcedure(java.lang.String storedProcedure)

lookupStoredProcedure

public static StoredProcedure lookupStoredProcedure(UserDatabaseConnection udc,
                                                    java.lang.String name)

createJdbcStatement

public static JdbcStatement createJdbcStatement(java.lang.String name)

createJdbcStatementDirect

public static JdbcStatement createJdbcStatementDirect(java.lang.String jdbcStatementString)

lookupTableInfo

public static TableInfo lookupTableInfo(java.lang.String connName,
                                        java.lang.String tableName)
Looks up TableInfo. The input tableName can represent either a table name or a view name.

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

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

Parameters:
connName - database connection name
tableName - table or view name
Returns:
TableInfo instance.

lookupTableInfo

public static TableInfo lookupTableInfo(UserDatabaseConnection udc,
                                        java.lang.String tableName)
Looks up TableInfo. The input tableName can represent either a table name or a view name.

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

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

Parameters:
udc - instance of UserDatabaseConnection
tableName - table or view name
Returns:
TableInfo instance.

lookupPrimaryKey

public static PrimaryKey lookupPrimaryKey(java.lang.String connName,
                                          java.lang.String tableName)
Looks up PrimaryKey.

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

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

Parameters:
connName - db connection name
tableName - table name
Returns:
PrimaryKey instance.

countTotalRecords

public static java.lang.Object countTotalRecords(java.lang.String connName,
                                                 java.lang.String table)
Returns total number of records in a table.

Parameters:
connName - database connection name
table - table name
Returns:
total record count

getFinderSQL

public static java.lang.String getFinderSQL(java.lang.String connName,
                                            java.lang.String table)
Returns finder SQL query statement.

Parameters:
connName - database connection name
table - table name
Returns:
finder SQL query

getExpandedTableName

public static java.lang.String getExpandedTableName(java.lang.String connName,
                                                    java.lang.String table)
Returns expanded table name which includes catalog and schema.

Parameters:
connName - database connection name
table - table name
Returns:
expanded table name

getTableKeyMapForRestfulId

public static java.util.Map<java.lang.String,java.lang.String> getTableKeyMapForRestfulId(RowInfo ri,
                                                                                          java.lang.String restfulId)
Returns a map of primary key fields with values from restfuId.

For a composite primary key, the restfuId value should have separators defined by the DatabaseConfig.PRIMARY_KEY_SEPARATOR constant.

Parameters:
ri - a RowInfo object
restfulId - restful id
Returns:
map