| java.lang.Object com.knowgate.dataobjs.DBPersist
All known Subclasses: com.knowgate.training.Subject, com.knowgate.hipergate.MetaAttribute, com.knowgate.hipergate.CategoryLabel, com.knowgate.scheduler.Atom, com.knowgate.hipergate.InvoiceLine, com.knowgate.projtrack.Duty, com.knowgate.billing.Account, com.knowgate.hipergate.Shop, com.knowgate.crm.SalesMan, com.knowgate.hipergate.OrderLine, com.knowgate.hipergate.AbstractOrder, com.knowgate.dataxslt.db.PageSetDB, com.knowgate.training.Course, com.knowgate.addrbook.Room, com.knowgate.addrbook.FellowTitle, com.knowgate.crm.Company, com.knowgate.hipergate.BankAccount, com.knowgate.projtrack.Project, com.knowgate.hipergate.ProductFare, com.knowgate.hipergate.Address, com.knowgate.crm.WelcomePack, com.knowgate.scheduler.Job, com.knowgate.hipergate.Keyword, com.knowgate.crm.WelcomePackChangeLog, com.knowgate.addrbook.ToDo, com.knowgate.projtrack.Bug, com.knowgate.training.Evaluation, com.knowgate.crm.SalesObjectives, com.knowgate.crm.Oportunity, com.knowgate.hipergate.ProductAttribute, com.knowgate.forums.Subscription, com.knowgate.training.AcademicCourse, com.knowgate.forums.NewsMessage, com.knowgate.acl.ACLUser, com.knowgate.crm.DistributionList, com.knowgate.projtrack.ProjectCost, com.knowgate.crm.Attachment, com.knowgate.hipergate.Term, com.knowgate.acl.ACLPwd, com.knowgate.crm.Contact, com.knowgate.acl.ACLDomain, com.knowgate.crm.PhoneCall, com.knowgate.hipergate.Image, com.knowgate.dataxslt.db.MicrositeDB, com.knowgate.acl.ACLGroup, com.knowgate.hipermail.MailAccount, com.knowgate.crm.MemberAddress, com.knowgate.hipergate.ProductLocation, com.knowgate.hipergate.DespatchAdviceLine, com.knowgate.hipergate.QueryByForm, com.knowgate.training.AcademicCourseBooking, com.knowgate.hipergate.Product, com.knowgate.hipergate.ProductKeyword, com.knowgate.training.AcademicCourseAlumni, com.knowgate.training.Absentism, com.knowgate.workareas.WorkArea, com.knowgate.addrbook.Fellow, com.knowgate.hipergate.Category, com.knowgate.crm.Note, com.knowgate.addrbook.Meeting,
DBPersist | public class DBPersist implements Map(Code) | | Core class for persisting Java objects as registers in a RDMS.
Althought not an abstract class, DBPersist is mainly designed to be inherited
by a child class implementing specific behavior for reading a writting a Java
object from and to a relational database.
DBPersist mantains an internal collection of values each one mapped to a database field.
This mapping is done automatically by DBPersist reading the target table metadata definition
and preparing the proper internal value set.
This object keeps the internal value set in memory as long as it is not garbage collected,
but it does not mantaing any session information nor transaction management with the database.
It is the programmer's responsability to pass an open database connection on each method call
and to commit or rollback transaction involving the usage of a DBPersist object.
author: Sergio Montoro Ten version: 3.0 |
Method Summary | |
public void | allcaps(boolean bAllValuesUpperCase) | public boolean | allcaps() | protected HashMap | changelog(DBPersist oOldInstance) | public void | clear() | public void | clone(DBPersist oSource) | public boolean | containsKey(Object oKey) | public boolean | containsValue(Object oKey) Returns true if any of this DBPersist fields has the specified value. | public boolean | delete(JDCConnection oConn) | public Set | entrySet() | public boolean | exists(JDCConnection oConn) | public Object | get(String sKey) Get value for a field name
Parameters: sKey - String Field Name Field value. | public Object | get(Object oKey) Get value for a field name
Parameters: sKey - String Field Name Field value. | public String | getAuditClassName() | public Date | getCreationDate(JDCConnection oConn) | public java.util.Date | getDate(String sKey) | public String | getDateFormated(String sKey, String sFormat) | public String | getDateShort(String sKey) | public String | getDateTime(String sKey) | public String | getDateTime24(String sKey) | public BigDecimal | getDecimal(String sKey) | public String | getDecimalFormated(String sKey, String sPattern) | public double | getDouble(String sKey) | public String | getDoubleFormated(String sKey, String sPattern) | public float | getFloat(String sKey) | public String | getFloatFormated(String sKey, String sPattern) | public int | getInt(String sKey) | public Integer | getInteger(String sKey) | public int | getIntervalPart(String sKey, String sPart) | public HashMap | getItemMap() | public Set | getItems() | public Money | getMoney(String sKey) | public java.sql.Date | getSQLDate(String sKey) | public Time | getSQLTime(String sKey) | public short | getShort(String sKey) | public String | getString(String sKey) | public String | getStringNull(String sKey, String sDefault) Get value for a CHAR, VARCHAR or LONGVARCHAR field replacing null
with a default value.
Parameters: sKey - Field Name Parameters: sDefault - Value to be returned if field is null. | public DBTable | getTable() | public DBTable | getTable(JDCConnection oConn) Get DBTable object witch holds this DBPersist registers.
Parameters: oConn - JDBC Database Connection DBTable object where data is storedor null if the table does not exist at the database. throws: IllegalStateException - DBPersist uses the internal static table mapfrom DBBind. | public String | getTableName() | public String | getTime(String sKey) | public Time | getTimeOfDay(String sKey) | public Timestamp | getTimestamp(String sKey) | protected static String | getUIdFromName(JDCConnection oConn, Integer iDomainId, String sInstanceNm, String sStoredProc) | public boolean | isEmpty() | public boolean | isNull(String sKey) Test is a readed field was null. | public Iterator | iterator() | public Set | keySet() | public boolean | load(JDCConnection oConn, Object[] PKVals) | public boolean | load(JDCConnection oConn, String sKey) | public void | parseXML(String sXMLFilePath) | public void | put(String sKey, String sVal) | public void | put(String sKey, Object oObj) | public Object | put(Object sKey, Object oObj) Set value at internal collection
If internal collection previously contained a mapping for this key, the old value is replaced. | public void | put(String sKey, int iVal) | public void | put(String sKey, short iVal) | public void | put(String sKey, Date dtVal) | public void | put(String sKey, Time tmVal) | public void | put(String sKey, String sDate, SimpleDateFormat oPattern) | public void | put(String sKey, double dVal) | public void | put(String sKey, BigDecimal oDecVal) | public void | put(String sKey, String sDecVal, DecimalFormat oPattern) | public void | put(String sKey, float fVal) | public void | put(String sKey, Money mVal) | public void | put(String sKey, File oFile) | public void | put(String sKey, byte[] aBytes) | public void | put(String sKey, char[] aChars) | public void | put(String sKey, String sData, int iSQLType) Set value at internal collection
Parameters: sKey - Field Name Parameters: sData - Field Value as a String. | public void | putAll(Properties oPropsCollection) | public void | putAll(Map oMap) | public void | remove(String sKey) | public Object | remove(Object oKey) | public void | replace(String sKey, Object oObj) | public void | replace(String sKey, int iVal) | public void | replace(String sKey, short iVal) | public void | replace(String sKey, float fVal) | public void | setAuditTransact(String sAuditTransact) Set transaction id for automatic operation auditing. | public void | setAuditUser(String sAuditUser) Set user id for automatic operation auditing. | public int | size() | public boolean | store(JDCConnection oConn) Store a register at database representing this instance of DBPersist
Insertions and updates : The store method automatically manages
register insertions and updates. | public void | toLowerCase(String sKey) | public void | toUpperCase(String sKey) | protected String | toXML(String sIdent, String sDelim, HashMap oAttrs) | public String | toXML(String sIdent, String sDelim) | public String | toXML(String sIdent) Get an XML dump for the DBPersist values.
Lines are delimited by a single Line Feed CHR(10) '\n' character.
Parameters: sIdent - Number of blank spaces for left padding at every line. | public String | toXML() | public Collection | values() |
DBPersist | public DBPersist(String sTableName, String sAuditClass) throws IllegalStateException(Code) | | Create instance for reading and writing register from a table
Parameters: sTable - Database table name for storing objects. Parameters: sAuditClass - Name of child Java class inheriting from DBPersist. throws: IllegalStateException - |
DBPersist | public DBPersist(String sTableName, String sAuditClass, boolean bAllValuesUpperCase) throws IllegalStateException(Code) | | Create instance for reading and writing register from a table
Parameters: sTable - Database table name for storing objects. Parameters: sAuditClass - Name of child Java class inheriting from DBPersist. Parameters: bAllValuesUpperCase - Convert all put string values to uppercase throws: IllegalStateException - since: 3.0 |
allcaps | public void allcaps(boolean bAllValuesUpperCase)(Code) | | Automatically convert put string values to uppercase
Parameters: bAllValuesUpperCase - boolean since: 3.0 |
allcaps | public boolean allcaps()(Code) | | Get allcaps state
boolean since: 3.0 |
changelog | protected HashMap changelog(DBPersist oOldInstance)(Code) | | Compares two objects and returns a Map of their differences
Parameters: oOldInstance - DBPersist HashMap |
clear | public void clear()(Code) | | Clears internal values.
No register is deleted at the database.
|
clone | public void clone(DBPersist oSource)(Code) | | Copy another DBPersist into this instance
Table and audit class values are replaced with to ones from source object
Parameters: oSource - Source Object since: 2.2 |
containsValue | public boolean containsValue(Object oKey)(Code) | | Returns true if any of this DBPersist fields has the specified value.
Parameters: oKey - Object whose presence in this map is to be tested boolean since: 2.2 |
delete | public boolean delete(JDCConnection oConn) throws SQLException(Code) | | Delete a register from database
The deleted register will be the one matching this DBPersist primary key,
as set at constructor or load() method.
Parameters: oConn - Database connection true if register was successfully erased, false if not. throws: SQLException - |
entrySet | public Set entrySet()(Code) | | Field Values Set since: 2.2 |
exists | public boolean exists(JDCConnection oConn) throws SQLException(Code) | | Find out whether or not a particular register exists at database
Parameters: oConn - database connection true if a register exists a DBPersist base table witchprimary key coincides with the one set in memory for the DBPersist. throws: SQLException - |
get | public Object get(String sKey)(Code) | | Get value for a field name
Parameters: sKey - String Field Name Field value. If field is null or DBPersist has not been loaded,or no field with given name exists at table, get() returns null. |
get | public Object get(Object oKey) throws NullPointerException(Code) | | Get value for a field name
Parameters: sKey - String Field Name Field value. If field is null or DBPersist has not been loaded,or no field with given name exists at table, get() returns null. throws: NullPointerException - If oKey is null since: 2.2 |
getAuditClassName | public String getAuditClassName()(Code) | | Get audit class name
Name of base table for this DBPersist |
getCreationDate | public Date getCreationDate(JDCConnection oConn) throws SQLException(Code) | | Get dt_created column of register corresponding to this DBPersist instace
Parameters: oConn - JDCConnection Date or null if no data is found throws: SQLException - If table for this DBPersist does not have a column named dt_created |
getDateTime | public String getDateTime(String sKey)(Code) | | Get value for a DATE, DATETIME or TIMESTAMP field formated a yyyy-MM-dd hh:mm:ss
Parameters: sKey - String Field Name String Formated date or null. throws: ClassCastException - if sKey field is not of type DATE since: 3.0 |
getDateTime24 | public String getDateTime24(String sKey)(Code) | | Get value for a DATE, DATETIME or TIMESTAMP field formated a yyyy-MM-dd HH:mm:ss
Parameters: sKey - String Field Name String Formated date or null. throws: ClassCastException - if sKey field is not of type DATE, DATETIME or TIMESTAMP since: 3.0 |
getItems | public Set getItems()(Code) | | Field Names Set |
getMoney | public Money getMoney(String sKey) throws NumberFormatException(Code) | | Get value of a VARCHAR field that holds a money+currency amount
Money values are stored with its currency sign embedded inside,
like "26.32 USD" or "$48.3" or "35.44 €"
Parameters: sKey - Field Name com.knowgate.math.Money throws: NumberFormatException - since: 3.0 |
getString | public String getString(String sKey) throws NullPointerException(Code) | | Get value for a CHAR, VARCHAR or LONGVARCHAR field
Parameters: sKey - Field Name Field value or null. throws: NullPointerException - if field is null or no field withsuch name was found at internal value collection. |
getStringNull | public String getStringNull(String sKey, String sDefault)(Code) | | Get value for a CHAR, VARCHAR or LONGVARCHAR field replacing null
with a default value.
Parameters: sKey - Field Name Parameters: sDefault - Value to be returned if field is null. sDefault may itselfbe null, provinding a null safe version of getString() method. Field value or default value. |
getTable | public DBTable getTable(JDCConnection oConn) throws SQLException, IllegalStateException(Code) | | Get DBTable object witch holds this DBPersist registers.
Parameters: oConn - JDBC Database Connection DBTable object where data is storedor null if the table does not exist at the database. throws: IllegalStateException - DBPersist uses the internal static table mapfrom DBBind. The internal DBBind table map is loaded upon first call toa DBBind constructor. Thus, if a DBPersist object is instantiated beforeinstantiating any DBBind object, the internal table map will not bepreloaded and an IllegalStateException will be raised. since: 2.0 |
getTableName | public String getTableName()(Code) | | Get base table name
Name of base table for this DBPersist |
getTimeOfDay | public Time getTimeOfDay(String sKey)(Code) | | Get value for SQL92 TIME field
Parameters: sKey - Field Name java.sql.Time since: 3.0 |
getTimestamp | public Timestamp getTimestamp(String sKey)(Code) | | Get value for a DATETIME or TIMESTAMP field
Parameters: sKey - Field Name Field value or null. |
getUIdFromName | protected static String getUIdFromName(JDCConnection oConn, Integer iDomainId, String sInstanceNm, String sStoredProc) throws SQLException(Code) | | Internal method for being called by inherited classes
Searches an object instance GUID from its unique name
Parameters: oConn - Database Connection Parameters: iDomainId - Domain Identifier Parameters: sInstanceNm - Instance Name Parameters: sStoredProc - Stored Procedure or PL/pgSQL Function Name Global Unique Identifier of instance been searched or nullif no instance was found with such name. throws: SQLException - |
isEmpty | public boolean isEmpty()(Code) | | Returns whether or not this DBPersist contains no field values
boolean |
isNull | public boolean isNull(String sKey)(Code) | | Test is a readed field was null.
Parameters: sKey - Field Name true if readed field was null or if no field with given namewas found at internal collection. |
iterator | public Iterator iterator()(Code) | | Iterator for values stored in-memory at this DBPersist. |
keySet | public Set keySet()(Code) | | Field Names Set since: 2.2 |
load | public boolean load(JDCConnection oConn, Object[] PKVals) throws SQLException(Code) | | Load the internal value set from a register at a database table
Parameters: oConn - Database Connection Parameters: PKVals - Primary key values in order of appearance true if a register was found, false if no register wasfound with such primary key. throws: SQLException - |
load | public boolean load(JDCConnection oConn, String sKey) throws SQLException(Code) | | Load the internal value set from a register at a database table
Parameters: oConn - JDCConnection Parameters: sKey - String Primary key value true if a register was found, false if no register wasfound with such primary key. throws: SQLException - since: 3.0 |
put | public Object put(Object sKey, Object oObj) throws NullPointerException(Code) | | Set value at internal collection
If internal collection previously contained a mapping for this key, the old value is replaced.
Parameters: sKey - Field Name Parameters: oObj - Field Value previous value associated with specified key, or null if there was no mapping for key throws: NullPointerException - If sKey is null since: 2.2 |
put | public void put(String sKey, int iVal)(Code) | | Set value at internal collection
Parameters: sKey - Field Name Parameters: iVal - Field Value |
put | public void put(String sKey, short iVal)(Code) | | Set value at internal collection
Parameters: sKey - Field Name Parameters: iVal - Field Value |
put | public void put(String sKey, Date dtVal)(Code) | | Set value at internal collection
Parameters: sKey - Field Name Parameters: dtVal - Field Value |
put | public void put(String sKey, Time tmVal)(Code) | | Set value at internal collection
Parameters: sKey - Field Name Parameters: tmVal - Field Value since: 3.0 |
put | public void put(String sKey, String sDate, SimpleDateFormat oPattern) throws ParseException(Code) | | Put Date value using specified format
Parameters: sKey - String Field Name Parameters: sDate - String Field Value as String Parameters: oPattern - SimpleDateFormat Date format to be used since: 3.0 |
put | public void put(String sKey, double dVal)(Code) | | Put double value at internal collection
Parameters: sKey - Field Name Parameters: dVal - Field Value |
put | public void put(String sKey, BigDecimal oDecVal)(Code) | | Put BigDecimal value at internal collection
Parameters: sKey - Field Name Parameters: oDecVal - Field Value |
put | public void put(String sKey, String sDecVal, DecimalFormat oPattern) throws ParseException(Code) | | Parse BigDecimal value and put it at internal collection
Parameters: sKey - String Field Name Parameters: sDecVal - Field Name as String Parameters: oPattern - DecimalFormat throws: ParseException - since: 3.0 |
put | public void put(String sKey, float fVal)(Code) | | Set value at internal collection
Parameters: sKey - Field Name Parameters: fVal - Field Value |
put | public void put(String sKey, Money mVal)(Code) | | Set value at internal collection
Parameters: sKey - Field Name Parameters: mVal - Field Value since: 3.0 |
put | public void put(String sKey, byte[] aBytes)(Code) | | Set reference to a byte array for a long field
Use this method only for binding LONGVARBINARY or BLOB fields
Parameters: sKey - Field Name Parameters: aBytes - byte array |
put | public void put(String sKey, char[] aChars)(Code) | | Set reference to a character array for a long field
Use this method only for binding LONGVARCHAR or CLOB fields
Parameters: sKey - Field Name Parameters: aChars - char array |
put | public void put(String sKey, String sData, int iSQLType) throws FileNotFoundException, IllegalArgumentException, NullPointerException(Code) | | Set value at internal collection
Parameters: sKey - Field Name Parameters: sData - Field Value as a String. If iSQLType is BLOB or LONGVARBINARYthen sData is interpreted as a full file path uri. Parameters: iSQLType - SQL Type for field throws: NullPointerException - If sKey is null throws: IllegalArgumentException - If SQL Type is not recognized.Recognized types are { CHAR, VARCHAR, LONGVARCHAR, CLOB, INTEGER, SMALLINT,DATE, TIMESTAMP, DOUBLE, FLOAT, REAL, DECIMAL, NUMERIC, BLOB, LONGVARBINARY } |
putAll | public void putAll(Map oMap)(Code) | | Put values from a Map into this DBPersist instance
allcaps has no effect on input data when calling this method
Parameters: oMap - since: 2.2 |
remove | public void remove(String sKey)(Code) | | Remove a value from internal collection
Parameters: sKey - Field Name |
remove | public Object remove(Object oKey)(Code) | | Remove a value from internal collection
Parameters: oKey - Field Name Object previos value associated with given field name since: 2.2 |
replace | public void replace(String sKey, Object oObj)(Code) | | Replace a value from internal collection
Parameters: sKey - Field Name Parameters: oObj - New Value |
replace | public void replace(String sKey, int iVal)(Code) | | Replace a value from internal collection
Parameters: sKey - Field Name Parameters: iVal - New int value |
replace | public void replace(String sKey, short iVal)(Code) | | Replace a value from internal collection
Parameters: sKey - Field Name Parameters: iVal - New short value |
replace | public void replace(String sKey, float fVal)(Code) | | Replace a value from internal collection
Parameters: sKey - Field Name Parameters: iVal - New float value |
setAuditTransact | public void setAuditTransact(String sAuditTransact)(Code) | | Set transaction id for automatic operation auditing.
|
setAuditUser | public void setAuditUser(String sAuditUser)(Code) | | Set user id for automatic operation auditing.
|
size | public int size()(Code) | | Actual number of field values on this DBPersist
int |
store | public boolean store(JDCConnection oConn) throws SQLException(Code) | | Store a register at database representing this instance of DBPersist
Insertions and updates : The store method automatically manages
register insertions and updates. If the stored object already exists at
database then it is updated, if it does not exists then it is inserted.
A primary key violation error is never thrown so ther is no need to call
delete() method before re-writing an existing object.
NULL fields : All values not set calling put() methods for DBPersist
will be assumed to be NULL. If a not nullable field is not set then an
SQLException will be raised.
On storing an already existing object all values will we overwrited,
so is a DBPersist is not fully loaded before storing it, values not set
by calling put() methods that already were present at database will be lost.
Parameters: oConn - Database Connection boolean true if register was stored for the first time,false if register already existed. throws: SQLException - |
toLowerCase | public void toLowerCase(String sKey)(Code) | | Convert value kept with given key to lowercase
Parameters: sKey - String since: 3.0 |
toUpperCase | public void toUpperCase(String sKey)(Code) | | Convert value kept with given key to uppercase
Parameters: sKey - String since: 3.0 |
toXML | protected String toXML(String sIdent, String sDelim, HashMap oAttrs) throws IllegalStateException(Code) | | Get an XML dump for the DBPersist values
Parameters: sIdent - Number of blank spaces for left padding at every line. Parameters: sDelim - Line delimiter (usually "\n" or "\r\n") Parameters: oAttrs - Map of values to be added as attributes of the toplevel node XML String throws: IllegalStateException - If XML method is invoked before DBPersist object is loaded since: 3.0 |
toXML | public String toXML(String sIdent, String sDelim) throws IllegalStateException(Code) | | Get an XML dump for the DBPersist values
Parameters: sIdent - Number of blank spaces for left padding at every line. Parameters: sDelim - Line delimiter (usually "\n" or "\r\n") XML String throws: IllegalStateException - If XML method is invoked before DBPersist object is loaded |
toXML | public String toXML(String sIdent)(Code) | | Get an XML dump for the DBPersist values.
Lines are delimited by a single Line Feed CHR(10) '\n' character.
Parameters: sIdent - Number of blank spaces for left padding at every line. XML String |
toXML | public String toXML()(Code) | | Get an XML dump for the DBPersist values.
No left padding is placed to the left of each line.
Lines are delimited by a single Line Feed CHR(10) '\n' character.
XML String |
|
|