|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.sql.JDBCRowStore<T>
public class JDBCRowStore<T extends DBEntry>
provides JDBC persistence for Objects that have a corresponding ObjectRowMapper. Note that this class should not be used by itself, but always through a Proxy wrapped by a SQLDatabase, so that all methods are properly synchronized via the transaction.
SQLDatabase,
BaseRowMapper| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.antelmann.db.DBClassStore |
|---|
DBClassStore.DBMethod |
| Field Summary | |
|---|---|
protected Database<Connection> |
database
|
protected boolean |
ensureTransactionsOnFetch
when set to true, the fetch-methods ensure a synchronized transactional context; false is the default |
protected ConnectionHelper |
helper
|
protected ObjectRowMapper<T> |
mapper
|
| Constructor Summary | |
|---|---|
JDBCRowStore(Database<Connection> database,
ObjectRowMapper<T> mapper,
Class<T> typeClass)
typeClass is used to specify the original class for the Stub objects |
|
JDBCRowStore(Database<Connection> database,
ObjectRowMapper<T> mapper,
Class<T> typeClass,
boolean ignoreInvalidProperties)
|
|
JDBCRowStore(Database<Connection> database,
ObjectRowMapper<T> mapper,
Class<T> typeClass,
boolean ignoreInvalidProperties,
boolean fastDelete)
|
|
| Method Summary | |
|---|---|
void |
add(Processor<T,? extends DatabaseException> processor)
|
protected void |
checkTransaction()
throws the exception if there is no active transaction |
boolean |
containsID(Object id)
determines whether the given ID is present in this store. |
int |
deleteEntries(Filter<? super T> filter)
supports SQLMapFilter for more effective deletion. |
boolean |
deleteEntry(Object id)
removes the entry with the given ID from this store in the database. |
DBEnumeration<T> |
fetch(Filter<? super T> filter)
Depending of the capabilities of the mapper in use, this method can support various special filters. |
DBEnumeration<Stub<T>> |
fetchStubs(Filter<? super Stub<?>> filter)
This implementation supports SQLStubFilter and SQLDirectQueryEntryFilter objects; but otherwise, it doesn't filter in any more intelligent way than leaving the filtering to the AbstractIterator. |
Object |
generateNewID()
returns a value supplied by the mapper |
String[] |
getColumnNames()
returns all the columns that are retrieved by the mapper when querying the database); the column names for the ID column and display column are included in the returned array. |
String[] |
getColumnsForTopic(Object topic)
allows to determine whether there are any columns that are applicable for the given topic |
int |
getColumnSize(String column)
allows to determine the size of the given column name. |
Database<Connection> |
getDatabase()
provides access to the database instance that also coordinates the transaction management. |
String |
getDisplayColumn()
for use in stubs (in case a single column is used as a display value) |
String |
getDisplayNameForColumn(String column)
returns a name suitable for display in a GUI if different from the column name used in the database |
T |
getEntry(Object id)
returns the DBEntry based on its ID. |
Class<T> |
getEntryClass()
returns the runtime class type this store represents |
String |
getIDColumn()
specifies the column where the ID of the entry is mapped to |
ObjectRowMapper<T> |
getMapper()
|
String |
getMappingForTopic(Object topic)
allows to determine whether a specific given topic maps to a distinct table, query or column name. |
int |
getSQLTypeforColumn(String column)
allows to determine the SQL-type for a given column name |
Stub<T> |
getStub(Object id)
returns a Stub representing the resource for the given ID or null. |
String |
getTableName()
provides the name of the table that stores the data for the store |
String |
getTableQuery()
if querying involves something different than just selecting all columns of the table, this method returns the string used to replace the table name in a query. |
void |
insert(T entry)
it is suggested to create the entry with an ID obtained through generateNewID() before passing it into
this method. |
Object |
insertAsNew(T entry)
inserts the given entry using an ID generated by generateNewID
while ignoring the ID of the given entry. |
boolean |
isFastDelete()
if set to true, the method deleteResources(Filter |
boolean |
isIgnoreInvalidProperties()
|
boolean |
remove(Processor<T,? extends DatabaseException> processor)
|
JDBCRowStore<T> |
setFastDelete(boolean fastDelete)
allows to set a flag that enables this implementation to directly delete on the JDBC level - if applicable. |
void |
setIgnoreInvalidProperties(boolean ignoreInvalidProperties)
|
int |
size(Filter<? super T> filter)
supports special performance optimization for SQLMapFilter and some other. |
static String |
trimIdString(String idColumn)
allows to strip the table name from the column name for cases where the id column needed to be specified as [table]. |
void |
update(T entry)
updates the given entry in the database. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Database<Connection> database
protected ConnectionHelper helper
protected ObjectRowMapper<T extends DBEntry> mapper
protected boolean ensureTransactionsOnFetch
DBUtils.ensureActive(com.antelmann.db.DBTransaction),
AbstractDatabase.setEnsureTransactions(boolean)| Constructor Detail |
|---|
public JDBCRowStore(Database<Connection> database,
ObjectRowMapper<T> mapper,
Class<T> typeClass)
public JDBCRowStore(Database<Connection> database,
ObjectRowMapper<T> mapper,
Class<T> typeClass,
boolean ignoreInvalidProperties)
public JDBCRowStore(Database<Connection> database,
ObjectRowMapper<T> mapper,
Class<T> typeClass,
boolean ignoreInvalidProperties,
boolean fastDelete)
| Method Detail |
|---|
public Database<Connection> getDatabase()
DBClassStore
getDatabase in interface DBClassStore<T extends DBEntry>public Class<T> getEntryClass()
DBClassStore
getEntryClass in interface DBClassStore<T extends DBEntry>public ObjectRowMapper<T> getMapper()
public String getDisplayColumn()
MappingInfo
getDisplayColumn in interface MappingInfopublic String getIDColumn()
MappingInfo
getIDColumn in interface MappingInfopublic String getTableName()
MappingInfo
getTableName in interface MappingInfoMappingInfo.getTableQuery()public String getTableQuery()
MappingInfoMappingInfo.getTableName() is used in all cases.
If non-null, this variable would have a value like '(select a.field1, b.* from a, b where a.id=b.id) as t1'.
getTableQuery in interface MappingInfoMappingInfo.getTableName()public String getMappingForTopic(Object topic)
MappingInfo
getMappingForTopic in interface MappingInfopublic String[] getColumnsForTopic(Object topic)
MappingInfo
getColumnsForTopic in interface MappingInfopublic String[] getColumnNames()
MappingInfo
getColumnNames in interface MappingInfoMappingInfo.getTableName(),
MappingInfo.getTableQuery(),
MappingInfo.getIDColumn(),
MappingInfo.getDisplayColumn()public String getDisplayNameForColumn(String column)
MappingInfo
getDisplayNameForColumn in interface MappingInfo
public int getSQLTypeforColumn(String column)
throws IllegalArgumentException
MappingInfo
getSQLTypeforColumn in interface MappingInfoIllegalArgumentException - if the given column is not knownTypes
public int getColumnSize(String column)
throws IllegalArgumentException
MappingInfo
getColumnSize in interface MappingInfoIllegalArgumentException - if the given column is not known
public boolean containsID(Object id)
throws DatabaseException
DBClassStore
containsID in interface DBClassStore<T extends DBEntry>DatabaseExceptionpublic boolean isFastDelete()
deleteEntries(Filter) will call deleteEntry(Object) for every affected row.
setFastDelete(boolean),
ObjectRowMapper.verifyBeforeDelete(Object)public JDBCRowStore<T> setFastDelete(boolean fastDelete)
deleteEntries(Filter)
when set to true, it can also be dangerous if a mapper relies on ObjectRowMapper.verifyBeforeDelete(Object)
or a subclass overrides deleteEntry(Object);
therefore, use this option with thought and caution!
isFastDelete()public boolean isIgnoreInvalidProperties()
public void setIgnoreInvalidProperties(boolean ignoreInvalidProperties)
public boolean deleteEntry(Object id)
throws DatabaseException
DBClassStore
deleteEntry in interface DBClassStore<T extends DBEntry>DatabaseException
public int deleteEntries(Filter<? super T> filter)
throws DatabaseException
deleteEntries in interface DBClassStore<T extends DBEntry>DatabaseExceptionSQLDirectQueryEntryFilter,
PreparedStatementEntryFilter,
SQLMapFilter,
fastDelete
public void insert(T entry)
throws DatabaseException
DBClassStoregenerateNewID() before passing it into
this method.
The ID of the entry must not already exist in the database.
insert in interface DBClassStore<T extends DBEntry>DatabaseExceptionDBClassStore.generateNewID()
public Object insertAsNew(T entry)
throws DatabaseException,
UnsupportedOperationException
DBClassStoregenerateNewID
while ignoring the ID of the given entry.
With this method, the same Object (with the same ID) can be inserted
multiple times, stored with a new ID on each call; the ID creation is handled
automatically.
This is an optional feature that might not be implemented in all cases.
insertAsNew in interface DBClassStore<T extends DBEntry>DatabaseException
UnsupportedOperationExceptionDBEntry.getID(),
DBClassStore.generateNewID()
public void update(T entry)
throws DatabaseException
DBClassStore
update in interface DBClassStore<T extends DBEntry>DatabaseException - if the database was not able to perform the update
or it the entry didn't exist in the database before calling this method
public T getEntry(Object id)
throws DatabaseException
DBClassStore
getEntry in interface DBClassStore<T extends DBEntry>id - the ID that is retrieved from Resource.getID()
DatabaseExceptionDBEntry.getID()
public Stub<T> getStub(Object id)
throws DatabaseException
DBClassStore
getStub in interface DBClassStore<T extends DBEntry>DatabaseException
protected void checkTransaction()
throws TransactionException
TransactionException
public DBEnumeration<T> fetch(Filter<? super T> filter)
throws DatabaseException
fetch in interface DBClassStore<T extends DBEntry>filter - may be null, in which case all entries from are returned.
DatabaseExceptionOffsetFilter,
IterationException,
BaseRowMapper.getResultSet(Filter)
public DBEnumeration<Stub<T>> fetchStubs(Filter<? super Stub<?>> filter)
throws DatabaseException
fetchStubs in interface DBClassStore<T extends DBEntry>DatabaseExceptionOffsetFilter,
SQLStubFilter,
SQLDirectQueryEntryFilter,
IterationException
public Object generateNewID()
throws DatabaseException,
UnsupportedOperationException
generateNewID in interface DBClassStore<T extends DBEntry>DatabaseException
UnsupportedOperationExceptionObjectRowMapper.generateNewID()
public int size(Filter<? super T> filter)
throws DatabaseException
size in interface DBClassStore<T extends DBEntry>filter - if non-null, only those elements will be counted that are applicable to the filter
DatabaseExceptionpublic void add(Processor<T,? extends DatabaseException> processor)
add in interface ProcessorHook<T extends DBEntry,DatabaseException>public boolean remove(Processor<T,? extends DatabaseException> processor)
remove in interface ProcessorHook<T extends DBEntry,DatabaseException>public static String trimIdString(String idColumn)
MappingInfo.getTableQuery()
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||