KickJava   Java API By Example, From Geeks To Geeks.

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


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 TModelDocDescTable
31 {
32   // private reference to the jUDDI logger
33
private static Log log = LogFactory.getLog(TModelDocDescTable.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_DOC_DESCR (");
46     sql.append("TMODEL_KEY,");
47     sql.append("TMODEL_DOC_DESCR_ID,");
48     sql.append("LANG_CODE,");
49     sql.append("DESCR) ");
50     sql.append("VALUES (?,?,?,?)");
51     insertSQL = sql.toString();
52
53     // build selectSQL
54
sql = new StringBuffer JavaDoc(200);
55     sql.append("SELECT ");
56     sql.append("LANG_CODE,");
57     sql.append("DESCR, ");
58     sql.append("TMODEL_DOC_DESCR_ID ");
59     sql.append("FROM TMODEL_DOC_DESCR ");
60     sql.append("WHERE TMODEL_KEY=? ");
61     sql.append("ORDER BY TMODEL_DOC_DESCR_ID");
62     selectSQL = sql.toString();
63
64     // build deleteSQL
65
sql = new StringBuffer JavaDoc(100);
66     sql.append("DELETE FROM TMODEL_DOC_DESCR ");
67     sql.append("WHERE TMODEL_KEY=?");
68     deleteSQL = sql.toString();
69   }
70
71   /**
72    * Insert new row into the TMODEL_DOC_DESCR table.
73    *
74    * @param tModelKey TModelKey to the TModel object that owns the info to be inserted
75    * @param descList Vector of Description objects holding values to be inserted
76    * @param connection JDBC connection
77    * @throws java.sql.SQLException
78    */

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

88     PreparedStatement JavaDoc statement = null;
89
90     try
91     {
92       statement = connection.prepareStatement(insertSQL);
93       statement.setString(1, tModelKey.toString());
94
95       int listSize = descList.size();
96       for (int descID = 0; descID < listSize; descID++)
97       {
98         Description desc = (Description) descList.elementAt(descID);
99
100         // okay, set the values to be inserted
101
statement.setInt(2, descID); // Sequence Number aka Description ID
102
statement.setString(3, desc.getLanguageCode());
103         statement.setString(4, desc.getValue());
104
105         log.debug(
106           "insert into TMODEL_DOC_DESCR table:\n\n\t"
107             + insertSQL
108             + "\n\t TMODEL_KEY="
109             + tModelKey.toString()
110             + "\n\t TMODEL_DOC_DESCR_ID="
111             + descID
112             + "\n\t LANG_CODE="
113             + desc.getLanguageCode()
114             + "\n\t DESCR="
115             + desc.getValue()
116             + "\n");
117
118         statement.executeUpdate();
119       }
120     }
121     finally
122     {
123       try
124       {
125         statement.close();
126       }
127       catch (Exception JavaDoc e)
128       { /* ignored */
129       }
130     }
131   }
132
133   /**
134    * Select all rows from the TMODEL_DOC_DESCR table for a given TModelKey.
135    *
136    * @param tModelKey TModelKey
137    * @param connection JDBC connection
138    * @throws java.sql.SQLException
139    */

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

194   public static void delete(String JavaDoc tModelKey, Connection JavaDoc connection)
195     throws java.sql.SQLException JavaDoc
196   {
197     PreparedStatement JavaDoc statement = null;
198
199     try
200     {
201       // prepare the delete
202
statement = connection.prepareStatement(deleteSQL);
203       statement.setString(1, tModelKey.toString());
204
205       log.debug(
206         "delete from TMODEL_DOC_DESCR table:\n\n\t"
207           + deleteSQL
208           + "\n\t TMODEL_KEY="
209           + tModelKey.toString()
210           + "\n");
211
212       // execute
213
statement.executeUpdate();
214     }
215     finally
216     {
217       try
218       {
219         statement.close();
220       }
221       catch (Exception JavaDoc e)
222       { /* ignored */
223       }
224     }
225   }
226 }
227
Popular Tags