QJCC homepage

biz.chitec.quarterback.util
Class DBAbstractor

java.lang.Object
  extended bybiz.chitec.quarterback.util.DBAbstractor

public class DBAbstractor
extends java.lang.Object

Convenience class with oftenly needed database operations.

Version:
$Id: 784bdffa414471f94d3d432b8bcdf27d7eef7bf9 $
Author:
Dirk Hillbrecht 1997-2000, chitec/Dirk Hillbrecht 2000. Distributed under the terms of the GNU LGPL.

Field Summary
(package private) static int jdbcdriver
           
(package private) static int JMS_MYSQL
           
(package private) static int MM_MYSQL
           
(package private) static int ORACLE
           
 
Constructor Summary
private DBAbstractor()
          Constructor for the DBAbstractor object
 
Method Summary
static java.lang.String charDate(EDate ed)
          EDate conversion for insert and update statements.
static java.lang.String charDate(java.lang.String s)
          Deprecated. Use charDate(EDate) instead.
static java.lang.String dayOfYearOf(java.lang.String s)
          Description of the Method
static java.lang.String escBinary(java.lang.String s)
          Escape everything to make binary data saveable.
static java.lang.String esrp(java.lang.String s)
          Description of the Method
static java.lang.String esrq(java.lang.String key, java.lang.String s)
          Description of the Method
static java.lang.String getDefaultValue(java.sql.Statement dbstmt, java.lang.String table, java.lang.String field)
           
static EDate getEDate(java.sql.ResultSet rs, int idx)
          Reads an EDate out of the given ResultSet at the given index.
static EDate getEDateOrAlternative(java.sql.ResultSet rs, int idx, EDate alternative)
          Reads an EDate and returns the given alternative if the content is malformatted.
static EDate getEDateOrCopiedAlternative(java.sql.ResultSet rs, int idx, EDate alternative)
          Reads an EDate and returns an independent copy of the given alternative if the content is malformatted.
static EDate getEDateOrCurrent(java.sql.ResultSet rs, int idx)
          Reads an EDate and returns the current time if the content is malformatted.
static EDate getEDateOrNull(java.sql.ResultSet rs, int idx)
          Reads an EDate and returns null if the content is malformatted.
static int getFirstInt(java.sql.Statement dbstmt, java.lang.String query)
          Returns the first row of the first reply as integer.
static EDate getNow(java.sql.Statement dbstmt)
          Returns current time using the database engine.
static java.lang.String hourOf(java.lang.String s)
          Description of the Method
static void init(java.lang.String drivername)
          Initialisation with drivername so that correct abstraction is chosen.
static java.lang.String makeSortString(java.lang.String s)
          Makes a all-lower-case, unspaceified version of the given string.
static java.lang.String minuteOf(java.lang.String s)
          Description of the Method
static java.lang.String nowLiteral()
          Return a literal which may be used for "now" in SQL clauses
static void putEDate(java.util.Map m, java.lang.Object key, java.sql.ResultSet rs, int idx)
          Reads an EDate and stores it into Map (throw NPE or NFE else).
static void putEDateIfAvailable(java.util.Map m, java.lang.Object key, java.sql.ResultSet rs, int idx)
          Reads an EDate and stores it into Map if it is available and valid (otherwise nothing is stored).
static java.lang.String secondOf(java.lang.String s)
          Description of the Method
static java.lang.String sqlDate(EDate d)
          EDate conversion for "where" parts of SQL clauses.
static java.lang.String straightJoin()
          Description of the Method
static java.lang.String toUpperCase(java.lang.String s)
          Transformation to all upper case with respect to the database handling of special chars
static boolean trueOnZero(java.sql.Statement dbstmt, java.lang.String query)
          Submits the query.
static java.lang.String yearOf(java.lang.String s)
          Description of the Method
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JMS_MYSQL

static final int JMS_MYSQL
See Also:
Constant Field Values

MM_MYSQL

static final int MM_MYSQL
See Also:
Constant Field Values

ORACLE

static final int ORACLE
See Also:
Constant Field Values

jdbcdriver

static int jdbcdriver
Constructor Detail

DBAbstractor

private DBAbstractor()
Constructor for the DBAbstractor object

Method Detail

init

public static void init(java.lang.String drivername)
                 throws java.sql.SQLException
Initialisation with drivername so that correct abstraction is chosen.

Throws:
java.sql.SQLException

escBinary

public static java.lang.String escBinary(java.lang.String s)
Escape everything to make binary data saveable.


makeSortString

public static java.lang.String makeSortString(java.lang.String s)
Makes a all-lower-case, unspaceified version of the given string.


toUpperCase

public static java.lang.String toUpperCase(java.lang.String s)
Transformation to all upper case with respect to the database handling of special chars


trueOnZero

public static boolean trueOnZero(java.sql.Statement dbstmt,
                                 java.lang.String query)
                          throws java.sql.SQLException
Submits the query. Returns true if first returned value is "0". Typically, the selected query begins with something like "select count(*) from...".

Parameters:
dbstmt - Statement for communication with the database.
query - Arbitrary "select" query which should return one integer value.
Returns:
True if first value of first returned ResultSet is 0, false otherwise.
Throws:
java.sql.SQLException

getFirstInt

public static int getFirstInt(java.sql.Statement dbstmt,
                              java.lang.String query)
                       throws java.sql.SQLException
Returns the first row of the first reply as integer.

Parameters:
dbstmt - Statement for communication with the database.
query - Arbitrary "select" query which should return one integer value.
Returns:
Numerical value of first replie's first row, -1 if not reply has been received
Throws:
java.sql.SQLException

getNow

public static EDate getNow(java.sql.Statement dbstmt)
                    throws java.sql.SQLException
Returns current time using the database engine.

Parameters:
dbstmt - Statement to use for communication with the database.
Returns:
Current date as EDate.
Throws:
java.sql.SQLException

getEDate

public static EDate getEDate(java.sql.ResultSet rs,
                             int idx)
                      throws java.sql.SQLException
Reads an EDate out of the given ResultSet at the given index.

Throws:
java.sql.SQLException

getEDateOrNull

public static EDate getEDateOrNull(java.sql.ResultSet rs,
                                   int idx)
Reads an EDate and returns null if the content is malformatted.


getEDateOrCurrent

public static EDate getEDateOrCurrent(java.sql.ResultSet rs,
                                      int idx)
Reads an EDate and returns the current time if the content is malformatted.


getEDateOrAlternative

public static EDate getEDateOrAlternative(java.sql.ResultSet rs,
                                          int idx,
                                          EDate alternative)
Reads an EDate and returns the given alternative if the content is malformatted.


getEDateOrCopiedAlternative

public static EDate getEDateOrCopiedAlternative(java.sql.ResultSet rs,
                                                int idx,
                                                EDate alternative)
Reads an EDate and returns an independent copy of the given alternative if the content is malformatted.


putEDateIfAvailable

public static void putEDateIfAvailable(java.util.Map m,
                                       java.lang.Object key,
                                       java.sql.ResultSet rs,
                                       int idx)
Reads an EDate and stores it into Map if it is available and valid (otherwise nothing is stored).


putEDate

public static void putEDate(java.util.Map m,
                            java.lang.Object key,
                            java.sql.ResultSet rs,
                            int idx)
Reads an EDate and stores it into Map (throw NPE or NFE else).


nowLiteral

public static java.lang.String nowLiteral()
Return a literal which may be used for "now" in SQL clauses

Returns:
Literal representing "now" in the database.

sqlDate

public static java.lang.String sqlDate(EDate d)
EDate conversion for "where" parts of SQL clauses.

Parameters:
d - EDate to be converted.
Returns:
String representation to be used in "where" part of an SQL clause.

charDate

public static java.lang.String charDate(java.lang.String s)
Deprecated. Use charDate(EDate) instead.

Transform String representing date into db understandable data.


charDate

public static java.lang.String charDate(EDate ed)
EDate conversion for insert and update statements.

Parameters:
ed - Date to be converted
Returns:
String representation of the date to be used in insert or update statements

hourOf

public static java.lang.String hourOf(java.lang.String s)
Description of the Method

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

minuteOf

public static java.lang.String minuteOf(java.lang.String s)
Description of the Method

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

secondOf

public static java.lang.String secondOf(java.lang.String s)
Description of the Method

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

yearOf

public static java.lang.String yearOf(java.lang.String s)
Description of the Method

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

dayOfYearOf

public static java.lang.String dayOfYearOf(java.lang.String s)
Description of the Method

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

esrq

public static java.lang.String esrq(java.lang.String key,
                                    java.lang.String s)
Description of the Method

Parameters:
key - Description of the Parameter
s - Description of the Parameter
Returns:
Description of the Return Value

esrp

public static java.lang.String esrp(java.lang.String s)
Description of the Method

Parameters:
s - Description of the Parameter
Returns:
Description of the Return Value

straightJoin

public static java.lang.String straightJoin()
Description of the Method

Returns:
Description of the Return Value

getDefaultValue

public static java.lang.String getDefaultValue(java.sql.Statement dbstmt,
                                               java.lang.String table,
                                               java.lang.String field)
                                        throws java.sql.SQLException
Throws:
java.sql.SQLException

QJCC homepage