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