com.extentech.ExtenBean
Class ExtenBeanFactory

java.lang.Object
  extended by com.extentech.ExtenBean.ExtenBeanFactory
All Implemented Interfaces:
PersistenceEngine
Direct Known Subclasses:
PagedDataFactory, WorkBookBeanFactory

public class ExtenBeanFactory
extends Object
implements PersistenceEngine

A DataObjectFactory which populates the data in classes which implement the DataObject interface. The factory also provides persistence services including updates, inserts and deletes.

Version:
1.0
Author:
John McMahon
See Also:
ExtenDataObject, colinfo

Field Summary
 Connection conn
           
 DatabaseMetaData dbmd
           
 Statement statement
           
 
Constructor Summary
ExtenBeanFactory()
          Blank constructor, you MUST NOW SET THE CONNECTION.
ExtenBeanFactory(Connection c)
          Allows the controller class to specify the connection
 
Method Summary
 DataObject createNewDataObject(DataObject d)
          Gets a new instance of a dataobject including empty fields.
 ResultSet doQuery(String query)
           
 void doUpdate(String query)
          Perform an UPDATE, INSERT or DELETE operation on the datastore
 void doUpdate(String[] query)
          Perform a series UPDATE, INSERT or DELETE operations on the datastore
 void finalize()
          Close all open resources and destroy object.
 Connection getConn()
           
 String getDateFormat()
           
 int getHiID(DataObject d)
          Get the current HI-ID for a numeric index field.
 int getHiID(PageableDataObject d)
          This version of getHiID() checks for support for an Oracle sequece to use for the next id
 String getSequenceName()
          set the name of the auto-increment sequence in the DB catalog.
 String getStringFromBLOB(ResultSet rs, int x)
          get a String from a ResultSet CLOB
 String getStringFromCLOB(ResultSet rs, int x)
          get a String from a ResultSet CLOB (Oracle)
 DataObject initDataObject(DataObject o)
          Loads data into a DataObject according to the DataObject's SQL statement.
 void log(String msg)
          Create a log-style system output.
 void logerr(String msg)
          Create a log-style system output.
 boolean removeDataObject(DataObject o)
          Delete a DataObject from its persistent store.
 void setConn(Connection cx)
           
 void setConnection(Connection c)
          Set the database connection for this factory.
 void setConnection(com.extentech.dbutil.ConnectionPool c)
          Set the database connection pool for this factory.
 void setDateBeginDelim(String s)
           
 void setDateDelim(String s)
          set special date delimiters for both the beginning and end of date values.
 void setDateDelim(String s, String t)
          set differing date delimiters for both the beginning and end of date values.
 void setDateEndDelim(String s)
           
 void setDateFormat(String df)
           
 void setDebug(boolean t)
           
 void setSequenceName(String sequenceName)
          set the name of the auto-increment sequence in the DB catalog.
 void setShowSQLOut(boolean b)
           
 void setStripTimestampMills(boolean f)
           
 void setTsBeginDelim(String s)
           
 void setTsEndDelim(String s)
           
 boolean storeDataObject(DataObject o)
          Insert a new DataObject into its persistent store.
 boolean updateDataObject(DataObject o)
          Persist changes to a DataObject back to its datastore
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

conn

public Connection conn

dbmd

public DatabaseMetaData dbmd

statement

public Statement statement
Constructor Detail

ExtenBeanFactory

public ExtenBeanFactory(Connection c)
Allows the controller class to specify the connection


ExtenBeanFactory

public ExtenBeanFactory()
Blank constructor, you MUST NOW SET THE CONNECTION.

Method Detail

setShowSQLOut

public void setShowSQLOut(boolean b)

setStripTimestampMills

public void setStripTimestampMills(boolean f)

setTsBeginDelim

public void setTsBeginDelim(String s)

setTsEndDelim

public void setTsEndDelim(String s)

setDateBeginDelim

public void setDateBeginDelim(String s)

setDateEndDelim

public void setDateEndDelim(String s)

getDateFormat

public String getDateFormat()

setDateFormat

public void setDateFormat(String df)

setDebug

public void setDebug(boolean t)

log

public void log(String msg)
Create a log-style system output.


logerr

public void logerr(String msg)
Create a log-style system output.


setDateDelim

public void setDateDelim(String s)
set special date delimiters for both the beginning and end of date values.


setDateDelim

public void setDateDelim(String s,
                         String t)
set differing date delimiters for both the beginning and end of date values.


finalize

public void finalize()
Close all open resources and destroy object.

Overrides:
finalize in class Object

initDataObject

public DataObject initDataObject(DataObject o)
                          throws SQLException
Loads data into a DataObject according to the DataObject's SQL statement.

Specified by:
initDataObject in interface PersistenceEngine
Parameters:
o - The DataObject for which you are requesting data.
Returns:
The DataObject populated with data.
Throws:
SQLException

getStringFromBLOB

public String getStringFromBLOB(ResultSet rs,
                                int x)
get a String from a ResultSet CLOB


getStringFromCLOB

public String getStringFromCLOB(ResultSet rs,
                                int x)
get a String from a ResultSet CLOB (Oracle)


updateDataObject

public boolean updateDataObject(DataObject o)
                         throws SQLException
Persist changes to a DataObject back to its datastore

To change DataObject values in the underlying database:
1. Set the new values:
u.setVal("FIRSTNAME", "Joe");
DataObjectFactory.java 2. When done, use the factory method to update the database
factory.updateDataObject(u);

Specified by:
updateDataObject in interface PersistenceEngine
Parameters:
o - The DataObject which you are deleting.
Returns:
Whether the operation succeeded.
Throws:
SQLException

storeDataObject

public boolean storeDataObject(DataObject o)
                        throws SQLException
Insert a new DataObject into its persistent store.

Specified by:
storeDataObject in interface PersistenceEngine
Parameters:
o - The DataObject which you are inserting
Returns:
Whether the operation succeeded.
Throws:
SQLException

doQuery

public ResultSet doQuery(String query)
                  throws SQLException
Throws:
SQLException

doUpdate

public void doUpdate(String[] query)
              throws SQLException
Perform a series UPDATE, INSERT or DELETE operations on the datastore

Parameters:
query - An array of Strings (SQL statements);
Throws:
SQLException

doUpdate

public void doUpdate(String query)
              throws SQLException
Perform an UPDATE, INSERT or DELETE operation on the datastore

Parameters:
o - The DataObject for which you are requesting data.
Throws:
SQLException

createNewDataObject

public DataObject createNewDataObject(DataObject d)
                               throws SQLException
Gets a new instance of a dataobject including empty fields. Because the code attempts to generate a new unique key for the new item, the database table must contain an INTEGER key column.

To Create a new DataObject, set its values, then save it to the database:
1. Use the new constructor to get an empty instance:
User u = new User();
2. Set the name of the table that you want to insert this object into, as well as the key column that the bean will use to perform the insert.
i.setTableName("USERS"); i.setDOLookupField("ID"); 3. Create (or use an existing) DataObjectFactory to do the work of populating the data.
DataObjectFactory factory = new DataObjectFactory();
4. Send the DataObject to the factory to get its MetaData information:
u = factory.createNewDataObject(u);
5. Use the methods of the empty object to set the data. The setVal command will set values based on the name of the columns in the database.
u.setVal(0,"FIRSTNAME", "John");
u.setVal(0,"LASTNAME", "Torres");
6. And perform the insert through the factory method:
factory.storeDataObject(i);

Specified by:
createNewDataObject in interface PersistenceEngine
Parameters:
o - The DataObject which you are creating.
Returns:
a new dataobject
Throws:
SQLException

setConnection

public void setConnection(Connection c)
Set the database connection for this factory.

Specified by:
setConnection in interface PersistenceEngine

setConnection

public void setConnection(com.extentech.dbutil.ConnectionPool c)
Set the database connection pool for this factory.


removeDataObject

public boolean removeDataObject(DataObject o)
                         throws SQLException
Delete a DataObject from its persistent store.

To delete a DataObject from the underlying database:
factory.removeDataObject(u);

Specified by:
removeDataObject in interface PersistenceEngine
Parameters:
o - The DataObject which you are deleting.
Returns:
Whether the operation succeeded.
Throws:
SQLException

setSequenceName

public void setSequenceName(String sequenceName)
set the name of the auto-increment sequence in the DB catalog.


getSequenceName

public String getSequenceName()
set the name of the auto-increment sequence in the DB catalog.


getHiID

public int getHiID(DataObject d)
Get the current HI-ID for a numeric index field.

Parameters:
o - The DataObject which you are deleting.
Returns:
Whether the operation succeeded.

getHiID

public int getHiID(PageableDataObject d)
This version of getHiID() checks for support for an Oracle sequece to use for the next id


getConn

public Connection getConn()
Returns:
Returns the conn.

setConn

public void setConn(Connection cx)
Parameters:
conn - The conn to set.


Copyright © 2011 Extentech Inc. All Rights Reserved.