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 BindingDescTable 31 { 32 private static Log log = LogFactory.getLog(BindingDescTable.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 BINDING_DESCR ("); 46 sql.append("BINDING_KEY,"); 47 sql.append("BINDING_DESCR_ID,"); 48 sql.append("LANG_CODE,"); 49 sql.append("DESCR) "); 50 sql.append("VALUES (?,?,?,?)"); 51 insertSQL = sql.toString(); 52 53 sql = new StringBuffer (200); 55 sql.append("SELECT "); 56 sql.append("LANG_CODE,"); 57 sql.append("DESCR, "); 58 sql.append("BINDING_DESCR_ID "); 59 sql.append("FROM BINDING_DESCR "); 60 sql.append("WHERE BINDING_KEY=? "); 61 sql.append("ORDER BY BINDING_DESCR_ID"); 62 selectSQL = sql.toString(); 63 64 sql = new StringBuffer (100); 66 sql.append("DELETE FROM BINDING_DESCR "); 67 sql.append("WHERE BINDING_KEY=?"); 68 deleteSQL = sql.toString(); 69 } 70 71 79 public static void insert( 80 String bindingKey, 81 Vector descList, 82 Connection connection) 83 throws java.sql.SQLException 84 { 85 if ((descList == null) || (descList.size() == 0)) 86 return; 88 PreparedStatement statement = null; 89 90 try 91 { 92 statement = connection.prepareStatement(insertSQL); 93 statement.setString(1, bindingKey.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 statement.setInt(2, descID); 101 statement.setString(3, desc.getLanguageCode()); 102 statement.setString(4, desc.getValue()); 103 104 log.debug( 105 "insert into BINDING_DESCR table:\n\n\t" 106 + insertSQL 107 + "\n\t BINDING_KEY=" 108 + bindingKey.toString() 109 + "\n\t BINDING_DESCR_ID=" 110 + descID 111 + "\n\t LANG_CODE=" 112 + desc.getLanguageCode() 113 + "\n\t DESCR=" 114 + desc.getValue() 115 + "\n"); 116 117 statement.executeUpdate(); 118 } 119 } 120 finally 121 { 122 try 123 { 124 statement.close(); 125 } 126 catch (Exception e) 127 { 128 } 129 } 130 } 131 132 139 public static Vector select(String bindingKey, Connection connection) 140 throws java.sql.SQLException 141 { 142 Vector descList = new Vector (); 143 PreparedStatement statement = null; 144 ResultSet resultSet = null; 145 146 try 147 { 148 statement = connection.prepareStatement(selectSQL); 150 statement.setString(1, bindingKey.toString()); 151 152 log.debug( 153 "select from BINDING_DESCR table:\n\n\t" 154 + selectSQL 155 + "\n\t BINDING_KEY=" 156 + bindingKey.toString() 157 + "\n"); 158 159 resultSet = statement.executeQuery(); 161 while (resultSet.next()) 162 { 163 Description desc = new Description(); 164 desc.setLanguageCode(resultSet.getString(1)); desc.setValue(resultSet.getString(2)); descList.add(desc); 167 } 168 169 return descList; 170 } 171 finally 172 { 173 try 174 { 175 resultSet.close(); 176 statement.close(); 177 } 178 catch (Exception e) 179 { 180 } 181 } 182 } 183 184 192 public static void delete(String bindingKey, Connection connection) 193 throws java.sql.SQLException 194 { 195 PreparedStatement statement = null; 196 197 try 198 { 199 statement = connection.prepareStatement(deleteSQL); 201 statement.setString(1, bindingKey.toString()); 202 203 log.debug( 204 "delete from BINDING_DESCR table:\n\n\t" 205 + deleteSQL 206 + "\n\t BINDING_KEY=" 207 + bindingKey.toString() 208 + "\n"); 209 210 statement.executeUpdate(); 212 } 213 finally 214 { 215 try 216 { 217 statement.close(); 218 } 219 catch (Exception e) 220 { 221 } 222 } 223 } 224 } 225 | Popular Tags |