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 ServiceDescTable
33 {
34
35 private static Log log = LogFactory.getLog(ServiceDescTable.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("SERVICE_DESCR (");
52 sql.append("SERVICE_KEY,");
53 sql.append("SERVICE_DESCR_ID,");
54 sql.append("LANG_CODE,");
55 sql.append("DESCR) ");
56 sql.append("VALUES (?,?,?,?)");
57 insertSQL = sql.toString();
58
59
60 sql = new StringBuffer(200);
61 sql.append("SELECT ");
62 sql.append("LANG_CODE,");
63 sql.append("DESCR, ");
64 sql.append("SERVICE_DESCR_ID ");
65 sql.append("FROM ").append(tablePrefix).append("SERVICE_DESCR ");
66 sql.append("WHERE SERVICE_KEY=? ");
67 sql.append("ORDER BY SERVICE_DESCR_ID");
68 selectSQL = sql.toString();
69
70
71 sql = new StringBuffer(100);
72 sql.append("DELETE FROM ").append(tablePrefix).append("SERVICE_DESCR ");
73 sql.append("WHERE SERVICE_KEY=?");
74 deleteSQL = sql.toString();
75 }
76
77 /***
78 * Insert new row into the SERVICE_DESCR table.
79 *
80 * @param serviceKey String to the BusinessEntity object that owns the Description to be inserted
81 * @param descList Vector of Description objects holding values to be inserted
82 * @param connection JDBC connection
83 * @throws java.sql.SQLException
84 */
85 public static void insert(
86 String serviceKey,
87 Vector descList,
88 Connection connection)
89 throws java.sql.SQLException
90 {
91 if ((descList == null) || (descList.size() == 0))
92 return;
93
94 PreparedStatement statement = null;
95
96 try
97 {
98 statement = connection.prepareStatement(insertSQL);
99 statement.setString(1, serviceKey.toString());
100
101 int listSize = descList.size();
102 for (int descID = 0; descID < listSize; descID++)
103 {
104 Description desc = (Description) descList.elementAt(descID);
105
106 statement.setInt(2, descID);
107 statement.setString(3, desc.getLanguageCode());
108 statement.setString(4, desc.getValue());
109
110 if (log.isDebugEnabled()) {
111 log.debug(
112 "insert into " + tablePrefix + "SERVICE_DESCR table:\n\n\t"
113 + insertSQL
114 + "\n\t SERVICE_KEY="
115 + serviceKey.toString()
116 + "\n\t SERVICE_DESCR_ID="
117 + descID
118 + "\n\t LANG_CODE="
119 + desc.getLanguageCode()
120 + "\n\t DESCR="
121 + desc.getValue()
122 + "\n");
123 }
124
125 statement.executeUpdate();
126 }
127 }
128 finally
129 {
130 try
131 {
132 statement.close();
133 }
134 catch (Exception e)
135 {
136 }
137 }
138 }
139
140 /***
141 * Select all rows from the SERVICE_DESCR table for a given BusinessKey.
142 *
143 * @param serviceKey String
144 * @param connection JDBC connection
145 * @throws java.sql.SQLException
146 */
147 public static Vector select(String serviceKey, Connection connection)
148 throws java.sql.SQLException
149 {
150 Vector descList = new Vector();
151 PreparedStatement statement = null;
152 ResultSet resultSet = null;
153
154 try
155 {
156
157 statement = connection.prepareStatement(selectSQL);
158 statement.setString(1, serviceKey.toString());
159
160 if (log.isDebugEnabled()) {
161 log.debug(
162 "select from " + tablePrefix + "SERVICE_DESCR table:\n\n\t"
163 + selectSQL
164 + "\n\t SERVICE_KEY="
165 + serviceKey.toString()
166 + "\n");
167 }
168
169
170 resultSet = statement.executeQuery();
171 while (resultSet.next())
172 {
173 Description desc = new Description();
174 desc.setLanguageCode(resultSet.getString(1));
175 desc.setValue(resultSet.getString(2));
176 descList.add(desc);
177 }
178
179 return descList;
180 }
181 finally
182 {
183 try
184 {
185 resultSet.close();
186 statement.close();
187 }
188 catch (Exception e)
189 {
190 }
191 }
192 }
193
194 /***
195 * Delete multiple rows from the SERVICE_DESCR table that are assigned to the
196 * BusinessKey specified.
197 *
198 * @param serviceKey String
199 * @param connection JDBC connection
200 * @throws java.sql.SQLException
201 */
202 public static void delete(String serviceKey, Connection connection)
203 throws java.sql.SQLException
204 {
205 PreparedStatement statement = null;
206
207 try
208 {
209
210 statement = connection.prepareStatement(deleteSQL);
211 statement.setString(1, serviceKey.toString());
212
213 if (log.isDebugEnabled()) {
214 log.debug(
215 "delete from SERVICE_DESCR table:\n\n\t"
216 + deleteSQL
217 + "\n\t SERVICE_KEY="
218 + serviceKey.toString()
219 + "\n");
220 }
221
222
223 statement.executeUpdate();
224 }
225 finally
226 {
227 try
228 {
229 statement.close();
230 }
231 catch (Exception e)
232 {
233 }
234 }
235 }
236 }