util
Class PersistentMap
java.lang.Object
|
+--java.util.AbstractMap
|
+--util.PersistentMap
- public class PersistentMap
- extends AbstractMap
A persistent hashtable (Map), which in this case maps to a SQL database.
This is based on AbstractMap, and for the most part is using
AbstractMap's methods for doing lookups. This means that hash
access is probably unbelievably slow, so using this for
speed-critical code will probably not make you happy.
Developer's Note: This is probably more correct anyway, since for
lookups we want to compare every item in the hashtable against the
test object using the equals() method in order to be sure we've got
the right thing.
Methods inherited from class java.util.AbstractMap |
clear,
containsKey,
containsValue,
equals,
get,
hashCode,
isEmpty,
keySet,
putAll,
remove,
size,
toString,
values |
tableName
protected String tableName
PersistentMap
public PersistentMap(String tabname,
Connection cnxn)
- Creates a new persistent map file. Takes a designation and a
database connection to create the table on the back-end. If the
table already exists, the class will assume that it holds old
data. If the existing table is of the wrong format, expect a
large number of exceptions.
- Parameters:
tabname
- The name of the map. This is used to create a
database table (any non-alphanumeric characters will be changed
to underscores so that SQL doesn't choke on it).cnxn
- The database connection url. See the java.sql
Connection class for more information.
PersistentMap
public PersistentMap(AgentID aid,
String tabname,
Connection cnxn)
- This constructor works like the regular one except that it
creates a table name specific to the agent instance. Takes into
account all parts of the agentID: society, occupation and
designation.
- Parameters:
aid
- an AgentID
valuetabname
- a String
valuecnxn
- a Connection
value
entrySet
public Set entrySet()
- Get all map entries as a set. Users of this class can use the
set's iterator to get all the entry information, or can use
AbstractMap's access methods to make their lives easier.
- Overrides:
- entrySet in class AbstractMap
put
public Object put(Object k,
Object v)
- Put a new value into the database. As of this version, this
doesn't look up the old value, and just returns null, so
applications that are dependent on the old value should probably
do a get() beforehand.
- Overrides:
- put in class AbstractMap
destroy
public void destroy()
- Destroy the underlying table. This method should probably be
rarely (if ever) called, since it gets rid of the very thing that
makes this persistent data. If any other methods are called
after this one, they will probably spew exceptions to the
standard error stream.
execSQL
protected int execSQL(String s)
execSQL
protected int execSQL(String s,
boolean loud)
querySQL
protected ResultSet querySQL(String s)
- Helper function to execute queries with automatic reconnection.
querySQL
protected ResultSet querySQL(String s,
boolean loud)
main
public static void main(String[] args)