KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jdbc > Statements


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 package org.apache.servicemix.jdbc;
18
19 /**
20  * @version $Revision: 1.4 $
21  *
22  * @org.apache.xbean.XBean element="statements"
23  *
24  */

25 public class Statements {
26
27     private String JavaDoc tablePrefix = "";
28     protected String JavaDoc storeTableName = "SM_STORE";
29
30     protected String JavaDoc binaryDataType = "BLOB";
31     protected String JavaDoc idDataType = "VARCHAR(48)";
32     private String JavaDoc storeDataStatement;
33     private String JavaDoc updateDataStatement;
34     private String JavaDoc removeDataStatement;
35     private String JavaDoc findDataStatement;
36     private String JavaDoc findAllIdsStatement;
37     private String JavaDoc findAllDataStatement;
38     private String JavaDoc countStatement;
39     private String JavaDoc[] createSchemaStatements;
40     private String JavaDoc[] dropSchemaStatements;
41
42     public String JavaDoc[] getCreateSchemaStatements() {
43         if (createSchemaStatements == null) {
44             createSchemaStatements = new String JavaDoc[] {
45                     "CREATE TABLE " + getFullStoreTableName() + "(" + "ID " + idDataType + " NOT NULL"
46                             + ", DATA " + binaryDataType
47                             + ", PRIMARY KEY ( ID ) )",
48             };
49         }
50         return createSchemaStatements;
51     }
52
53     public String JavaDoc[] getDropSchemaStatements() {
54         if (dropSchemaStatements == null) {
55             dropSchemaStatements = new String JavaDoc[] {
56                     "DROP TABLE " + getFullStoreTableName() + "",
57             };
58         }
59         return dropSchemaStatements;
60     }
61
62     public String JavaDoc getStoreDataStatement() {
63         if (storeDataStatement == null) {
64             storeDataStatement = "INSERT INTO " + getFullStoreTableName()
65                     + "(ID, DATA) VALUES (?, ?)";
66         }
67         return storeDataStatement;
68     }
69
70     public String JavaDoc getUpdateDataStatement() {
71         if (updateDataStatement == null) {
72             updateDataStatement = "UPDATE " + getFullStoreTableName() + " SET DATA=? WHERE ID=?";
73         }
74         return updateDataStatement;
75     }
76
77     public String JavaDoc getRemoveDataStatement() {
78         if (removeDataStatement == null) {
79             removeDataStatement = "DELETE FROM " + getFullStoreTableName() + " WHERE ID=?";
80         }
81         return removeDataStatement;
82     }
83
84     public String JavaDoc getFindDataStatement() {
85         if (findDataStatement == null) {
86             findDataStatement = "SELECT DATA FROM " + getFullStoreTableName() + " WHERE ID=?";
87         }
88         return findDataStatement;
89     }
90
91     public String JavaDoc getFindAllIdsStatement() {
92         if (findAllIdsStatement == null) {
93             findAllIdsStatement = "SELECT ID FROM " + getFullStoreTableName()
94                     + " ORDER BY ID";
95         }
96         return findAllIdsStatement;
97     }
98
99     public String JavaDoc getFindAllDataStatement() {
100         if (findAllDataStatement == null) {
101             findAllDataStatement = "SELECT ID, DATA FROM " + getFullStoreTableName()
102                     + " WHERE ORDER BY ID";
103         }
104         return findAllDataStatement;
105     }
106
107     public String JavaDoc getCountStatement() {
108         if (countStatement == null) {
109             countStatement = "SELECT COUNT(ID) FROM " + getFullStoreTableName();
110         }
111         return countStatement;
112     }
113
114     public String JavaDoc getFullStoreTableName() {
115         return getTablePrefix() + getStoreTableName();
116     }
117
118     /**
119      * @return Returns the messageDataType.
120      */

121     public String JavaDoc getBinaryDataType() {
122         return binaryDataType;
123     }
124
125     /**
126      * @param messageDataType
127      * The messageDataType to set.
128      */

129     public void setBinaryDataType(String JavaDoc messageDataType) {
130         this.binaryDataType = messageDataType;
131     }
132
133     /**
134      * @return Returns the storeTableName.
135      */

136     public String JavaDoc getStoreTableName() {
137         return storeTableName;
138     }
139
140     /**
141      * @param storeTableName
142      * The storeTableName to set.
143      */

144     public void setStoreTableName(String JavaDoc storeTableName) {
145         this.storeTableName = storeTableName;
146     }
147
148     /**
149      * @return Returns the idDataType.
150      */

151     public String JavaDoc getIdDataType() {
152         return idDataType;
153     }
154
155     /**
156      * @param idDataType
157      * The idDataType to set.
158      */

159     public void setIdDataType(String JavaDoc msgIdDataType) {
160         this.idDataType = msgIdDataType;
161     }
162
163     /**
164      * @return Returns the tablePrefix.
165      */

166     public String JavaDoc getTablePrefix() {
167         return tablePrefix;
168     }
169
170     /**
171      * @param tablePrefix
172      * The tablePrefix to set.
173      */

174     public void setTablePrefix(String JavaDoc tablePrefix) {
175         this.tablePrefix = tablePrefix;
176     }
177
178     public void setStoreDataStatement(String JavaDoc addMessageStatment) {
179         this.storeDataStatement = addMessageStatment;
180     }
181
182     public void setCreateSchemaStatements(String JavaDoc[] createSchemaStatments) {
183         this.createSchemaStatements = createSchemaStatments;
184     }
185
186     public void setDropSchemaStatements(String JavaDoc[] dropSchemaStatments) {
187         this.dropSchemaStatements = dropSchemaStatments;
188     }
189
190     public void setFindAllDataStatement(String JavaDoc findAllMessagesStatment) {
191         this.findAllDataStatement = findAllMessagesStatment;
192     }
193
194     public void setFindDataStatement(String JavaDoc findMessageStatment) {
195         this.findDataStatement = findMessageStatment;
196     }
197
198     public void setRemoveDataStatement(String JavaDoc removeMessageStatment) {
199         this.removeDataStatement = removeMessageStatment;
200     }
201
202     public void setUpdateDataStatement(String JavaDoc updateMessageStatment) {
203         this.updateDataStatement = updateMessageStatment;
204     }
205
206     public void setFindAllIdsStatement(String JavaDoc findAllIdsStatement) {
207         this.findAllIdsStatement = findAllIdsStatement;
208     }
209
210     public void setCountStatement(String JavaDoc getCountStatement) {
211         this.countStatement = getCountStatement;
212     }
213
214 }
Popular Tags