|
xmlBlaster 2.2.0 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xmlBlaster.util.queue.jdbc.CommonTableDatabaseAccessor
public class CommonTableDatabaseAccessor
Delegate class which takes care of SQL specific stuff for the JdbcQueuePlugin class.
One instance of this is created by Global for each StorageId prefix, so one instance for 'history', one for 'cb' etc.
The tables needed for each JdbcManagerCommonTable instance are the following:
Field Summary | |
---|---|
(package private) static int |
BLOB
|
private java.lang.String |
blobTxt
|
private java.lang.String |
blobVarName
|
private java.lang.String |
booleanTxt
|
private java.lang.String |
byteSizeColName
|
private java.lang.String |
colNamePrefix
|
private int |
countDumps
|
private short |
countTest
|
(package private) static int |
DATA_ID
Column index into XB_ENTRIES table |
private java.lang.String |
dataIdColName
|
private static java.lang.String |
DUMMY_VALUE
|
private boolean |
enableBatchMode
forces the desactivation of batch mode when adding entries |
private java.lang.String |
entriesTableName
|
private I_EntryFactory |
factory
|
private static boolean |
first
|
private Global |
glob
|
private java.lang.String |
intTxt
|
private boolean |
isConnected
|
private boolean |
isDB2
|
private boolean |
isFirebird
|
private boolean |
isHSQLDatabaseEngine
|
private boolean |
isLdbc
|
private boolean |
isMicrosoftSQLServer
|
private boolean |
isMySql
|
private boolean |
isOracle
|
private boolean |
isPostgres
|
private boolean |
isSQLite
|
private java.lang.String |
keyAttr
|
private java.util.WeakHashMap |
listener
|
private static java.util.logging.Logger |
log
|
private java.lang.String |
longintTxt
|
private int |
maxNumStatements
|
private int |
maxSelectLimit
|
private int |
maxStatementLength
|
private static java.lang.String |
ME
|
(package private) static int |
PERSISTENT
|
private java.sql.PreparedStatement |
pingPrepared
|
private JdbcConnectionPool |
pool
|
(package private) static int |
PRIO
|
(package private) static int |
QUEUE_NAME
|
private int |
queueCounter
Counts the queues using this manager. |
(package private) static int |
SIZE_IN_BYTES
|
private I_Storage |
storage
|
private java.lang.String |
stringTxt
|
private boolean |
supportsBatch
tells wether the used database supports batch updates or not. |
private java.lang.String |
tableNamePrefix
|
private boolean |
testException
|
(package private) static int |
TYPE_NAME
|
Fields inherited from interface org.xmlBlaster.util.queue.I_StorageProblemListener |
---|
AVAILABLE, UNAVAILABLE, UNDEF |
Constructor Summary | |
---|---|
CommonTableDatabaseAccessor(JdbcConnectionPool pool,
I_EntryFactory factory,
java.lang.String managerName,
I_Storage storage)
|
Method Summary | |
---|---|
int[] |
addEntries(java.lang.String queueName,
I_Entry[] entries)
Adds several rows to the specified queue table in batch mode to improve performance |
private int[] |
addEntriesSingleMode(java.sql.Connection conn,
java.lang.String queueName,
I_Entry[] entries)
|
boolean |
addEntry(java.lang.String queueName,
I_Entry entry)
Adds a row to the specified queue table |
private boolean |
addSingleEntry(java.lang.String queueName,
I_Entry entry,
java.sql.Connection conn)
Adds a row to the specified queue table |
protected boolean |
checkIfDBLoss(java.sql.Connection conn,
java.lang.String location,
java.lang.Throwable ex)
|
protected boolean |
checkIfDBLoss(java.sql.Connection conn,
java.lang.String location,
java.lang.Throwable ex,
java.lang.String trace)
Handles the SQLException. |
int |
cleanUp(java.lang.String queueName)
Cleans up the specified queue. |
static CommonTableDatabaseAccessor |
createInstance(Global glob,
I_EntryFactory factory,
java.lang.String confType,
java.lang.String confVersion,
java.util.Properties properties)
The Properties to use as a default are these from the QueuePlugin with the configuration name specified by defaultConfName (default is 'JDBC'). |
int |
deleteAllTransient(java.lang.String queueName)
deletes all transient messages |
boolean[] |
deleteEntries(java.lang.String queueName,
long[] uniqueIds)
Deletes the entries specified by the entries array. |
private boolean[] |
deleteEntriesNoSplit(java.lang.String queueName,
long[] uniqueIds)
|
int |
deleteEntry(java.lang.String queueName,
long uniqueId)
Deletes the entry specified |
ReturnDataHolder |
deleteFirstEntries(java.lang.String queueName,
long numOfEntries,
long amount)
Deletes number of entries specified by the argument list. |
void |
dumpMetaData()
Dumps the metadata to the log object. |
ReturnDataHolder |
getAndDeleteLowest(StorageId storageId,
int numOfEntries,
long numOfBytes,
int maxPriority,
long minUniqueId,
boolean leaveOne,
boolean doDelete)
Under the same transaction it gets and deletes all the entries which fit into the constrains specified in the argument list. |
java.util.ArrayList |
getEntries(StorageId storageId,
int numOfEntries,
long numOfBytes,
I_EntryFilter entryFilter)
gets the first numOfEntries of the queue. |
java.util.ArrayList |
getEntries(StorageId storageId,
long[] dataids)
gets all the entries which have the dataid specified in the argument list. |
java.util.ArrayList |
getEntriesByPriority(StorageId storageId,
int numOfEntries,
long numOfBytes,
int minPrio,
int maxPrio,
I_EntryFilter entryFilter)
gets the first numOfEntries of the queue which have the priority in the range specified by prioMin and prioMax (inclusive). |
java.util.ArrayList |
getEntriesBySamePriority(StorageId storageId,
int numOfEntries,
long numOfBytes)
gets the first numOfEntries of the queue which have the same priority. |
java.util.ArrayList |
getEntriesLike(java.lang.String queueNamePattern,
java.lang.String flag,
int numOfEntries,
long numOfBytes,
I_EntryFilter entryFilter)
Raw access to the table. |
java.util.ArrayList |
getEntriesWithLimit(StorageId storageId,
I_Entry limitEntry)
gets the first numOfEntries of the queue until the limitEntry is reached. |
private java.lang.String |
getLogId(java.lang.String queueName,
java.lang.String methodName)
|
EntryCount |
getNumOfAll(java.lang.String queueName)
Gets the real number of entries. |
long |
getNumOfBytes(java.lang.String queueName)
Deprecated. Use getNumOfAll(String) |
long |
getNumOfEntries(java.lang.String queueName)
Deprecated. Use getNumOfAll(String) |
long |
getNumOfPersistents(java.lang.String queueName)
Deprecated. Use getNumOfAll(String) |
JdbcConnectionPool |
getPool()
Returns the pool associated to this object. |
long |
getSizeOfPersistents(java.lang.String queueName)
Deprecated. Use getNumOfAll(String)
Replaced all four selects with one:
"select count(*), sum(byteSize), durable from XB_ENTRIES WHERE queueName='history_xmlBlaster_192_168_1_4_3412Hello' GROUP BY durable;" |
I_StorageProblemListener[] |
getStorageProblemListenerArr()
|
private java.util.HashSet |
getXbTableNames(java.sql.Connection conn)
Gets the names of all the tables used by XmlBlaster. |
boolean |
isDB2()
|
boolean |
isFirebird()
|
boolean |
isHSQLDatabaseEngine()
|
private boolean |
isInsideRange(int numEntries,
int maxNumEntries,
long numBytes,
long maxNumBytes)
Helper method to find out if still to retrieve entries in getAndDeleteLowest or not. |
boolean |
isLdbc()
|
boolean |
isMicrosoftSQLServer()
|
boolean |
isMySql()
|
boolean |
isOracle()
|
private boolean |
isPersistent(java.lang.String persistentAsChar)
|
boolean |
isPostgres()
|
boolean |
isSQLite()
|
static void |
main(java.lang.String[] args)
This main method can be used to delete all tables on the db which start with a certain prefix. |
long |
modifyEntry(java.lang.String queueName,
I_Entry entry,
I_Entry oldEntry)
modifies a row in the specified queue table |
boolean |
pingDatabase()
pings with a newly created jdbc connection to check if the DB is up and running. |
private java.util.ArrayList |
processResultSet(java.sql.ResultSet rs,
StorageId storageIdDefault,
int numOfEntries,
long numOfBytes,
boolean onlyId,
I_EntryFilter entryFilter)
|
private ReturnDataHolder |
processResultSetForDeleting(java.sql.ResultSet rs,
int numOfEntries,
long numOfBytes,
java.util.List<java.lang.Long> retL)
It accepts result sets with (long dataId, long size) |
void |
registerQueue(I_Queue queue)
|
boolean |
registerStorageProblemListener(I_StorageProblemListener entry)
Adds (registers) a listener for connection/disconnection events. |
long |
removeEntriesWithLimit(StorageId storageId,
I_Entry limitEntry,
boolean inclusive)
deletes the first numOfEntries of the queue until the limitEntry is reached. |
void |
setUp()
Sets up a table for the queue specified by this queue name. |
void |
shutdown()
|
void |
storageAvailable(int oldStatus)
Invoked by the I_StorageProblemNotifier when the storage becomes available again (for example on a DB when the jdbc connection is broken). |
void |
storageUnavailable(int oldStatus)
Invoked by the I_StorageProblemNotifier when the storage becomes unavailable (for example on a DB when the jdbc connection is broken). |
boolean |
tablesCheckAndSetup(boolean createTables)
Checks if all necessary tables exist. |
void |
unregisterQueue(I_Queue queue)
|
boolean |
unRegisterStorageProblemListener(I_StorageProblemListener entry)
Adds (registers) a listener for connection/disconnection events. |
private int |
update(java.lang.String request)
A generic invocation for a simple update on the database. |
private int |
update(java.lang.String request,
java.sql.Connection conn)
This version makes an update but does no connection management, i.e. |
private java.util.ArrayList |
whereInStatement(java.lang.String reqPrefix,
long[] uniqueIds)
The prefix is the initial part of the SQL update/query. |
int |
wipeOutDB(boolean doSetupNewTables)
Wipes out the entire DB. |
static void |
wipeOutDB(Global glob,
java.lang.String confType,
java.lang.String confVersion,
java.util.Properties properties,
boolean setupNewTables)
wipes out the db. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String ME
private final Global glob
private static java.util.logging.Logger log
private final JdbcConnectionPool pool
private final I_EntryFactory factory
private final java.util.WeakHashMap listener
private static final java.lang.String DUMMY_VALUE
private final java.lang.String tableNamePrefix
private final java.lang.String colNamePrefix
private java.lang.String stringTxt
private java.lang.String longintTxt
private java.lang.String intTxt
private java.lang.String blobTxt
private java.lang.String booleanTxt
private int maxStatementLength
private boolean isConnected
private static boolean first
private java.lang.String entriesTableName
private java.lang.String blobVarName
private java.lang.String byteSizeColName
private java.lang.String dataIdColName
private java.lang.String keyAttr
private boolean isPostgres
private boolean isOracle
private boolean isDB2
private boolean isFirebird
private boolean isMicrosoftSQLServer
private boolean isHSQLDatabaseEngine
private boolean isMySql
private boolean isLdbc
private boolean isSQLite
private final I_Storage storage
private java.sql.PreparedStatement pingPrepared
private int queueCounter
private boolean supportsBatch
private boolean enableBatchMode
static final int DATA_ID
static final int QUEUE_NAME
static final int PRIO
static final int TYPE_NAME
static final int PERSISTENT
static final int SIZE_IN_BYTES
static final int BLOB
private int maxNumStatements
private int maxSelectLimit
private final boolean testException
private volatile short countTest
private int countDumps
Constructor Detail |
---|
public CommonTableDatabaseAccessor(JdbcConnectionPool pool, I_EntryFactory factory, java.lang.String managerName, I_Storage storage) throws XmlBlasterException
storage
- TODOJdbcConnectionPool
- the pool to be used for the connections to
the database. IMPORTANT: The pool must have been previously
initialized.
XmlBlasterException
Method Detail |
---|
public boolean pingDatabase()
We don't use a connection from the pool for this check as it could be stale even if the database is alive.
public boolean registerStorageProblemListener(I_StorageProblemListener entry)
registerStorageProblemListener
in interface I_StorageProblemNotifier
public boolean unRegisterStorageProblemListener(I_StorageProblemListener entry)
unRegisterStorageProblemListener
in interface I_StorageProblemNotifier
public void storageUnavailable(int oldStatus)
I_StorageProblemListener
storageUnavailable
in interface I_StorageProblemListener
oldStatus
- the status before the storage became unavailable.I_StorageProblemListener.storageUnavailable(int)
public void storageAvailable(int oldStatus)
I_StorageProblemListener
storageAvailable
in interface I_StorageProblemListener
I_StorageProblemListener.storageAvailable(int)
public I_StorageProblemListener[] getStorageProblemListenerArr()
protected final boolean checkIfDBLoss(java.sql.Connection conn, java.lang.String location, java.lang.Throwable ex)
checkIfDBLoss(Connection, String, Throwable, String)
protected final boolean checkIfDBLoss(java.sql.Connection conn, java.lang.String location, java.lang.Throwable ex, java.lang.String trace)
location
- where the exception occured.ex
- the exception which has to be handled.trace
- additional information to put in the logetLogId(tableName, storageId, "getEntries") logging trace.
private java.util.HashSet getXbTableNames(java.sql.Connection conn) throws java.sql.SQLException
conn
- the connection on which to retrieve the metadata.
java.sql.SQLException
public final boolean tablesCheckAndSetup(boolean createTables) throws XmlBlasterException
XmlBlasterException
public long modifyEntry(java.lang.String queueName, I_Entry entry, I_Entry oldEntry) throws XmlBlasterException
queueName
- The name of the queue on which to perform the operationentry
- the object to be stored.oldEntry
- the old one
XmlBlasterException
- if an error occurred when trying to get a connection or an SQLException
occurred.private final boolean addSingleEntry(java.lang.String queueName, I_Entry entry, java.sql.Connection conn) throws XmlBlasterException
queueName
- The name of the queue on which to perform the operationentry
- the object to be stored.
java.sql.SQLException
- if an error other than double entry occured while adding the row
XmlBlasterException
- if an error occured when trying to get a connectionpublic final boolean addEntry(java.lang.String queueName, I_Entry entry) throws XmlBlasterException
queueName
- The name of the queue on which to perform the operationentry
- the object to be stored.
java.sql.SQLException
- if an error occured while adding the row
XmlBlasterException
- if an error occured when trying to get a connectionprivate int[] addEntriesSingleMode(java.sql.Connection conn, java.lang.String queueName, I_Entry[] entries) throws XmlBlasterException
XmlBlasterException
public int[] addEntries(java.lang.String queueName, I_Entry[] entries) throws XmlBlasterException
queueName
- The name of the queue on which to perform the operationentries
- the entries to store
java.sql.SQLException
- if an error occured while adding the row
XmlBlasterException
- if an error occured when trying to get a connectionpublic final int cleanUp(java.lang.String queueName) throws XmlBlasterException
XmlBlasterException
public int wipeOutDB(boolean doSetupNewTables) throws XmlBlasterException
doSetupNewTables
- if set to 'true' it recreates the necessary empty tables.
XmlBlasterException
public void dumpMetaData()
public long getNumOfBytes(java.lang.String queueName) throws XmlBlasterException
getNumOfAll(String)
tableName
- the name of the table in which to count
XmlBlasterException
public final void setUp() throws XmlBlasterException
XmlBlasterException
private boolean isPersistent(java.lang.String persistentAsChar)
private final java.util.ArrayList processResultSet(java.sql.ResultSet rs, StorageId storageIdDefault, int numOfEntries, long numOfBytes, boolean onlyId, I_EntryFilter entryFilter) throws java.sql.SQLException, XmlBlasterException
java.sql.SQLException
XmlBlasterException
private final ReturnDataHolder processResultSetForDeleting(java.sql.ResultSet rs, int numOfEntries, long numOfBytes, java.util.List<java.lang.Long> retL) throws java.sql.SQLException, XmlBlasterException
numOfBytes
- as input is the maximum number of bytes to process. As
output it stores the number of bytes processed.numOfEntries
- the maximum number of entries to process
java.sql.SQLException
XmlBlasterException
public JdbcConnectionPool getPool()
private final int update(java.lang.String request) throws java.sql.SQLException, XmlBlasterException
request
- the request stringfetchSize
- the number of entries to fetch, i.e. to update
java.sql.SQLException
XmlBlasterException
private final int update(java.lang.String request, java.sql.Connection conn) throws java.sql.SQLException
request
- the string specifying which request to makeconn
- the connection to use for this request
java.sql.SQLException
public int deleteAllTransient(java.lang.String queueName) throws XmlBlasterException
XmlBlasterException
private final java.util.ArrayList whereInStatement(java.lang.String reqPrefix, long[] uniqueIds)
private final boolean isInsideRange(int numEntries, int maxNumEntries, long numBytes, long maxNumBytes)
public ReturnDataHolder getAndDeleteLowest(StorageId storageId, int numOfEntries, long numOfBytes, int maxPriority, long minUniqueId, boolean leaveOne, boolean doDelete) throws XmlBlasterException
XmlBlasterException
I_Queue.takeLowest(int, long, org.xmlBlaster.util.queue.I_QueueEntry, boolean)
public boolean[] deleteEntries(java.lang.String queueName, long[] uniqueIds) throws XmlBlasterException
tableName
- the name of the table on which to delete the entriesuniqueIds
- the array containing all the uniqueId for the entries to delete.
XmlBlasterException
private boolean[] deleteEntriesNoSplit(java.lang.String queueName, long[] uniqueIds) throws XmlBlasterException
XmlBlasterException
public int deleteEntry(java.lang.String queueName, long uniqueId) throws XmlBlasterException
tableName
- the name of the table on which to delete the entriesuniqueIds
- the array containing all the uniqueId for the entries to delete.
XmlBlasterException
public ReturnDataHolder deleteFirstEntries(java.lang.String queueName, long numOfEntries, long amount) throws XmlBlasterException
tableName
- the name of the table on which to act.numOfEntries
- the number of entries to be deleted.amount
- the maximum amount of bytes to remove. Note that if no entries
fit into this size, the first entry is taken anyway (to avoid deadlocks)
XmlBlasterException
public java.util.ArrayList getEntriesByPriority(StorageId storageId, int numOfEntries, long numOfBytes, int minPrio, int maxPrio, I_EntryFilter entryFilter) throws XmlBlasterException
storageId
- the storageId of the queue/storage from which to retrieve the information.numOfEntries
- the maximum number of elements to retrieve. If negative there is no constriction.numOfBytes
- the maximum number of bytes to retrieve. If negative, there is no constriction.minPrio
- the minimum priority to retreive (inclusive).maxPrio
- the maximum priority to retrieve (inclusive).
XmlBlasterException
public java.util.ArrayList getEntriesBySamePriority(StorageId storageId, int numOfEntries, long numOfBytes) throws XmlBlasterException
numOfEntries
- the maximum number of elements to retrieve
XmlBlasterException
public java.util.ArrayList getEntries(StorageId storageId, int numOfEntries, long numOfBytes, I_EntryFilter entryFilter) throws XmlBlasterException
Is public for testsuite only.
numOfEntries
- Access num entries, if -1 access all entries currently foundnumOfBytes
- is the maximum size in bytes of the array to return, -1 is unlimited .
XmlBlasterException
public java.util.ArrayList getEntriesLike(java.lang.String queueNamePattern, java.lang.String flag, int numOfEntries, long numOfBytes, I_EntryFilter entryFilter) throws XmlBlasterException
numOfEntries
- the maximum number of elements to retrieve
XmlBlasterException
public java.util.ArrayList getEntriesWithLimit(StorageId storageId, I_Entry limitEntry) throws XmlBlasterException
numOfEntries
- the maximum number of elements to retrieve
XmlBlasterException
public long removeEntriesWithLimit(StorageId storageId, I_Entry limitEntry, boolean inclusive) throws XmlBlasterException
numOfEntries
- the maximum number of elements to retrieve
XmlBlasterException
public java.util.ArrayList getEntries(StorageId storageId, long[] dataids) throws XmlBlasterException
XmlBlasterException
public final EntryCount getNumOfAll(java.lang.String queueName) throws XmlBlasterException
XmlBlasterException
public final long getNumOfEntries(java.lang.String queueName) throws XmlBlasterException
getNumOfAll(String)
XmlBlasterException
public final long getNumOfPersistents(java.lang.String queueName) throws XmlBlasterException
getNumOfAll(String)
XmlBlasterException
public final long getSizeOfPersistents(java.lang.String queueName) throws XmlBlasterException
getNumOfAll(String)
Replaced all four selects with one:
"select count(*), sum(byteSize), durable from XB_ENTRIES WHERE queueName='history_xmlBlaster_192_168_1_4_3412Hello' GROUP BY durable;"
XmlBlasterException
private final java.lang.String getLogId(java.lang.String queueName, java.lang.String methodName)
queueName
- or null
public static CommonTableDatabaseAccessor createInstance(Global glob, I_EntryFactory factory, java.lang.String confType, java.lang.String confVersion, java.util.Properties properties) throws XmlBlasterException
confType
- the name of the configuration to use as default. If you pass null, then
'JDBC' will be taken.confVersion
- the version to use as a default. If you pass null, then '1.0' will be taken.properties
- the properties to use to overwrite the default properties. If you pass null, no
properties will be overwritten, and the default will be used.
XmlBlasterException
public static void wipeOutDB(Global glob, java.lang.String confType, java.lang.String confVersion, java.util.Properties properties, boolean setupNewTables) throws XmlBlasterException
confType
- the name of the configuration to use as default. If you pass null, then
'JDBC' will be taken.confVersion
- the version to use as a default. If you pass null, then '1.0' will be taken.properties
- the properties to use to overwrite the default properties. If you pass null, no
properties will be overwritten, and the default will be used.setupNewTables
- tells the manager to recreate empty tables if set to 'true'. Note that this flag only
has effect if the JdbcManagerCommonTable is used.
XmlBlasterException
public static void main(java.lang.String[] args)
public void shutdown()
public void registerQueue(I_Queue queue)
public void unregisterQueue(I_Queue queue)
public boolean isDB2()
public boolean isHSQLDatabaseEngine()
public boolean isMicrosoftSQLServer()
public boolean isMySql()
public boolean isOracle()
public boolean isPostgres()
public boolean isFirebird()
public boolean isLdbc()
public boolean isSQLite()
|
xmlBlaster 2.2.0 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |