asgaard.skid
Class BeanBrokerCall

java.lang.Object
  |
  +--asgaard.skid.BeanBrokerCall

public class BeanBrokerCall
extends java.lang.Object

This class avoids the recreation from a set of objects like a database-connection and hides the Database - layer. e.g. if stored procedures are available or not. All the SQL-Code is encapsulated in this class, different SQL-dialects are maintained with the Resource-classes SQLRes*.java.

See Also:
asgaard.skid.resources.SQLRes

Field Summary
protected static boolean blobWorkaround
           
static java.lang.String NAME_PREFIX
          Method-name convention prefix: getXXXX - Methods are analyzed
protected static java.util.ResourceBundle sRes
           
 
Constructor Summary
BeanBrokerCall(java.lang.String callStr, java.lang.String stmtStr, java.lang.String createStr, boolean getResult)
          Creeates a new database-call.
 
Method Summary
static java.lang.String addAndClause(java.lang.String clause)
          Returns the Clause with an prefix - AND
static java.lang.String addListClause(java.lang.String clause)
          Returns the Clause with an prefix - Semikolon
 java.sql.ResultSet exec(java.lang.Object[] args, java.lang.String callPoint)
          Does the wraped call including a backup (if LogLevel >= BACKUP).
static java.lang.String getCreateKeyClause(java.lang.Class aClass)
          Returns the Create-Clause for the Key(s) in the keytable
static java.lang.String getCreateKeyToken(int fieldnr, byte type, java.lang.String part)
          Returns a part of a CREATE statement to construct the Key-Table of an Bean.
 java.lang.String getFilterClause(byte fieldno, byte filter, java.lang.Object value, java.lang.String where)
          Returns a new Element in the Filter-clause.
 int getInt(int column)
          Returns an int containing to the column-number and the actual resultset, hides any SQL-Exception.
static java.lang.String getKeyNullClause()
          Returns an "null-Clause" for the Search in a Keytable
 long getLong(int column)
          Returns an long containing to the column-number and the actual resultset, hides any SQL-Exception.
 java.lang.Object getObject(int column, boolean isBean)
          Returns the Object containing to the column-number and the actual resultset, hides any SQL-Exception.
static java.lang.String getSecondaryKeyClause(int fieldno)
          Returns the Key-Clause for the second Key
static java.lang.String getSelectKeyToken(int fieldnr, byte op, java.lang.String value)
          Creates a Token for selecting from a Key-Table.
protected static java.lang.String getSQLOp(byte filter, java.lang.String prefix, java.lang.String postfix)
          Returns the Operater in SQL-syntax defined by BeanBroker.FILTER_* adding an prefix- and postfix String.
 java.lang.String getString(int column)
          Returns an String containing to the column-number and the actual resultset, hides any SQL-Exception.
static java.lang.String getTableName(java.lang.Class aClass)
          Generates the Tablename for the keys of a Class
 java.lang.String getZeroClause(byte fieldno)
          Returns a Filter-clause > 0.
 boolean next()
          Indicates, if there is a next Entry at the Resultset, hides any SQL-Exception.
static void setConnection(java.sql.Connection aConn, asgaard.utils.log.LogClient aLog, java.util.ResourceBundle sqlRes)
          Creeates a new database-call.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME_PREFIX

public static final java.lang.String NAME_PREFIX
Method-name convention prefix: getXXXX - Methods are analyzed

blobWorkaround

protected static boolean blobWorkaround

sRes

protected static java.util.ResourceBundle sRes
Constructor Detail

BeanBrokerCall

public BeanBrokerCall(java.lang.String callStr,
                      java.lang.String stmtStr,
                      java.lang.String createStr,
                      boolean getResult)
               throws java.sql.SQLException
Creeates a new database-call.
Parameters:
callStr - the Statement (parameterless)
stmtStr - the Log-Statement for automated backup (without stored procedure call)
getResult - if the preprocessed statement produces a ResultSet or not
createStr - is the CREATE TABLE Statement to analyze the parameter names (optional).
Throws:
java.sql.SQLException - if the statement cannot be created.
Method Detail

setConnection

public static void setConnection(java.sql.Connection aConn,
                                 asgaard.utils.log.LogClient aLog,
                                 java.util.ResourceBundle sqlRes)
Creeates a new database-call.
Parameters:
Conn - the database - connection
Log - the Log for automated backup
sqlRes - the SQL-Syntax-Resources

exec

public java.sql.ResultSet exec(java.lang.Object[] args,
                               java.lang.String callPoint)
                        throws java.sql.SQLException
Does the wraped call including a backup (if LogLevel >= BACKUP). The number of required parameters is not checked!
Parameters:
args - a set of Arguments as String, for Backup all none-Strings are encoded to HEX.
callPoint - the Servicepoint for the call (used for the LogMsg)
Throws:
java.sql.SQLException - if the statement cannot be processed

getObject

public java.lang.Object getObject(int column,
                                  boolean isBean)
Returns the Object containing to the column-number and the actual resultset, hides any SQL-Exception.
Parameters:
column - number of the field, first starts with 1
isBean - if the Object may be encoded
Returns:
the Object if any

getInt

public int getInt(int column)
Returns an int containing to the column-number and the actual resultset, hides any SQL-Exception.
Parameters:
column - number of the field, first starts with 1
Returns:
an int-value (-1 if it fails)

getString

public java.lang.String getString(int column)
Returns an String containing to the column-number and the actual resultset, hides any SQL-Exception.
Parameters:
column - number of the field, first starts with 1
Returns:
an String (null if it fails)

getLong

public long getLong(int column)
Returns an long containing to the column-number and the actual resultset, hides any SQL-Exception.
Parameters:
column - number of the field, first starts with 1
Returns:
an long-value (-1 if it fails)

next

public boolean next()
Indicates, if there is a next Entry at the Resultset, hides any SQL-Exception.
Returns:
if ther is a former result

getFilterClause

public java.lang.String getFilterClause(byte fieldno,
                                        byte filter,
                                        java.lang.Object value,
                                        java.lang.String where)
Returns a new Element in the Filter-clause.
Parameters:
fieldno - number of the field (starts with 0)
filter - the filter-code
value - the value to compare (to a String quotes are added)
where - the old clause
Returns:
a new clause

getTableName

public static java.lang.String getTableName(java.lang.Class aClass)
                                     throws java.rmi.RemoteException
Generates the Tablename for the keys of a Class

getKeyNullClause

public static java.lang.String getKeyNullClause()
Returns an "null-Clause" for the Search in a Keytable

getCreateKeyClause

public static java.lang.String getCreateKeyClause(java.lang.Class aClass)
Returns the Create-Clause for the Key(s) in the keytable
Parameters:
Class - the class generate the key-clause

addListClause

public static java.lang.String addListClause(java.lang.String clause)
Returns the Clause with an prefix - Semikolon
Parameters:
clause - the token

addAndClause

public static java.lang.String addAndClause(java.lang.String clause)
Returns the Clause with an prefix - AND
Parameters:
clause - the token

getSecondaryKeyClause

public static java.lang.String getSecondaryKeyClause(int fieldno)
Returns the Key-Clause for the second Key
Parameters:
fieldno - the number of the property

getCreateKeyToken

public static java.lang.String getCreateKeyToken(int fieldnr,
                                                 byte type,
                                                 java.lang.String part)
Returns a part of a CREATE statement to construct the Key-Table of an Bean.
Parameters:
fieldnr - number of the getXXX-method (by Class.getMethods)
type - of the Return-Type of the method
part - the old token
Returns:
the concated Tokens

getSelectKeyToken

public static java.lang.String getSelectKeyToken(int fieldnr,
                                                 byte op,
                                                 java.lang.String value)
Creates a Token for selecting from a Key-Table.

getZeroClause

public java.lang.String getZeroClause(byte fieldno)
Returns a Filter-clause > 0.
Parameters:
fieldno - number of the field (starts with 0)

getSQLOp

protected static java.lang.String getSQLOp(byte filter,
                                           java.lang.String prefix,
                                           java.lang.String postfix)
Returns the Operater in SQL-syntax defined by BeanBroker.FILTER_* adding an prefix- and postfix String.
Parameters:
filter - the filter-code
prefix - the prefix
postfix - the postfix
Returns:
the String with the operator