001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.activemq.store.jdbc;
018    
019    /**
020     * 
021     * 
022     * @org.apache.xbean.XBean element="statements"
023     * 
024     */
025    public class Statements {
026    
027        protected String messageTableName = "ACTIVEMQ_MSGS";
028        protected String durableSubAcksTableName = "ACTIVEMQ_ACKS";
029        protected String lockTableName = "ACTIVEMQ_LOCK";
030        protected String binaryDataType = "BLOB";
031        protected String containerNameDataType = "VARCHAR(250)";
032        protected String msgIdDataType = "VARCHAR(250)";
033        protected String sequenceDataType = "BIGINT";
034        protected String longDataType = "BIGINT";
035        protected String stringIdDataType = "VARCHAR(250)";
036        protected boolean useExternalMessageReferences;
037    
038        private String tablePrefix = "";
039        private String addMessageStatement;
040        private String updateMessageStatement;
041        private String removeMessageStatement;
042        private String findMessageSequenceIdStatement;
043        private String findMessageStatement;
044        private String findMessageByIdStatement;
045        private String findAllMessagesStatement;
046        private String findLastSequenceIdInMsgsStatement;
047        private String findLastSequenceIdInAcksStatement;
048        private String createDurableSubStatement;
049        private String findDurableSubStatement;
050        private String findAllDurableSubsStatement;
051        private String updateLastPriorityAckRowOfDurableSubStatement;
052        private String deleteSubscriptionStatement;
053        private String findAllDurableSubMessagesStatement;
054        private String findDurableSubMessagesStatement;
055        private String findDurableSubMessagesByPriorityStatement;
056        private String findAllDestinationsStatement;
057        private String removeAllMessagesStatement;
058        private String removeAllSubscriptionsStatement;
059        private String[] createSchemaStatements;
060        private String[] dropSchemaStatements;
061        private String lockCreateStatement;
062        private String lockUpdateStatement;
063        private String nextDurableSubscriberMessageStatement;
064        private String durableSubscriberMessageCountStatement;
065        private String lastAckedDurableSubscriberMessageStatement;
066        private String destinationMessageCountStatement;
067        private String findNextMessagesStatement;
068        private String findNextMessagesByPriorityStatement;
069        private boolean useLockCreateWhereClause;
070        private String findAllMessageIdsStatement;
071        private String lastProducerSequenceIdStatement;
072        private String selectDurablePriorityAckStatement;
073    
074        private String insertDurablePriorityAckStatement;
075        private String updateDurableLastAckStatement;
076        private String deleteOldMessagesStatementWithPriority;
077        private String durableSubscriberMessageCountStatementWithPriority;
078        private String dropAckPKAlterStatementEnd;
079        private String updateXidFlagStatement;
080        private String findOpsPendingOutcomeStatement;
081        private String clearXidFlagStatement;
082        private String updateDurableLastAckInTxStatement;
083        private String findAcksPendingOutcomeStatement;
084        private String clearDurableLastAckInTxStatement;
085        private String updateDurableLastAckWithPriorityStatement;
086        private String updateDurableLastAckWithPriorityInTxStatement;
087        private String findXidByIdStatement;
088        private String leaseObtainStatement;
089        private String currentDateTimeStatement;
090        private String leaseUpdateStatement;
091        private String leaseOwnerStatement;
092    
093        public String[] getCreateSchemaStatements() {
094            if (createSchemaStatements == null) {
095                createSchemaStatements = new String[] {
096                    "CREATE TABLE " + getFullMessageTableName() + "(" + "ID " + sequenceDataType + " NOT NULL"
097                        + ", CONTAINER " + containerNameDataType + ", MSGID_PROD " + msgIdDataType + ", MSGID_SEQ "
098                        + sequenceDataType + ", EXPIRATION " + longDataType + ", MSG "
099                        + (useExternalMessageReferences ? stringIdDataType : binaryDataType)
100                        + ", PRIMARY KEY ( ID ) )",
101                    "CREATE INDEX " + getFullMessageTableName() + "_MIDX ON " + getFullMessageTableName() + " (MSGID_PROD,MSGID_SEQ)",
102                    "CREATE INDEX " + getFullMessageTableName() + "_CIDX ON " + getFullMessageTableName() + " (CONTAINER)",
103                    "CREATE INDEX " + getFullMessageTableName() + "_EIDX ON " + getFullMessageTableName() + " (EXPIRATION)",
104                    "CREATE TABLE " + getFullAckTableName() + "(" + "CONTAINER " + containerNameDataType + " NOT NULL"
105                        + ", SUB_DEST " + stringIdDataType 
106                        + ", CLIENT_ID " + stringIdDataType + " NOT NULL" + ", SUB_NAME " + stringIdDataType
107                        + " NOT NULL" + ", SELECTOR " + stringIdDataType + ", LAST_ACKED_ID " + sequenceDataType
108                        + ", PRIMARY KEY ( CONTAINER, CLIENT_ID, SUB_NAME))", 
109                    "CREATE TABLE " + getFullLockTableName() 
110                        + "( ID " + longDataType + " NOT NULL, TIME " + longDataType
111                        + ", BROKER_NAME " + stringIdDataType + ", PRIMARY KEY (ID) )",
112                    "INSERT INTO " + getFullLockTableName() + "(ID) VALUES (1)",
113                    "ALTER TABLE " + getFullMessageTableName() + " ADD PRIORITY " + sequenceDataType,
114                    "CREATE INDEX " + getFullMessageTableName() + "_PIDX ON " + getFullMessageTableName() + " (PRIORITY)",
115                    "ALTER TABLE " + getFullMessageTableName() + " ADD XID " + binaryDataType,
116                    "ALTER TABLE " + getFullAckTableName() + " ADD PRIORITY " + sequenceDataType  + " DEFAULT 5 NOT NULL",
117                    "ALTER TABLE " + getFullAckTableName() + " ADD XID " + binaryDataType,
118                    "ALTER TABLE " + getFullAckTableName() + " " + getDropAckPKAlterStatementEnd(),
119                    "ALTER TABLE " + getFullAckTableName() + " ADD PRIMARY KEY (CONTAINER, CLIENT_ID, SUB_NAME, PRIORITY)",
120                };
121            }
122            return createSchemaStatements;
123        }
124    
125        public String getDropAckPKAlterStatementEnd() {
126            if (dropAckPKAlterStatementEnd == null) {
127                dropAckPKAlterStatementEnd = "DROP PRIMARY KEY";
128            }
129            return dropAckPKAlterStatementEnd;
130        }
131    
132        public void setDropAckPKAlterStatementEnd(String dropAckPKAlterStatementEnd) {
133            this.dropAckPKAlterStatementEnd = dropAckPKAlterStatementEnd;
134        }
135    
136        public String[] getDropSchemaStatements() {
137            if (dropSchemaStatements == null) {
138                dropSchemaStatements = new String[] {"DROP TABLE " + getFullAckTableName() + "",
139                                                     "DROP TABLE " + getFullMessageTableName() + "",
140                                                     "DROP TABLE " + getFullLockTableName() + ""};
141            }
142            return dropSchemaStatements;
143        }
144    
145        public String getAddMessageStatement() {
146            if (addMessageStatement == null) {
147                addMessageStatement = "INSERT INTO "
148                                      + getFullMessageTableName()
149                                      + "(ID, MSGID_PROD, MSGID_SEQ, CONTAINER, EXPIRATION, PRIORITY, MSG, XID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
150            }
151            return addMessageStatement;
152        }
153    
154        public String getUpdateMessageStatement() {
155            if (updateMessageStatement == null) {
156                updateMessageStatement = "UPDATE " + getFullMessageTableName() + " SET MSG=? WHERE ID=?";
157            }
158            return updateMessageStatement;
159        }
160    
161        public String getRemoveMessageStatement() {
162            if (removeMessageStatement == null) {
163                removeMessageStatement = "DELETE FROM " + getFullMessageTableName() + " WHERE ID=?";
164            }
165            return removeMessageStatement;
166        }
167    
168        public String getFindMessageSequenceIdStatement() {
169            if (findMessageSequenceIdStatement == null) {
170                findMessageSequenceIdStatement = "SELECT ID, PRIORITY FROM " + getFullMessageTableName()
171                                                 + " WHERE MSGID_PROD=? AND MSGID_SEQ=? AND CONTAINER=?";
172            }
173            return findMessageSequenceIdStatement;
174        }
175    
176        public String getFindMessageStatement() {
177            if (findMessageStatement == null) {
178                findMessageStatement = "SELECT MSG FROM " + getFullMessageTableName() + " WHERE MSGID_PROD=? AND MSGID_SEQ=?";
179            }
180            return findMessageStatement;
181        }
182    
183        public String getFindMessageByIdStatement() {
184            if (findMessageByIdStatement == null) {
185                    findMessageByIdStatement = "SELECT MSG FROM " + getFullMessageTableName() + " WHERE ID=?";
186            }
187            return findMessageByIdStatement;
188        }
189    
190        public String getFindXidByIdStatement() {
191            if (findXidByIdStatement == null) {
192                findXidByIdStatement = "SELECT XID FROM " + getFullMessageTableName() + " WHERE ID=?";
193            }
194            return findXidByIdStatement;
195        }
196    
197        public String getFindAllMessagesStatement() {
198            if (findAllMessagesStatement == null) {
199                findAllMessagesStatement = "SELECT ID, MSG FROM " + getFullMessageTableName()
200                                           + " WHERE CONTAINER=? ORDER BY ID";
201            }
202            return findAllMessagesStatement;
203        }
204        
205        public String getFindAllMessageIdsStatement() {
206            //  this needs to be limited maybe need to use getFindLastSequenceIdInMsgsStatement
207            // and work back for X
208            if (findAllMessageIdsStatement == null) {
209                findAllMessageIdsStatement = "SELECT ID, MSGID_PROD, MSGID_SEQ FROM " + getFullMessageTableName()
210                                           + " ORDER BY ID DESC";
211            }
212            return findAllMessageIdsStatement;
213        }
214    
215        public String getFindLastSequenceIdInMsgsStatement() {
216            if (findLastSequenceIdInMsgsStatement == null) {
217                findLastSequenceIdInMsgsStatement = "SELECT MAX(ID) FROM " + getFullMessageTableName();
218            }
219            return findLastSequenceIdInMsgsStatement;
220        }
221    
222        public String getLastProducerSequenceIdStatement() {
223            if (lastProducerSequenceIdStatement == null) {
224                lastProducerSequenceIdStatement = "SELECT MAX(MSGID_SEQ) FROM " + getFullMessageTableName()
225                                                + " WHERE MSGID_PROD=?";
226            }
227            return lastProducerSequenceIdStatement;
228        }
229    
230    
231        public String getFindLastSequenceIdInAcksStatement() {
232            if (findLastSequenceIdInAcksStatement == null) {
233                findLastSequenceIdInAcksStatement = "SELECT MAX(LAST_ACKED_ID) FROM " + getFullAckTableName();
234            }
235            return findLastSequenceIdInAcksStatement;
236        }
237    
238        public String getCreateDurableSubStatement() {
239            if (createDurableSubStatement == null) {
240                createDurableSubStatement = "INSERT INTO "
241                                            + getFullAckTableName()
242                                            + "(CONTAINER, CLIENT_ID, SUB_NAME, SELECTOR, LAST_ACKED_ID, SUB_DEST, PRIORITY) "
243                                            + "VALUES (?, ?, ?, ?, ?, ?, ?)";
244            }
245            return createDurableSubStatement;
246        }
247    
248        public String getFindDurableSubStatement() {
249            if (findDurableSubStatement == null) {
250                findDurableSubStatement = "SELECT SELECTOR, SUB_DEST " + "FROM " + getFullAckTableName()
251                                          + " WHERE CONTAINER=? AND CLIENT_ID=? AND SUB_NAME=?";
252            }
253            return findDurableSubStatement;
254        }
255    
256        public String getFindAllDurableSubsStatement() {
257            if (findAllDurableSubsStatement == null) {
258                findAllDurableSubsStatement = "SELECT SELECTOR, SUB_NAME, CLIENT_ID, SUB_DEST" + " FROM "
259                                              + getFullAckTableName() + " WHERE CONTAINER=? AND PRIORITY=0";
260            }
261            return findAllDurableSubsStatement;
262        }
263    
264        public String getUpdateLastPriorityAckRowOfDurableSubStatement() {
265            if (updateLastPriorityAckRowOfDurableSubStatement == null) {
266                updateLastPriorityAckRowOfDurableSubStatement = "UPDATE " + getFullAckTableName() + " SET LAST_ACKED_ID=?"
267                                                     + " WHERE CONTAINER=? AND CLIENT_ID=? AND SUB_NAME=? AND PRIORITY=?";
268            }
269            return updateLastPriorityAckRowOfDurableSubStatement;
270        }
271    
272        public String getDeleteSubscriptionStatement() {
273            if (deleteSubscriptionStatement == null) {
274                deleteSubscriptionStatement = "DELETE FROM " + getFullAckTableName()
275                                              + " WHERE CONTAINER=? AND CLIENT_ID=? AND SUB_NAME=?";
276            }
277            return deleteSubscriptionStatement;
278        }
279    
280        public String getFindAllDurableSubMessagesStatement() {
281            if (findAllDurableSubMessagesStatement == null) {
282                findAllDurableSubMessagesStatement = "SELECT M.ID, M.MSG FROM " + getFullMessageTableName()
283                                                     + " M, " + getFullAckTableName() + " D "
284                                                     + " WHERE D.CONTAINER=? AND D.CLIENT_ID=? AND D.SUB_NAME=?"
285                                                     + " AND M.CONTAINER=D.CONTAINER AND M.ID > D.LAST_ACKED_ID"
286                                                     + " ORDER BY M.PRIORITY DESC, M.ID";
287            }
288            return findAllDurableSubMessagesStatement;
289        }
290    
291        public String getFindDurableSubMessagesStatement() {
292            if (findDurableSubMessagesStatement == null) {
293                findDurableSubMessagesStatement = "SELECT M.ID, M.MSG FROM " + getFullMessageTableName() + " M, "
294                                                  + getFullAckTableName() + " D "
295                                                  + " WHERE D.CONTAINER=? AND D.CLIENT_ID=? AND D.SUB_NAME=?"
296                                                  + " AND M.XID IS NULL"
297                                                  + " AND M.CONTAINER=D.CONTAINER AND M.ID > D.LAST_ACKED_ID"
298                                                  + " AND M.ID > ?"
299                                                  + " ORDER BY M.ID";
300            }
301            return findDurableSubMessagesStatement;
302        }
303        
304        public String getFindDurableSubMessagesByPriorityStatement() {
305            if (findDurableSubMessagesByPriorityStatement == null) {
306                findDurableSubMessagesByPriorityStatement = "SELECT M.ID, M.MSG FROM " + getFullMessageTableName() + " M,"
307                                                  + " " + getFullAckTableName() + " D"
308                                                  + " WHERE D.CONTAINER=? AND D.CLIENT_ID=? AND D.SUB_NAME=?"
309                                                  + " AND M.XID IS NULL"
310                                                  + " AND M.CONTAINER=D.CONTAINER"
311                                                  + " AND M.PRIORITY=D.PRIORITY AND M.ID > D.LAST_ACKED_ID"
312                                                  + " AND M.ID > ? AND M.PRIORITY = ?"
313                                                  + " ORDER BY M.ID";
314            }
315            return findDurableSubMessagesByPriorityStatement;
316        }    
317    
318        public String findAllDurableSubMessagesStatement() {
319            if (findAllDurableSubMessagesStatement == null) {
320                findAllDurableSubMessagesStatement = "SELECT M.ID, M.MSG FROM " + getFullMessageTableName()
321                                                     + " M, " + getFullAckTableName() + " D "
322                                                     + " WHERE D.CONTAINER=? AND D.CLIENT_ID=? AND D.SUB_NAME=?"
323                                                     + " AND M.CONTAINER=D.CONTAINER AND M.ID > D.LAST_ACKED_ID"
324                                                     + " ORDER BY M.ID";
325            }
326            return findAllDurableSubMessagesStatement;
327        }
328    
329        public String getNextDurableSubscriberMessageStatement() {
330            if (nextDurableSubscriberMessageStatement == null) {
331                nextDurableSubscriberMessageStatement = "SELECT M.ID, M.MSG FROM "
332                                                        + getFullMessageTableName()
333                                                        + " M, "
334                                                        + getFullAckTableName()
335                                                        + " D "
336                                                        + " WHERE D.CONTAINER=? AND D.CLIENT_ID=? AND D.SUB_NAME=?"
337                                                        + " AND M.CONTAINER=D.CONTAINER AND M.ID > ?"
338                                                        + " ORDER BY M.ID ";
339            }
340            return nextDurableSubscriberMessageStatement;
341        }
342    
343        /**
344         * @return the durableSubscriberMessageCountStatement
345         */
346    
347        public String getDurableSubscriberMessageCountStatement() {
348            if (durableSubscriberMessageCountStatement == null) {
349                durableSubscriberMessageCountStatement = "SELECT COUNT(*) FROM "
350                                                         + getFullMessageTableName()
351                                                         + " M, "
352                                                         + getFullAckTableName()
353                                                         + " D "
354                                                         + " WHERE D.CONTAINER=? AND D.CLIENT_ID=? AND D.SUB_NAME=?"
355                                                         + " AND M.CONTAINER=D.CONTAINER "
356                                                         + "     AND M.ID >"
357                                                         + "          ( SELECT LAST_ACKED_ID FROM " + getFullAckTableName()
358                                                         + "           WHERE CONTAINER=D.CONTAINER AND CLIENT_ID=D.CLIENT_ID"
359                                                         + "           AND SUB_NAME=D.SUB_NAME )";
360    
361            }
362            return durableSubscriberMessageCountStatement;
363        }
364    
365        public String getDurableSubscriberMessageCountStatementWithPriority() {
366            if (durableSubscriberMessageCountStatementWithPriority == null) {
367                durableSubscriberMessageCountStatementWithPriority = "SELECT COUNT(*) FROM "
368                                                         + getFullMessageTableName()
369                                                         + " M, "
370                                                         + getFullAckTableName()
371                                                         + " D "
372                                                         + " WHERE D.CONTAINER=? AND D.CLIENT_ID=? AND D.SUB_NAME=?"
373                                                         + " AND M.CONTAINER=D.CONTAINER "
374                                                         + " AND M.PRIORITY=D.PRIORITY "
375                                                         + " AND M.ID > D.LAST_ACKED_ID";
376            }
377    
378            return durableSubscriberMessageCountStatementWithPriority;
379        }
380    
381        public String getFindAllDestinationsStatement() {
382            if (findAllDestinationsStatement == null) {
383                findAllDestinationsStatement = "SELECT DISTINCT CONTAINER FROM " + getFullMessageTableName()
384                        + " UNION SELECT DISTINCT CONTAINER FROM "  + getFullAckTableName();
385            }
386            return findAllDestinationsStatement;
387        }
388    
389        public String getRemoveAllMessagesStatement() {
390            if (removeAllMessagesStatement == null) {
391                removeAllMessagesStatement = "DELETE FROM " + getFullMessageTableName() + " WHERE CONTAINER=?";
392            }
393            return removeAllMessagesStatement;
394        }
395    
396        public String getRemoveAllSubscriptionsStatement() {
397            if (removeAllSubscriptionsStatement == null) {
398                removeAllSubscriptionsStatement = "DELETE FROM " + getFullAckTableName() + " WHERE CONTAINER=?";
399            }
400            return removeAllSubscriptionsStatement;
401        }
402    
403        public String getDeleteOldMessagesStatementWithPriority() {
404            if (deleteOldMessagesStatementWithPriority == null) {
405                deleteOldMessagesStatementWithPriority = "DELETE FROM " + getFullMessageTableName()
406                                             + " WHERE (PRIORITY=? AND ID <= "
407                                             + "     ( SELECT min(" + getFullAckTableName() + ".LAST_ACKED_ID)"
408                                             + "       FROM " + getFullAckTableName() + " WHERE "
409                                             +          getFullAckTableName() + ".CONTAINER="
410                                             +          getFullMessageTableName() + ".CONTAINER"
411                                             + "        AND " + getFullAckTableName() + ".PRIORITY=?)"
412                                             + "   )";
413            }
414            return deleteOldMessagesStatementWithPriority;
415        }
416    
417        public String getLockCreateStatement() {
418            if (lockCreateStatement == null) {
419                lockCreateStatement = "SELECT * FROM " + getFullLockTableName();
420                if (useLockCreateWhereClause) {
421                    lockCreateStatement += " WHERE ID = 1";
422                }
423                lockCreateStatement += " FOR UPDATE";
424            }
425            return lockCreateStatement;
426        }
427    
428        public String getLeaseObtainStatement() {
429            if (leaseObtainStatement == null) {
430                leaseObtainStatement = "UPDATE " + getFullLockTableName()
431                        + " SET BROKER_NAME=?, TIME=?"
432                        + " WHERE (TIME IS NULL OR TIME < ?) AND ID = 1";
433            }
434            return leaseObtainStatement;
435        }
436    
437        public String getCurrentDateTime() {
438            if (currentDateTimeStatement == null) {
439                currentDateTimeStatement = "SELECT CURRENT_TIMESTAMP FROM " + getFullLockTableName();
440            }
441            return currentDateTimeStatement;
442        }
443    
444        public String getLeaseUpdateStatement() {
445            if (leaseUpdateStatement == null) {
446                leaseUpdateStatement = "UPDATE " + getFullLockTableName()
447                        + " SET BROKER_NAME=?, TIME=?"
448                        + " WHERE BROKER_NAME=? AND ID = 1";
449            }
450            return leaseUpdateStatement;
451        }
452    
453        public String getLeaseOwnerStatement() {
454            if (leaseOwnerStatement == null) {
455                leaseOwnerStatement = "SELECT BROKER_NAME, TIME FROM " + getFullLockTableName()
456                        + " WHERE ID = 1";
457            }
458            return leaseOwnerStatement;
459        }
460    
461        public String getLockUpdateStatement() {
462            if (lockUpdateStatement == null) {
463                lockUpdateStatement = "UPDATE " + getFullLockTableName() + " SET TIME = ? WHERE ID = 1";
464            }
465            return lockUpdateStatement;
466        }
467    
468        /**
469         * @return the destinationMessageCountStatement
470         */
471        public String getDestinationMessageCountStatement() {
472            if (destinationMessageCountStatement == null) {
473                destinationMessageCountStatement = "SELECT COUNT(*) FROM " + getFullMessageTableName()
474                                                   + " WHERE CONTAINER=? AND XID IS NULL";
475            }
476            return destinationMessageCountStatement;
477        }
478    
479        /**
480         * @return the findNextMessagesStatement
481         */
482        public String getFindNextMessagesStatement() {
483            if (findNextMessagesStatement == null) {
484                findNextMessagesStatement = "SELECT ID, MSG FROM " + getFullMessageTableName()
485                                            + " WHERE CONTAINER=? AND ID > ? AND XID IS NULL ORDER BY ID";
486            }
487            return findNextMessagesStatement;
488        }
489    
490        /**
491         * @return the findNextMessagesStatement
492         */
493        public String getFindNextMessagesByPriorityStatement() {
494            if (findNextMessagesByPriorityStatement == null) {
495                findNextMessagesByPriorityStatement = "SELECT ID, MSG FROM " + getFullMessageTableName()
496                                            + " WHERE CONTAINER=?"
497                                            + " AND XID IS NULL"
498                                            + " AND ((ID > ? AND PRIORITY = ?) OR PRIORITY < ?)"
499                                            + " ORDER BY PRIORITY DESC, ID";
500            }
501            return findNextMessagesByPriorityStatement;
502        }    
503        
504        /**
505         * @return the lastAckedDurableSubscriberMessageStatement
506         */
507        public String getLastAckedDurableSubscriberMessageStatement() {
508            if (lastAckedDurableSubscriberMessageStatement == null) {
509                lastAckedDurableSubscriberMessageStatement = "SELECT MAX(LAST_ACKED_ID) FROM "
510                                                             + getFullAckTableName()
511                                                             + " WHERE CONTAINER=? AND CLIENT_ID=? AND SUB_NAME=?";                                                    
512            }
513            return lastAckedDurableSubscriberMessageStatement;
514        }
515    
516        public String getSelectDurablePriorityAckStatement() {
517            if (selectDurablePriorityAckStatement == null) {
518                selectDurablePriorityAckStatement = "SELECT LAST_ACKED_ID FROM " + getFullAckTableName()
519                                                        + " WHERE CONTAINER=? AND CLIENT_ID=? AND SUB_NAME=?"
520                                                        + " AND PRIORITY = ?";
521            }
522            return selectDurablePriorityAckStatement;
523        }
524    
525        public String getInsertDurablePriorityAckStatement() {
526            if (insertDurablePriorityAckStatement == null) {
527                insertDurablePriorityAckStatement = "INSERT INTO "
528                                      + getFullAckTableName()
529                                      + "(CONTAINER, CLIENT_ID, SUB_NAME, PRIORITY)"
530                                      + " VALUES (?, ?, ?, ?)";            
531           }
532            return insertDurablePriorityAckStatement;
533        }
534    
535    
536        public String getUpdateDurableLastAckStatement() {
537            if (updateDurableLastAckStatement == null) {
538                updateDurableLastAckStatement  = "UPDATE " + getFullAckTableName()
539                        + " SET LAST_ACKED_ID=?, XID = NULL WHERE CONTAINER=? AND CLIENT_ID=? AND SUB_NAME=?";
540            }
541            return  updateDurableLastAckStatement;
542        }
543    
544        public String getUpdateDurableLastAckInTxStatement() {
545            if (updateDurableLastAckInTxStatement == null) {
546                updateDurableLastAckInTxStatement = "UPDATE " + getFullAckTableName()
547                        + " SET XID=? WHERE CONTAINER=? AND CLIENT_ID=? AND SUB_NAME=?";
548            }
549            return updateDurableLastAckInTxStatement;
550        }
551    
552        public String getUpdateDurableLastAckWithPriorityStatement() {
553            if (updateDurableLastAckWithPriorityStatement == null) {
554                updateDurableLastAckWithPriorityStatement  = "UPDATE " + getFullAckTableName()
555                        + " SET LAST_ACKED_ID=?, XID = NULL WHERE CONTAINER=? AND CLIENT_ID=? AND SUB_NAME=? AND PRIORITY=?";
556            }
557            return  updateDurableLastAckWithPriorityStatement;
558        }
559    
560        public String getUpdateDurableLastAckWithPriorityInTxStatement() {
561            if (updateDurableLastAckWithPriorityInTxStatement == null) {
562                updateDurableLastAckWithPriorityInTxStatement  = "UPDATE " + getFullAckTableName()
563                        + " SET XID=? WHERE CONTAINER=? AND CLIENT_ID=? AND SUB_NAME=? AND PRIORITY=?";
564            }
565            return  updateDurableLastAckWithPriorityInTxStatement;
566        }
567    
568        public String getClearDurableLastAckInTxStatement() {
569            if (clearDurableLastAckInTxStatement == null) {
570                clearDurableLastAckInTxStatement = "UPDATE " + getFullAckTableName()
571                        + " SET XID = NULL WHERE CONTAINER=? AND CLIENT_ID=? AND SUB_NAME=? AND PRIORITY=?";
572            }
573            return clearDurableLastAckInTxStatement;
574        }
575    
576        public String getFindOpsPendingOutcomeStatement() {
577            if (findOpsPendingOutcomeStatement == null) {
578                findOpsPendingOutcomeStatement = "SELECT ID, XID, MSG FROM " + getFullMessageTableName()
579                        + " WHERE XID IS NOT NULL ORDER BY ID";
580            }
581            return findOpsPendingOutcomeStatement;
582        }
583    
584        public String getFindAcksPendingOutcomeStatement() {
585            if (findAcksPendingOutcomeStatement == null) {
586                findAcksPendingOutcomeStatement = "SELECT XID," +
587                        " CONTAINER, CLIENT_ID, SUB_NAME FROM " + getFullAckTableName()
588                        + " WHERE XID IS NOT NULL";
589            }
590            return findAcksPendingOutcomeStatement;
591        }
592    
593        public String getUpdateXidFlagStatement() {
594            if (updateXidFlagStatement == null) {
595                updateXidFlagStatement = "UPDATE " + getFullMessageTableName()
596                        + " SET XID = ? WHERE ID = ?";
597            }
598            return updateXidFlagStatement;
599        }
600    
601        public String getClearXidFlagStatement() {
602            if (clearXidFlagStatement == null) {
603                clearXidFlagStatement = "UPDATE "  + getFullMessageTableName()
604                        + " SET XID = NULL WHERE ID = ?";
605            }
606            return clearXidFlagStatement;
607        }
608    
609        public String getFullMessageTableName() {
610            return getTablePrefix() + getMessageTableName();
611        }
612    
613        public String getFullAckTableName() {
614            return getTablePrefix() + getDurableSubAcksTableName();
615        }
616    
617        public String getFullLockTableName() {
618            return getTablePrefix() + getLockTableName();
619        }
620    
621        /**
622         * @return Returns the containerNameDataType.
623         */
624        public String getContainerNameDataType() {
625            return containerNameDataType;
626        }
627    
628        /**
629         * @param containerNameDataType The containerNameDataType to set.
630         */
631        public void setContainerNameDataType(String containerNameDataType) {
632            this.containerNameDataType = containerNameDataType;
633        }
634    
635        /**
636         * @return Returns the messageDataType.
637         */
638        public String getBinaryDataType() {
639            return binaryDataType;
640        }
641    
642        /**
643         * @param messageDataType The messageDataType to set.
644         */
645        public void setBinaryDataType(String messageDataType) {
646            this.binaryDataType = messageDataType;
647        }
648    
649        /**
650         * @return Returns the messageTableName.
651         */
652        public String getMessageTableName() {
653            return messageTableName;
654        }
655    
656        /**
657         * @param messageTableName The messageTableName to set.
658         */
659        public void setMessageTableName(String messageTableName) {
660            this.messageTableName = messageTableName;
661        }
662    
663        /**
664         * @return Returns the msgIdDataType.
665         */
666        public String getMsgIdDataType() {
667            return msgIdDataType;
668        }
669    
670        /**
671         * @param msgIdDataType The msgIdDataType to set.
672         */
673        public void setMsgIdDataType(String msgIdDataType) {
674            this.msgIdDataType = msgIdDataType;
675        }
676    
677        /**
678         * @return Returns the sequenceDataType.
679         */
680        public String getSequenceDataType() {
681            return sequenceDataType;
682        }
683    
684        /**
685         * @param sequenceDataType The sequenceDataType to set.
686         */
687        public void setSequenceDataType(String sequenceDataType) {
688            this.sequenceDataType = sequenceDataType;
689        }
690    
691        /**
692         * @return Returns the tablePrefix.
693         */
694        public String getTablePrefix() {
695            return tablePrefix;
696        }
697    
698        /**
699         * @param tablePrefix The tablePrefix to set.
700         */
701        public void setTablePrefix(String tablePrefix) {
702            this.tablePrefix = tablePrefix;
703        }
704    
705        /**
706         * @return Returns the durableSubAcksTableName.
707         */
708        public String getDurableSubAcksTableName() {
709            return durableSubAcksTableName;
710        }
711    
712        /**
713         * @param durableSubAcksTableName The durableSubAcksTableName to set.
714         */
715        public void setDurableSubAcksTableName(String durableSubAcksTableName) {
716            this.durableSubAcksTableName = durableSubAcksTableName;
717        }
718    
719        public String getLockTableName() {
720            return lockTableName;
721        }
722    
723        public void setLockTableName(String lockTableName) {
724            this.lockTableName = lockTableName;
725        }
726    
727        public String getLongDataType() {
728            return longDataType;
729        }
730    
731        public void setLongDataType(String longDataType) {
732            this.longDataType = longDataType;
733        }
734    
735        public String getStringIdDataType() {
736            return stringIdDataType;
737        }
738    
739        public void setStringIdDataType(String stringIdDataType) {
740            this.stringIdDataType = stringIdDataType;
741        }
742    
743        public void setUseExternalMessageReferences(boolean useExternalMessageReferences) {
744            this.useExternalMessageReferences = useExternalMessageReferences;
745        }
746    
747        public boolean isUseExternalMessageReferences() {
748            return useExternalMessageReferences;
749        }
750    
751        public void setAddMessageStatement(String addMessageStatment) {
752            this.addMessageStatement = addMessageStatment;
753        }
754    
755        public void setCreateDurableSubStatement(String createDurableSubStatment) {
756            this.createDurableSubStatement = createDurableSubStatment;
757        }
758    
759        public void setCreateSchemaStatements(String[] createSchemaStatments) {
760            this.createSchemaStatements = createSchemaStatments;
761        }
762    
763        public void setDeleteOldMessagesStatementWithPriority(String deleteOldMessagesStatementWithPriority) {
764            this.deleteOldMessagesStatementWithPriority = deleteOldMessagesStatementWithPriority;
765        }
766    
767        public void setDeleteSubscriptionStatement(String deleteSubscriptionStatment) {
768            this.deleteSubscriptionStatement = deleteSubscriptionStatment;
769        }
770    
771        public void setDropSchemaStatements(String[] dropSchemaStatments) {
772            this.dropSchemaStatements = dropSchemaStatments;
773        }
774    
775        public void setFindAllDestinationsStatement(String findAllDestinationsStatment) {
776            this.findAllDestinationsStatement = findAllDestinationsStatment;
777        }
778    
779        public void setFindAllDurableSubMessagesStatement(String findAllDurableSubMessagesStatment) {
780            this.findAllDurableSubMessagesStatement = findAllDurableSubMessagesStatment;
781        }
782    
783        public void setFindAllDurableSubsStatement(String findAllDurableSubsStatment) {
784            this.findAllDurableSubsStatement = findAllDurableSubsStatment;
785        }
786    
787        public void setFindAllMessagesStatement(String findAllMessagesStatment) {
788            this.findAllMessagesStatement = findAllMessagesStatment;
789        }
790    
791        public void setFindDurableSubStatement(String findDurableSubStatment) {
792            this.findDurableSubStatement = findDurableSubStatment;
793        }
794    
795        public void setFindLastSequenceIdInAcksStatement(String findLastSequenceIdInAcks) {
796            this.findLastSequenceIdInAcksStatement = findLastSequenceIdInAcks;
797        }
798    
799        public void setFindLastSequenceIdInMsgsStatement(String findLastSequenceIdInMsgs) {
800            this.findLastSequenceIdInMsgsStatement = findLastSequenceIdInMsgs;
801        }
802    
803        public void setFindMessageSequenceIdStatement(String findMessageSequenceIdStatment) {
804            this.findMessageSequenceIdStatement = findMessageSequenceIdStatment;
805        }
806    
807        public void setFindMessageStatement(String findMessageStatment) {
808            this.findMessageStatement = findMessageStatment;
809        }
810        
811        public void setFindMessageByIdStatement(String findMessageByIdStatement) {
812            this.findMessageByIdStatement = findMessageByIdStatement;
813        }
814    
815        public void setRemoveAllMessagesStatement(String removeAllMessagesStatment) {
816            this.removeAllMessagesStatement = removeAllMessagesStatment;
817        }
818    
819        public void setRemoveAllSubscriptionsStatement(String removeAllSubscriptionsStatment) {
820            this.removeAllSubscriptionsStatement = removeAllSubscriptionsStatment;
821        }
822    
823        public void setRemoveMessageStatment(String removeMessageStatement) {
824            this.removeMessageStatement = removeMessageStatement;
825        }
826    
827        public void setUpdateLastPriorityAckRowOfDurableSubStatement(String updateLastPriorityAckRowOfDurableSubStatement) {
828            this.updateLastPriorityAckRowOfDurableSubStatement = updateLastPriorityAckRowOfDurableSubStatement;
829        }
830    
831        public void setUpdateMessageStatement(String updateMessageStatment) {
832            this.updateMessageStatement = updateMessageStatment;
833        }
834    
835        public boolean isUseLockCreateWhereClause() {
836            return useLockCreateWhereClause;
837        }
838    
839        public void setUseLockCreateWhereClause(boolean useLockCreateWhereClause) {
840            this.useLockCreateWhereClause = useLockCreateWhereClause;
841        }
842    
843        public void setLockCreateStatement(String lockCreateStatement) {
844            this.lockCreateStatement = lockCreateStatement;
845        }
846    
847        public void setLockUpdateStatement(String lockUpdateStatement) {
848            this.lockUpdateStatement = lockUpdateStatement;
849        }
850    
851        /**
852         * @param findDurableSubMessagesStatement the
853         *                findDurableSubMessagesStatement to set
854         */
855        public void setFindDurableSubMessagesStatement(String findDurableSubMessagesStatement) {
856            this.findDurableSubMessagesStatement = findDurableSubMessagesStatement;
857        }
858    
859        /**
860         * @param nextDurableSubscriberMessageStatement the nextDurableSubscriberMessageStatement to set
861         */
862        public void setNextDurableSubscriberMessageStatement(String nextDurableSubscriberMessageStatement) {
863            this.nextDurableSubscriberMessageStatement = nextDurableSubscriberMessageStatement;
864        }
865    
866        /**
867         * @param durableSubscriberMessageCountStatement the durableSubscriberMessageCountStatement to set
868         */
869        public void setDurableSubscriberMessageCountStatement(String durableSubscriberMessageCountStatement) {
870            this.durableSubscriberMessageCountStatement = durableSubscriberMessageCountStatement;
871        }
872    
873        public void setDurableSubscriberMessageCountStatementWithPriority(String durableSubscriberMessageCountStatementWithPriority) {
874            this.durableSubscriberMessageCountStatementWithPriority = durableSubscriberMessageCountStatementWithPriority;
875        }
876    
877        /**
878         * @param findNextMessagesStatement the findNextMessagesStatement to set
879         */
880        public void setFindNextMessagesStatement(String findNextMessagesStatement) {
881            this.findNextMessagesStatement = findNextMessagesStatement;
882        }
883    
884        /**
885         * @param destinationMessageCountStatement the destinationMessageCountStatement to set
886         */
887        public void setDestinationMessageCountStatement(String destinationMessageCountStatement) {
888            this.destinationMessageCountStatement = destinationMessageCountStatement;
889        }
890    
891        /**
892         * @param lastAckedDurableSubscriberMessageStatement the lastAckedDurableSubscriberMessageStatement to set
893         */
894        public void setLastAckedDurableSubscriberMessageStatement(
895                                                                  String lastAckedDurableSubscriberMessageStatement) {
896            this.lastAckedDurableSubscriberMessageStatement = lastAckedDurableSubscriberMessageStatement;
897        }
898    
899    
900        public void setLastProducerSequenceIdStatement(String lastProducerSequenceIdStatement) {
901            this.lastProducerSequenceIdStatement = lastProducerSequenceIdStatement;
902        }
903    
904        public void setSelectDurablePriorityAckStatement(String selectDurablePriorityAckStatement) {
905            this.selectDurablePriorityAckStatement = selectDurablePriorityAckStatement;
906        }
907    
908        public void setInsertDurablePriorityAckStatement(String insertDurablePriorityAckStatement) {
909            this.insertDurablePriorityAckStatement = insertDurablePriorityAckStatement;
910        }
911    
912        public void setUpdateDurableLastAckStatement(String updateDurableLastAckStatement) {
913            this.updateDurableLastAckStatement = updateDurableLastAckStatement;
914        }
915    
916        public void setUpdateXidFlagStatement(String updateXidFlagStatement) {
917            this.updateXidFlagStatement = updateXidFlagStatement;
918        }
919    
920        public void setFindOpsPendingOutcomeStatement(String findOpsPendingOutcomeStatement) {
921            this.findOpsPendingOutcomeStatement = findOpsPendingOutcomeStatement;
922        }
923    
924        public void setClearXidFlagStatement(String clearXidFlagStatement) {
925            this.clearXidFlagStatement = clearXidFlagStatement;
926        }
927    
928        public void setUpdateDurableLastAckInTxStatement(String updateDurableLastAckInTxStatement) {
929            this.updateDurableLastAckInTxStatement = updateDurableLastAckInTxStatement;
930        }
931    
932        public void setFindAcksPendingOutcomeStatement(String findAcksPendingOutcomeStatement) {
933            this.findAcksPendingOutcomeStatement = findAcksPendingOutcomeStatement;
934        }
935    
936        public void setClearDurableLastAckInTxStatement(String clearDurableLastAckInTxStatement) {
937            this.clearDurableLastAckInTxStatement = clearDurableLastAckInTxStatement;
938        }
939    
940        public void setUpdateDurableLastAckWithPriorityStatement(String updateDurableLastAckWithPriorityStatement) {
941            this.updateDurableLastAckWithPriorityStatement = updateDurableLastAckWithPriorityStatement;
942        }
943    
944        public void setUpdateDurableLastAckWithPriorityInTxStatement(String updateDurableLastAckWithPriorityInTxStatement) {
945            this.updateDurableLastAckWithPriorityInTxStatement = updateDurableLastAckWithPriorityInTxStatement;
946        }
947    
948        public void setFindXidByIdStatement(String findXidByIdStatement) {
949            this.findXidByIdStatement = findXidByIdStatement;
950        }
951    
952        public void setLeaseObtainStatement(String leaseObtainStatement) {
953            this.leaseObtainStatement = leaseObtainStatement;
954        }
955    
956        public void setCurrentDateTimeStatement(String currentDateTimeStatement) {
957            this.currentDateTimeStatement = currentDateTimeStatement;
958        }
959    
960        public void setLeaseUpdateStatement(String leaseUpdateStatement) {
961            this.leaseUpdateStatement = leaseUpdateStatement;
962        }
963    
964        public void setLeaseOwnerStatement(String leaseOwnerStatement) {
965            this.leaseOwnerStatement = leaseOwnerStatement;
966        }
967    }