D - The type of the data objectpublic abstract class DataObject<D extends DataObject<D>> extends Object
DataObject class is intended to make it easier to read and write
objects from and to a database. In order to achieve this some restrictions
had to be posed upon the data object and its representation in the database.
long.| Modifier | Constructor and Description |
|---|---|
protected |
DataObject(DataObjectFactory<D> dataObjectFactory,
long id)
Creates a new data object.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
clearDirtyFlag()
Clears the dirty flag.
|
static <D extends DataObject<D>> |
create(Database database,
DataObjectFactory<D> dataObjectFactory,
ValueField... valueFields)
Creates a new data object with the given value fields.
|
boolean |
delete(Database database)
Deletes this data object from the database.
|
static <D extends DataObject<D>> |
deleteById(Database database,
DataObjectFactory<D> dataObjectFactory,
long id)
Deletes the data object with the given ID from the database.
|
static <D extends DataObject<D>> |
deleteByWhereClause(Database database,
DataObjectFactory<D> dataObjectFactory,
WhereClause whereClause)
Deletes all objects from the database that match the given WHERE clause.
|
long |
getId()
Returns the ID of the data object.
|
protected Object |
getProperty(String name)
Returns the value of the property with the given name.
|
protected abstract Set<ValueField> |
getSaveFields()
Retuns the fields that need to be saved when the object has changed.
|
static <D extends DataObject<D>> |
loadAllByWhereClause(Database database,
DataObjectFactory<D> dataObjectFactory,
WhereClause whereClause,
OrderField... orderFields)
Loads all data objects that match the given where clause from the given
database.
|
static <D extends DataObject<D>> |
loadById(Database database,
DataObjectFactory<D> dataObjectFactory,
long id)
Loads a data object from the given database by the given ID.
|
static <D extends DataObject<D>> |
loadByWhereClause(Database database,
DataObjectFactory<D> dataObjectFactory,
WhereClause whereClause,
OrderField... orderFields)
Loads the first data object that matches the given where clause from the
given database.
|
void |
save(Database database)
Saves this data object to the database if it is dirty.
|
void |
save(Database database,
boolean force)
Saves this data object to the database if it is dirty, or if the
force parameter is true. |
protected void |
setProperty(String name,
Object value)
Sets the property with the given name to the given value.
|
protected DataObject(DataObjectFactory<D> dataObjectFactory, long id)
dataObjectFactory - The data object factory that create this objectid - The ID of the data objectpublic final long getId()
protected void setProperty(String name, Object value)
name - The name of the propertyvalue - The value of the propertyprotected Object getProperty(String name)
name - The name of the propertynull if the property does
not existprotected void clearDirtyFlag()
protected abstract Set<ValueField> getSaveFields()
public void save(Database database) throws DatabaseException
database - The database to store the object toDatabaseException - if a database error occurspublic void save(Database database, boolean force) throws DatabaseException
force parameter is true.database - The database to store the object toforce - true to force saving to the database, false to
not save if the object is not dirtyDatabaseException - if a database error occurspublic boolean delete(Database database) throws DatabaseException
save(Database) methods should
NOT be called!database - The database to delete the object fromtrue if the object was deleted, false otherwiseDatabaseException - if a database error occurspublic static <D extends DataObject<D>> D loadById(Database database, DataObjectFactory<D> dataObjectFactory, long id) throws DatabaseException
D - The type of the object to loaddatabase - The database to load the object fromdataObjectFactory - The data object factoryid - The ID to loadnull if there was no object with
the given IDDatabaseException - if a database error occurspublic static <D extends DataObject<D>> D loadByWhereClause(Database database, DataObjectFactory<D> dataObjectFactory, WhereClause whereClause, OrderField... orderFields) throws DatabaseException
D - The type of the object to loaddatabase - The database to load the object fromdataObjectFactory - The data object factorywhereClause - The where clause to match the objectorderFields - The fields to order the results bynull if
there was no object that matchedDatabaseException - if a database error occurspublic static <D extends DataObject<D>> List<D> loadAllByWhereClause(Database database, DataObjectFactory<D> dataObjectFactory, WhereClause whereClause, OrderField... orderFields) throws DatabaseException
D - The type of the objects to loaddatabase - The database to load the objects fromdataObjectFactory - The data object factorywhereClause - The where clause to match the objectsorderFields - The order fields to sort the results byDatabaseException - if a database error occurspublic static <D extends DataObject<D>> D create(Database database, DataObjectFactory<D> dataObjectFactory, ValueField... valueFields) throws DatabaseException
D - The type of the data objectdatabase - The database to create the object indataObjectFactory - The data object factoryvalueFields - The value fieldsDatabaseException - if a database error occurspublic static <D extends DataObject<D>> boolean deleteById(Database database, DataObjectFactory<D> dataObjectFactory, long id) throws DatabaseException
D - The type of the data objectdatabase - The database to delete the object fromdataObjectFactory - The data object factoryid - The ID of the object to deletetrue if an object was deleted, false otherwiseDatabaseException - if a database error occurspublic static <D extends DataObject<D>> int deleteByWhereClause(Database database, DataObjectFactory<D> dataObjectFactory, WhereClause whereClause) throws DatabaseException
D - The type of the data objectdatabase - The database to delete the objects fromdataObjectFactory - The data object factorywhereClause - The WHERE clause to match for deletionDatabaseException - if a database error occursCopyright © 2026. All rights reserved.