public class RuntimeExceptionDao<T,ID> extends Object implements Dao<T,ID>
Dao that wraps each Exception and rethrows it as RuntimeException. You can use this if your usage
pattern is to ignore all exceptions. That's not a pattern that I like so it's not the default.
RuntimeExceptionDao<Account, String> accountDao = RuntimeExceptionDao.createDao(connectionSource, Account.class);
Dao.CreateOrUpdateStatus, Dao.DaoObserver| Constructor and Description |
|---|
RuntimeExceptionDao(Dao<T,ID> dao) |
| Modifier and Type | Method and Description |
|---|---|
void |
assignEmptyForeignCollection(T parent,
String fieldName)
Creates an empty collection and assigns it to the appropriate field in the parent object.
|
<CT> CT |
callBatchTasks(Callable<CT> callable)
Call the call-able that will perform a number of batch tasks.
|
void |
clearObjectCache()
Flush the object cache if it has been enabled.
|
CloseableIterator<T> |
closeableIterator()
Returns an iterator over a set of elements of type T which can be closed.
|
void |
closeLastIterator()
This closes the last iterator returned by the
Dao.iterator() method. |
void |
commit(DatabaseConnection connection)
If you have previously set auto-commit to false using
Dao.setAutoCommit(DatabaseConnection, boolean) then
this will commit all changes to the database made from that point up to now on the connection returned by the
Dao.startThreadConnection(). |
long |
countOf()
Returns the number of rows in the table associated with the data class.
|
long |
countOf(PreparedQuery<T> preparedQuery)
Returns the number of rows in the table associated with the prepared query passed in.
|
int |
create(Collection<T> datas)
Just like
Dao.create(Object) but with a collection of objects. |
int |
create(T data)
Create a new row in the database from an object.
|
static <T,ID> RuntimeExceptionDao<T,ID> |
createDao(ConnectionSource connectionSource,
Class<T> clazz)
Call through to
DaoManager.createDao(ConnectionSource, Class) with the returned DAO wrapped in a
RuntimeExceptionDao. |
static <T,ID> RuntimeExceptionDao<T,ID> |
createDao(ConnectionSource connectionSource,
DatabaseTableConfig<T> tableConfig)
Call through to
DaoManager.createDao(ConnectionSource, DatabaseTableConfig) with the returned DAO wrapped
in a RuntimeExceptionDao. |
T |
createIfNotExists(T data)
This is a convenience method to creating a data item but only if the ID does not already exist in the table.
|
T |
createObjectInstance()
Instantiate an instance of the object that this dao manages.
|
Dao.CreateOrUpdateStatus |
createOrUpdate(T data)
This is a convenience method for creating an item in the database if it does not exist.
|
int |
delete(Collection<T> datas)
Delete a collection of objects from the database using an IN SQL clause.
|
int |
delete(PreparedDelete<T> preparedDelete)
Delete the objects that match the prepared statement parameter.
|
int |
delete(T data)
Delete the database row corresponding to the id from the data parameter.
|
DeleteBuilder<T,ID> |
deleteBuilder()
Like
Dao.queryBuilder() but allows you to build an DELETE statement. |
int |
deleteById(ID id)
Delete an object from the database that has an id.
|
int |
deleteIds(Collection<ID> ids)
Delete the objects that match the collection of ids from the database using an IN SQL clause.
|
void |
endThreadConnection(DatabaseConnection connection)
WARNING: This method is for advanced users only.
|
int |
executeRaw(String statement,
String... arguments)
Run a raw execute SQL statement to the database.
|
int |
executeRawNoArgs(String statement)
Run a raw execute SQL statement on the database without any arguments.
|
ID |
extractId(T data)
Returns the ID from the data parameter passed in.
|
FieldType |
findForeignFieldType(Class<?> clazz)
Returns the class of the DAO.
|
ConnectionSource |
getConnectionSource()
Return the associated ConnectionSource or null if none set on the DAO yet.
|
Class<T> |
getDataClass()
Returns the class of the DAO.
|
<FT> ForeignCollection<FT> |
getEmptyForeignCollection(String fieldName)
Like
Dao.assignEmptyForeignCollection(Object, String) but it returns the empty collection that you assign to
the appropriate field. |
ObjectCache |
getObjectCache()
Returns the current object-cache being used by the DAO or null if none.
|
RawRowMapper<T> |
getRawRowMapper()
Return a row mapper that is suitable for use with
Dao.queryRaw(String, RawRowMapper, String...). |
GenericRowMapper<T> |
getSelectStarRowMapper()
Return a row mapper that is suitable for mapping results from a query to select * (star).
|
TableInfo<T,ID> |
getTableInfo()
Get the table information associated with the class that this dao manages.
|
String |
getTableName()
Return the name of the table that this DAO is handling.
|
CloseableWrappedIterable<T> |
getWrappedIterable()
This makes a one time use iterable class that can be closed afterwards.
|
CloseableWrappedIterable<T> |
getWrappedIterable(PreparedQuery<T> preparedQuery)
Same as
Dao.getWrappedIterable() but with a prepared query parameter. |
boolean |
idExists(ID id)
Returns true if an object exists that matches this ID otherwise false.
|
boolean |
isAutoCommit(DatabaseConnection connection)
Return true if the database connection returned by the
Dao.startThreadConnection() is in auto-commit mode
otherwise false. |
boolean |
isTableExists()
Returns true if the table already exists otherwise false.
|
boolean |
isUpdatable()
Returns true if we can call update on this class.
|
CloseableIterator<T> |
iterator()
This satisfies the
Iterable interface for the class and allows you to iterate through the objects in the
table using SQL. |
CloseableIterator<T> |
iterator(int resultFlags)
Same as
Dao.iterator() but while specifying flags for the results. |
CloseableIterator<T> |
iterator(PreparedQuery<T> preparedQuery)
Same as
Dao.iterator() but with a prepared query parameter. |
CloseableIterator<T> |
iterator(PreparedQuery<T> preparedQuery,
int resultFlags)
Same as
Dao.iterator(PreparedQuery) but while specifying flags for the results. |
T |
mapSelectStarRow(DatabaseResults results)
Return the latest row from the database results from a query to select * (star).
|
void |
notifyChanges()
Notify any registered
Dao.DaoObservers that the underlying data may have changed. |
boolean |
objectsEqual(T data1,
T data2)
Return true if the two parameters are equal.
|
String |
objectToString(T data)
Return the string version of the object with each of the known field values shown.
|
List<T> |
query(PreparedQuery<T> preparedQuery)
Query for the items in the object table which match the prepared query.
|
QueryBuilder<T,ID> |
queryBuilder()
Create and return a new query builder object which allows you to build a custom SELECT statement.
|
List<T> |
queryForAll()
Query for all of the items in the object table.
|
List<T> |
queryForEq(String fieldName,
Object value)
Query for the items in the object table that match a simple where with a single field = value type of WHERE
clause.
|
List<T> |
queryForFieldValues(Map<String,Object> fieldValues)
Query for the rows in the database that matches all of the field to value entries from the map passed in.
|
List<T> |
queryForFieldValuesArgs(Map<String,Object> fieldValues)
Same as
Dao.queryForFieldValues(Map) but this uses SelectArg and SQL ? arguments. |
T |
queryForFirst()
Query for the first entry in the table returning null if none.
|
T |
queryForFirst(PreparedQuery<T> preparedQuery)
Query for and return the first item in the object table which matches the PreparedQuery.
|
T |
queryForId(ID id)
Retrieves an object associated with a specific ID.
|
List<T> |
queryForMatching(T matchObj)
Query for the rows in the database that match the object passed in as a parameter.
|
List<T> |
queryForMatchingArgs(T matchObj)
Same as
Dao.queryForMatching(Object) but this uses SelectArg and SQL ? arguments. |
T |
queryForSameId(T data)
Query for a data item in the table that has the same id as the data parameter.
|
<UO> GenericRawResults<UO> |
queryRaw(String query,
DatabaseResultsMapper<UO> mapper,
String... arguments)
Similar to the
Dao.queryRaw(String, RawRowMapper, String...) but this iterator returns rows that you can map
yourself using DatabaseResultsMapper. |
<UO> GenericRawResults<UO> |
queryRaw(String query,
DataType[] columnTypes,
RawRowObjectMapper<UO> mapper,
String... arguments)
Similar to the
Dao.queryRaw(String, RawRowMapper, String...) but uses the column-types array to present an
array of object results to the mapper instead of strings. |
GenericRawResults<Object[]> |
queryRaw(String query,
DataType[] columnTypes,
String... arguments)
Similar to the
Dao.queryRaw(String, String...) but instead of an array of String results being returned by
the iterator, this uses the column-types parameter to return an array of Objects instead. |
<UO> GenericRawResults<UO> |
queryRaw(String query,
RawRowMapper<UO> mapper,
String... arguments)
Similar to the
Dao.queryRaw(String, String...) but this iterator returns rows that you can map yourself. |
GenericRawResults<String[]> |
queryRaw(String query,
String... arguments)
Similar to the
Dao.iterator(PreparedQuery) except it returns a GenericRawResults object associated with the
SQL select query argument. |
long |
queryRawValue(String query,
String... arguments)
Perform a raw query that returns a single value (usually an aggregate function like MAX or COUNT).
|
int |
refresh(T data)
Does a query for the data parameter's id and copies in each of the field values from the database to refresh the
data parameter.
|
void |
registerObserver(Dao.DaoObserver observer)
Register an observer that will be called when data changes for this DAO.
|
void |
rollBack(DatabaseConnection connection)
If you have previously set auto-commit to false using
Dao.setAutoCommit(DatabaseConnection, boolean) then
this will roll-back and flush all changes to the database made from that point up to now on the connection
returned by the Dao.startThreadConnection() . |
void |
setAutoCommit(DatabaseConnection connection,
boolean autoCommit)
Set auto-commit mode to be true or false on the connection returned by the
Dao.startThreadConnection(). |
void |
setObjectCache(boolean enabled)
Call this with true to enable an object cache for the DAO.
|
void |
setObjectCache(ObjectCache objectCache)
Same as
Dao.setObjectCache(boolean) except you specify the actual cache instance to use for the DAO. |
void |
setObjectFactory(ObjectFactory<T> objectFactory)
Set an object factory so we can wire in controls over an object when it is constructed.
|
DatabaseConnection |
startThreadConnection()
WARNING: This method is for advanced users only.
|
void |
unregisterObserver(Dao.DaoObserver observer)
Remove the observer from the registered list.
|
int |
update(PreparedUpdate<T> preparedUpdate)
Update all rows in the table according to the prepared statement parameter.
|
int |
update(T data)
Store the fields from an object to the database row corresponding to the id from the data parameter.
|
UpdateBuilder<T,ID> |
updateBuilder()
Like
Dao.queryBuilder() but allows you to build an UPDATE statement. |
int |
updateId(T data,
ID newId)
Update the data parameter in the database to change its id to the newId parameter.
|
int |
updateRaw(String statement,
String... arguments)
Run a raw update SQL statement to the database.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic static <T,ID> RuntimeExceptionDao<T,ID> createDao(ConnectionSource connectionSource, Class<T> clazz) throws SQLException
DaoManager.createDao(ConnectionSource, Class) with the returned DAO wrapped in a
RuntimeExceptionDao.SQLExceptionpublic static <T,ID> RuntimeExceptionDao<T,ID> createDao(ConnectionSource connectionSource, DatabaseTableConfig<T> tableConfig) throws SQLException
DaoManager.createDao(ConnectionSource, DatabaseTableConfig) with the returned DAO wrapped
in a RuntimeExceptionDao.SQLExceptionpublic T queryForId(ID id)
DaoqueryForId in interface Dao<T,ID>id - Identifier that matches a specific row in the database to find and return.Dao.queryForId(Object)public T queryForFirst(PreparedQuery<T> preparedQuery)
DaoDao.queryBuilder() for more information. This can be used to return the object that matches a single unique
column. You should use Dao.queryForId(Object) if you want to query for the id column.queryForFirst in interface Dao<T,ID>preparedQuery - Query used to match the objects in the database.Dao.queryForFirst(PreparedQuery)public List<T> queryForAll()
DaoDao.iterator() method instead.queryForAll in interface Dao<T,ID>Dao.queryForAll()public T queryForFirst()
DaoqueryForFirst in interface Dao<T,ID>Dao.queryForFirst()public List<T> queryForEq(String fieldName, Object value)
DaoqueryForEq in interface Dao<T,ID>Dao.queryForEq(String, Object)public List<T> queryForMatching(T matchObj)
DaoDao.queryForMatchingArgs(Object).queryForMatching in interface Dao<T,ID>Dao.queryForMatching(Object)public List<T> queryForMatchingArgs(T matchObj)
DaoDao.queryForMatching(Object) but this uses SelectArg and SQL ? arguments. This is slightly
more expensive but you don't have to worry about SQL quote escaping.queryForMatchingArgs in interface Dao<T,ID>Dao.queryForMatchingArgs(Object)public List<T> queryForFieldValues(Map<String,Object> fieldValues)
DaoDao.queryForFieldValuesArgs(Map).queryForFieldValues in interface Dao<T,ID>Dao.queryForFieldValues(Map)public List<T> queryForFieldValuesArgs(Map<String,Object> fieldValues)
DaoDao.queryForFieldValues(Map) but this uses SelectArg and SQL ? arguments. This is slightly
more expensive but you don't have to worry about SQL quote escaping.queryForFieldValuesArgs in interface Dao<T,ID>Dao.queryForFieldValuesArgs(Map)public T queryForSameId(T data)
DaoqueryForSameId in interface Dao<T,ID>Dao.queryForSameId(Object)public QueryBuilder<T,ID> queryBuilder()
DaoQueryBuilder.prepare() once you are
ready to build. This returns a PreparedQuery object which gets passed to Dao.query(PreparedQuery) or
Dao.iterator(PreparedQuery).queryBuilder in interface Dao<T,ID>Dao.queryBuilder()public UpdateBuilder<T,ID> updateBuilder()
DaoDao.queryBuilder() but allows you to build an UPDATE statement. You can then call call
UpdateBuilder.prepare() and pass the returned PreparedUpdate to Dao.update(PreparedUpdate).updateBuilder in interface Dao<T,ID>Dao.updateBuilder()public DeleteBuilder<T,ID> deleteBuilder()
DaoDao.queryBuilder() but allows you to build an DELETE statement. You can then call call
DeleteBuilder.prepare() and pass the returned PreparedDelete to Dao.delete(PreparedDelete).deleteBuilder in interface Dao<T,ID>Dao.deleteBuilder()public List<T> query(PreparedQuery<T> preparedQuery)
DaoDao.queryBuilder() for more
information.
NOTE: For medium sized or large tables, this may load a lot of objects into memory so you should consider
using the Dao.iterator(PreparedQuery) method instead.
query in interface Dao<T,ID>preparedQuery - Query used to match the objects in the database.Dao.query(PreparedQuery)public int create(T data)
DaoDatabaseField.generatedId() then the data parameter will be modified and set with the corresponding id
from the database.create in interface Dao<T,ID>data - The data item that we are creating in the database.Dao.create(Object)public int create(Collection<T> datas)
DaoDao.create(Object) but with a collection of objects. This will wrap the creates using the same
mechanism as Dao.callBatchTasks(Callable).create in interface Dao<T,ID>datas - The collection of data items that we are creating in the database.Dao.create(Collection)public T createIfNotExists(T data)
DaoDao.queryForId(Object) on it, returning the data if it
exists. If it does not exist Dao.create(Object) will be called with the parameter.
NOTE: This method is synchronized because otherwise race conditions would be encountered if this is used by multiple threads.
createIfNotExists in interface Dao<T,ID>Dao.createIfNotExists(Object)public Dao.CreateOrUpdateStatus createOrUpdate(T data)
DaoNOTE: This method is synchronized because otherwise race conditions would be encountered if this is used by multiple threads.
createOrUpdate in interface Dao<T,ID>Dao.createOrUpdate(Object)public int update(T data)
DaoDao.updateId(T, ID) .
NOTE: This will not save changes made to foreign objects or to foreign collections.
update in interface Dao<T,ID>data - The data item that we are updating in the database.Dao.update(Object)public int updateId(T data, ID newId)
DaoNOTE: Depending on the database type and the id type, you may be unable to change the id of the field.
updateId in interface Dao<T,ID>data - The data item that we are updating in the database with the current id.newId - The new id that you want to update the data with.Dao.updateId(Object, Object)public int update(PreparedUpdate<T> preparedUpdate)
DaoUpdateBuilder must have set-columns applied to it using the
UpdateBuilder.updateColumnValue(String, Object) or
UpdateBuilder.updateColumnExpression(String, String) methods.update in interface Dao<T,ID>preparedUpdate - A prepared statement to match database rows to be deleted and define the columns to update.Dao.update(PreparedUpdate)public int refresh(T data)
Daorefresh in interface Dao<T,ID>data - The data item that we are refreshing with fields from the database.Dao.refresh(Object)public int delete(T data)
Daodelete in interface Dao<T,ID>data - The data item that we are deleting from the database.Dao.delete(Object)public int deleteById(ID id)
DaodeleteById in interface Dao<T,ID>id - The id of the item that we are deleting from the database.Dao.deleteById(Object)public int delete(Collection<T> datas)
Daodelete in interface Dao<T,ID>datas - A collection of data items to be deleted.Dao.delete(Collection)public int deleteIds(Collection<ID> ids)
DaodeleteIds in interface Dao<T,ID>ids - A collection of data ids to be deleted.Dao.deleteIds(Collection)public int delete(PreparedDelete<T> preparedDelete)
Daodelete in interface Dao<T,ID>preparedDelete - A prepared statement to match database rows to be deleted.Dao.delete(PreparedDelete)public CloseableIterator<T> iterator()
DaoIterable interface for the class and allows you to iterate through the objects in the
table using SQL. You can use code similar to the following:
for (Account account : accountDao) { ... }
WARNING: because the Iterator.hasNext(), Iterator.next(), etc. methods can only throw
RuntimeException, the code has to wrap any SQLException with IllegalStateException. Make
sure to catch IllegalStateException and look for a SQLException cause.
WARNING: The underlying results object will only be closed if you page all the way to the end of the
iterator using the for() loop or if you call AutoCloseable.close() directly. You can also call the
Dao.closeLastIterator() if you are not iterating across this DAO in multiple threads.
NOTE: With this iterator you can only move forward through the object collection. See the
Dao.iterator(int) method to create a cursor that can go both directions.
public CloseableIterator<T> closeableIterator()
CloseableIterablecloseableIterator in interface CloseableIterable<T>CloseableIterable.closeableIterator()public CloseableIterator<T> iterator(int resultFlags)
DaoDao.iterator() but while specifying flags for the results. This is necessary with certain database
types. The resultFlags could be something like ResultSet.TYPE_SCROLL_INSENSITIVE or other values.
WARNING: Depending on the database type the underlying connection may never be freed -- even if you go all
of the way through the results. It is strongly recommended that you call the
AutoCloseable.close() method when you are done with the iterator.
iterator in interface Dao<T,ID>Dao.iterator(int)public CloseableWrappedIterable<T> getWrappedIterable()
Dao
This makes a one time use iterable class that can be closed afterwards. The DAO itself is
CloseableWrappedIterable but multiple threads can each call this to get their own closeable iterable.
This allows you to do something like:
CloseableWrappedIterable<Foo> wrappedIterable = fooDao.getWrappedIterable();
try {
for (Foo foo : wrappedIterable) {
...
}
} finally {
wrappedIterable.close();
}
getWrappedIterable in interface Dao<T,ID>Dao.getWrappedIterable()public CloseableWrappedIterable<T> getWrappedIterable(PreparedQuery<T> preparedQuery)
DaoDao.getWrappedIterable() but with a prepared query parameter. See Dao.queryBuilder() or
Dao.iterator(PreparedQuery) for more information.getWrappedIterable in interface Dao<T,ID>Dao.getWrappedIterable(PreparedQuery)public void closeLastIterator()
DaoDao.iterator() method.
NOTE: This is not reentrant. If multiple threads are getting iterators from this DAO then you should use
the Dao.getWrappedIterable() method to get a wrapped iterable for each thread instead.
closeLastIterator in interface Dao<T,ID>Dao.closeLastIterator()public CloseableIterator<T> iterator(PreparedQuery<T> preparedQuery)
DaoDao.iterator() but with a prepared query parameter. See Dao.queryBuilder() for more information.
You use it like the following:
QueryBuilder<Account, String> qb = accountDao.queryBuilder();
... custom query builder methods
CloseableIterator<Account> iterator = partialDao.iterator(qb.prepare());
try {
while (iterator.hasNext()) {
Account account = iterator.next();
...
}
} finish {
iterator.close();
}
iterator in interface Dao<T,ID>preparedQuery - Query used to iterate across a sub-set of the items in the database.Dao.iterator(PreparedQuery)public CloseableIterator<T> iterator(PreparedQuery<T> preparedQuery, int resultFlags)
DaoDao.iterator(PreparedQuery) but while specifying flags for the results. This is necessary with
certain database types.iterator in interface Dao<T,ID>Dao.iterator(PreparedQuery, int)public GenericRawResults<String[]> queryRaw(String query, String... arguments)
Dao
Similar to the Dao.iterator(PreparedQuery) except it returns a GenericRawResults object associated with the
SQL select query argument. Although you should use the Dao.iterator() for most queries, this method allows
you to do special queries that aren't supported otherwise. Like the above iterator methods, you must call close
on the returned RawResults object once you are done with it. The arguments are optional but can be set with
strings to expand ? type of SQL.
You can use the StatementBuilder.prepareStatementString() method here if you want to build the query using
the structure of the QueryBuilder.
QueryBuilder<Account, Integer> qb = accountDao.queryBuilder();
qb.where().ge("orderCount", 10);
results = accountDao.queryRaw(qb.prepareStatementString());
If you want to use the QueryBuilder with arguments to the raw query then you should do something like:
QueryBuilder<Account, Integer> qb = accountDao.queryBuilder();
// we specify a SelectArg here to generate a ? in the statement string below
qb.where().ge("orderCount", new SelectArg());
// the 10 at the end is an optional argument to fulfill the SelectArg above
results = accountDao.queryRaw(qb.prepareStatementString(), rawRowMapper, 10);
NOTE: If you are using the StatementBuilder.prepareStatementString() to build your query, it may have
added the id column to the selected column list if the Dao object has an id you did not include it in the columns
you selected. So the results might have one more column than you are expecting.
queryRaw in interface Dao<T,ID>Dao.queryRaw(String, String...)public long queryRawValue(String query, String... arguments)
DaoqueryRawValue in interface Dao<T,ID>Dao.queryRawValue(String, String...)public <UO> GenericRawResults<UO> queryRaw(String query, RawRowMapper<UO> mapper, String... arguments)
DaoDao.queryRaw(String, String...) but this iterator returns rows that you can map yourself. For
every result that is returned by the database, the RawRowMapper.mapRow(String[], String[]) method is
called so you can convert the result columns into an object to be returned by the iterator. The arguments are
optional but can be set with strings to expand ? type of SQL. For a simple implementation of a raw row mapper,
see Dao.getRawRowMapper().queryRaw in interface Dao<T,ID>Dao.queryRaw(String, RawRowMapper, String...)public <UO> GenericRawResults<UO> queryRaw(String query, DataType[] columnTypes, RawRowObjectMapper<UO> mapper, String... arguments)
DaoDao.queryRaw(String, RawRowMapper, String...) but uses the column-types array to present an
array of object results to the mapper instead of strings. The arguments are optional but can be set with strings
to expand ? type of SQL.queryRaw in interface Dao<T,ID>Dao.queryRaw(String, DataType[], RawRowObjectMapper, String...)public GenericRawResults<Object[]> queryRaw(String query, DataType[] columnTypes, String... arguments)
DaoDao.queryRaw(String, String...) but instead of an array of String results being returned by
the iterator, this uses the column-types parameter to return an array of Objects instead. The arguments are
optional but can be set with strings to expand ? type of SQL.queryRaw in interface Dao<T,ID>Dao.queryRaw(String, DataType[], String...)public <UO> GenericRawResults<UO> queryRaw(String query, DatabaseResultsMapper<UO> mapper, String... arguments)
DaoDao.queryRaw(String, RawRowMapper, String...) but this iterator returns rows that you can map
yourself using DatabaseResultsMapper.queryRaw in interface Dao<T,ID>Dao.queryRaw(String, DatabaseResultsMapper, String...)public int executeRaw(String statement, String... arguments)
DaoDao.executeRawNoArgs(String).executeRaw in interface Dao<T,ID>Dao.executeRaw(String, String...)public int executeRawNoArgs(String statement)
DaoexecuteRawNoArgs in interface Dao<T,ID>Dao.executeRawNoArgs(String)public int updateRaw(String statement, String... arguments)
DaoupdateRaw in interface Dao<T,ID>Dao.updateRaw(String, String...)public <CT> CT callBatchTasks(Callable<CT> callable)
DaoNOTE: If neither auto-commit nor transactions are supported by the database type then this may just call the callable. Also, "commit()" is not called on the connection at all. If "auto-commit" is disabled then this will leave it off and nothing will have been persisted.
NOTE: Depending on your underlying database implementation and whether or not you are working with a
single database connection, this may synchronize internally to ensure that there are not race-conditions around
the transactions on the single connection. Android (for example) will synchronize. Also, you may also need to
synchronize calls to here and calls to Dao.setAutoCommit(DatabaseConnection, boolean).
callBatchTasks in interface Dao<T,ID>Dao.callBatchTasks(Callable)public String objectToString(T data)
DaoobjectToString in interface Dao<T,ID>data - The data item for which we are returning the toString information.Dao.objectToString(Object)public boolean objectsEqual(T data1, T data2)
DaoobjectsEqual in interface Dao<T,ID>data1 - One of the data items that we are checking for equality.data2 - The other data item that we are checking for equality.Dao.objectsEqual(Object, Object)public ID extractId(T data)
DaoextractId in interface Dao<T,ID>Dao.extractId(Object)public Class<T> getDataClass()
DaogetDataClass in interface Dao<T,ID>Dao.getDataClass()public FieldType findForeignFieldType(Class<?> clazz)
DaofindForeignFieldType in interface Dao<T,ID>Dao.findForeignFieldType(Class)public boolean isUpdatable()
DaoisUpdatable in interface Dao<T,ID>Dao.isUpdatable()public boolean isTableExists()
DaoisTableExists in interface Dao<T,ID>Dao.isTableExists()public long countOf()
DaocountOf in interface Dao<T,ID>Dao.countOf()public long countOf(PreparedQuery<T> preparedQuery)
Dao
NOTE: If the query was prepared with the QueryBuilder then you should have called the
QueryBuilder.setCountOf(boolean) with true before you prepared the query. You may instead want to use
QueryBuilder.countOf() which makes it all easier.
countOf in interface Dao<T,ID>Dao.countOf(PreparedQuery)public void assignEmptyForeignCollection(T parent, String fieldName)
DaoCreates an empty collection and assigns it to the appropriate field in the parent object. This allows you to add things to the collection from the start.
For example let's say you have an Account which has the field:
@ForeignCollectionField(columnName = "orders") Collection<Order> orders;
You would then call:
accoundDao.assignEmptyForeignCollection(account, "orders"); // this would add it the collection and the internal DAO account.orders.add(order1);
assignEmptyForeignCollection in interface Dao<T,ID>parent - Parent object that will be associated with all items added to this collection if not already assigned.fieldName - parameter is the field name of the foreign collection field -- you might consider using the
ForeignCollectionField.columnName() to set the name to a static name.Dao.assignEmptyForeignCollection(Object, String)public <FT> ForeignCollection<FT> getEmptyForeignCollection(String fieldName)
DaoDao.assignEmptyForeignCollection(Object, String) but it returns the empty collection that you assign to
the appropriate field.
NOTE: May be deprecated in the future.
getEmptyForeignCollection in interface Dao<T,ID>Dao.getEmptyForeignCollection(String)public void setObjectCache(boolean enabled)
DaoReferenceObjectCache of the objects (using
WeakReference) referenced by the DAO. No support for objects returned by the Dao.queryRaw(java.lang.String, java.lang.String...) methods.setObjectCache in interface Dao<T,ID>Dao.setObjectCache(boolean)public ObjectCache getObjectCache()
DaogetObjectCache in interface Dao<T,ID>Dao.getObjectCache()public void setObjectCache(ObjectCache objectCache)
DaoDao.setObjectCache(boolean) except you specify the actual cache instance to use for the DAO. This
allows you to use a ReferenceObjectCache with SoftReference setting, the LruObjectCache,
or inject your own cache implementation. Call it with null to disable the cache.setObjectCache in interface Dao<T,ID>Dao.setObjectCache(ObjectCache)public void clearObjectCache()
DaoclearObjectCache in interface Dao<T,ID>Dao.clearObjectCache()public T mapSelectStarRow(DatabaseResults results)
DaomapSelectStarRow in interface Dao<T,ID>Dao.mapSelectStarRow(DatabaseResults)public GenericRowMapper<T> getSelectStarRowMapper()
DaogetSelectStarRowMapper in interface Dao<T,ID>Dao.getSelectStarRowMapper()public boolean idExists(ID id)
DaoidExists in interface Dao<T,ID>Dao.idExists(Object)public DatabaseConnection startThreadConnection()
Dao
WARNING: This method is for advanced users only. It is only to support the
Dao.setAutoCommit(DatabaseConnection, boolean) and other methods below. Chances are you should be using the
Dao.callBatchTasks(Callable) instead of this method unless you know what you are doing.
This allocates a connection for this specific thread that will be used in all other DAO operations. The thread
must call Dao.endThreadConnection(DatabaseConnection) once it is done with the connection. It is
highly recommended that a
try { conn = dao.startThreadConnection(); ... } finally { dao.endThreadConnection(conn); } type of
pattern be used here to ensure you do not leak connections.
startThreadConnection in interface Dao<T,ID>Dao.startThreadConnection()public void endThreadConnection(DatabaseConnection connection)
Dao
WARNING: This method is for advanced users only. It is only to support the
Dao.setAutoCommit(DatabaseConnection, boolean) and other methods below. Chances are you should be using the
Dao.callBatchTasks(Callable) instead of this method unless you know what you are doing.
This method is used to free the connection returned by the Dao.startThreadConnection() above.
endThreadConnection in interface Dao<T,ID>connection - Connection to be freed. If null then it will be a no-op.Dao.endThreadConnection(DatabaseConnection)public void setAutoCommit(DatabaseConnection connection, boolean autoCommit)
DaoDao.startThreadConnection(). This
may not be supported by all database types.
WARNING: Chances are you should be using the Dao.callBatchTasks(Callable) instead of this method
unless you know what you are doing.
NOTE: Depending on your underlying database implementation and whether or not you are working with a
single database connection, you may need to synchronize calls to here and calls to
Dao.callBatchTasks(Callable), Dao.commit(DatabaseConnection), and Dao.rollBack(DatabaseConnection)
.
setAutoCommit in interface Dao<T,ID>Dao.setAutoCommit(DatabaseConnection, boolean)public boolean isAutoCommit(DatabaseConnection connection)
DaoDao.startThreadConnection() is in auto-commit mode
otherwise false. This may not be supported by all database types.isAutoCommit in interface Dao<T,ID>Dao.isAutoCommit(DatabaseConnection)public void commit(DatabaseConnection connection)
DaoDao.setAutoCommit(DatabaseConnection, boolean) then
this will commit all changes to the database made from that point up to now on the connection returned by the
Dao.startThreadConnection(). The changes will be written to the database and discarded. The connection will
continue to stay in the current auto-commit mode.
WARNING: Chances are you should be using the Dao.callBatchTasks(Callable) instead of this method
unless you know what you are doing.
NOTE: Depending on your underlying database implementation and whether or not you are working with a
single database connection, you may need to synchronize calls to here and calls to
Dao.callBatchTasks(Callable), Dao.setAutoCommit(DatabaseConnection, boolean), and
Dao.rollBack(DatabaseConnection).
commit in interface Dao<T,ID>Dao.commit(DatabaseConnection)public void rollBack(DatabaseConnection connection)
DaoDao.setAutoCommit(DatabaseConnection, boolean) then
this will roll-back and flush all changes to the database made from that point up to now on the connection
returned by the Dao.startThreadConnection() . None of those changes will be written to the database and are
discarded. The connection will continue to stay in the current auto-commit mode.
WARNING: Chances are you should be using the Dao.callBatchTasks(Callable) instead of this method
unless you know what you are doing.
NOTE: Depending on your underlying database implementation and whether or not you are working with a
single database connection, you may need to synchronize calls to here and calls to
Dao.callBatchTasks(Callable), Dao.setAutoCommit(DatabaseConnection, boolean), and
Dao.commit(DatabaseConnection).
rollBack in interface Dao<T,ID>Dao.rollBack(DatabaseConnection)public void setObjectFactory(ObjectFactory<T> objectFactory)
DaosetObjectFactory in interface Dao<T,ID>Dao.setObjectFactory(ObjectFactory)public RawRowMapper<T> getRawRowMapper()
DaoDao.queryRaw(String, RawRowMapper, String...). This is a
bit experimental at this time. It most likely will _not_ work with all databases since the string output for each
data type is hard to forecast. Please provide feedback.getRawRowMapper in interface Dao<T,ID>Dao.getRawRowMapper()public ConnectionSource getConnectionSource()
DaogetConnectionSource in interface Dao<T,ID>Dao.getConnectionSource()public void registerObserver(Dao.DaoObserver observer)
DaoDao.unregisterObserver(DaoObserver) to de-register the observer after you are done with it.registerObserver in interface Dao<T,ID>Dao.registerObserver(com.j256.ormlite.dao.Dao.DaoObserver)public void unregisterObserver(Dao.DaoObserver observer)
DaounregisterObserver in interface Dao<T,ID>Dao.unregisterObserver(com.j256.ormlite.dao.Dao.DaoObserver)public void notifyChanges()
DaoDao.DaoObservers that the underlying data may have changed. This is done automatically
when using Dao.create(Object), Dao.update(Object), or Dao.delete(Object) type methods. Batch
methods will be notified once at the end of the batch, not for every statement in the batch.
NOTE: The Dao.updateRaw(String, String...) and other raw methods will _not_ call notify automatically. You
will have to call this method yourself after you use the raw methods to change the entities.notifyChanges in interface Dao<T,ID>Dao.notifyChanges()public String getTableName()
DaogetTableName in interface Dao<T,ID>Dao.getTableName()public T createObjectInstance()
DaocreateObjectInstance in interface Dao<T,ID>Dao.createObjectInstance()public TableInfo<T,ID> getTableInfo()
DaogetTableInfo in interface Dao<T,ID>Dao.getTableInfo()This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.