KickJava   Java API By Example, From Geeks To Geeks.

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


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 TModelInstanceInfoDescTable
31 {
32   // private reference to the jUDDI logger
33
private static Log log = LogFactory.getLog(TModelInstanceInfoDescTable.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 TMODEL_INSTANCE_INFO_DESCR (");
46     sql.append("BINDING_KEY,");
47     sql.append("TMODEL_INSTANCE_INFO_ID,");
48     sql.append("TMODEL_INSTANCE_INFO_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("TMODEL_INSTANCE_INFO_DESCR_ID ");
60     sql.append("FROM TMODEL_INSTANCE_INFO_DESCR ");
61     sql.append("WHERE BINDING_KEY=? ");
62     sql.append("AND TMODEL_INSTANCE_INFO_ID=? ");
63     sql.append("ORDER BY TMODEL_INSTANCE_INFO_DESCR_ID");
64     selectSQL = sql.toString();
65
66     // build deleteSQL
67
sql = new StringBuffer JavaDoc(100);
68     sql.append("DELETE FROM TMODEL_INSTANCE_INFO_DESCR ");
69     sql.append("WHERE BINDING_KEY=?");
70     deleteSQL = sql.toString();
71   }
72
73   /**
74    * Insert new row into the TMODEL_INSTANCE_INFO_DESCR table.
75    *
76    * @param bindingKey String to the BusinessEntity object that owns the Contact to be inserted
77    * @param descList Vector of Description objects holding values to be inserted
78    * @param connection JDBC connection
79    * @throws java.sql.SQLException
80    */

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

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

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

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