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.KeyedReference; 26 27 30 class BusinessCategoryTable 31 { 32 private static Log log = LogFactory.getLog(BusinessCategoryTable.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 BUSINESS_CATEGORY ("); 46 sql.append("BUSINESS_KEY,"); 47 sql.append("CATEGORY_ID,"); 48 sql.append("TMODEL_KEY_REF,"); 49 sql.append("KEY_NAME,"); 50 sql.append("KEY_VALUE) "); 51 sql.append("VALUES (?,?,?,?,?)"); 52 insertSQL = sql.toString(); 53 54 sql = new StringBuffer (200); 56 sql.append("SELECT "); 57 sql.append("TMODEL_KEY_REF,"); 58 sql.append("KEY_NAME,"); 59 sql.append("KEY_VALUE, "); 60 sql.append("CATEGORY_ID "); 61 sql.append("FROM BUSINESS_CATEGORY "); 62 sql.append("WHERE BUSINESS_KEY=? "); 63 sql.append("ORDER BY CATEGORY_ID"); 64 selectSQL = sql.toString(); 65 66 sql = new StringBuffer (100); 68 sql.append("DELETE FROM BUSINESS_CATEGORY "); 69 sql.append("WHERE BUSINESS_KEY=?"); 70 deleteSQL = sql.toString(); 71 } 72 73 81 public static void insert( 82 String businessKey, 83 Vector keyRefs, 84 Connection connection) 85 throws java.sql.SQLException 86 { 87 PreparedStatement statement = null; 88 89 try 90 { 91 statement = connection.prepareStatement(insertSQL); 92 statement.setString(1, businessKey.toString()); 93 94 int listSize = keyRefs.size(); 95 for (int categoryID = 0; categoryID < listSize; categoryID++) 96 { 97 KeyedReference keyRef = (KeyedReference) keyRefs.elementAt(categoryID); 98 99 String tModelKeyValue = null; 101 if (keyRef.getTModelKey() != null) 102 tModelKeyValue = keyRef.getTModelKey().toString(); 103 104 statement.setInt(2, categoryID); 106 statement.setString(3, tModelKeyValue); 107 statement.setString(4, keyRef.getKeyName()); 108 statement.setString(5, keyRef.getKeyValue()); 109 110 log.debug( 111 "insert into BUSINESS_CATEGORY table:\n\n\t" 112 + insertSQL 113 + "\n\t BUSINESS_KEY=" 114 + businessKey.toString() 115 + "\n\t CATEGORY_ID=" 116 + categoryID 117 + "\n\t TMODEL_KEY_REF=" 118 + tModelKeyValue 119 + "\n\t KEY_NAME=" 120 + keyRef.getKeyName() 121 + "\n\t KEY_VALUE=" 122 + keyRef.getKeyValue() 123 + "\n"); 124 125 statement.executeUpdate(); 127 } 128 } 129 finally 130 { 131 try 132 { 133 statement.close(); 134 } 135 catch (Exception e) 136 { 137 } 138 } 139 } 140 141 148 public static Vector select(String businessKey, Connection connection) 149 throws java.sql.SQLException 150 { 151 Vector keyRefList = new Vector (); 152 PreparedStatement statement = null; 153 ResultSet resultSet = null; 154 155 try 156 { 157 statement = connection.prepareStatement(selectSQL); 159 statement.setString(1, businessKey.toString()); 160 161 log.debug( 162 "select from BUSINESS_CATEGORY table:\n\n\t" 163 + selectSQL 164 + "\n\t BUSINESS_KEY=" 165 + businessKey.toString() 166 + "\n"); 167 168 resultSet = statement.executeQuery(); 170 171 KeyedReference keyRef = null; 172 while (resultSet.next()) 173 { 174 keyRef = new KeyedReference(); 175 keyRef.setTModelKey(resultSet.getString(1)); keyRef.setKeyName(resultSet.getString(2)); keyRef.setKeyValue(resultSet.getString(3)); keyRefList.add(keyRef); 179 keyRef = null; 180 } 181 182 return keyRefList; 183 } 184 finally 185 { 186 try 187 { 188 resultSet.close(); 189 statement.close(); 190 } 191 catch (Exception e) 192 { 193 } 194 } 195 } 196 197 205 public static void delete(String businessKey, Connection connection) 206 throws java.sql.SQLException 207 { 208 PreparedStatement statement = null; 209 210 try 211 { 212 statement = connection.prepareStatement(deleteSQL); 214 statement.setString(1, businessKey.toString()); 215 216 log.debug( 217 "delete from BUSINESS_CATEGORY table:\n\n\t" 218 + deleteSQL 219 + "\n\t BUSINESS_KEY=" 220 + businessKey.toString() 221 + "\n"); 222 223 statement.executeUpdate(); 225 } 226 finally 227 { 228 try 229 { 230 statement.close(); 231 } 232 catch (Exception e) 233 { 234 } 235 } 236 } 237 } 238 | Popular Tags |