org.placelab.mapper
Class JDBCMapper

java.lang.Object
  extended byorg.placelab.mapper.AbstractMapper
      extended byorg.placelab.mapper.JDBCMapper
All Implemented Interfaces:
Mapper
Direct Known Subclasses:
HsqlMapper

public class JDBCMapper
extends AbstractMapper

A Mapper that uses a JDBC database to store Beacons. The default db location is specified by the system property "placelab.jdbc_url".


Field Summary
protected  boolean bulkPuts
           
protected  java.sql.Connection connection
           
protected  int putCount
           
static java.lang.String TABLE_NAME
           
protected  java.lang.String url
           
 
Fields inherited from class org.placelab.mapper.AbstractMapper
UNKNOWN_BEACON_CLASS
 
Constructor Summary
JDBCMapper(java.lang.String url, java.lang.String driver, boolean shouldCache)
          Create a new JDBCMapper for the given database.
 
Method Summary
 boolean close()
          Closes the Mapper.
 boolean deleteAll()
          Deletes all Beacon records in the Mapper.
 void endBulkPuts()
           
protected  boolean executePutBeacon(java.lang.String id, java.lang.String type, java.lang.String lat, java.lang.String lon, java.lang.String storageStr)
           
protected  java.util.Vector findBeaconsImpl(java.lang.String id)
           
 boolean isOpened()
           
 boolean open()
          Opens the Mapper.
 boolean open(boolean createTable)
           
 boolean overrideOnPut()
           
protected  boolean putBeaconsImpl(java.lang.String id, java.util.Vector beacons)
           
 java.util.Enumeration query(Coordinate c1, Coordinate c2)
          c1 and c2 define opposing corners of a rectangular area in which you wish to get an Iterator over all Beacons in that area.
 void startBulkPuts()
          Signals to the Mapper that it is about to be loaded in bulk.
 
Methods inherited from class org.placelab.mapper.AbstractMapper
addBeaconClass, addBeaconClass, createBeacon, findBeacon, findBeacons, getBeaconsFromStorageString, putBeacon, putBeacons
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

url

protected java.lang.String url

connection

protected java.sql.Connection connection

bulkPuts

protected boolean bulkPuts

putCount

protected int putCount

TABLE_NAME

public static final java.lang.String TABLE_NAME
See Also:
Constant Field Values
Constructor Detail

JDBCMapper

public JDBCMapper(java.lang.String url,
                  java.lang.String driver,
                  boolean shouldCache)
           throws java.lang.ClassNotFoundException,
                  java.sql.SQLException
Create a new JDBCMapper for the given database. It will create a table to store the Beacons in if it doesn't already exist, and will open a connection to the database at that time.

Parameters:
url - the jdbc:url url for the database, including username and password
driver - the jdbc driver class to use (see your database docs)
shouldCache - whether or not to cache access Beacons in memory
Throws:
java.lang.ClassNotFoundException - if your jdbc driver couldn't be found
java.sql.SQLException - if the database was angry about something
Method Detail

findBeaconsImpl

protected java.util.Vector findBeaconsImpl(java.lang.String id)
Specified by:
findBeaconsImpl in class AbstractMapper

putBeaconsImpl

protected boolean putBeaconsImpl(java.lang.String id,
                                 java.util.Vector beacons)
Specified by:
putBeaconsImpl in class AbstractMapper

executePutBeacon

protected boolean executePutBeacon(java.lang.String id,
                                   java.lang.String type,
                                   java.lang.String lat,
                                   java.lang.String lon,
                                   java.lang.String storageStr)

open

public boolean open(boolean createTable)
             throws java.sql.SQLException
Throws:
java.sql.SQLException

query

public java.util.Enumeration query(Coordinate c1,
                                   Coordinate c2)
Description copied from interface: Mapper
c1 and c2 define opposing corners of a rectangular area in which you wish to get an Iterator over all Beacons in that area.

Specified by:
query in interface Mapper
Specified by:
query in class AbstractMapper

open

public boolean open()
Description copied from interface: Mapper
Opens the Mapper. You must call this method before querying the mapper.

Returns:
whether or not the Mapper was successfully opened.

close

public boolean close()
Description copied from interface: Mapper
Closes the Mapper. Closed Mappers can no longer be queried.

Returns:
whether or not the Mapper was successfully closed.

deleteAll

public boolean deleteAll()
Description copied from interface: Mapper
Deletes all Beacon records in the Mapper. This is typically used by MapLoaders prior to reloading the Mapper with data.

Returns:
whether or not the Mapper was successfully emptied.

isOpened

public boolean isOpened()

startBulkPuts

public void startBulkPuts()
Description copied from interface: Mapper
Signals to the Mapper that it is about to be loaded in bulk. Some implementations can use this to lock their underlying database and speed up loading. You should not query the Mapper while using bulk loading.

See Also:
Mapper.endBulkPuts()

endBulkPuts

public void endBulkPuts()

overrideOnPut

public boolean overrideOnPut()
Specified by:
overrideOnPut in interface Mapper
Overrides:
overrideOnPut in class AbstractMapper