com.ds.fw.beans
Class FwDBBean

java.lang.Object
  |
  +--com.ds.fw.beans.FwBaseBean
        |
        +--com.ds.fw.beans.FwDBBean

public class FwDBBean
extends FwBaseBean

Class FwDBBean ought to be used for DataBase interface. Generally extends FwBaseBean class and your framework for storing data, and methods for accessing information. It was implements SQL requests and suggest more user frendly interface for DataBase. Used set and get methods for setting and getting information in default DB. If you needed specify methods, Feel free to extends this class. When you stopping use this instance, you may have release connection with release method. Notice by default autocommitetd is false, use commit method!!!


Field Summary
static java.lang.String STRING_ENCODING_DB
           
static java.lang.String STRING_ENCODING_OUT
           
 
Fields inherited from class com.ds.fw.beans.FwBaseBean
DEBUG_QUERY, result
 
Constructor Summary
FwDBBean()
          Creates new FwDBBean.
FwDBBean(com.ds.fw.dbcon.FwDBConnManager c)
           
FwDBBean(java.lang.String db)
           
 
Method Summary
 int buildDeleteQuery(java.lang.String sqlStr)
          Builds Delete query and executes it .
 long buildInsertQuery(java.util.Hashtable pair, java.lang.String tableName)
          Builds the INSERT query and executes it.
 long buildInsertQuery(java.util.Vector columnNames, java.util.Vector values, java.lang.String tableName)
          Builds the INSERT query and executes it.
 boolean buildSelectQuery(java.util.Vector selColumn, java.util.Vector tables, java.lang.String whereParam)
          Builds the SELECT query and executes it.
 int buildUpdateQuery(java.util.Hashtable pair, java.lang.String table, java.lang.String whereParam)
          Builds Update query and executes it .
static com.ds.fw.dbcon.FwDBConnManager createDBConnManager()
           
static com.ds.fw.dbcon.FwDBConnManager createDBConnManager(java.lang.String database)
           
static java.lang.String encodeSQL(java.lang.String s)
           
 long execInsertQuery(java.lang.String sqlStr)
           
 int execNonSelectQuery(java.lang.String sqlStr)
          Executes all non Select query.
 boolean execSelectQuery(java.lang.String sqlStr)
          Executes a SELECT query.
 void finalize()
          Destroy FwDBBean.
 java.sql.Blob getBlob(java.lang.String key, long k)
          Gets the k'th element in the column Key as an Blob.
 java.util.Vector getColumn(java.lang.String key)
          Return column by key
 java.lang.String getDataBase()
           
 java.util.Hashtable getHashtable()
          Return all stored information in this instance.
 boolean isStore()
          If the return value is true - we can store some information in DB If false - the information is not stored into DB
static void releaseDBConnManager(com.ds.fw.dbcon.FwDBConnManager c)
           
static void releaseDBConnManager(java.lang.String database, com.ds.fw.dbcon.FwDBConnManager c)
           
 void set(java.lang.String key, java.lang.String set)
          Set new value (simple) in Column point by given key
 void set(java.lang.String key, java.util.Vector set)
          Set column by given key
 void setBlob(java.lang.String key, java.sql.Blob blob, long k)
          Sets Blob as an Blob object at position k corresponding to Key
 void setDataBase(java.lang.String n)
           
 void setDBConnManager(com.ds.fw.dbcon.FwDBConnManager c)
           
 void setStore(boolean stored)
          Set isStored changed information into DB
 
Methods inherited from class com.ds.fw.beans.FwBaseBean
clear, findIndexOf, get, get, get, getBigDecimal, getColumn, getColumnNames, getDate, getDouble, getFloat, getInt, getLong, getNumber, getNumRows, getNumRows, getResult, getString, lastIndexOf, set, set, set, setBigDecimal, setColumn, setColumn, setDate, setDouble, setFloat, setInt, setLong, setNumber, setResult, setString, size, toString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STRING_ENCODING_DB

public static java.lang.String STRING_ENCODING_DB

STRING_ENCODING_OUT

public static java.lang.String STRING_ENCODING_OUT
Constructor Detail

FwDBBean

public FwDBBean()
Creates new FwDBBean. Constructor. It initialize private fields with defalut values and set connection to db. Notice connection has be setting here!!!


FwDBBean

public FwDBBean(com.ds.fw.dbcon.FwDBConnManager c)

FwDBBean

public FwDBBean(java.lang.String db)
Method Detail

finalize

public void finalize()
Destroy FwDBBean.

Overrides:
finalize in class java.lang.Object

createDBConnManager

public static com.ds.fw.dbcon.FwDBConnManager createDBConnManager(java.lang.String database)
                                                           throws java.sql.SQLException
java.sql.SQLException

releaseDBConnManager

public static void releaseDBConnManager(java.lang.String database,
                                        com.ds.fw.dbcon.FwDBConnManager c)

createDBConnManager

public static com.ds.fw.dbcon.FwDBConnManager createDBConnManager()
                                                           throws java.sql.SQLException
java.sql.SQLException

releaseDBConnManager

public static void releaseDBConnManager(com.ds.fw.dbcon.FwDBConnManager c)

setDBConnManager

public void setDBConnManager(com.ds.fw.dbcon.FwDBConnManager c)

getBlob

public java.sql.Blob getBlob(java.lang.String key,
                             long k)
                      throws java.lang.ClassCastException
Gets the k'th element in the column Key as an Blob. In case the corresponding Object is not of class Blob the method throws ClassCastException.

Parameters:
key - the column name
Throws:
java.lang.ClassCastException - in case the corresponding Object is not of class Blob.

setBlob

public void setBlob(java.lang.String key,
                    java.sql.Blob blob,
                    long k)
Sets Blob as an Blob object at position k corresponding to Key

Parameters:
key - the column name
blob - the Blob value
k - the integer value

execSelectQuery

public boolean execSelectQuery(java.lang.String sqlStr)
                        throws java.sql.SQLException
Executes a SELECT query.

Parameters:
sqlStr - - the query
Returns:
true if the select operation from database was successfull false otherwise
java.sql.SQLException
See Also:
buildSelectQuery(Vector, Vector, String)

execNonSelectQuery

public int execNonSelectQuery(java.lang.String sqlStr)
                       throws java.sql.SQLException
Executes all non Select query.

Parameters:
sqlStr - - the query
Returns:
0 if there was a problem during the execution of the query (or it was successful, but no rows were updated) and the number of the updated rows otherwise
java.sql.SQLException

execInsertQuery

public long execInsertQuery(java.lang.String sqlStr)
                     throws java.sql.SQLException
java.sql.SQLException

buildSelectQuery

public boolean buildSelectQuery(java.util.Vector selColumn,
                                java.util.Vector tables,
                                java.lang.String whereParam)
                         throws java.sql.SQLException
Builds the SELECT query and executes it.

Parameters:
selColumn - - Vector, containing the columns from which selection is made
tables - - Vector, containing the tables from which selection is made
whereParam - - the select condition
Returns:
true if the select operation from database was successful and false otherwise
java.sql.SQLException
See Also:
execSelectQuery(String)

buildInsertQuery

public long buildInsertQuery(java.util.Vector columnNames,
                             java.util.Vector values,
                             java.lang.String tableName)
                      throws java.sql.SQLException
Builds the INSERT query and executes it. Calls execNonSelectQuery(String)

Parameters:
columnNames - - Vector, containing the columns in which we want to insert a value
values - - Vector, containing the values to be inserted
tableName - - the name of the table in which we want to insert
Returns:
0 if there was a problem during the execution of the query and 1 - otherwise
java.sql.SQLException

buildInsertQuery

public long buildInsertQuery(java.util.Hashtable pair,
                             java.lang.String tableName)
                      throws java.sql.SQLException
Builds the INSERT query and executes it. Calls execNonSelectQuery(String)

Parameters:
pair - - a hashtable,containing the elements(as keys), that must be inserted and the new values
tableName - - the name of the table, in which we have to insert
Returns:
0 if there was a problem during the execution of the query and 1 - otherwise
java.sql.SQLException

buildUpdateQuery

public int buildUpdateQuery(java.util.Hashtable pair,
                            java.lang.String table,
                            java.lang.String whereParam)
                     throws java.sql.SQLException
Builds Update query and executes it . Calls method execNonSelectQuery(String)

Parameters:
pair - - a hashtable,containing the elements(as keys), that must be modified and the new values
table - - the name of the table,that must be modified
whereParam - - the where clause in the query statement
Returns:
0 if there was a problem during the execution of the query (or it was successful, but no rows were updated) and the number of the updated rows otherwise
java.sql.SQLException

buildDeleteQuery

public int buildDeleteQuery(java.lang.String sqlStr)
                     throws java.sql.SQLException
Builds Delete query and executes it . This method calls execNonSelectQuery(String)

Parameters:
sqlStr - - the query string
Returns:
0 if there was a problem during the execution of the query (or it was successful, but no rows were deleted) and the number of the deleted rows otherwise
java.sql.SQLException

getHashtable

public java.util.Hashtable getHashtable()
Return all stored information in this instance.


getColumn

public java.util.Vector getColumn(java.lang.String key)
Return column by key

Overrides:
getColumn in class FwBaseBean

set

public void set(java.lang.String key,
                java.lang.String set)
         throws java.sql.SQLException
Set new value (simple) in Column point by given key

java.sql.SQLException

set

public void set(java.lang.String key,
                java.util.Vector set)
         throws java.sql.SQLException
Set column by given key

java.sql.SQLException

setStore

public void setStore(boolean stored)
Set isStored changed information into DB


isStore

public boolean isStore()
If the return value is true - we can store some information in DB If false - the information is not stored into DB

Returns:
- the store value

getDataBase

public java.lang.String getDataBase()

setDataBase

public void setDataBase(java.lang.String n)

encodeSQL

public static java.lang.String encodeSQL(java.lang.String s)