1 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 27 30 class InstanceDetailsDescTable 31 { 32 private static Log log = LogFactory.getLog(InstanceDetailsDescTable.class); 34 35 static String insertSQL = null; 36 static String selectSQL = null; 37 static String deleteSQL = null; 38 39 static { 40 StringBuffer sql = null; 42 43 sql = new StringBuffer (150); 45 sql.append("INSERT INTO INSTANCE_DETAILS_DESCR ("); 46 sql.append("BINDING_KEY,"); 47 sql.append("TMODEL_INSTANCE_INFO_ID,"); 48 sql.append("INSTANCE_DETAILS_DESCR_ID,"); 49 sql.append("LANG_CODE,"); 50 sql.append("DESCR) "); 51 sql.append("VALUES (?,?,?,?,?)"); 52 insertSQL = sql.toString(); 53 54 sql = new StringBuffer (200); 56 sql.append("SELECT "); 57 sql.append("LANG_CODE,"); 58 sql.append("DESCR, "); 59 sql.append("INSTANCE_DETAILS_DESCR_ID "); 60 sql.append("FROM INSTANCE_DETAILS_DESCR "); 61 sql.append("WHERE BINDING_KEY=? "); 62 sql.append("AND TMODEL_INSTANCE_INFO_ID=? "); 63 sql.append("ORDER BY INSTANCE_DETAILS_DESCR_ID"); 64 selectSQL = sql.toString(); 65 66 sql = new StringBuffer (100); 68 sql.append("DELETE FROM INSTANCE_DETAILS_DESCR "); 69 sql.append("WHERE BINDING_KEY=?"); 70 deleteSQL = sql.toString(); 71 } 72 73 82 public static void insert( 83 String bindingKey, 84 int tModelInstanceInfoID, 85 Vector descList, 86 Connection connection) 87 throws java.sql.SQLException 88 { 89 if ((descList == null) || (descList.size() == 0)) 90 return; 92 PreparedStatement 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 statement.setInt(3, descID); statement.setString(4, desc.getLanguageCode()); 108 statement.setString(5, desc.getValue()); 109 110 log.debug( 111 "insert into INSTANCE_DETAILS_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_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 e) 135 { 136 } 137 } 138 } 139 140 148 public static Vector select( 149 String bindingKey, 150 int tModelInstanceInfoID, 151 Connection connection) 152 throws java.sql.SQLException 153 { 154 Vector descList = new Vector (); 155 PreparedStatement statement = null; 156 ResultSet resultSet = null; 157 158 try 159 { 160 statement = connection.prepareStatement(selectSQL); 162 statement.setString(1, bindingKey.toString()); 163 statement.setInt(2, tModelInstanceInfoID); 164 165 log.debug( 166 "select from INSTANCE_DETAILS_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 resultSet = statement.executeQuery(); 176 while (resultSet.next()) 177 { 178 Description desc = new Description(); 179 desc.setLanguageCode(resultSet.getString(1)); desc.setValue(resultSet.getString(2)); descList.add(desc); 182 desc = null; 183 } 184 185 return descList; 186 } 187 finally 188 { 189 try 190 { 191 resultSet.close(); 192 statement.close(); 193 } 194 catch (Exception e) 195 { 196 } 197 } 198 } 199 200 208 public static void delete(String bindingKey, Connection connection) 209 throws java.sql.SQLException 210 { 211 PreparedStatement statement = null; 212 213 try 214 { 215 statement = connection.prepareStatement(deleteSQL); 217 statement.setString(1, bindingKey.toString()); 218 219 log.debug( 220 "delete from INSTANCE_DETAILS_DESCR table:\n\n\t" 221 + deleteSQL 222 + "\n\t BINDING_KEY=" 223 + bindingKey.toString() 224 + "\n"); 225 226 statement.executeUpdate(); 228 } 229 finally 230 { 231 try 232 { 233 statement.close(); 234 } 235 catch (Exception e) 236 { 237 } 238 } 239 } 240 } 241 | Popular Tags |