KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > datastore > jdbc > InstanceDetailsDocDescTable


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.juddi.datastore.jdbc;
17
18 import java.sql.Connection JavaDoc;
19 import java.sql.PreparedStatement JavaDoc;
20 import java.sql.ResultSet JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.juddi.datatype.Description;
26
27 /**
28  * @author Steve Viens (sviens@apache.org)
29  */

30 class InstanceDetailsDocDescTable
31 {
32   // private reference to the jUDDI logger
33
private static Log log = LogFactory.getLog(InstanceDetailsDocDescTable.class);
34
35   static String JavaDoc insertSQL = null;
36   static String JavaDoc selectSQL = null;
37   static String JavaDoc deleteSQL = null;
38
39   static {
40     // buffer used to build SQL statements
41
StringBuffer JavaDoc sql = null;
42
43     // build insertSQL
44
sql = new StringBuffer JavaDoc(150);
45     sql.append("INSERT INTO INSTANCE_DETAILS_DOC_DESCR (");
46     sql.append("BINDING_KEY,");
47     sql.append("TMODEL_INSTANCE_INFO_ID,");
48     sql.append("INSTANCE_DETAILS_DOC_DESCR_ID,");
49     sql.append("LANG_CODE,");
50     sql.append("DESCR) ");
51     sql.append("VALUES (?,?,?,?,?)");
52     insertSQL = sql.toString();
53
54     // build selectSQL
55
sql = new StringBuffer JavaDoc(200);
56     sql.append("SELECT ");
57     sql.append("LANG_CODE,");
58     sql.append("DESCR, ");
59     sql.append("INSTANCE_DETAILS_DOC_DESCR_ID ");
60     sql.append("FROM INSTANCE_DETAILS_DOC_DESCR ");
61     sql.append("WHERE BINDING_KEY=? ");
62     sql.append("AND TMODEL_INSTANCE_INFO_ID=? ");
63     sql.append("ORDER BY INSTANCE_DETAILS_DOC_DESCR_ID");
64     selectSQL = sql.toString();
65
66     // build deleteSQL
67
sql = new StringBuffer JavaDoc(100);
68     sql.append("DELETE FROM INSTANCE_DETAILS_DOC_DESCR ");
69     sql.append("WHERE BINDING_KEY=?");
70     deleteSQL = sql.toString();
71   }
72
73   /**
74    * Insert new row into the INSTANCE_DETAILS_DOC_DESCR table.
75    *
76    * @param bindingKey BindingKey to the BindingTemplate object
77    * @param tModelInstanceInfoID int
78    * @param descList Vector of Description objects holding values to be inserted
79    * @param connection JDBC connection
80    * @throws java.sql.SQLException
81    */

82   public static void insert(
83     String JavaDoc bindingKey,
84     int tModelInstanceInfoID,
85     Vector JavaDoc descList,
86     Connection JavaDoc connection)
87     throws java.sql.SQLException JavaDoc
88   {
89     if ((descList == null) || (descList.size() == 0))
90       return; // everything is valid but no elements to insert
91

92     PreparedStatement JavaDoc statement = null;
93
94     try
95     {
96       statement = connection.prepareStatement(insertSQL);
97       statement.setString(1, bindingKey.toString());
98       statement.setInt(2, tModelInstanceInfoID);
99
100       int listSize = descList.size();
101       for (int descID = 0; descID < listSize; descID++)
102       {
103         Description desc = (Description) descList.elementAt(descID);
104
105         // okay, set the values to be inserted
106
statement.setInt(3, descID); // Sequence Number aka Desc ID
107
statement.setString(4, desc.getLanguageCode());
108         statement.setString(5, desc.getValue());
109
110         log.debug(
111           "insert into INSTANCE_DETAILS_DOC_DESCR table:\n\n\t"
112             + insertSQL
113             + "\n\t BINDING_KEY="
114             + bindingKey.toString()
115             + "\n\t TMODEL_INSTANCE_INFO_ID="
116             + tModelInstanceInfoID
117             + "\n\t INSTANCE_DETAILS_DOC_DESCR_ID="
118             + descID
119             + "\n\t LANG_CODE="
120             + desc.getLanguageCode()
121             + "\n\t DESCR="
122             + desc.getValue()
123             + "\n");
124
125         statement.executeUpdate();
126       }
127     }
128     finally
129     {
130       try
131       {
132         statement.close();
133       }
134       catch (Exception JavaDoc e)
135       { /* ignored */
136       }
137     }
138   }
139
140   /**
141    * Select all rows from the TMODEL_INST_INFO table for a given BusinessKey.
142    *
143    * @param bindingKey BindingKey
144    * @param tModelInstanceInfoID ID (sequence number) of the parent TModelInstanceInfo object
145    * @param connection JDBC connection
146    * @throws java.sql.SQLException
147    */

148   public static Vector JavaDoc select(
149     String JavaDoc bindingKey,
150     int tModelInstanceInfoID,
151     Connection JavaDoc connection)
152     throws java.sql.SQLException JavaDoc
153   {
154     Vector JavaDoc descList = new Vector JavaDoc();
155     PreparedStatement JavaDoc statement = null;
156     ResultSet JavaDoc resultSet = null;
157
158     try
159     {
160       // create a statement to query with
161
statement = connection.prepareStatement(selectSQL);
162       statement.setString(1, bindingKey.toString());
163       statement.setInt(2, tModelInstanceInfoID);
164
165       log.debug(
166         "select from INSTANCE_DETAILS_DOC_DESCR table:\n\n\t"
167           + selectSQL
168           + "\n\t BINDING_KEY="
169           + bindingKey.toString()
170           + "\n\t TMODEL_INSTANCE_INFO_ID="
171           + tModelInstanceInfoID
172           + "\n");
173
174       // execute the statement
175
resultSet = statement.executeQuery();
176       while (resultSet.next())
177       {
178         Description desc = new Description();
179         desc.setLanguageCode(resultSet.getString(1));//("LANG_CODE"));
180
desc.setValue(resultSet.getString(1));//("DESCR"));
181
descList.add(desc);
182       }
183
184       return descList;
185     }
186     finally
187     {
188       try
189       {
190         resultSet.close();
191         statement.close();
192       }
193       catch (Exception JavaDoc e)
194       { /* ignored */
195       }
196     }
197   }
198
199   /**
200    * Delete multiple rows from the INSTANCE_DETAILS_DOC_DESCR table
201    * that are assigned to the BindingKey specified.
202    *
203    * @param bindingKey BindingKey
204    * @param connection JDBC connection
205    * @throws java.sql.SQLException
206    */

207   public static void delete(String JavaDoc bindingKey, Connection JavaDoc connection)
208     throws java.sql.SQLException JavaDoc
209   {
210     PreparedStatement JavaDoc statement = null;
211
212     try
213     {
214       // prepare the delete
215
statement = connection.prepareStatement(deleteSQL);
216       statement.setString(1, bindingKey.toString());
217
218       log.debug(
219         "delete from INSTANCE_DETAILS_DOC_DESCR table:\n\n\t"
220           + deleteSQL
221           + "\n\t BINDING_KEY="
222           + bindingKey.toString()
223           + "\n");
224
225       // execute
226
statement.executeUpdate();
227     }
228     finally
229     {
230       try
231       {
232         statement.close();
233       }
234       catch (Exception JavaDoc e)
235       { /* ignored */
236       }
237     }
238   }
239 }
240
Popular Tags