net.sourceforge.idrs.utils
Class DB

java.lang.Object
  |
  +--net.sourceforge.idrs.utils.DB
All Implemented Interfaces:
java.io.Serializable

public class DB
extends java.lang.Object
implements java.io.Serializable

Class DB DB.java Copyright (C) 2000 Marc Boorshtein under the GNU General Public License offered without warenty Purpose: This class is used as a wrapper for JDBC to insure cross database compatability. This class allows for the connection to and retrieval from DB's without the need for dirrect use of JDBC

See Also:
Serialized Form

Field Summary
static int CLIENT
           
(package private)  java.sql.Connection con
           
(package private)  IDRSScript idrs
           
static int INPUT
           
static int OUTPUT
           
(package private)  java.sql.ResultSet rs
           
static int SERVER
           
 
Constructor Summary
DB(java.lang.String ID)
           
 
Method Summary
 void addVar(java.lang.String val, java.lang.String type)
          pre:none post: used to add a var to a query
 void clearVars()
          Clears all variables
 void close()
          Closes the connection and recordset
 java.sql.Connection getConnection()
          Is used to retrieve a connection to DB
 int getCurrLocation()
          Returns the current cursor location of the db
 java.lang.String getDBDriver()
          returns the name of the driver being used
 java.lang.String getDBName()
          Returns the name of the DBName
 int getDirection()
           
 java.lang.String getFieldData(java.lang.String fieldname, java.lang.String format)
          pre: fields is poulated fieldname exists in fields if no format, then it should be set to null format must follow java.text.MessageFormat() specs post: returns the data in fieldname with applied format
 int getFirstRec()
          Returns the number of the first record to be retrieved from dataset, used only with client side cursur
 boolean getHasNext()
          Retruns wether or not the db has another row in it
 java.lang.String getID()
           
 boolean getIsPaged()
          Returns wether or not current DB is paged
 int getNumRecs()
          Returns the number of records should be retrieved in current report
 java.lang.String getPassword()
          returns the password
 int getUpdateResult()
           
 java.lang.String getUserName()
          returns the user name
 boolean moveTo(int location)
          Moves to a specific position within a db, only usable with client cursor
 boolean next()
          pre:rs is populated post:if the there is another record, advance a record readin the fields else return false
 void procMethod(ObjectStore obj, java.lang.String method, java.util.Vector vals)
          Pre: setDBName() has been executed successfully SQL is a valid SQL statement OR SQL is the name of a stored procedure all parameters must be shown in SQL using the ? character the vars and varTypes vectors must be filled for each parameter in SQL the vars and varTypes must contain information acording to the order in which the parametes apear in SQL if there are no parameters, then vars and varTypes must be empty Post: retrieves information based on SQL
 void ProcSQL(java.lang.String SQL, boolean isProc)
           
 void removeVar(int index)
          pre: index < vars.size(); post: removes variable index from vars and varTypes vectors
 void setConnection(java.sql.Connection con)
          Is used to set a pre-made connection to a DB
 void setCursurType(int type)
           
 void setDBDriver(java.lang.String driver)
          Pre: driver must be in the CLASSPATH Post: dirver is loaded by the VM and is ready for use
 void setDBName(java.lang.String name)
          Pre: setDBDriver(), setUser(), setPassword() must all be executed Post: object is connected to the specified database
 void setDBName(java.lang.String name, boolean connect)
           
 void setDirection(int dir)
          Sets wether or not a DB was retrieved from a cache
 void setIDRS(IDRSScript idrs)
           
 void setIsPaged(boolean page)
          Sets wether or not the db is paged
 void setNumRecs(int recs)
          Sets the number of records to be retrieved in a report
 void setPassword(java.lang.String pass)
          Pre: none post: sets passwords, use "" for no password
 void setUserName(java.lang.String user)
          Pre:none Post: sets user name, use "" for no user name
 void setVar(java.lang.String val, java.lang.String type, int index)
          pre: index < vars.size() post: sets a variable's value and type at index
 boolean shouldPool()
           
 void startWith(int location)
           
 boolean wasCached()
          Returns wether or not the db was retrieved from a cache
 void wasCached(boolean yup)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVER

public static final int SERVER

CLIENT

public static final int CLIENT

INPUT

public static final int INPUT

OUTPUT

public static final int OUTPUT

rs

java.sql.ResultSet rs

con

java.sql.Connection con

idrs

IDRSScript idrs
Constructor Detail

DB

public DB(java.lang.String ID)
Method Detail

setDirection

public void setDirection(int dir)
Sets wether or not a DB was retrieved from a cache

getDirection

public int getDirection()

wasCached

public void wasCached(boolean yup)
               throws java.lang.Exception

wasCached

public boolean wasCached()
                  throws java.lang.Exception
Returns wether or not the db was retrieved from a cache

getFirstRec

public int getFirstRec()
                throws java.lang.Exception
Returns the number of the first record to be retrieved from dataset, used only with client side cursur

getNumRecs

public int getNumRecs()
               throws java.lang.Exception
Returns the number of records should be retrieved in current report

setNumRecs

public void setNumRecs(int recs)
                throws java.lang.Exception
Sets the number of records to be retrieved in a report

getIsPaged

public boolean getIsPaged()
                   throws java.lang.Exception
Returns wether or not current DB is paged

setIsPaged

public void setIsPaged(boolean page)
                throws java.lang.Exception
Sets wether or not the db is paged

getCurrLocation

public int getCurrLocation()
                    throws java.lang.Exception
Returns the current cursor location of the db

getID

public java.lang.String getID()
                       throws java.lang.Exception

setCursurType

public void setCursurType(int type)
                   throws java.lang.Exception

setIDRS

public void setIDRS(IDRSScript idrs)

shouldPool

public boolean shouldPool()

close

public void close()
           throws java.lang.Exception
Closes the connection and recordset

setDBDriver

public void setDBDriver(java.lang.String driver)
                 throws java.lang.Exception
Pre: driver must be in the CLASSPATH Post: dirver is loaded by the VM and is ready for use

getDBDriver

public java.lang.String getDBDriver()
                             throws java.lang.Exception
returns the name of the driver being used

setDBName

public void setDBName(java.lang.String name)
               throws java.lang.Exception
Pre: setDBDriver(), setUser(), setPassword() must all be executed Post: object is connected to the specified database

setDBName

public void setDBName(java.lang.String name,
                      boolean connect)
               throws java.lang.Exception

getDBName

public java.lang.String getDBName()
                           throws java.lang.Exception
Returns the name of the DBName

setUserName

public void setUserName(java.lang.String user)
                 throws java.lang.Exception
Pre:none Post: sets user name, use "" for no user name

getUserName

public java.lang.String getUserName()
                             throws java.lang.Exception
returns the user name

setPassword

public void setPassword(java.lang.String pass)
                 throws java.lang.Exception
Pre: none post: sets passwords, use "" for no password

getPassword

public java.lang.String getPassword()
                             throws java.lang.Exception
returns the password

setConnection

public void setConnection(java.sql.Connection con)
                   throws java.lang.Exception
Is used to set a pre-made connection to a DB

getConnection

public java.sql.Connection getConnection()
                                  throws java.lang.Exception
Is used to retrieve a connection to DB

procMethod

public void procMethod(ObjectStore obj,
                       java.lang.String method,
                       java.util.Vector vals)
                throws java.lang.Exception
Pre: setDBName() has been executed successfully SQL is a valid SQL statement OR SQL is the name of a stored procedure all parameters must be shown in SQL using the ? character the vars and varTypes vectors must be filled for each parameter in SQL the vars and varTypes must contain information acording to the order in which the parametes apear in SQL if there are no parameters, then vars and varTypes must be empty Post: retrieves information based on SQL

ProcSQL

public void ProcSQL(java.lang.String SQL,
                    boolean isProc)
             throws java.lang.Exception

addVar

public void addVar(java.lang.String val,
                   java.lang.String type)
            throws java.lang.Exception
pre:none post: used to add a var to a query

removeVar

public void removeVar(int index)
               throws java.lang.Exception
pre: index < vars.size(); post: removes variable index from vars and varTypes vectors

setVar

public void setVar(java.lang.String val,
                   java.lang.String type,
                   int index)
            throws java.lang.Exception
pre: index < vars.size() post: sets a variable's value and type at index

clearVars

public void clearVars()
               throws java.lang.Exception
Clears all variables

getUpdateResult

public int getUpdateResult()
                    throws java.lang.Exception

getFieldData

public java.lang.String getFieldData(java.lang.String fieldname,
                                     java.lang.String format)
                              throws java.lang.Exception
pre: fields is poulated fieldname exists in fields if no format, then it should be set to null format must follow java.text.MessageFormat() specs post: returns the data in fieldname with applied format

moveTo

public boolean moveTo(int location)
               throws java.lang.Exception
Moves to a specific position within a db, only usable with client cursor

startWith

public void startWith(int location)
               throws java.lang.Exception

next

public boolean next()
             throws java.lang.Exception
pre:rs is populated post:if the there is another record, advance a record readin the fields else return false

getHasNext

public boolean getHasNext()
                   throws java.lang.Exception
Retruns wether or not the db has another row in it