public abstract class DBObject extends TransferableObject implements DBRecord
DataSource object. You may either instantiate a
DBConnectionPool object and set it with setDataSource(DataSource)
or you call one of the connect(Credential) methods, which creates an internal
connection pool for you.
begin() starts a
database transaction. Every method call done by this thread in the same or
any other DBObject will then happen in a transaction until either
commit() or rollback() is called. The internal connection pool
ensures that the same thread always gets the same connection he is working on
until he has finished the transaction. Many threads may run transactions at
the same time - as many as you have got connections in the pool.
Note that nested transactions are supported. Thus begin() may be called n times by the same thread, each call increasing the nesting level. Accordingly commit() must be called n times decreasing the nesting level again. If nesting level 0 is reached by a commit() call then the database COMMIT is actually performed. A rollback() call at any nesting level will immediately break the transaction and fall back to nesting level 0.
Note: because the transaction mechanism described above is provided by the
DBConnectionPool class it only will work if the DataSource actually is an
instance of that class. If your DataSource however is provided i.e. by
your J2EE environment you must instead use the transaction monitor of that
environment.
LogSupport
which reports details of database operations (full dump of record) to the
system console. Typically your ApplicationContext is set as the current logger.
The default logger is AppUtil.getDefaultContext().
You may create your own error handler by providing a class that
implements the LogSupport interface and install it
with the setErrorLogger(LogSupport) method.| Modifier and Type | Field and Description |
|---|---|
static int |
BOOLEAN_CHAR |
static java.lang.String |
DBO_PREFIX |
static java.lang.String |
FALSE_STR |
static java.lang.String |
TRUE_STR |
| Modifier | Constructor and Description |
|---|---|
protected |
DBObject()
Note that only the subclasses can provide actual useful Constructors.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
addRecordChangeListener(RecordChangeEvent.Listener l)
You may register for record changes here.
|
static void |
addSqlListener(SqlEvent.Listener l)
You may register for SQL statements here.
|
static int |
begin()
Starts a transaction on the current connection.
|
static int |
begin(int txIsolationLevel)
Same as begin() but allows for setting the isolation level to any of Connection.TRANSACTION_*.
|
static boolean |
checkSubclassVersion(java.lang.Class subClass,
java.lang.String subClassVersion) |
void |
clearAttributes()
Clears all member variables of this dbobject except the primary key values.
|
void |
clearPrimaryKey()
Clears all primary key variables of this DBObject.
|
static void |
clearStatementCache()
Clears the statement cache and thus forgets about all cached
prepared statements.
|
void |
clearValues()
Clears all member variables of this dbobject including the primary key values.
|
DBObject |
clone() |
static void |
close()
Closes the underlying connection-pool using an immediate shutdown.
|
static void |
close(int shutDownDelay)
Closes the underlying connection-pool using a friendly shutdown.
|
static void |
commit()
Commits the current transaction and finalizes the changes in the database.
|
int |
compareTo(java.lang.Object o)
Implementation of Comparable interface.
|
static DBConnectionPool |
connect(Credential cred)
Tries to create the database connection with the given credential information.
|
static void |
connect(DatabaseCommandLineParser clp)
Tries to create the database connection by reading the credential information
from the command line.
|
static void |
connect(java.lang.String jdbcDriver,
java.lang.String dbUrl,
java.lang.String dbUser,
java.lang.String dbPasswd,
java.lang.String dbSchema,
int minConns,
int maxConns)
Tries to create the database connection with the given JDBC driver name and
the given connection URL.
|
static java.lang.Object |
convertArray(java.lang.Class newArrayClass,
java.lang.Object sourceArray)
Converts the sourceArray to an array of type arrayClass so that
the resultArray is castable to arrayClass.
|
void |
copyRecordValues(DBRecord otherRecord,
boolean isIncludePK)
Copies all values of an other record of the same type to this one.
|
protected java.lang.String |
createDumpHeader() |
protected abstract DBRecord |
createInstance() |
static DBObject |
createInstance(java.lang.Class dboClass)
Creates an empty instance of the given DBObject type.
|
static DBObject |
createInstance(java.lang.Class dboClass,
java.lang.String... primaryKeys)
Creates an instance of the given DBObject type for the given primary key.
|
protected abstract DBRecord |
createInstance(java.lang.String... primaryKeys) |
int |
dbCountRecords()
Counts the number of records in the table by issuing a
select count(*) from ...
|
int |
dbCountRecords(SqlCondition cond)
Counts the number of records in the table by issuing a
select count(*) from ...
|
void |
dbCreateForeignKeyConstraints()
This call adds all foreign key constraints to a table.
|
void |
dbCreateTable()
Creates the underlying table in the database if it does not exist yet.
|
void |
dbDelete()
Deletes the record from the underlying database table using a prepared
DELETE statement.
|
int |
dbDelete(SqlCondition condition)
Performs a conditional deletion of all DBObjects of the given type, that
match the given condition.
|
void |
dbDropTable()
Removes the underlying table from the database.
|
void |
dbExists()
Checks whether this DBObject exists as a record in the underlying
database table by performing a high performant index only SELECT.
|
boolean |
dbExistsTable()
Checks the existence of the underlying table in the database.
|
void |
dbForceInsert()
Performs a forced insert of the DBObject.
|
void |
dbForceUpdate()
Performs a forced update of the DBObject.
|
protected java.sql.Blob |
dbGetBlob(java.sql.ResultSet rs,
int index) |
protected boolean |
dbGetBoolean(java.sql.ResultSet rs,
int index) |
protected java.lang.Boolean |
dbGetBooleanFromChar(java.sql.ResultSet rs,
int index) |
protected java.sql.Clob |
dbGetClob(java.sql.ResultSet rs,
int index) |
protected java.sql.Date |
dbGetDate(java.sql.ResultSet rs,
int index) |
protected double |
dbGetDouble(java.sql.ResultSet rs,
int index) |
protected float |
dbGetFloat(java.sql.ResultSet rs,
int index) |
protected int |
dbGetInt(java.sql.ResultSet rs,
int index) |
protected long |
dbGetLong(java.sql.ResultSet rs,
int index) |
protected java.lang.String |
dbGetString(java.sql.ResultSet rs,
int index) |
protected java.sql.Time |
dbGetTime(java.sql.ResultSet rs,
int index) |
protected java.sql.Timestamp |
dbGetTimestamp(java.sql.ResultSet rs,
int index) |
void |
dbInsert()
Inserts a record into the underlying database table using a prepared
INSERT statement.
|
void |
dbLoad(DBLoadMonitor monitor)
|
void |
dbLoad(DBLoadMonitor monitor,
SqlCondition condition)
|
void |
dbLoad(DBLoadMonitor monitor,
SqlCondition condition,
SqlOrder order)
Loads records according to the given condition and order.
|
void |
dbLoad(DBLoadMonitor monitor,
SqlOrder order)
|
void |
dbRehash()
Re-reads the current DBObject from the database using a prepared SELECT
statement.
|
void |
dbSearch(DBLoadMonitor monitor,
SqlCondition condition)
|
void |
dbSearch(DBLoadMonitor monitor,
SqlCondition condition,
SqlOrder order)
|
DBRecord[] |
dbSearch(SqlCondition condition)
Same as
dbSelect(SqlCondition condition). |
DBRecord[] |
dbSearch(SqlCondition condition,
SqlOrder order)
|
DBRecord[] |
dbSelect()
Reads all records of the underlying table without any condition,
ordered by primary key.
|
DBRecord[] |
dbSelect(SqlCondition condition)
Reads all records that match the given condition,
ordered by primary key.
|
DBRecord[] |
dbSelect(SqlCondition condition,
SqlOrder order)
Reads all records that match the given condition,
ordered by the given order clause.
|
DBRecord[] |
dbSelect(SqlOrder order)
Reads all records of the table ordered by the given order.
|
protected void |
dbSetBlob(java.sql.PreparedStatement ps,
int index,
java.sql.Blob blob,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetBlob(java.sql.PreparedStatement ps,
int index,
java.sql.Blob blob,
DumpString ds,
java.lang.String fieldName) |
protected void |
dbSetBoolean(java.sql.PreparedStatement ps,
int index,
boolean value,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetBooleanAsChar(java.sql.PreparedStatement ps,
int index,
java.lang.Boolean value,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetClob(java.sql.PreparedStatement ps,
int index,
java.sql.Clob clob,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetClob(java.sql.PreparedStatement ps,
int index,
java.sql.Clob clob,
DumpString ds,
java.lang.String fieldName) |
protected void |
dbSetDate(java.sql.PreparedStatement ps,
int index,
java.sql.Date value,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetDouble(java.sql.PreparedStatement ps,
int index,
double value,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetFloat(java.sql.PreparedStatement ps,
int index,
float value,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetInt(java.sql.PreparedStatement ps,
int index,
int value,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetLong(java.sql.PreparedStatement ps,
int index,
long value,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetPersistentId(java.sql.PreparedStatement ps,
int index,
PersistentId value,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetPersistentName(java.sql.PreparedStatement ps,
int index,
PersistentName value,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetPK(java.sql.PreparedStatement ps,
int index,
java.lang.String valueStr,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetString(java.sql.PreparedStatement ps,
int index,
java.lang.String value,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetTime(java.sql.PreparedStatement ps,
int index,
java.sql.Time value,
DumpString ds,
DBColumnKey col) |
protected void |
dbSetTimestamp(java.sql.PreparedStatement ps,
int index,
java.sql.Timestamp value,
DumpString ds,
DBColumnKey col) |
void |
dbUpdate()
Updates the record in the underlying database table using a prepared
UPDATE statement.
|
static void |
dumpStatementCache(java.io.PrintStream ps)
Dumps the content of the statement cache to the given stream for debugging.
|
boolean |
equalAttributes(java.lang.Object o)
Compares two DBObject's by comparing their attribute values.
|
boolean |
equalPrimaryKeys(java.lang.Object o)
Compares two DBObject's by comparing their primary key values.
|
boolean |
equals(java.lang.Object o)
Compares two DBObject's by comparing their primary key values.
|
static java.sql.ResultSet |
executeQuery(java.lang.String sql)
Executes the given statement in the Database and returns a ResultSet with the matching records.
|
static int |
executeSQL(java.lang.String sql)
Executes the given statement in the Database and returns the number of records affected
|
boolean |
exists()
Same as
dbExists() just any Exception that may have been thrown
is caught away. |
boolean |
existsField(java.lang.String fieldName)
Tells whether this field name exists in this DBObject
|
boolean |
forceInsert()
Performs a forced insert of the DBObject.
|
boolean |
forceUpdate()
Performs a forced update of the DBObject.
|
DBColumnKey[] |
getAllColumns()
Returns an array of all column definitions
|
abstract DBColumnKey[] |
getAttributeColumns()
Returns the attribute column definitions from the concrete subclass
|
int |
getAttributeCount()
Returns the number of attribute fields
|
java.lang.String[] |
getAttributeFullNames()
Returns the names of the attribute columns in the format table.column
|
java.lang.String[] |
getAttributeNames()
Returns the names of the attribute columns
|
java.lang.Object[] |
getAttributeValues()
Returns the current values of the attribute columns
|
static javax.sql.DataSource |
getDataSource()
Returns the underlying connection-pool object.
|
static int |
getDecimalRoundingDigits()
Returns the current decimal rounding digits.
|
static java.math.RoundingMode |
getDecimalRoundingMode()
Returns the current decimal rounding mode.
|
static LogSupport |
getErrorLogger() |
DBColumnKey |
getFieldByIndex(int index)
Accesses a field definition by index
|
DBColumnKey |
getFieldByName(java.lang.String fieldName)
Fetches the field definition by name.
|
int |
getFieldCount()
Returns the total number of fields (primary keys plus attribute fields)
|
protected java.lang.String |
getFieldDefinition(java.lang.String fieldName)
Returns the column definition string as used in CREATE TABLE.
|
java.lang.String[] |
getFieldFullNames()
Returns the names of all database fields in the format table.column>.
|
java.lang.String |
getFieldIcon(java.lang.String fieldName)
Returns a name for an icon if the field is a primary key field, null otherwise.
|
int |
getFieldLength(java.lang.String fieldName)
Returns the length (in number or characters) of the given fieldname.
|
java.lang.String[] |
getFieldNames()
Returns the pure column-names of all database fields not containing the tablename.
|
java.lang.String |
getForeignKeyGroup(java.lang.String columnName)
Returns the group name of a particular foreign key column
|
java.lang.String[] |
getForeignKeyGroups()
Returns an array of the available oreign key groups, if any.
|
java.lang.String |
getForeignKeyRef(java.lang.String columnName)
Returns the reference of a foreign key column in the format table.column
|
int |
getIndexOf(java.lang.String fieldName)
Returns the index of the given fieldname
|
static InsertFactory |
getInsertFactory()
Returns the current
InsertFactory if any (may be null). |
java.lang.Class |
getJavaType(java.lang.String fieldName)
Returns the java variable type of the given fieldname.
|
int |
getJdbcType(java.lang.String fieldName)
Returns the jdbc-type of the given fieldname.
|
DBObject[] |
getManagedDBObjects()
Returns always the identity reference.
|
abstract DBRecord |
getMasterRecord() |
static DBRecord |
getMasterRecord(java.lang.Class clazz)
Returns a cached DBObject instance of the given subclass.
|
abstract DBColumnKey[] |
getPrimaryKeyColumns()
Returns the primary key column definition from the concrete subclass
|
int |
getPrimaryKeyCount()
Returns the number of primary key fields
|
static PrimaryKeyFactory |
getPrimaryKeyFactory()
Tells which PrimaryKeyFactory is currently in use (may be null).
|
java.lang.String[] |
getPrimaryKeyFullNames()
Returns the names of the primary key columns in the format table.column
|
java.lang.String[] |
getPrimaryKeyNames()
Returns the names of the primary key columns
|
SqlOrder |
getPrimaryKeyOrder()
Returns the ORDER clause for ordering by primary key,
or null if no primary key exists.
|
java.lang.String[] |
getPrimaryKeyValues()
Returns the values of the primary key columns
|
static RdbmsInfo |
getRdbmsInfo()
Returns an RdbmsInfo object which caches the most frequently used
database meta data of the current connection.
|
static RdbmsSupport |
getRdbmsSupport()
Returns an RDBMS specific RdbmsSupport object which encapsulates the
particularities of the RDBMS system we currently are connected to.
|
java.lang.String |
getRecordName()
Returns the name of the underlying database table on a DBObject.
|
java.awt.Color |
getRenderColor() |
javax.swing.Icon |
getRenderIcon() |
java.lang.String |
getRenderText()
Returns a String that that represents this object in a GUI component.
|
static java.lang.String |
getSchema()
Returns the current schema name if any.
|
abstract java.lang.String |
getTableName()
Returns the name of the underlying database table
|
java.lang.Object |
getValue(DBColumnKey columnKey)
Returns the current value of the given fieldname
|
java.lang.Object |
getValue(java.lang.String fieldName)
Returns the current value of the given fieldname
|
java.lang.Object[] |
getValues()
Returns the values of all database fields as an array
|
static AppSuiteVersion |
getVersion()
The version of the DBObject Suite package that created the DBObject subclasses.
|
static boolean |
hasConnection()
Tells whether the DBObject class has got an underlying ConnectionPool set.
|
int |
hashCode()
Overridden to return a class specific hash-code.
|
boolean |
hasPrimaryKey()
Tells whether this DBObject has got a Primary Key defined in the database
|
void |
invalidate()
Sets the valid flag of this DBObject to false.
|
static boolean |
isDecimalRounding()
Tells if decimal rounding is active.
|
boolean |
isDirty()
Returns false if this object is known to be consistent with the database.
|
boolean |
isFieldNumeric(java.lang.String fieldName) |
boolean |
isFieldVirtual(java.lang.String fieldName)
Returns always false.
|
boolean |
isForeignKey(java.lang.String fieldName)
Tells whether the given field is a foreign key field
|
boolean |
isNotNullField(java.lang.String fieldName)
Tells wasCancelled this field is a not null field.
|
boolean |
isPrimaryKey(java.lang.String fieldName)
Tells whether the given field is a primary key field
|
boolean |
isPrimaryKeyValid()
Tells whether this DBObject has a valid primary key.
|
boolean |
isPrimaryKeyValid(java.lang.String... pkValues)
Checks whether the given pkValues array is a valid primary key
for this DBObject.
|
boolean |
isReadPrimaryKeyOnly()
Tells whether only primary keys are read from the database.
|
static boolean |
isSilent()
Tells whether DBObjects should do logging
|
static boolean |
isStoreZeroAsNull()
Tells whether numeric zero values should be written as null.
|
static boolean |
isTrimStringsOnRead()
Tells whether Strings are trimmed when they are read from the database
By default strings are trimmed.
|
static boolean |
isTrimStringsOnWrite()
Tells whether Strings are trimmed when they are written to the database.
|
protected abstract void |
readAttributes(DBObject obj,
int idx,
java.sql.ResultSet rs) |
protected DBObject |
readObject(DBObject dbo,
int pkValue) |
protected DBObject |
readObject(DBObject dbo,
java.lang.String... pkValues) |
protected abstract void |
readPrimaryKeys(DBObject obj,
int idx,
java.sql.ResultSet rs) |
static void |
removeRecordChangeListener(RecordChangeEvent.Listener l) |
static void |
removeSqlListener(SqlEvent.Listener l) |
static boolean |
rollback()
Rolls back the last transaction started.
|
static double |
roundValue(double value)
Rounds a double value according to the current decimal RoundingMode.
|
static float |
roundValue(float value)
Rounds a float value according to the current decimal RoundingMode.
|
static void |
setDataSource(javax.sql.DataSource conPool)
Sets the ConnectionPool to be used for accessing the JDBC database connection.
|
static void |
setDecimalRounding(java.math.RoundingMode mode,
int digits)
Sets the decimal rounding mode and the rounding digits.
|
static void |
setErrorLogger(LogSupport logger)
Set a custom
LogSupport which reports DBObject activity. |
void |
setFieldValue(java.lang.String fieldName,
java.lang.Object value)
Sets the value of the instance variable which represents the database column
fieldName |
void |
setFieldValue(java.lang.String fieldName,
java.lang.String valueStr)
Sets the value of the instance variable which represents the database column
fieldName . |
static InsertFactory |
setInsertFactory(InsertFactory factory)
Sets the InsertFactory to be used for record INSERTs.
|
static void |
setPrimaryKeyFactory(PrimaryKeyFactory factory)
Sets the PrimaryKeyFactory to be used for record INSERTs.
|
void |
setPrimaryKeyValues(java.lang.String... pkValues)
Sets the values of the primary key columns
|
void |
setReadPrimaryKeyOnly(boolean readPKOnly)
Enforces that only primary key values are read from the database
when performing a dbSelect() or dbSearch() call.
|
static void |
setSchema(java.lang.String schema)
This allows for setting a schema name that will used as a tablename
prefix when accessing the underlying database table.
|
static void |
setSilent(boolean silent)
Turns logging on or off without changing the ErrorLogger.
|
static void |
setStoreZeroAsNull(boolean storeAsNull)
This is a global switch that enforces storage of numeric zero
values as null values in numeric fields.
|
static void |
setTrimStringsOnRead(boolean doTrim)
Enforces Strings to be trimmed when they are read from the database
|
static void |
setTrimStringsOnWrite(boolean doTrim)
Enforces Strings to be trimmed when they are written to the database
|
DumpString |
toDumpString(DumpString s)
Fills the given DumpString with debugging information about this DBObject.
|
static java.lang.String |
toKey(java.lang.String key) |
static java.lang.String |
toKey(java.lang.String[] keys) |
protected java.lang.Object |
toObject(boolean value) |
protected java.lang.Object |
toObject(double value) |
protected java.lang.Object |
toObject(float value) |
protected java.lang.Object |
toObject(int value) |
protected java.lang.Object |
toObject(long value) |
protected java.lang.Object |
toObject(java.lang.Object value) |
ToString |
toString(ToString s)
Returns a String representation of this DBObject which consists of the tablename and the primary key values
|
protected abstract void |
writeAttributes(int idx,
java.sql.PreparedStatement ps,
DumpString ds) |
protected abstract void |
writePrimaryKeys(int idx,
java.sql.PreparedStatement ps,
DumpString ds) |
deepCloneconfigureDumpHeadlineLength, configureDumpMaxElementsPrinted, copyDumpStringValues, copyToStringValues, toDumpString, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitgetTranslationAppKeydeepClonetoDumpString, toStringpublic static final java.lang.String DBO_PREFIX
public static final java.lang.String TRUE_STR
public static final java.lang.String FALSE_STR
public static final int BOOLEAN_CHAR
protected DBObject()
public static void addRecordChangeListener(RecordChangeEvent.Listener l)
public static void removeRecordChangeListener(RecordChangeEvent.Listener l)
public static void addSqlListener(SqlEvent.Listener l)
public static void removeSqlListener(SqlEvent.Listener l)
public static InsertFactory setInsertFactory(InsertFactory factory)
public static InsertFactory getInsertFactory()
InsertFactory if any (may be null).public static void setPrimaryKeyFactory(PrimaryKeyFactory factory)
public static PrimaryKeyFactory getPrimaryKeyFactory()
public static void setDataSource(javax.sql.DataSource conPool)
public static javax.sql.DataSource getDataSource()
public static boolean hasConnection()
public static void connect(java.lang.String jdbcDriver,
java.lang.String dbUrl,
java.lang.String dbUser,
java.lang.String dbPasswd,
java.lang.String dbSchema,
int minConns,
int maxConns)
throws java.lang.Exception
jdbcDriver - The fully qualified class name of the JDBC driverdbUrl - The database access URLdbUser - The name of the userdbPasswd - The password of the userdbSchema - The database schema (may be null)minConns - The number of connections that should initially be establishedmaxConns - The max number of connections that can be established on demandjava.lang.Exceptionpublic static DBConnectionPool connect(Credential cred) throws java.lang.Exception
java.lang.ExceptionDBConnectionPoolpublic static void connect(DatabaseCommandLineParser clp) throws java.lang.Exception
DatabaseCommandLineParser to find out which command
line options are evaluated for creating the database connection.java.lang.ExceptionDatabaseCommandLineParser,
DBConnectionPoolpublic static void close()
DBConnectionPool.close(int)public static void close(int shutDownDelay)
DBConnectionPool.close(int)public static void clearStatementCache()
public static void dumpStatementCache(java.io.PrintStream ps)
public static boolean checkSubclassVersion(java.lang.Class subClass,
java.lang.String subClassVersion)
public static AppSuiteVersion getVersion()
public abstract java.lang.String getTableName()
public java.lang.String getRecordName()
getRecordName in interface DBPersistentgetTableName(),
ComposedRecordpublic java.lang.String getRenderText()
getRenderText in interface Renderablepublic javax.swing.Icon getRenderIcon()
getRenderIcon in interface Renderablepublic java.awt.Color getRenderColor()
getRenderColor in interface Renderablepublic java.lang.String[] getPrimaryKeyNames()
getPrimaryKeyColumns()public java.lang.String[] getPrimaryKeyFullNames()
getPrimaryKeyColumns()public abstract DBColumnKey[] getPrimaryKeyColumns()
public void setPrimaryKeyValues(java.lang.String... pkValues)
setPrimaryKeyValues in interface DBPersistentgetPrimaryKeyValues()public java.lang.String[] getPrimaryKeyValues()
getPrimaryKeyValues in interface DBPersistentsetPrimaryKeyValues(String...)public java.lang.Object[] getAttributeValues()
java.lang.ExceptiongetAttributeColumns()public java.lang.String[] getAttributeNames()
getAttributeColumns()public java.lang.String[] getAttributeFullNames()
getAttributeColumns()public abstract DBColumnKey[] getAttributeColumns()
public DBColumnKey[] getAllColumns()
public java.lang.Class getJavaType(java.lang.String fieldName)
DBRecordgetJavaType in interface DBRecordfieldName - might be a pure column name or in the format table.column -
only the column name is checked!public int getJdbcType(java.lang.String fieldName)
DBRecordgetJdbcType in interface DBRecordfieldName - might be a pure column name or in the format table.column -
only the column name is checked!Typespublic int getFieldLength(java.lang.String fieldName)
DBRecordgetFieldLength in interface DBRecordfieldName - might be a pure column name or in the format table.column -
only the column name is checked!public boolean isNotNullField(java.lang.String fieldName)
DBRecordisNotNullField in interface DBRecordfieldName - might be a pure column name or in the format table.column -
only the column name is checked!public abstract DBRecord getMasterRecord()
getMasterRecord in interface DBRecordprotected abstract void readPrimaryKeys(DBObject obj, int idx, java.sql.ResultSet rs) throws java.sql.SQLException
java.sql.SQLExceptionprotected abstract void readAttributes(DBObject obj, int idx, java.sql.ResultSet rs) throws java.sql.SQLException
java.sql.SQLExceptionprotected abstract void writePrimaryKeys(int idx,
java.sql.PreparedStatement ps,
DumpString ds)
throws java.sql.SQLException
java.sql.SQLExceptionprotected abstract void writeAttributes(int idx,
java.sql.PreparedStatement ps,
DumpString ds)
throws java.sql.SQLException
java.sql.SQLExceptionpublic boolean isFieldVirtual(java.lang.String fieldName)
isFieldVirtual in interface DBRecordfieldName - can be the pure column name or in the format table.column -
only the column name is checked!ComposedRecordprotected java.lang.String getFieldDefinition(java.lang.String fieldName)
public void invalidate()
dbUpdate(),
dbRehash()public boolean isDirty()
dbInsert() method was called.isDirty in interface DBPersistentdbInsert(),
dbUpdate(),
dbDelete(),
dbRehash()public static boolean isSilent()
public static void setSilent(boolean silent)
public boolean hasPrimaryKey()
hasPrimaryKey in interface DBPersistentpublic int getPrimaryKeyCount()
getPrimaryKeyCount in interface DBPersistentpublic int getAttributeCount()
public int getFieldCount()
getFieldCount in interface DBRecordpublic java.lang.String[] getFieldFullNames()
getFieldFullNames in interface DBRecordgetFieldNames()public java.lang.String[] getFieldNames()
getFieldNames in interface DBRecordgetFieldFullNames()public DBColumnKey getFieldByName(java.lang.String fieldName)
public boolean existsField(java.lang.String fieldName)
existsField in interface DBRecordfieldName - might be a pure column name or in the format table.column -
only the column name is checked!public int getIndexOf(java.lang.String fieldName)
public DBColumnKey getFieldByIndex(int index)
public java.lang.Object getValue(DBColumnKey columnKey)
public java.lang.Object getValue(java.lang.String fieldName)
public java.lang.Object[] getValues()
protected DBObject readObject(DBObject dbo, int pkValue) throws java.sql.SQLException, RecordNotFoundException, InvalidPrimaryKeyException
java.sql.SQLExceptionRecordNotFoundExceptionInvalidPrimaryKeyExceptionprotected DBObject readObject(DBObject dbo, java.lang.String... pkValues) throws java.sql.SQLException, RecordNotFoundException, InvalidPrimaryKeyException
java.sql.SQLExceptionRecordNotFoundExceptionInvalidPrimaryKeyExceptionpublic void dbExists()
throws InvalidPrimaryKeyException,
RecordNotFoundException,
java.sql.SQLException
InvalidPrimaryKeyException - Thrown if the primary key is not valid.RecordNotFoundException - Thrown if the record could not be found.java.sql.SQLException - Thrown on any other database problem.exists()public int dbDelete(SqlCondition condition) throws java.sql.SQLException
isDirty() state of the deleted DBObjects may
not be consistent with the database.java.sql.SQLExceptionpublic SqlOrder getPrimaryKeyOrder()
public ToString toString(ToString s)
toString in interface DumpabletoString in class DumpableObjectpublic DumpString toDumpString(DumpString s)
toDumpString in interface DumpabletoDumpString in class DumpableObjectDumpableObject.toDumpString()protected java.lang.String createDumpHeader()
createDumpHeader in class DumpableObjectpublic void dbInsert()
throws InvalidPrimaryKeyException,
InsertFailedException,
java.sql.SQLException
Note that primary key fields are treated somewhat special. If the primary key field is set, then the INSERT operation is tried with that value. If it is omitted, the DBObject tries to determine a new PK value by performing the following calculation:
Futhermore if an InsertFactory is set, then it is checked for insert default values for any of the yet unset fields. If values are found then they are automatically applied before the insert is tried. Number fields with a value of 0 and boolean fields with a value of false are considered to be unset.
After a successful insert isDirty() will return false.
dbInsert in interface DBPersistentInsertFailedException - Thrown if record insertion failed.java.sql.SQLException - Thrown if the databases makes trouble.InvalidPrimaryKeyExceptiondbUpdate(),
dbDelete(),
forceInsert(),
isDirty(),
InsertFactory,
PrimaryKeyFactorypublic void setFieldValue(java.lang.String fieldName,
java.lang.Object value)
throws java.lang.Exception
fieldName - the name of the database columnvalue - the valuejava.lang.Exception - if the value type does not match the field typepublic void setFieldValue(java.lang.String fieldName,
java.lang.String valueStr)
throws java.lang.Exception
java.lang.ExceptionsetFieldValue(String, Object)public void dbUpdate()
throws InvalidPrimaryKeyException,
RecordNotFoundException,
java.sql.SQLException
isDirty() will return false.dbUpdate in interface DBPersistentInvalidPrimaryKeyException - Thrown if the primary key is invalid.RecordNotFoundException - Thrown if the record does not exist in the database.java.sql.SQLException - Thrown if the databases makes trouble.isDirty(),
forceUpdate(),
dbUpdate()public boolean forceInsert()
forceUpdate()public boolean forceUpdate()
forceInsert()public void dbForceUpdate()
throws java.sql.SQLException,
InvalidPrimaryKeyException,
InsertFailedException
java.sql.SQLExceptionInvalidPrimaryKeyExceptionInsertFailedExceptiondbForceInsert()public void dbForceInsert()
throws java.sql.SQLException,
RecordNotFoundException,
InvalidPrimaryKeyException
java.sql.SQLExceptionRecordNotFoundExceptionInvalidPrimaryKeyExceptiondbForceUpdate()public void dbDelete()
throws InvalidPrimaryKeyException,
RecordNotFoundException,
java.sql.SQLException
dbDelete in interface DBPersistentInvalidPrimaryKeyException - Thrown if the primary key is invalid.java.sql.SQLException - Thrown if the databases makes trouble.RecordNotFoundExceptionisDirty()public boolean exists()
dbExists() just any Exception that may have been thrown
is caught away.exists in interface DBPersistentdbExists()public void dbRehash()
throws InvalidPrimaryKeyException,
RecordNotFoundException,
java.sql.SQLException
isDirty() will return false.dbRehash in interface DBPersistentInvalidPrimaryKeyException - Thrown if the primary key is not valid.RecordNotFoundException - Thrown if no according record was found in the database.java.sql.SQLException - Thrown if a database problem occurred.exists()public static DBRecord getMasterRecord(java.lang.Class clazz)
Note: DBObject instantiation is somewhat tricky! For creation of a DBObject of type XX we must use the createInstance() method of an instance of an XX object. Thus in order to create an XX we first must have an XX!! Thats why the subclass caches an instance of itself as a once- object. Thus we reuse the same masterXX for the creation of all the other instances.
public DBRecord[] dbSearch(SqlCondition condition) throws java.sql.SQLException
dbSelect(SqlCondition condition).
It makes a difference only for composed DBObjects.dbSearch in interface DBPersistentjava.sql.SQLExceptionpublic DBRecord[] dbSearch(SqlCondition condition, SqlOrder order) throws java.sql.SQLException
dbSelect(SqlCondition condition, SqlOrder order).
It makes a difference only for composed DBObjects.dbSearch in interface DBPersistentjava.sql.SQLExceptionpublic void dbSearch(DBLoadMonitor monitor, SqlCondition condition) throws java.sql.SQLException
dbLoad(DBLoadMonitor monitor, SqlCondition condition).
It makes a difference only for composed DBObjects.dbSearch in interface DBPersistentjava.sql.SQLExceptionpublic void dbSearch(DBLoadMonitor monitor, SqlCondition condition, SqlOrder order) throws java.sql.SQLException
dbLoad(DBLoadMonitor monitor, SqlCondition condition, SqlOrder order).
It makes a difference only for composed DBObjects.dbSearch in interface DBPersistentjava.sql.SQLExceptionpublic DBRecord[] dbSelect() throws java.sql.SQLException
java.sql.SQLExceptionpublic DBRecord[] dbSelect(SqlCondition condition) throws java.sql.SQLException
dbSelect in interface DBPersistentjava.sql.SQLExceptionpublic DBRecord[] dbSelect(SqlOrder order) throws java.sql.SQLException
java.sql.SQLExceptionpublic DBRecord[] dbSelect(SqlCondition condition, SqlOrder order) throws java.sql.SQLException
dbSelect in interface DBPersistentjava.sql.SQLExceptionpublic void dbLoad(DBLoadMonitor monitor) throws java.sql.SQLException
dbLoad(DBLoadMonitor monitor, SqlCondition condition, SqlOrder order).
With no condition and ordering by primary key.java.sql.SQLExceptionpublic void dbLoad(DBLoadMonitor monitor, SqlCondition condition) throws java.sql.SQLException
dbLoad(DBLoadMonitor monitor, SqlCondition condition, SqlOrder order).
The default ordering is by primary key.dbLoad in interface DBPersistentjava.sql.SQLExceptionpublic void dbLoad(DBLoadMonitor monitor, SqlOrder order) throws java.sql.SQLException
dbLoad(DBLoadMonitor monitor, SqlCondition condition, SqlOrder order).
With no condition and the given order.java.sql.SQLExceptionpublic void dbLoad(DBLoadMonitor monitor, SqlCondition condition, SqlOrder order) throws java.sql.SQLException
dbLoad in interface DBPersistentjava.sql.SQLExceptionDBLoadTaskprotected abstract DBRecord createInstance()
protected abstract DBRecord createInstance(java.lang.String... primaryKeys) throws java.sql.SQLException, RecordNotFoundException, InvalidPrimaryKeyException
java.sql.SQLExceptionRecordNotFoundExceptionInvalidPrimaryKeyExceptionpublic static DBObject createInstance(java.lang.Class dboClass, java.lang.String... primaryKeys) throws java.sql.SQLException, RecordNotFoundException, InvalidPrimaryKeyException
java.sql.SQLExceptionRecordNotFoundExceptionInvalidPrimaryKeyExceptionpublic static DBObject createInstance(java.lang.Class dboClass)
public int dbCountRecords()
throws java.sql.SQLException
java.sql.SQLExceptionpublic int dbCountRecords(SqlCondition cond) throws java.sql.SQLException
java.sql.SQLExceptionpublic static int begin()
throws java.sql.SQLException
Note that nested transactions are supported. Thus begin() may be called n times by the same thread, each call increasing the nesting level. Accordingly commit() must be called n times decreasing the nesting level again. If nesting level 0 is reached by a commit() call then the database COMMIT is actually performed. A rollback() call at any nesting level will immediately break the transaction and fall back to nesting level 0.
Note that the default isolation level for a transaction is READ_COMMITTED.
java.sql.SQLExceptionbegin(int)public static int begin(int txIsolationLevel)
throws java.sql.SQLException
java.sql.SQLExceptionbegin()public static void commit()
throws java.sql.SQLException,
NotInTransactionException
java.sql.SQLExceptionNotInTransactionExceptionpublic static boolean rollback()
Note that this method does intentionally NOT throw an Exception. If the rollback fails in the database then there is nothing we can do about it anyway.
public boolean isPrimaryKeyValid()
public boolean isPrimaryKeyValid(java.lang.String... pkValues)
public boolean isFieldNumeric(java.lang.String fieldName)
public java.lang.String getFieldIcon(java.lang.String fieldName)
getFieldIcon in interface DBRecordfieldName - might be a pure column name or in the format table.column -
only the column name is checked!public boolean isPrimaryKey(java.lang.String fieldName)
isPrimaryKey in interface DBRecordfieldName - might be a pure column name or in the format table.column -
only the column name is checked!public boolean isForeignKey(java.lang.String fieldName)
isForeignKey in interface DBRecordfieldName - might be a pure column name or in the format table.column -
only the column name is checked!DBRecord.getForeignKeyRef(String)public java.lang.String getForeignKeyRef(java.lang.String columnName)
getForeignKeyRef in interface DBRecordcolumnName - The name of the field in the format table.column -
only the column name is checked!public java.lang.String getForeignKeyGroup(java.lang.String columnName)
getForeignKeyGroups()public java.lang.String[] getForeignKeyGroups()
getForeignKeyGroup(String)public boolean equals(java.lang.Object o)
Note that the current valid-state is not considered for determining equality.
equals in class java.lang.Objectpublic DBObject clone()
clone in class TransferableObjectpublic boolean equalAttributes(java.lang.Object o)
public boolean equalPrimaryKeys(java.lang.Object o)
public int hashCode()
hashCode in class java.lang.Objectpublic int compareTo(java.lang.Object o)
compareTo in interface java.lang.Comparablepublic boolean dbExistsTable()
public void dbDropTable()
throws java.sql.SQLException
java.sql.SQLExceptionpublic void dbCreateTable()
throws java.sql.SQLException
java.sql.SQLExceptionpublic void dbCreateForeignKeyConstraints()
throws java.sql.SQLException
java.sql.SQLExceptionpublic static int executeSQL(java.lang.String sql)
throws ConnectionNotEstablishedException,
java.sql.SQLException
ConnectionNotEstablishedExceptionjava.sql.SQLExceptionpublic static java.sql.ResultSet executeQuery(java.lang.String sql)
throws ConnectionNotEstablishedException,
java.sql.SQLException
ConnectionNotEstablishedExceptionjava.sql.SQLExceptionpublic DBObject[] getManagedDBObjects()
ComposedRecord types.getManagedDBObjects in interface DBRecordComposedRecordpublic static java.lang.String toKey(java.lang.String key)
public static java.lang.String toKey(java.lang.String[] keys)
public static RdbmsSupport getRdbmsSupport()
public static RdbmsInfo getRdbmsInfo()
public static void setErrorLogger(LogSupport logger)
LogSupport which reports DBObject activity.
The default is LogChannel.getDefault().
Note that this logger is optional, it is used to report details (record full dumps)
when actions on a record do fail.setSilent(boolean)public static LogSupport getErrorLogger()
setErrorLogger(LogSupport)public static void setDecimalRounding(java.math.RoundingMode mode,
int digits)
roundValue(double)public static boolean isDecimalRounding()
public static java.math.RoundingMode getDecimalRoundingMode()
public static int getDecimalRoundingDigits()
public static java.lang.Object convertArray(java.lang.Class newArrayClass,
java.lang.Object sourceArray)
protected java.lang.String dbGetString(java.sql.ResultSet rs,
int index)
throws java.sql.SQLException
java.sql.SQLExceptionprotected int dbGetInt(java.sql.ResultSet rs,
int index)
throws java.sql.SQLException
java.sql.SQLExceptionprotected long dbGetLong(java.sql.ResultSet rs,
int index)
throws java.sql.SQLException
java.sql.SQLExceptionprotected float dbGetFloat(java.sql.ResultSet rs,
int index)
throws java.sql.SQLException
java.sql.SQLExceptionprotected double dbGetDouble(java.sql.ResultSet rs,
int index)
throws java.sql.SQLException
java.sql.SQLExceptionprotected boolean dbGetBoolean(java.sql.ResultSet rs,
int index)
throws java.sql.SQLException
java.sql.SQLExceptionprotected java.lang.Boolean dbGetBooleanFromChar(java.sql.ResultSet rs,
int index)
throws java.sql.SQLException
java.sql.SQLExceptionprotected java.sql.Date dbGetDate(java.sql.ResultSet rs,
int index)
throws java.sql.SQLException
java.sql.SQLExceptionprotected java.sql.Time dbGetTime(java.sql.ResultSet rs,
int index)
throws java.sql.SQLException
java.sql.SQLExceptionprotected java.sql.Timestamp dbGetTimestamp(java.sql.ResultSet rs,
int index)
throws java.sql.SQLException
java.sql.SQLExceptionprotected java.sql.Blob dbGetBlob(java.sql.ResultSet rs,
int index)
protected java.sql.Clob dbGetClob(java.sql.ResultSet rs,
int index)
protected void dbSetClob(java.sql.PreparedStatement ps,
int index,
java.sql.Clob clob,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetClob(java.sql.PreparedStatement ps,
int index,
java.sql.Clob clob,
DumpString ds,
java.lang.String fieldName)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetBlob(java.sql.PreparedStatement ps,
int index,
java.sql.Blob blob,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetBlob(java.sql.PreparedStatement ps,
int index,
java.sql.Blob blob,
DumpString ds,
java.lang.String fieldName)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetPersistentName(java.sql.PreparedStatement ps,
int index,
PersistentName value,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetPersistentId(java.sql.PreparedStatement ps,
int index,
PersistentId value,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetString(java.sql.PreparedStatement ps,
int index,
java.lang.String value,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetInt(java.sql.PreparedStatement ps,
int index,
int value,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetLong(java.sql.PreparedStatement ps,
int index,
long value,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetFloat(java.sql.PreparedStatement ps,
int index,
float value,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetDouble(java.sql.PreparedStatement ps,
int index,
double value,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetBoolean(java.sql.PreparedStatement ps,
int index,
boolean value,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetBooleanAsChar(java.sql.PreparedStatement ps,
int index,
java.lang.Boolean value,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetDate(java.sql.PreparedStatement ps,
int index,
java.sql.Date value,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetTime(java.sql.PreparedStatement ps,
int index,
java.sql.Time value,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetTimestamp(java.sql.PreparedStatement ps,
int index,
java.sql.Timestamp value,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected void dbSetPK(java.sql.PreparedStatement ps,
int index,
java.lang.String valueStr,
DumpString ds,
DBColumnKey col)
throws java.sql.SQLException
java.sql.SQLExceptionprotected java.lang.Object toObject(boolean value)
protected java.lang.Object toObject(int value)
protected java.lang.Object toObject(long value)
protected java.lang.Object toObject(float value)
protected java.lang.Object toObject(double value)
protected java.lang.Object toObject(java.lang.Object value)
public static boolean isTrimStringsOnRead()
public static void setTrimStringsOnRead(boolean doTrim)
public static boolean isTrimStringsOnWrite()
public static void setTrimStringsOnWrite(boolean doTrim)
public static void setStoreZeroAsNull(boolean storeAsNull)
Note that zero values can be stored as nulls in the database, but if they are read back, they will be stored in primitive int, long, float or double fields as 0 values again.
public static boolean isStoreZeroAsNull()
setStoreZeroAsNull(boolean)public static java.lang.String getSchema()
setSchema(String)public static void setSchema(java.lang.String schema)
getSchema()public boolean isReadPrimaryKeyOnly()
setReadPrimaryKeyOnly(boolean)public void setReadPrimaryKeyOnly(boolean readPKOnly)
public void clearPrimaryKey()
clearAttributes()public void clearValues()
clearAttributes()public void clearAttributes()
clearValues()public static float roundValue(float value)
public static double roundValue(double value)
public void copyRecordValues(DBRecord otherRecord, boolean isIncludePK) throws java.lang.Exception
copyRecordValues in interface DBRecordjava.lang.ExceptionCopyright © 2014 EsprIT-Systems. All Rights Reserved.