DefaultStatementProvider xref

View Javadoc

    1   /***
    2    *
    3    * Copyright 2004 Hiram Chirino
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18  package org.codehaus.activemq.store.jdbc.adapter;
    19
    20  import org.codehaus.activemq.store.jdbc.StatementProvider;
    21
    22
    23  /***
    24   * @version $Revision: 1.6 $
    25   */
    26  public class DefaultStatementProvider implements StatementProvider {
    27
    28      protected String tablePrefix = "";
    29      protected String messageTableName = "ACTIVEMQ_MSGS";
    30      protected String txTableName = "ACTIVEMQ_TXS";
    31      protected String durableSubAcksTableName = "ACTIVEMQ_ACKS";
    32
    33      protected String binaryDataType = "BLOB";
    34      protected String containerNameDataType = "VARCHAR(250)";
    35      protected String xidDataType = "VARCHAR(250)";
    36      protected String msgIdDataType = "VARCHAR(250)";
    37      protected String subscriptionIdDataType = "VARCHAR(250)";
    38      protected String sequenceDataType = "INTEGER";
    39      protected String stringIdDataType = "VARCHAR(250)";
    40
    41
    42
    43      public String [] getCreateSchemaStatments() {
    44          return new String[]{
    45              "CREATE TABLE "+tablePrefix+messageTableName+"("
    46              			   +"ID "+sequenceDataType
    47              			   +", CONTAINER "+containerNameDataType
    48              			   +", MSGID "+msgIdDataType
    49              			   +", MSG "+binaryDataType
    50              			   +", PRIMARY KEY ( ID ) )",
    51              "CREATE INDEX "+tablePrefix+messageTableName+"_MIDX ON "+tablePrefix+messageTableName+" (MSGID)",
    52              "CREATE INDEX "+tablePrefix+messageTableName+"_CIDX ON "+tablePrefix+messageTableName+" (CONTAINER)",
    53
    54              "CREATE TABLE "+tablePrefix+txTableName+"("
    55              			   +"XID "+xidDataType
    56              			   +", TX "+binaryDataType
    57              			   +", PRIMARY KEY ( XID ))",
    58
    59              "CREATE TABLE "+tablePrefix+durableSubAcksTableName+"("
    60                             +"SUB "+subscriptionIdDataType
    61                             +", CONTAINER "+containerNameDataType
    62                             +", LAST_ACKED_ID "+sequenceDataType
    63              			   +", SE_ID INTEGER"
    64              			   +", SE_CLIENT_ID "+stringIdDataType
    65              			   +", SE_CONSUMER_NAME "+stringIdDataType
    66              			   +", SE_SELECTOR "+stringIdDataType
    67              			   +", PRIMARY KEY ( SUB ))",
    68              "CREATE INDEX "+tablePrefix+durableSubAcksTableName+"_CIDX ON "+tablePrefix+durableSubAcksTableName+" (CONTAINER)",
    69          };
    70      }
    71
    72      public String [] getDropSchemaStatments() {
    73          return new String[]{
    74              "DROP TABLE "+tablePrefix+durableSubAcksTableName+"",
    75              "DROP TABLE "+tablePrefix+messageTableName+"",
    76              "DROP TABLE "+tablePrefix+txTableName+""
    77          };
    78      }
    79
    80      public String getAddMessageStatment() {
    81          return "INSERT INTO "+tablePrefix+messageTableName+"(ID, CONTAINER, MSGID, MSG) VALUES (?, ?, ?, ?)";
    82      }
    83      public String getUpdateMessageStatment() {
    84          return "UPDATE "+tablePrefix+messageTableName+" SET MSG=? WHERE ID=?";
    85      }
    86      public String getRemoveMessageStatment() {
    87          return "DELETE FROM "+tablePrefix+messageTableName+" WHERE ID=?";
    88      }
    89      public String getFindMessageSequenceIdStatment() {
    90          return "SELECT ID FROM "+tablePrefix+messageTableName+" WHERE MSGID=?";
    91      }
    92      public String getFindMessageStatment() {
    93          return "SELECT MSG FROM "+tablePrefix+messageTableName+" WHERE ID=?";
    94      }
    95      public String getFindAllMessagesStatment() {
    96          return "SELECT ID, MSGID FROM "+tablePrefix+messageTableName+" WHERE CONTAINER=? ORDER BY ID";
    97      }
    98      public String getFindLastSequenceId() {
    99          return "SELECT MAX(ID) FROM "+tablePrefix+messageTableName+"";
    100     }
    101
    102     public String getAddXidStatment() {
    103         return "INSERT INTO "+tablePrefix+txTableName+"(XID, TX) VALUES (?, ?)";
    104     }
    105     public String getUpdateXidStatment() {
    106         return "UPDATE "+tablePrefix+txTableName+" SET TX=? WHERE XID=?";
    107     }
    108     public String getRemoveXidStatment() {
    109         return "DELETE FROM "+tablePrefix+txTableName+" WHERE XID=?";
    110     }
    111     public String getFindXidStatment() {
    112         return "SELECT TX FROM "+tablePrefix+txTableName+" WHERE XID=?";
    113     }
    114     public String getFindAllXidStatment() {
    115         return "SELECT XID FROM "+tablePrefix+txTableName+"";
    116     }
    117     public String getFindAllTxStatment() {
    118         return "SELECT XID, TX FROM "+tablePrefix+txTableName+"";
    119     }
    120
    121     public String getCreateDurableSubStatment() {
    122         return "INSERT INTO "+tablePrefix+durableSubAcksTableName
    123         	   +"(SE_ID, SE_CLIENT_ID, SE_CONSUMER_NAME, SE_SELECTOR, SUB, CONTAINER, LAST_ACKED_ID) "
    124          	   +"VALUES (?, ?, ?, ?, ?, ?, ?)";
    125     }
    126
    127     public String getUpdateDurableSubStatment() {
    128         return "UPDATE "+tablePrefix+durableSubAcksTableName
    129                +" SET SE_ID=?, SE_CLIENT_ID=?, SE_CONSUMER_NAME=?, SE_SELECTOR=? WHERE SUB=? AND CONTAINER=?";
    130     }
    131
    132     public String getFindDurableSubStatment() {
    133         return "SELECT SE_ID, SE_CLIENT_ID, SE_CONSUMER_NAME, SE_SELECTOR, CONTAINER=? "+tablePrefix+durableSubAcksTableName
    134 				+" WHERE SUB=? AND CONTAINER=?";
    135     }
    136
    137     public String getUpdateLastAckOfDurableSub() {
    138         return "UPDATE "+tablePrefix+durableSubAcksTableName
    139 				+" SET LAST_ACKED_ID=? WHERE SUB=? AND CONTAINER=?";
    140     }
    141
    142     public String getFindAllDurableSubMessagesStatment() {
    143         return "SELECT M.ID, M.MSGID FROM "
    144 		        +tablePrefix+messageTableName+" M, "
    145 			    +tablePrefix+durableSubAcksTableName +" D "
    146 		        +" WHERE D.CONTAINER=? AND D.SUB=? "
    147 				+" AND M.CONTAINER=D.CONTAINER AND M.ID > D.LAST_ACKED_ID"
    148 				+" ORDER BY M.ID";
    149     }
    150
    151     /***
    152      * @return Returns the containerNameDataType.
    153      */
    154     public String getContainerNameDataType() {
    155         return containerNameDataType;
    156     }
    157     /***
    158      * @param containerNameDataType The containerNameDataType to set.
    159      */
    160     public void setContainerNameDataType(String containerNameDataType) {
    161         this.containerNameDataType = containerNameDataType;
    162     }
    163     /***
    164      * @return Returns the messageDataType.
    165      */
    166     public String getBinaryDataType() {
    167         return binaryDataType;
    168     }
    169     /***
    170      * @param messageDataType The messageDataType to set.
    171      */
    172     public void setBinaryDataType(String messageDataType) {
    173         this.binaryDataType = messageDataType;
    174     }
    175     /***
    176      * @return Returns the messageTableName.
    177      */
    178     public String getMessageTableName() {
    179         return messageTableName;
    180     }
    181     /***
    182      * @param messageTableName The messageTableName to set.
    183      */
    184     public void setMessageTableName(String messageTableName) {
    185         this.messageTableName = messageTableName;
    186     }
    187     /***
    188      * @return Returns the msgIdDataType.
    189      */
    190     public String getMsgIdDataType() {
    191         return msgIdDataType;
    192     }
    193     /***
    194      * @param msgIdDataType The msgIdDataType to set.
    195      */
    196     public void setMsgIdDataType(String msgIdDataType) {
    197         this.msgIdDataType = msgIdDataType;
    198     }
    199     /***
    200      * @return Returns the sequenceDataType.
    201      */
    202     public String getSequenceDataType() {
    203         return sequenceDataType;
    204     }
    205     /***
    206      * @param sequenceDataType The sequenceDataType to set.
    207      */
    208     public void setSequenceDataType(String sequenceDataType) {
    209         this.sequenceDataType = sequenceDataType;
    210     }
    211     /***
    212      * @return Returns the tablePrefix.
    213      */
    214     public String getTablePrefix() {
    215         return tablePrefix;
    216     }
    217     /***
    218      * @param tablePrefix The tablePrefix to set.
    219      */
    220     public void setTablePrefix(String tablePrefix) {
    221         this.tablePrefix = tablePrefix;
    222     }
    223     /***
    224      * @return Returns the txTableName.
    225      */
    226     public String getTxTableName() {
    227         return txTableName;
    228     }
    229     /***
    230      * @param txTableName The txTableName to set.
    231      */
    232     public void setTxTableName(String txTableName) {
    233         this.txTableName = txTableName;
    234     }
    235     /***
    236      * @return Returns the xidDataType.
    237      */
    238     public String getXidDataType() {
    239         return xidDataType;
    240     }
    241     /***
    242      * @param xidDataType The xidDataType to set.
    243      */
    244     public void setXidDataType(String xidDataType) {
    245         this.xidDataType = xidDataType;
    246     }
    247     /***
    248      * @return Returns the durableSubAcksTableName.
    249      */
    250     public String getDurableSubAcksTableName() {
    251         return durableSubAcksTableName;
    252     }
    253     /***
    254      * @param durableSubAcksTableName The durableSubAcksTableName to set.
    255      */
    256     public void setDurableSubAcksTableName(String durableSubAcksTableName) {
    257         this.durableSubAcksTableName = durableSubAcksTableName;
    258     }
    259     /***
    260      * @return Returns the subscriptionIdDataType.
    261      */
    262     public String getSubscriptionIdDataType() {
    263         return subscriptionIdDataType;
    264     }
    265     /***
    266      * @param subscriptionIdDataType The subscriptionIdDataType to set.
    267      */
    268     public void setSubscriptionIdDataType(String subscriptionIdDataType) {
    269         this.subscriptionIdDataType = subscriptionIdDataType;
    270     }
    271 }