com.arsdigita.db
Class DbHelper

java.lang.Object
  extended bycom.arsdigita.db.DbHelper

public class DbHelper
extends Object


Field Summary
static int DB_DEFAULT
           
static int DB_MAX
           
static int DB_ORACLE
           
static int DB_POSTGRES
           
 
Method Summary
static int getDatabase()
          This will return the type of database that is being used by the system.
static int getDatabase(Connection conn)
           
static int getDatabase(DatabaseMetaData md)
           
static int getDatabase(ResultSet rs)
           
static int getDatabase(Statement stmt)
           
static String getDatabaseDirectory()
          Gets the directory name for the current database
static String getDatabaseDirectory(int database)
          Gets the directory name to be used for database specific files
static int getDatabaseFromURL(String url)
          Parses the JDBC url to determine the database type, will return DB_DEFAULT if no supported database is determined.
static String getDatabaseName(int database)
          Gets the pretty name for a given database integer identifier.
static String getDatabaseSuffix()
          Gets the filename suffix used to distinguish between resource files based on database.
static String getDatabaseSuffix(int database)
          Gets the filename suffix used to distinguish between resource files based on database.
static String[] getDatabaseSuffixes()
           
static void setDatabase(int database)
          Sets the database type.
static String truncateString(String s, int maxLength)
          Truncate a string to a specified length, respecting character boundaries.
static void unsupportedDatabaseError(String operation)
          Convenience method for throwing a DbUnsupportedException filling in the message for the current database type.
static int varcharLength(String str)
          Returns the width of the VARCHAR column required to store str in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DB_DEFAULT

public static final int DB_DEFAULT
See Also:
Constant Field Values

DB_ORACLE

public static final int DB_ORACLE
See Also:
Constant Field Values

DB_POSTGRES

public static final int DB_POSTGRES
See Also:
Constant Field Values

DB_MAX

public static final int DB_MAX
See Also:
Constant Field Values
Method Detail

setDatabase

public static void setDatabase(int database)
Sets the database type. The parameter should be one of the constants specified in this file.


getDatabase

public static int getDatabase()
This will return the type of database that is being used by the system. It will return DB_DEFAULT if no database has been specified. Otherwise, it will return an int corresponding to one of the database constants defined in this file.


getDatabase

public static int getDatabase(DatabaseMetaData md)

getDatabase

public static int getDatabase(Connection conn)

getDatabase

public static int getDatabase(Statement stmt)

getDatabase

public static int getDatabase(ResultSet rs)

getDatabaseDirectory

public static String getDatabaseDirectory()
Gets the directory name for the current database


getDatabaseDirectory

public static String getDatabaseDirectory(int database)
Gets the directory name to be used for database specific files


getDatabaseSuffix

public static String getDatabaseSuffix()
Gets the filename suffix used to distinguish between resource files based on database.


getDatabaseSuffix

public static String getDatabaseSuffix(int database)
Gets the filename suffix used to distinguish between resource files based on database.


getDatabaseSuffixes

public static String[] getDatabaseSuffixes()

getDatabaseFromURL

public static int getDatabaseFromURL(String url)
Parses the JDBC url to determine the database type, will return DB_DEFAULT if no supported database is determined.


getDatabaseName

public static String getDatabaseName(int database)
Gets the pretty name for a given database integer identifier.


unsupportedDatabaseError

public static void unsupportedDatabaseError(String operation)
Convenience method for throwing a DbUnsupportedException filling in the message for the current database type.


varcharLength

public static int varcharLength(String str)
Returns the width of the VARCHAR column required to store str in the database.

This abstracts the differences in the interpretation of, say, VARCHAR(100) in Oracle and Postgres. In Oracle, this means 100 bytes. Therefore, a 100-character long string may not fit in a VARCHAR(100) column in Oracle, depending on the particular encoding used. In Postgres, VARCHAR(100) means 100 characters.

Returns:
1 if str is null; otherwise a db-specific positive value.

truncateString

public static String truncateString(String s,
                                    int maxLength)
Truncate a string to a specified length, respecting character boundaries.

Parameters:
s - The string to be truncated.
maxLength - The maximum length of the string, in units that are database-dependent (for PG, characters; for Oracle, bytes).
See Also:
varcharLength(String)


Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 21 2004:2337 UTC