|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.fosstrak.llrp.client.repository.sql.AbstractSQLRepository
public abstract class AbstractSQLRepository
The AbstractSQLRepository
represents a common super class for all
SQL based Repositories. The class implements the different methods like
put(LLRPMessageItem)
or get(String)
in an
abstract manner, using the strategy pattern. We explain the idea below:
Two examples:
Statement sCreateTable = conn.createStatement();
sCreateTable.execute(sqlCreateTable());
sCreateTable.close();
AbstractSQLRepository
runs on a prepared
statement (in this case a normal SQL statement would do as well), but this
statement is not hard-coded. The create SQL is obtained via the method
sqlCreateTable()
. Depending on the implementing data base,
different SQL statements for the create instruction can be used. Example: a
derby implementation DerbyRepository
uses a different create SQL
than a MySQLRepository
(as the data types differ).
PreparedStatement psRemove = conn.prepareStatement(
sqlRemoveAllAdapterMessages());
psRemove.setString(1, adapter);
psRemove.executeUpdate();
psRemove.close();
AbstractSQLRepository
executes a prepared statement. The
name of the adapter to be cleared, is injected from the code in the
AbstractSQLRepository
. Again, the actual query is delivered from the
implementing strategy (example: MySQLRepository
).
AbstractSQLRepository
uses the SQL commands tailored
to the Derby database (as this is the default internal database). So, if
you do not override certain SQL "queries-getter", please be aware that this
might cause trouble with a database differing from Derby.
Field Summary | |
---|---|
protected java.util.Map<java.lang.String,java.lang.String> |
args
map with additional arguments to be passed to the initializer. |
protected java.sql.Connection |
conn
the JDBC connection. |
protected java.lang.String |
connectURL
the connection URL. |
static java.lang.String |
DB_DRIVER
the database driver to use. |
static java.lang.String |
DB_NAME
the name of the database in the database server. |
protected boolean |
isHealth
whether the repository is healthy or not. |
protected boolean |
logROAccess
whether to log RO_ACCESS_REPORT. |
protected static int |
NUM_TABLE_COLUMNS
the number of table columns. |
protected java.lang.String |
password
the database password. |
static int |
SELECTOR_ADAPTOR
column index of the adapter name. |
static int |
SELECTOR_COMMENT
column index of the comment field. |
static int |
SELECTOR_CONTENT
column index of the comment column. |
static int |
SELECTOR_ID
column index of the ID. |
static int |
SELECTOR_MARK
column index of the mark. |
static int |
SELECTOR_MESSAGE_TYPE
column index of the message type. |
static int |
SELECTOR_READER
column index of the reader name. |
static int |
SELECTOR_STATUS
column index of the status flag. |
static int |
SELECTOR_TIMESTAMP
column index of the time-stamp column. |
static java.lang.String |
TABLE_LLRP_REPOSITORY
the name of the LLRP message repository table. |
protected java.lang.String |
username
the database user name. |
protected boolean |
wipe
whether to wipe the database at startup or not. |
protected boolean |
wipeROAccess
whether to wipe the RO_ACCESS_REPORTS database at startup or not. |
Fields inherited from interface org.fosstrak.llrp.client.Repository |
---|
RETRIEVE_ALL |
Constructor Summary | |
---|---|
AbstractSQLRepository()
|
Method Summary | |
---|---|
void |
clearAdapter(java.lang.String adapter)
clear the repository from entries to a given adapter. |
void |
clearAll()
remove all the messages from the repository. |
void |
clearReader(java.lang.String adapter,
java.lang.String reader)
clear the repository from entries to a given adapter and a given reader. |
void |
close()
Close the database connection. |
int |
count(java.lang.String adaptor,
java.lang.String reader)
the method computes the number of messages stored in the repository depending on the input parameters: (adaptor == null) then compute all messages in the repository. |
protected void |
createTable()
generates the necessary tables. |
protected void |
dropTable()
drops the table. |
protected boolean |
existsTable()
checks whether the required tables exist or not. |
LLRPMessageItem |
get(java.lang.String aMsgSysId)
Get the LLRP Message Item from repository according to the unique Message ID. |
java.util.ArrayList<LLRPMessageItem> |
get(java.lang.String adaptorName,
java.lang.String readerName,
int num,
boolean content)
returns all the messages from the specified adaptor and the reader limited by num. if you set num to RETRIEVE_ALL all messages get returned. |
java.util.Map<java.lang.String,java.lang.String> |
getArgs()
|
java.sql.Connection |
getDBConnection()
|
protected java.lang.String |
getDBDriver()
Returns the class name of the JDBC driver to be used. |
void |
initialize(java.util.Map<java.lang.String,java.lang.String> args)
Initializer method for the repository. |
boolean |
isHealth()
|
protected boolean |
loadDriver()
Loads the appropriate JDBC driver for this environment/framework. |
protected abstract java.sql.Connection |
openConnection()
Opens the JDBC connection to the database. |
void |
put(LLRPMessageItem aMessage)
store an LLRP message into the repository. |
protected java.lang.String |
sqlCreateTable()
NOTICE: this SQL command corresponds to derby SQL!. |
protected java.lang.String |
sqlDropTable()
NOTICE: this SQL command corresponds to derby SQL!. |
protected java.lang.String |
sqlInsertMessage()
NOTICE: this SQL command corresponds to derby SQL!. |
protected java.lang.String |
sqlRemoveAllAdapterMessages()
NOTICE: this SQL command corresponds to derby SQL!. |
protected java.lang.String |
sqlRemoveAllMessages()
NOTICE: this SQL command corresponds to derby SQL!. |
protected java.lang.String |
sqlRemoveAllReaderMessages()
NOTICE: this SQL command corresponds to derby SQL!. |
protected java.lang.String |
sqlSelectByAdapterAndReaderWithContent()
NOTICE: this SQL command corresponds to derby SQL!. |
protected java.lang.String |
sqlSelectByAdapterAndReaderWithoutContent()
NOTICE: this SQL command corresponds to derby SQL!. |
protected java.lang.String |
sqlSelectByAdapterWithContent()
NOTICE: this SQL command corresponds to derby SQL!. |
protected java.lang.String |
sqlSelectByAdapterWithoutContent()
NOTICE: this SQL command corresponds to derby SQL!. |
protected java.lang.String |
sqlSelectMessageByID()
NOTICE: this SQL command corresponds to derby SQL!. |
protected java.lang.String |
sqlSelectMessagesWithContent()
NOTICE: this SQL command corresponds to derby SQL!. |
protected java.lang.String |
sqlSelectMessagesWithoutContent()
NOTICE: this SQL command corresponds to derby SQL!. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.fosstrak.llrp.client.Repository |
---|
getROAccessRepository |
Field Detail |
---|
public static final int SELECTOR_ID
public static final int SELECTOR_MESSAGE_TYPE
public static final int SELECTOR_READER
public static final int SELECTOR_ADAPTOR
public static final int SELECTOR_TIMESTAMP
public static final int SELECTOR_STATUS
public static final int SELECTOR_COMMENT
public static final int SELECTOR_MARK
public static final int SELECTOR_CONTENT
public static final java.lang.String DB_NAME
public static final java.lang.String TABLE_LLRP_REPOSITORY
protected boolean isHealth
protected static final int NUM_TABLE_COLUMNS
protected java.sql.Connection conn
public static final java.lang.String DB_DRIVER
protected java.lang.String username
protected java.lang.String password
protected java.lang.String connectURL
protected boolean wipe
protected boolean wipeROAccess
protected boolean logROAccess
protected java.util.Map<java.lang.String,java.lang.String> args
Constructor Detail |
---|
public AbstractSQLRepository()
Method Detail |
---|
protected java.lang.String sqlCreateTable()
protected java.lang.String sqlRemoveAllMessages()
protected java.lang.String sqlDropTable()
protected java.lang.String sqlRemoveAllAdapterMessages()
protected java.lang.String sqlRemoveAllReaderMessages()
protected java.lang.String sqlInsertMessage()
protected java.lang.String sqlSelectMessageByID()
protected java.lang.String sqlSelectMessagesWithContent()
protected java.lang.String sqlSelectMessagesWithoutContent()
protected java.lang.String sqlSelectByAdapterWithContent()
protected java.lang.String sqlSelectByAdapterWithoutContent()
protected java.lang.String sqlSelectByAdapterAndReaderWithContent()
protected java.lang.String sqlSelectByAdapterAndReaderWithoutContent()
protected boolean loadDriver()
protected java.lang.String getDBDriver()
protected abstract java.sql.Connection openConnection() throws java.lang.Exception
java.lang.Exception
- whenever the connection could not be established.public void initialize(java.util.Map<java.lang.String,java.lang.String> args) throws LLRPRuntimeException
Repository
initialize
in interface Repository
args
- hash-map with the parameters.
LLRPRuntimeException
public java.util.Map<java.lang.String,java.lang.String> getArgs()
getArgs
in interface Repository
protected boolean existsTable()
protected void dropTable()
protected void createTable()
public void put(LLRPMessageItem aMessage)
put
in interface Repository
aMessage
- the message to be stored.public void clearAll()
clearAll
in interface Repository
public boolean isHealth()
isHealth
in interface Repository
public int count(java.lang.String adaptor, java.lang.String reader)
count
in interface Repository
adaptor
- the name of the adapter.reader
- the name of the reader.
public void clearAdapter(java.lang.String adapter)
clearAdapter
in interface Repository
adapter
- the name of the adapter to clean out.public void clearReader(java.lang.String adapter, java.lang.String reader)
clearReader
in interface Repository
adapter
- the name of the adapter.reader
- the name of the reader.public void close()
close
in interface Repository
public java.util.ArrayList<LLRPMessageItem> get(java.lang.String adaptorName, java.lang.String readerName, int num, boolean content)
get
in interface Repository
adaptorName
- the name of the adaptor.readerName
- the name of the reader.num
- how many messages to retrieve.content
- if true retrieve the message content, false no content.
public LLRPMessageItem get(java.lang.String aMsgSysId)
Repository
get
in interface Repository
aMsgSysId
- the message id of the item to be retrieved.
public java.sql.Connection getDBConnection()
getDBConnection
in interface Repository
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |