| java.util.HashMap de.danet.an.util.persistentmaps.JDBCPersistentMap
All known Subclasses: de.danet.an.workflow.ejbs.core.ProcessDataStore,
JDBCPersistentMap | public class JDBCPersistentMap extends HashMap implements PersistentMap,Serializable(Code) | | This class provides an implementation of
de.danet.an.util.PersistentMap PersistentMap that
uses JDBC to implement the persistence.
The class uses an abstract SQL table model. The table consists of
a column for the map id, the entry key and two value
entries.
All columns except the second value entry are of type string,
with lengths as appropriate for the
application. The second value field is of type BLOB (binary large
object) and is used if either the value to be stored is not
of type
java.lang.String String or longer
than a given limit.
The map id enables storing of several
jdbc persistent maps in a single table. It is passed as paramter
to all constructors of this class. Only a single instance for a
map id may be created as creating two instances may
corrupt caching.
The SQL statements used to retrieve and save data are configurable.
Thus any table or view may be used as a base for a jdbc persistent map.
Note that this implementation is not synchronized. If multiple
threads access this map concurrently, and at least one of the threads
modifies the map structurally, it must be synchronized externally.
(A structural modification is any operation that adds or deletes one or more
mappings; merely changing the value associated with a key that an instance
already contains is not a structural modification.) This is typically
accomplished by synchronizing on some object that naturally encapsulates the
map.
This can be done at creation time, to prevent accidental unsynchronized
access to the map:
JDBCPersistentMap pm = new JDBCPersistentMap(...);
Map m = Collections.synchronizedMap(pm);
Since only the methods defined by Map are synchronized by this
mechanism, all supplemented methods (like 'load' or 'store' have to be
synchronized on the map object 'm', created above, e.g.:
synchronized(m) {
pm.load(); // Must be in the synchronized block
}
The class is serializable. Note, however, that the database connection
is transient.
|
Method Summary | |
public void | clear() Removes all mappings from this map. | public Connection | getConnection() Returns the database connection set by
JDBCPersistentMap.setConnection setConnection . | public String | getDeleteAllStatement() Returns the SQL statement used to delete all entries for this
map in the database table. | public String | getDeleteStatement() Returns the SQL statement used to delete an entry for this
map in the database table. | public String | getInsertStatement() Returns the SQL statement used to insert an entry for this
map into the database table. | public String | getLoadStatement() Returns the SQL statement used to retrieve all entries for this
map from the database table. | public Object | getMapId() Returns the map id of this map. | public int | getSValueMax() Returns the maximum length for string value in the SVALUE
column of the database table. | public String | getUpdateStatement() Returns the SQL statement used to update an entry for this
map in the database table. | public boolean | isModified() Indicates whether modifications need to be saved currently. | protected boolean | isSValue(String value) Verify if the string will be stored as string, not as object. | public void | load() Loads the map from persistent store. | public int | maxKeyLength() Retrieves the information about the maximum string length of key
entries. | public Object | put(Object key, Object value) Associates the specified value with the specified key in this map.
The key has to have a non-null value.
If the map previously contained a mapping for this key, the old value
is replaced.
This implementation ensures consistency between the map and the
persistent store.
Parameters: key - key with which the specified value is to be associated. Parameters: value - value to be associated with the specified key. | public void | putAll(Map t) Copies all of the mappings from the specified map to this map. | public Object | remove(Object key) Removes the mapping for this key from this map if present.
This implementation ensures consistency between the map and the
persistent store.
Parameters: key - key with which the specified value is to be associated. | public void | setConnection(Connection con) Sets the database connection used in
JDBCPersistentMap.load load and
JDBCPersistentMap.store store . | public void | setDataSource(DataSource dataSource) Set the data source for this map. | public void | setDeleteAllStatement(String statement) Sets the SQL statement used to delete all entries for this map
in the database table. | public void | setDeleteStatement(String statement) Sets the SQL statement used to delete an entry for this map
in the database table. | public void | setInsertStatement(String statement) Sets the SQL statement used to insert an entry for this map
in the database table. | public void | setLoadStatement(String statement) Sets the SQL statement used to retrieve all entries for this map
from the database table. | public void | setMapId(String mapId) Sets the map id for this map. | public void | setMapId(Long mapId) Sets the map id for this map. | public void | setNewMap() May be called after constructor or setMapId and
before the first call to store() to indicate that
the map is newly created. | public void | setSValueMax(int limit) Sets the maximum length for string value in the
SVALUE column of the database table. | public void | setUpdateStatement(String statement) Sets the SQL statement used to update an entry for this map in
the database table. | public void | store() Stores the map in persistent store. |
JDBCPersistentMap | public JDBCPersistentMap(DataSource dataSource, String mapId) throws SQLException(Code) | | Returns a new JDBC persistent map. The map is formed by all entries
in the underlying table with the given map id. The
table used by the default SQL statements is
DEFAULTPERSISTENCEMAP .
Parameters: dataSource - the data source that will be used to obtainconnections. Parameters: mapId - the map id. throws: SQLException - if a database related error occurs |
JDBCPersistentMap | public JDBCPersistentMap(DataSource dataSource, Long mapId) throws SQLException(Code) | | Returns a new JDBC persistent map. The map is formed by all entries
in the underlying table with the given map id. The
table used by the default SQL statements is
DEFAULTPERSISTENCEMAP .
Parameters: dataSource - the data source that will be used to obtainconnections. Parameters: mapId - the map id. throws: SQLException - if a database related error occurs |
JDBCPersistentMap | public JDBCPersistentMap(DataSource dataSource, String mapId, String dbtable) throws SQLException(Code) | | Returns a new JDBC persistent map. The map is formed by all entries
in the underlying table with the given persistence group.
Parameters: dataSource - the data source that will be used to obtainconnections. Parameters: mapId - the map id. Parameters: dbtable - the table used in the default SQL statements. throws: SQLException - if a database related error occurs |
JDBCPersistentMap | public JDBCPersistentMap(DataSource dataSource, Long mapId, String dbtable) throws SQLException(Code) | | Returns a new JDBC persistent map. The map is formed by all entries
in the underlying table with the given persistence group.
Parameters: dataSource - the data source that will be used to obtainconnections. Parameters: mapId - the map id. Parameters: dbtable - the table used in the default SQL statements. throws: SQLException - if a database related error occurs |
clear | public void clear()(Code) | | Removes all mappings from this map.
This implementation ensures consistency between the map and the
persistent store.
|
getSValueMax | public int getSValueMax()(Code) | | Returns the maximum length for string value in the SVALUE
column of the database table.
the current maximum length See Also: JDBCPersistentMap.setSValueMax |
isModified | public boolean isModified()(Code) | | Indicates whether modifications need to be saved currently.
true, if there are non-saved modifications, otherwise false. |
isSValue | protected boolean isSValue(String value)(Code) | | Verify if the string will be stored as string, not as object.
Parameters: value - the string true if the string will be stored as "svalue" |
load | public void load() throws IOException(Code) | | Loads the map from persistent store.
The map is cleared before loading.
throws: IOException - problems while loading the map |
maxKeyLength | public int maxKeyLength() throws IOException(Code) | | Retrieves the information about the maximum string length of key
entries.
the maximum string length of key entries throws: IOException - problems while storing the map |
put | public Object put(Object key, Object value)(Code) | | Associates the specified value with the specified key in this map.
The key has to have a non-null value.
If the map previously contained a mapping for this key, the old value
is replaced.
This implementation ensures consistency between the map and the
persistent store.
Parameters: key - key with which the specified value is to be associated. Parameters: value - value to be associated with the specified key. previous value associated with specified key, or null if there was no mapping for key. |
putAll | public void putAll(Map t)(Code) | | Copies all of the mappings from the specified map to this map.
These mappings will replace any mappings that this map had for any of
the keys currently in the specified map.
This implementation ensures consistency between the map and the
persistent store.
Parameters: t - Mappings to be stored in this map. |
remove | public Object remove(Object key)(Code) | | Removes the mapping for this key from this map if present.
This implementation ensures consistency between the map and the
persistent store.
Parameters: key - key with which the specified value is to be associated. previous value associated with specified key, or null if there was no mapping for key. |
setDataSource | public void setDataSource(DataSource dataSource) throws SQLException(Code) | | Set the data source for this map. This must be called after
deserialization. Calling this method resets the connection and
must therefore be followed by a call to
JDBCPersistentMap.setConnectionsetConnection .
Parameters: dataSource - the data source that will be used to obtainconnections. throws: SQLException - if a database related error occurs |
setDeleteAllStatement | public void setDeleteAllStatement(String statement)(Code) | | Sets the SQL statement used to delete all entries for this map
in the database table. The default is
DELETE FROM table WHERE MAPID=?
where table defaults to
DEFAULTPERSISTENCEMAP and can be set by calling the
JDBCPersistentMap.JDBCPersistentMap(String,String) extended constructor .
NOTE: The statement must declare semantically corresponding
columns for all the restriction values described in the example
above!
Parameters: statement - the delete statement. See Also: JDBCPersistentMap.getDeleteAllStatement |
setDeleteStatement | public void setDeleteStatement(String statement)(Code) | | Sets the SQL statement used to delete an entry for this map
in the database table. The default is
DELETE FROM table WHERE MAPID=? AND ITEM=?
where table defaults to
DEFAULTPERSISTENCEMAP and can be set by calling the
JDBCPersistentMap.JDBCPersistentMap(String,String) extended constructor .
NOTE: The statement must declare semantically corresponding
columns for all the restriction values described in the example
above!
Parameters: statement - the delete statement. See Also: JDBCPersistentMap.getDeleteStatement |
setInsertStatement | public void setInsertStatement(String statement)(Code) | | Sets the SQL statement used to insert an entry for this map
in the database table. The default is
INSERT INTO table (MAPID, ITEM, SVALUE, BVALUE)
VALUES (?, ?, ?, ?)
where table defaults to
DEFAULTPERSISTENCEMAP and can be set by calling the
JDBCPersistentMap.JDBCPersistentMap(String,String) extended constructor .
NOTE: The statement must declare semantically corresponding
columns for all the values described in the example above!
Parameters: statement - the insert statement. See Also: JDBCPersistentMap.getInsertStatement |
setLoadStatement | public void setLoadStatement(String statement)(Code) | | Sets the SQL statement used to retrieve all entries for this map
from the database table. The default is
SELECT ITEM, SVALUE, BVALUE FROM table WHERE MAPID = ?
where table defaults to
DEFAULTPERSISTENCEMAP and can be set by calling the
JDBCPersistentMap.JDBCPersistentMap(String,String) extended constructor .
NOTE: The statement must declare semantically corresponding
columns for all the selection and restriction values described in
the example above!
Parameters: statement - the load statement. See Also: JDBCPersistentMap.getLoadStatement |
setMapId | public void setMapId(String mapId)(Code) | | Sets the map id for this map. Clears the cached modifications
as a side effect if the map id differs from the current map id.
Parameters: mapId - the new map id. See Also: JDBCPersistentMap.getMapId |
setMapId | public void setMapId(Long mapId)(Code) | | Sets the map id for this map. Clears the cached modifications
as a side effect if the map id differs from the current map id.
Parameters: mapId - the new map id. See Also: JDBCPersistentMap.getMapId |
setNewMap | public void setNewMap()(Code) | | May be called after constructor or setMapId and
before the first call to store() to indicate that
the map is newly created. This allows the persistent map
implementation to optimize the storage bahaviour.
|
setSValueMax | public void setSValueMax(int limit)(Code) | | Sets the maximum length for string value in the
SVALUE column of the database table. The default
is 256 . If the given length value is greater than
the column length in the database scheme (a DB connection that
supports column information assumed), the length value is restricted
to the DB column length.
Parameters: limit - the maximum length for values in the SVALUE column. See Also: JDBCPersistentMap.getSValueMax |
setUpdateStatement | public void setUpdateStatement(String statement)(Code) | | Sets the SQL statement used to update an entry for this map in
the database table. The default is UPDATE table SET
SVALUE = ?, BVALUE = ? WHERE MAPID=? AND ITEM=? where
table defaults to
DEFAULTPERSISTENCEMAP and can be set by calling
the
JDBCPersistentMap.JDBCPersistentMap(String,String) extendedconstructor . NOTE: The statement must declare
semantically corresponding columns for all the data and
restriction values described in the example above! The names of
the key columns in the restriction phrase have to be in the
same order as above (first: map-ident, second: item-ident)
Parameters: statement - the update statement. See Also: JDBCPersistentMap.getUpdateStatement |
store | public void store() throws IOException(Code) | | Stores the map in persistent store.
If the set has not been loaded before, all entries with the current
map id are deleted from the persistent store first.
Only modified (new, changed, deleted) map entries are changed in the
peristent store.
throws: IOException - problems while storing the map |
|
|