com.extentech.ExtenBean
Class ExtenDataObject

java.lang.Object
  extended by com.extentech.ExtenBean.DataObjectImpl
      extended by com.extentech.ExtenBean.ExtenDataObject
All Implemented Interfaces:
DataObject, RelationalObject, SimpleDataObject, SQLObject, Serializable, Runnable
Direct Known Subclasses:
CellRangeDataObject, GenericDataObject

public abstract class ExtenDataObject
extends DataObjectImpl
implements DataObject, Serializable

The ExtenDataObject provides the functionality of a persistent entity bean.

It is intended to be subclassed by objects which
represent data in a database or other persistent store.


An example of an implementation of the ExtenDataObject would be
a User class which contains information such as first name,
last name, and login credentials.


By using the built-in methods of the ExtenDataObject, a subclass
can easily populate itself with data from a database,
then perform updates/inserts/deletes with single method calls.


To instantiate an ExtenDataObject with data requires a number of steps
and the use of a ExtenBeanFactory which performs the database
calls to populate the object.


******** How To Retrieve Data Using DataObjects ********
1. Use the new constructor to get an empty instance of a subclass of a DataObject:

User u = new User();

2. Set the SQL for the object according to the data that
you wish to load into the object:

u.setSQL("SELECT * FROM USERS WHERE FIRSTNAME = " + firstname);

(note) for a more 'hard-coded' object, you can setSQL within the
constructor for the object.

3. Create (or use an existing) ExtenBeanFactory to do
the work of populating the data.

ExtenBeanFactory factory = new ExtenBeanFactory();

4. Send the DataObject to the factory to get its data:

u = factory.initDataObject(u);

5. Now that the DataObject has data, you can use the built-in
ExtenDataObject methods to access values.
The getVal command will access values based on
the name of the columns returned by the SQL query.

Logger.logInfo(u.getVal("FIRSTNAME");

******** How To Insert Data Using DataObjects ********

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) ExtenBeanFactory to do
the work of populating the data.

ExtenBeanFactory factory = new ExtenBeanFactory();

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:

u.store();

******** How To Delete Data Using DataObjects ********

factory.removeDataObject(u);

******** How To Update Data Using DataObjects ********
1. Set the new values:

u.setVal("FIRSTNAME", "Joe");

2. When done, use the factory method to update the database

u.store();

Version:
1.1
Author:
John McMahon -- Copyright ©2011Extentech Inc.
See Also:
ExtenBeanFactory, DataObject, colinfo, Serialized Form

Field Summary
 boolean bof
           
 boolean eof
           
 int index
           
 boolean validateEarly
           
 
Fields inherited from class com.extentech.ExtenBean.DataObjectImpl
dataObjectActionListeners, doparent, EXTENBEAN_LOADER_NAME, props
 
Constructor Summary
ExtenDataObject()
           
 
Method Summary
 void activate()
          A container invokes this method when the instance is taken out of the pool of available instances to become associated with a specific EJB object.
 void addChildObject(RelationalObject o)
           
 void addCol(String colname)
          add a new col to this dataobject may affect ability to persist if model does not match
 void addOrderByItem(int idx, Object obj)
          Maintain a numeric lookup for this DataObject.
 boolean beginTrans()
          A simple roll-back mechanism copies the data to a backup hashtable, then waits for a commit from factory.
 void dumpNameVals()
          a convenience method for debugging which outputs all names and values for the data in this object.
 Object get(Object name)
          implementation of Input Validation interface
 int getAbsolutePage()
           
 boolean getBOF()
           
 int getChangedRowCount()
           
 Object[] getChangedRows()
           
 List getChildObjects()
          return a Listof all Child Objects
 colinfo[] getColinfo()
          Returns the column metadata for this row of data.
 colinfo getColinfoByName(String colname)
           
 int getColNumByName(String colname)
          Find the column number in the data array which contains the column represented by this columnname.
 Map getData()
           
 Object[] getDataArray()
          This returns only the first row of the data array as an array of objects.
 SimpleDataObject getDataObject(int x)
          get a new DataObject from this collection of Data.
 Object[] getDataRow(int idx)
          get the data Object Array at the specified index.
 String getDOLookupField()
           
 boolean getEOF()
           
 boolean getHasChildren()
           
 int getId()
           
 int getIndex()
           
 boolean getIsLastPage()
           
 boolean getIsMultiKey()
           
 boolean getIsMultiple()
           
 colinfo getKeyCol()
           
 String getKeyColName()
          get the key column name for this dataobject
 int getLevel()
           
 Hashtable getMetaDataHashtable()
           
 Hashtable getOrderByHash()
           
 int getPageSize()
           
 int getParentId()
          get the unique id of the parent object
 RelationalObject getParentObject()
          get the parent DataObject for this child
 String getResourceName()
           
 String getSequenceName()
           
 String getSQL()
           
 String getStringVal(int idx, String key)
          return the String value for the named column (field) at the row index specified ie: '0' for singleton DataObjects
 Object getVal(int idx, String key)
          Get String value for field at the specified index.
 Object getVal(int idx, String key, boolean nativeType)
           
 String getVal(Object key)
          Look up the key value, return the String value of the first field.
 Object getVal(Object key, boolean nativeType)
          Returns native datatype.
 String getVal(Object key, int col)
          Get value for field at the specified index.
 Object getVal(Object key, int col, boolean nativeType)
           
 Object getVal(Object key, String field)
          Get value for field at the specified index.
 Object getVal(Object key, String field, boolean nativeType)
           
 Object getVal(String key)
          Look up the key value, return the String value of the first field.
 Object getVal(String key, boolean nativeType)
           
 void init()
          perform post-data-initialization tasks
 boolean isPageable()
           
 void moveFirst()
           
 void moveLast()
           
 void moveNext()
           
 void movePrevous()
           
 void passivate()
          A container invokes this method on an instance before the instance becomes disassociated with a specific EJB object.
 void remove()
          A container invokes this method before it removes the EJB object that is currently associated with the instance.
 void removeAll()
           
 void removeByKey(Object key)
           
 void removeChangedRow(Object o)
          removes a changed row identified by the Object index
 void removeChangedRows()
           
 boolean rollBack()
          A simple roll-back mechanism copies the data back from a backup hashtable, then waits for a DB update from factory.
 void setAbsolutePage(int absolutePage)
           
 void setBOF(boolean b)
           
 void setColinfo(colinfo[] c)
          set the array of colinfos for this DataObject
 void setData(Map d)
           
 void setDataRowChanged(int idx)
           
 void setDataRowChanged(Object idx)
           
 void setDEBUG(boolean b)
           
 void setDOLookupField(String k)
          set the lookup (unique id) field for this DataObject
 void setEOF(boolean b)
           
 void setHasChildren(boolean b)
           
 void setId(int id)
          set the Id for this DataObject
 boolean setIndex(int index)
           
 void setIsLastPage(boolean isLastPage)
           
 void setKeyCol(colinfo c)
           
 void setKeyCol(String c)
          Set the key column for this DataObject Manually
 void setLevel(int i)
          the level indicates the depth of this object in a Relational Heirarchy
 void setMetaDataHashtable(Hashtable h)
           
 void setMethodValsFromDO()
          set the values of this dataobject using the set methods with the data from the getVal() methods.
 void setPageSize(int pageSize)
           
 void setParent(RelationalObject par)
          set the parent DataObject for this child
 void setParentForeignKey(String fldname)
          set the key name of the parent DataObject
 void setResourceName(String s)
           
 void setSequenceName(String sequenceName)
           
 void setSQL(String sql)
          set the SQL for this XDO
 void setVal(int idx, String key, Object val)
          update the value in the data object array pointed to by the index value
 void setVal(Object idx, Object key, Object val)
          update the value in the data object array pointed to by the index value
 void setVal(String key, Object val)
          update the first value in the data object array pointed to by the index value
 void setValsFromObject(Object obj)
          pass an Object to this DataObject and set the DataObject values to the values of the Object where the member variable names have matching setVal("fieldname") fields.
 void setValsOnObject(Object obj)
          pass an Object to this DataObject and set the Object's values to the values of the DataObject where the member variable names have matching getVal("fieldname") fields.
 void store()
          A container invokes this method to instruct the instance to synchronize its state by storing it to the underlying database.
 
Methods inherited from class com.extentech.ExtenBean.DataObjectImpl
addDataObjectActionListener, dumpNameVals, fireDataObjectActionEvent, getAllChildrenInHeirarchy, getCascadeUpdates, getChildByName, getChildrenByName, getColnames, getColNames, getDataObjectActionListeners, getFactory, getIsNew, getIsUpdateable, getNumRows, getParentForeignKey, getProps, getStringVal, getTableName, hasChildren, initFromDataObject, isNew, load, removeDataObjectActionListener, removeDataObjectActionListeners, run, setCascadeUpdates, setFactory, setIsMultiple, setIsNew, setIsUpdateable, setProps, setTableName, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.extentech.ExtenBean.DataObject
addDataObjectActionListener, fireDataObjectActionEvent, getCascadeUpdates, getChildByName, getColnames, getDataObjectActionListeners, getFactory, getIsNew, getNumRows, load, removeDataObjectActionListener, removeDataObjectActionListeners, setCascadeUpdates, setFactory, setIsMultiple, setIsNew
 
Methods inherited from interface com.extentech.ExtenBean.SimpleDataObject
getColNames, getStringVal, isNew
 
Methods inherited from interface com.extentech.ExtenBean.RelationalObject
getAllChildrenInHeirarchy, hasChildren
 
Methods inherited from interface com.extentech.ExtenBean.SQLObject
getIsUpdateable, getParentForeignKey, getTableName, setIsUpdateable, setTableName
 

Field Detail

validateEarly

public boolean validateEarly

index

public int index

eof

public boolean eof

bof

public boolean bof
Constructor Detail

ExtenDataObject

public ExtenDataObject()
Method Detail

getChangedRowCount

public int getChangedRowCount()
Specified by:
getChangedRowCount in interface DataObject
Overrides:
getChangedRowCount in class DataObjectImpl

setDEBUG

public void setDEBUG(boolean b)
Overrides:
setDEBUG in class DataObjectImpl

setResourceName

public void setResourceName(String s)

getResourceName

public String getResourceName()

isPageable

public boolean isPageable()
Specified by:
isPageable in interface DataObject
Overrides:
isPageable in class DataObjectImpl

setEOF

public void setEOF(boolean b)

setBOF

public void setBOF(boolean b)

getEOF

public boolean getEOF()

getBOF

public boolean getBOF()

setLevel

public void setLevel(int i)
the level indicates the depth of this object in a Relational Heirarchy

Specified by:
setLevel in interface RelationalObject
Overrides:
setLevel in class DataObjectImpl

getLevel

public int getLevel()
Specified by:
getLevel in interface RelationalObject
Overrides:
getLevel in class DataObjectImpl

activate

public void activate()
A container invokes this method when the instance is taken out of the pool of available instances to become associated with a specific EJB object.

Specified by:
activate in interface DataObject

passivate

public void passivate()
A container invokes this method on an instance before the instance becomes disassociated with a specific EJB object.

Specified by:
passivate in interface DataObject
Overrides:
passivate in class DataObjectImpl

remove

public void remove()
            throws SQLException
A container invokes this method before it removes the EJB object that is currently associated with the instance.

Specified by:
remove in interface DataObject
Specified by:
remove in interface SimpleDataObject
Overrides:
remove in class DataObjectImpl
Throws:
SQLException

store

public void store()
           throws SQLException
A container invokes this method to instruct the instance to synchronize its state by storing it to the underlying database.

Specified by:
store in interface DataObject
Specified by:
store in interface SimpleDataObject
Overrides:
store in class DataObjectImpl
Throws:
SQLException

get

public Object get(Object name)
implementation of Input Validation interface


dumpNameVals

public void dumpNameVals()
a convenience method for debugging which outputs all names and values for the data in this object.

Overrides:
dumpNameVals in class DataObjectImpl

setValsFromObject

public void setValsFromObject(Object obj)
pass an Object to this DataObject and set the DataObject values to the values of the Object where the member variable names have matching setVal("fieldname") fields.


setMethodValsFromDO

public void setMethodValsFromDO()
set the values of this dataobject using the set methods with the data from the getVal() methods.


setValsOnObject

public void setValsOnObject(Object obj)
pass an Object to this DataObject and set the Object's values to the values of the DataObject where the member variable names have matching getVal("fieldname") fields.


setPageSize

public void setPageSize(int pageSize)

getPageSize

public int getPageSize()

setAbsolutePage

public void setAbsolutePage(int absolutePage)

getAbsolutePage

public int getAbsolutePage()

setIsLastPage

public void setIsLastPage(boolean isLastPage)

getIsLastPage

public boolean getIsLastPage()

getSequenceName

public String getSequenceName()

setSequenceName

public void setSequenceName(String sequenceName)

setIndex

public boolean setIndex(int index)

getIndex

public int getIndex()

moveFirst

public void moveFirst()

moveLast

public void moveLast()

movePrevous

public void movePrevous()

moveNext

public void moveNext()

getVal

public Object getVal(String key,
                     boolean nativeType)

getStringVal

public String getStringVal(int idx,
                           String key)
Description copied from interface: DataObject
return the String value for the named column (field) at the row index specified ie: '0' for singleton DataObjects

Specified by:
getStringVal in interface DataObject
Specified by:
getStringVal in interface SimpleDataObject
Overrides:
getStringVal in class DataObjectImpl

getVal

public Object getVal(Object key,
                     boolean nativeType)
Returns native datatype.


getVal

public Object getVal(Object key,
                     String field,
                     boolean nativeType)

getVal

public Object getVal(Object key,
                     int col,
                     boolean nativeType)

getVal

public Object getVal(int idx,
                     String key,
                     boolean nativeType)

getKeyColName

public String getKeyColName()
get the key column name for this dataobject

Specified by:
getKeyColName in interface SQLObject
Overrides:
getKeyColName in class DataObjectImpl

setKeyCol

public void setKeyCol(colinfo c)
Specified by:
setKeyCol in interface SQLObject
Overrides:
setKeyCol in class DataObjectImpl

setParentForeignKey

public void setParentForeignKey(String fldname)
set the key name of the parent DataObject

Specified by:
setParentForeignKey in interface SQLObject
Overrides:
setParentForeignKey in class DataObjectImpl

getParentId

public int getParentId()
get the unique id of the parent object

Specified by:
getParentId in interface SQLObject
Overrides:
getParentId in class DataObjectImpl

setParent

public void setParent(RelationalObject par)
set the parent DataObject for this child

Specified by:
setParent in interface RelationalObject
Overrides:
setParent in class DataObjectImpl

getParentObject

public RelationalObject getParentObject()
get the parent DataObject for this child

Specified by:
getParentObject in interface RelationalObject
Overrides:
getParentObject in class DataObjectImpl

setKeyCol

public void setKeyCol(String c)
Set the key column for this DataObject Manually

Specified by:
setKeyCol in interface SQLObject
Overrides:
setKeyCol in class DataObjectImpl

getKeyCol

public colinfo getKeyCol()
Specified by:
getKeyCol in interface SQLObject
Overrides:
getKeyCol in class DataObjectImpl

getDOLookupField

public String getDOLookupField()
Specified by:
getDOLookupField in interface DataObject
Overrides:
getDOLookupField in class DataObjectImpl

setDOLookupField

public void setDOLookupField(String k)
Description copied from interface: DataObject
set the lookup (unique id) field for this DataObject

Specified by:
setDOLookupField in interface DataObject
Overrides:
setDOLookupField in class DataObjectImpl

getIsMultiKey

public boolean getIsMultiKey()
Overrides:
getIsMultiKey in class DataObjectImpl

init

public void init()
perform post-data-initialization tasks

Specified by:
init in interface DataObject

getDataObject

public SimpleDataObject getDataObject(int x)
get a new DataObject from this collection of Data.

Specified by:
getDataObject in interface SimpleDataObject

rollBack

public boolean rollBack()
A simple roll-back mechanism copies the data back from a backup hashtable, then waits for a DB update from factory.

Specified by:
rollBack in interface SQLObject
Overrides:
rollBack in class DataObjectImpl

beginTrans

public boolean beginTrans()
A simple roll-back mechanism copies the data to a backup hashtable, then waits for a commit from factory.

Specified by:
beginTrans in interface SQLObject
Overrides:
beginTrans in class DataObjectImpl

addOrderByItem

public void addOrderByItem(int idx,
                           Object obj)
Maintain a numeric lookup for this DataObject.

Specified by:
addOrderByItem in interface DataObject
Overrides:
addOrderByItem in class DataObjectImpl

getOrderByHash

public Hashtable getOrderByHash()
Specified by:
getOrderByHash in interface DataObject
Overrides:
getOrderByHash in class DataObjectImpl

getColinfo

public colinfo[] getColinfo()
Description copied from interface: DataObject
Returns the column metadata for this row of data.

Specified by:
getColinfo in interface DataObject
Specified by:
getColinfo in interface SimpleDataObject
Overrides:
getColinfo in class DataObjectImpl
Returns:
An array of colinfo objects containing

setColinfo

public void setColinfo(colinfo[] c)
Description copied from interface: DataObject
set the array of colinfos for this DataObject

Specified by:
setColinfo in interface DataObject
Overrides:
setColinfo in class DataObjectImpl

getDataArray

public Object[] getDataArray()
This returns only the first row of the data array as an array of objects.

Overrides:
getDataArray in class DataObjectImpl

setDataRowChanged

public void setDataRowChanged(int idx)
Overrides:
setDataRowChanged in class DataObjectImpl

setDataRowChanged

public void setDataRowChanged(Object idx)
Overrides:
setDataRowChanged in class DataObjectImpl

getChangedRows

public Object[] getChangedRows()
Specified by:
getChangedRows in interface DataObject
Overrides:
getChangedRows in class DataObjectImpl

removeChangedRow

public void removeChangedRow(Object o)
Description copied from interface: DataObject
removes a changed row identified by the Object index

Specified by:
removeChangedRow in interface DataObject
Overrides:
removeChangedRow in class DataObjectImpl

removeChangedRows

public void removeChangedRows()
Specified by:
removeChangedRows in interface DataObject
Overrides:
removeChangedRows in class DataObjectImpl

setMetaDataHashtable

public void setMetaDataHashtable(Hashtable h)

getMetaDataHashtable

public Hashtable getMetaDataHashtable()

setData

public void setData(Map d)
Specified by:
setData in interface SQLObject
Overrides:
setData in class DataObjectImpl

getData

public Map getData()
Specified by:
getData in interface DataObject
Overrides:
getData in class DataObjectImpl

getHasChildren

public boolean getHasChildren()

getSQL

public String getSQL()
Specified by:
getSQL in interface SQLObject
Overrides:
getSQL in class DataObjectImpl

setHasChildren

public void setHasChildren(boolean b)
Overrides:
setHasChildren in class DataObjectImpl

setSQL

public void setSQL(String sql)
set the SQL for this XDO

Specified by:
setSQL in interface SQLObject
Overrides:
setSQL in class DataObjectImpl

getVal

public Object getVal(String key)
Look up the key value, return the String value of the first field.

Specified by:
getVal in interface DataObject
Specified by:
getVal in interface SimpleDataObject
Overrides:
getVal in class DataObjectImpl

getVal

public String getVal(Object key)
Look up the key value, return the String value of the first field. String is the name of the field that you are getting. Look up the key value, then return the String value of the field at the named field.


getVal

public Object getVal(Object key,
                     String field)
Get value for field at the specified index. String is the name of the field that you are getting. Look up the key value, then return the String value of the field at the named field.

Specified by:
getVal in interface DataObject
Overrides:
getVal in class DataObjectImpl
Parameters:
key -
field -
Returns:

getVal

public String getVal(Object key,
                     int col)
Get value for field at the specified index. String is the name of the field that you are getting. Look up the key value, then return the String value of the field at the named field.

Parameters:
key -
field -

getVal

public Object getVal(int idx,
                     String key)
Get String value for field at the specified index. int is the number of the row that you are getting.

Specified by:
getVal in interface DataObject
Specified by:
getVal in interface SimpleDataObject
Overrides:
getVal in class DataObjectImpl
Parameters:
key -
idx -

addCol

public void addCol(String colname)
add a new col to this dataobject may affect ability to persist if model does not match

Parameters:
colname -

setVal

public void setVal(String key,
                   Object val)
update the first value in the data object array pointed to by the index value

Specified by:
setVal in interface DataObject
Specified by:
setVal in interface SimpleDataObject
Overrides:
setVal in class DataObjectImpl

setVal

public void setVal(int idx,
                   String key,
                   Object val)
update the value in the data object array pointed to by the index value

Specified by:
setVal in interface DataObject
Specified by:
setVal in interface SimpleDataObject
Overrides:
setVal in class DataObjectImpl

setVal

public void setVal(Object idx,
                   Object key,
                   Object val)
update the value in the data object array pointed to by the index value

Overrides:
setVal in class DataObjectImpl

getColinfoByName

public colinfo getColinfoByName(String colname)
Specified by:
getColinfoByName in interface DataObject
Specified by:
getColinfoByName in interface SimpleDataObject
Overrides:
getColinfoByName in class DataObjectImpl

getColNumByName

public int getColNumByName(String colname)
Find the column number in the data array which contains the column represented by this columnname.

Specified by:
getColNumByName in interface DataObject
Overrides:
getColNumByName in class DataObjectImpl

getDataRow

public Object[] getDataRow(int idx)
get the data Object Array at the specified index.

Specified by:
getDataRow in interface DataObject
Specified by:
getDataRow in interface SimpleDataObject
Overrides:
getDataRow in class DataObjectImpl
Returns:
An array of values from a database

addChildObject

public void addChildObject(RelationalObject o)
Specified by:
addChildObject in interface RelationalObject
Overrides:
addChildObject in class DataObjectImpl

getChildObjects

public List getChildObjects()
Description copied from interface: RelationalObject
return a Listof all Child Objects

Specified by:
getChildObjects in interface RelationalObject
Overrides:
getChildObjects in class DataObjectImpl
Returns:

getIsMultiple

public boolean getIsMultiple()
Specified by:
getIsMultiple in interface DataObject
Specified by:
getIsMultiple in interface SimpleDataObject
Overrides:
getIsMultiple in class DataObjectImpl

getId

public int getId()
Specified by:
getId in interface DataObject
Overrides:
getId in class DataObjectImpl

setId

public void setId(int id)
Description copied from interface: DataObject
set the Id for this DataObject

Specified by:
setId in interface DataObject
Overrides:
setId in class DataObjectImpl

removeAll

public void removeAll()
Overrides:
removeAll in class DataObjectImpl

removeByKey

public void removeByKey(Object key)
Overrides:
removeByKey in class DataObjectImpl


Copyright © 2011 Extentech Inc. All Rights Reserved.