KickJava   Java API By Example, From Geeks To Geeks.

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


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.OverviewDoc;
26 import org.apache.juddi.datatype.binding.InstanceDetails;
27 import org.apache.juddi.datatype.binding.InstanceParms;
28 import org.apache.juddi.datatype.binding.TModelInstanceInfo;
29
30 /**
31  * @author Steve Viens (sviens@apache.org)
32  */

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

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

93     PreparedStatement JavaDoc statement = null;
94
95     try
96     {
97       statement = connection.prepareStatement(insertSQL);
98       statement.setString(1, bindingKey.toString());
99
100       int listSize = infoList.size();
101       for (int infoID = 0; infoID < listSize; infoID++)
102       {
103         String JavaDoc tModelKey = null;
104         String JavaDoc overURL = null;
105         String JavaDoc instParms = null;
106
107         TModelInstanceInfo info =
108           (TModelInstanceInfo) infoList.elementAt(infoID);
109         if (info.getTModelKey() != null)
110           tModelKey = info.getTModelKey().toString();
111
112         InstanceDetails details = info.getInstanceDetails();
113         if (details != null)
114         {
115           if (details.getOverviewDoc() != null)
116             overURL = details.getOverviewDoc().getOverviewURLString();
117
118           if (details.getInstanceParms() != null)
119             instParms = details.getInstanceParms().getValue();
120         }
121
122         // insert sequence number
123
statement.setInt(2, infoID);
124         statement.setString(3, tModelKey);
125         statement.setString(4, overURL);
126         statement.setString(5, instParms);
127
128         log.debug(
129           "insert into TMODEL_INSTANCE_INFO table:\n\n\t"
130             + insertSQL
131             + "\n\t BINDING_KEY="
132             + bindingKey.toString()
133             + "\n\t TMODEL_INSTANCE_INFO_ID="
134             + infoID
135             + "\n\t TMODEL_KEY="
136             + tModelKey
137             + "\n\t OVERVIEW_URL="
138             + overURL
139             + "\n\t INSTANCE_PARMS="
140             + instParms
141             + "\n");
142
143         statement.executeUpdate();
144       }
145     }
146     finally
147     {
148       try
149       {
150         statement.close();
151       }
152       catch (Exception JavaDoc e)
153       { /* ignored */
154       }
155     }
156   }
157
158   /**
159    * Select all rows from the TMODEL_INST_INFO table for a given BusinessKey.
160    *
161    * @param bindingKey String
162    * @param connection JDBC connection
163    * @throws java.sql.SQLException
164    */

165   public static Vector JavaDoc select(String JavaDoc bindingKey, Connection JavaDoc connection)
166     throws java.sql.SQLException JavaDoc
167   {
168     Vector JavaDoc infoList = new Vector JavaDoc();
169     PreparedStatement JavaDoc statement = null;
170     ResultSet JavaDoc resultSet = null;
171
172     try
173     {
174       // create a statement to query with
175
statement = connection.prepareStatement(selectSQL);
176       statement.setString(1, bindingKey.toString());
177
178       log.debug(
179         "select from TMODEL_INSTANCE_INFO table:\n\n\t"
180           + selectSQL
181           + "\n\t BINDING_KEY="
182           + bindingKey.toString()
183           + "\n");
184
185       // execute the statement
186
resultSet = statement.executeQuery();
187
188       while (resultSet.next())
189       {
190         String JavaDoc tModelKey = resultSet.getString(1);//("TMODEL_KEY");
191
String JavaDoc overURL = resultSet.getString(2);//("OVERVIEW_URL");
192
String JavaDoc instParms = resultSet.getString(3);//("INSTANCE_PARMS");
193

194         if (tModelKey != null)
195         {
196           TModelInstanceInfo info = new TModelInstanceInfo();
197           info.setTModelKey(tModelKey);
198
199           OverviewDoc overviewDoc = null;
200           if (overURL != null)
201           {
202             overviewDoc = new OverviewDoc();
203             overviewDoc.setOverviewURL(overURL);
204           }
205
206           InstanceParms instanceParms = null;
207           if (instParms != null)
208           {
209             instanceParms = new InstanceParms();
210             instanceParms.setText(instParms);
211           }
212
213           InstanceDetails details = null;
214           if ((overviewDoc != null) || (instanceParms != null))
215           {
216             details = new InstanceDetails();
217             details.setOverviewDoc(overviewDoc);
218             details.setInstanceParms(instanceParms);
219             info.setInstanceDetails(details);
220           }
221
222           infoList.add(info);
223         }
224       }
225
226       return infoList;
227     }
228     finally
229     {
230       try
231       {
232         resultSet.close();
233         statement.close();
234       }
235       catch (Exception JavaDoc e)
236       { /* ignored */
237       }
238     }
239   }
240
241   /**
242    * Delete multiple rows from the TMODEL_INST_INFO table that are assigned to the
243    * BusinessKey specified.
244    *
245    * @param bindingKey String
246    * @param connection JDBC connection
247    * @throws java.sql.SQLException
248    */

249   public static void delete(String JavaDoc bindingKey, Connection JavaDoc connection)
250     throws java.sql.SQLException JavaDoc
251   {
252     PreparedStatement JavaDoc statement = null;
253
254     try
255     {
256       // prepare the delete
257
statement = connection.prepareStatement(deleteSQL);
258       statement.setString(1, bindingKey.toString());
259
260       log.debug(
261         "delete from TMODEL_INSTANCE_INFO table:\n\n\t"
262           + deleteSQL
263           + "\n\t BINDING_KEY="
264           + bindingKey.toString()
265           + "\n");
266
267       // execute
268
statement.executeUpdate();
269     }
270     finally
271     {
272       try
273       {
274         statement.close();
275       }
276       catch (Exception JavaDoc e)
277       { /* ignored */
278       }
279     }
280   }
281 }
282
Popular Tags