1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.datastore.jdbc;
17
18 import java.sql.Connection;
19 import java.sql.PreparedStatement;
20 import java.sql.ResultSet;
21 import java.util.Vector;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.juddi.datatype.Description;
26 import org.apache.juddi.registry.RegistryEngine;
27 import org.apache.juddi.util.Config;
28
29 /***
30 * @author Steve Viens (sviens@apache.org)
31 */
32 class InstanceDetailsDocDescTable
33 {
34
35 private static Log log = LogFactory.getLog(InstanceDetailsDocDescTable.class);
36
37 static String insertSQL = null;
38 static String selectSQL = null;
39 static String deleteSQL = null;
40 static String tablePrefix;
41
42 static
43 {
44 tablePrefix = Config.getStringProperty(
45 RegistryEngine.PROPNAME_TABLE_PREFIX,RegistryEngine.DEFAULT_TABLE_PREFIX);
46
47 StringBuffer sql = null;
48
49
50 sql = new StringBuffer(150);
51 sql.append("INSERT INTO ").append(tablePrefix).append("INSTANCE_DETAILS_DOC_DESCR (");
52 sql.append("BINDING_KEY,");
53 sql.append("TMODEL_INSTANCE_INFO_ID,");
54 sql.append("INSTANCE_DETAILS_DOC_DESCR_ID,");
55 sql.append("LANG_CODE,");
56 sql.append("DESCR) ");
57 sql.append("VALUES (?,?,?,?,?)");
58 insertSQL = sql.toString();
59
60
61 sql = new StringBuffer(200);
62 sql.append("SELECT ");
63 sql.append("LANG_CODE,");
64 sql.append("DESCR, ");
65 sql.append("INSTANCE_DETAILS_DOC_DESCR_ID ");
66 sql.append("FROM ").append(tablePrefix).append("INSTANCE_DETAILS_DOC_DESCR ");
67 sql.append("WHERE BINDING_KEY=? ");
68 sql.append("AND TMODEL_INSTANCE_INFO_ID=? ");
69 sql.append("ORDER BY INSTANCE_DETAILS_DOC_DESCR_ID");
70 selectSQL = sql.toString();
71
72
73 sql = new StringBuffer(100);
74 sql.append("DELETE FROM ").append(tablePrefix).append("INSTANCE_DETAILS_DOC_DESCR ");
75 sql.append("WHERE BINDING_KEY=?");
76 deleteSQL = sql.toString();
77 }
78
79 /***
80 * Insert new row into the INSTANCE_DETAILS_DOC_DESCR table.
81 *
82 * @param bindingKey BindingKey to the BindingTemplate object
83 * @param tModelInstanceInfoID int
84 * @param descList Vector of Description objects holding values to be inserted
85 * @param connection JDBC connection
86 * @throws java.sql.SQLException
87 */
88 public static void insert(
89 String bindingKey,
90 int tModelInstanceInfoID,
91 Vector descList,
92 Connection connection)
93 throws java.sql.SQLException
94 {
95 if ((descList == null) || (descList.size() == 0))
96 return;
97
98 PreparedStatement statement = null;
99
100 try
101 {
102 statement = connection.prepareStatement(insertSQL);
103 statement.setString(1, bindingKey.toString());
104 statement.setInt(2, tModelInstanceInfoID);
105
106 int listSize = descList.size();
107 for (int descID = 0; descID < listSize; descID++)
108 {
109 Description desc = (Description) descList.elementAt(descID);
110
111
112 statement.setInt(3, descID);
113 statement.setString(4, desc.getLanguageCode());
114 statement.setString(5, desc.getValue());
115
116 if (log.isDebugEnabled()) {
117 log.debug(
118 "insert into " + tablePrefix + "INSTANCE_DETAILS_DOC_DESCR table:\n\n\t"
119 + insertSQL
120 + "\n\t BINDING_KEY="
121 + bindingKey.toString()
122 + "\n\t TMODEL_INSTANCE_INFO_ID="
123 + tModelInstanceInfoID
124 + "\n\t INSTANCE_DETAILS_DOC_DESCR_ID="
125 + descID
126 + "\n\t LANG_CODE="
127 + desc.getLanguageCode()
128 + "\n\t DESCR="
129 + desc.getValue()
130 + "\n");
131 }
132
133 statement.executeUpdate();
134 }
135 }
136 finally
137 {
138 try
139 {
140 statement.close();
141 }
142 catch (Exception e)
143 {
144 }
145 }
146 }
147
148 /***
149 * Select all rows from the TMODEL_INST_INFO table for a given BusinessKey.
150 *
151 * @param bindingKey BindingKey
152 * @param tModelInstanceInfoID ID (sequence number) of the parent TModelInstanceInfo object
153 * @param connection JDBC connection
154 * @throws java.sql.SQLException
155 */
156 public static Vector select(
157 String bindingKey,
158 int tModelInstanceInfoID,
159 Connection connection)
160 throws java.sql.SQLException
161 {
162 Vector descList = new Vector();
163 PreparedStatement statement = null;
164 ResultSet resultSet = null;
165
166 try
167 {
168
169 statement = connection.prepareStatement(selectSQL);
170 statement.setString(1, bindingKey.toString());
171 statement.setInt(2, tModelInstanceInfoID);
172
173 if (log.isDebugEnabled()) {
174 log.debug(
175 "select from " + tablePrefix + "INSTANCE_DETAILS_DOC_DESCR table:\n\n\t"
176 + selectSQL
177 + "\n\t BINDING_KEY="
178 + bindingKey.toString()
179 + "\n\t TMODEL_INSTANCE_INFO_ID="
180 + tModelInstanceInfoID
181 + "\n");
182 }
183
184
185 resultSet = statement.executeQuery();
186 while (resultSet.next())
187 {
188 Description desc = new Description();
189 desc.setLanguageCode(resultSet.getString(1));
190 desc.setValue(resultSet.getString(1));
191 descList.add(desc);
192 }
193
194 return descList;
195 }
196 finally
197 {
198 try
199 {
200 resultSet.close();
201 statement.close();
202 }
203 catch (Exception e)
204 {
205 }
206 }
207 }
208
209 /***
210 * Delete multiple rows from the INSTANCE_DETAILS_DOC_DESCR table
211 * that are assigned to the BindingKey specified.
212 *
213 * @param bindingKey BindingKey
214 * @param connection JDBC connection
215 * @throws java.sql.SQLException
216 */
217 public static void delete(String bindingKey, Connection connection)
218 throws java.sql.SQLException
219 {
220 PreparedStatement statement = null;
221
222 try
223 {
224
225 statement = connection.prepareStatement(deleteSQL);
226 statement.setString(1, bindingKey.toString());
227
228 if (log.isDebugEnabled()) {
229 log.debug(
230 "delete from " + tablePrefix + "INSTANCE_DETAILS_DOC_DESCR table:\n\n\t"
231 + deleteSQL
232 + "\n\t BINDING_KEY="
233 + bindingKey.toString()
234 + "\n");
235 }
236
237
238 statement.executeUpdate();
239 }
240 finally
241 {
242 try
243 {
244 statement.close();
245 }
246 catch (Exception e)
247 {
248 }
249 }
250 }
251 }