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.2 $
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              			   +")",
51              "CREATE TABLE "+tablePrefix+txTableName+"("
52              			   +"XID "+xidDataType
53              			   +", TX "+binaryDataType
54              			   +")",
55              "CREATE TABLE "+tablePrefix+durableSubAcksTableName+"("
56                             +"SUB "+subscriptionIdDataType
57                             +", CONTAINER "+containerNameDataType
58                             +", LAST_ACKED_ID "+sequenceDataType
59              			   +", SE_ID INTEGER"
60              			   +", SE_CLIENT_ID "+stringIdDataType
61              			   +", SE_CONSUMER_NAME "+stringIdDataType
62              			   +", SE_SELECTOR "+stringIdDataType
63              			   +")",
64          };
65      }
66      private int subscriberID;
67      private String clientID;
68      private String consumerName;
69      private String destination;
70      private String selector;
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 getFindMessageStatment() {
90          return "SELECT MSG FROM "+tablePrefix+messageTableName+" WHERE ID=?";
91      }
92      public String getFindAllMessagesStatment() {
93          return "SELECT ID, MSGID FROM "+tablePrefix+messageTableName+" WHERE CONTAINER=? ORDER BY ID";
94      }
95      public String getFindLastSequenceId() {
96          return "SELECT MAX(ID) FROM "+tablePrefix+messageTableName+"";
97      }
98  
99      public String getAddXidStatment() {
100         return "INSERT INTO "+tablePrefix+txTableName+"(XID, TX) VALUES (?, ?)";
101     }
102     public String getUpdateXidStatment() {
103         return "UPDATE "+tablePrefix+txTableName+" SET TX=? WHERE XID=?";
104     }
105     public String getRemoveXidStatment() {
106         return "DELETE FROM "+tablePrefix+txTableName+" WHERE XID=?";
107     }
108     public String getFindXidStatment() {
109         return "SELECT TX FROM "+tablePrefix+txTableName+" WHERE XID=?";
110     }
111     public String getFindAllXidStatment() {
112         return "SELECT XID FROM "+tablePrefix+txTableName+"";
113     }
114     public String getFindAllTxStatment() {
115         return "SELECT XID, TX FROM "+tablePrefix+txTableName+"";
116     }
117 
118     public String getCreateDurableSubStatment() {
119         return "INSERT INTO "+tablePrefix+durableSubAcksTableName
120 				+"(SE_ID, SE_CLIENT_ID, SE_CONSUMER_NAME, SE_SELECTOR, SUB, CONTAINER) VALUES (?, ?, ?, ?, ?, ?)";
121     }
122 
123     public String getUpdateDurableSubStatment() {
124         return "UPDATE "+tablePrefix+durableSubAcksTableName
125 				+" SET SE_ID=?, SE_CLIENT_ID=?, SE_CONSUMER_NAME=?, SE_SELECTOR? WHERE SUB=? AND CONTAINER=?";
126     }
127 
128     public String getFindDurableSubStatment() {
129         return "SELECT SE_ID, SE_CLIENT_ID, SE_CONSUMER_NAME, SE_SELECTOR, CONTAINER=? "+tablePrefix+durableSubAcksTableName
130 				+" WHERE SUB=? AND CONTAINER=?";
131     }
132 
133     public String getUpdateLastAckOfDurableSub() {
134         return "UPDATE "+tablePrefix+durableSubAcksTableName
135 				+" SET LAST_ACKED_ID=? WHERE SUB=? AND CONTAINER=?";
136     }
137 
138     public String getFindAllDurableSubMessagesStatment() {
139         return "SELECT M.ID, M.MSGID FROM "
140 		        +tablePrefix+messageTableName+" M, "
141 			    +tablePrefix+durableSubAcksTableName +" D "
142 		        +" WHERE D.CONTAINER=? AND D.SUB=? " 
143 				+" AND M.CONTAINER=D.CONTAINER AND M.ID > D.LAST_ACKED_ID"
144 				+" ORDER BY M.ID";
145     }
146     
147     /***
148      * @return Returns the containerNameDataType.
149      */
150     public String getContainerNameDataType() {
151         return containerNameDataType;
152     }
153     /***
154      * @param containerNameDataType The containerNameDataType to set.
155      */
156     public void setContainerNameDataType(String containerNameDataType) {
157         this.containerNameDataType = containerNameDataType;
158     }
159     /***
160      * @return Returns the messageDataType.
161      */
162     public String getBinaryDataType() {
163         return binaryDataType;
164     }
165     /***
166      * @param messageDataType The messageDataType to set.
167      */
168     public void setBinaryDataType(String messageDataType) {
169         this.binaryDataType = messageDataType;
170     }
171     /***
172      * @return Returns the messageTableName.
173      */
174     public String getMessageTableName() {
175         return messageTableName;
176     }
177     /***
178      * @param messageTableName The messageTableName to set.
179      */
180     public void setMessageTableName(String messageTableName) {
181         this.messageTableName = messageTableName;
182     }
183     /***
184      * @return Returns the msgIdDataType.
185      */
186     public String getMsgIdDataType() {
187         return msgIdDataType;
188     }
189     /***
190      * @param msgIdDataType The msgIdDataType to set.
191      */
192     public void setMsgIdDataType(String msgIdDataType) {
193         this.msgIdDataType = msgIdDataType;
194     }
195     /***
196      * @return Returns the sequenceDataType.
197      */
198     public String getSequenceDataType() {
199         return sequenceDataType;
200     }
201     /***
202      * @param sequenceDataType The sequenceDataType to set.
203      */
204     public void setSequenceDataType(String sequenceDataType) {
205         this.sequenceDataType = sequenceDataType;
206     }
207     /***
208      * @return Returns the tablePrefix.
209      */
210     public String getTablePrefix() {
211         return tablePrefix;
212     }
213     /***
214      * @param tablePrefix The tablePrefix to set.
215      */
216     public void setTablePrefix(String tablePrefix) {
217         this.tablePrefix = tablePrefix;
218     }
219     /***
220      * @return Returns the txTableName.
221      */
222     public String getTxTableName() {
223         return txTableName;
224     }
225     /***
226      * @param txTableName The txTableName to set.
227      */
228     public void setTxTableName(String txTableName) {
229         this.txTableName = txTableName;
230     }
231     /***
232      * @return Returns the xidDataType.
233      */
234     public String getXidDataType() {
235         return xidDataType;
236     }
237     /***
238      * @param xidDataType The xidDataType to set.
239      */
240     public void setXidDataType(String xidDataType) {
241         this.xidDataType = xidDataType;
242     }
243     /***
244      * @return Returns the durableSubAcksTableName.
245      */
246     public String getDurableSubAcksTableName() {
247         return durableSubAcksTableName;
248     }
249     /***
250      * @param durableSubAcksTableName The durableSubAcksTableName to set.
251      */
252     public void setDurableSubAcksTableName(String durableSubAcksTableName) {
253         this.durableSubAcksTableName = durableSubAcksTableName;
254     }
255     /***
256      * @return Returns the subscriptionIdDataType.
257      */
258     public String getSubscriptionIdDataType() {
259         return subscriptionIdDataType;
260     }
261     /***
262      * @param subscriptionIdDataType The subscriptionIdDataType to set.
263      */
264     public void setSubscriptionIdDataType(String subscriptionIdDataType) {
265         this.subscriptionIdDataType = subscriptionIdDataType;
266     }
267 }