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 TModelCategoryTable 31 { 32 private static Log log = LogFactory.getLog(TModelCategoryTable.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 TMODEL_CATEGORY ("); 46 sql.append("TMODEL_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 TMODEL_CATEGORY "); 62 sql.append("WHERE TMODEL_KEY=? "); 63 sql.append("ORDER BY CATEGORY_ID"); 64 selectSQL = sql.toString(); 65 66 sql = new StringBuffer (100); 68 sql.append("DELETE FROM TMODEL_CATEGORY "); 69 sql.append("WHERE TMODEL_KEY=?"); 70 deleteSQL = sql.toString(); 71 } 72 73 81 public static void insert( 82 String tModelKey, 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, tModelKey.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 TMODEL_CATEGORY table:\n\n\t" 112 + insertSQL 113 + "\n\t BUSINESS_KEY=" 114 + tModelKey.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 tModelKey, 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, tModelKey.toString()); 160 161 log.debug( 162 "select from TMODEL_CATEGORY table:\n\n\t" 163 + selectSQL 164 + "\n\t TMODEL_KEY=" 165 + tModelKey.toString() 166 + "\n"); 167 168 resultSet = statement.executeQuery(); 170 while (resultSet.next()) 171 { 172 KeyedReference keyRef = new KeyedReference(); 173 keyRef.setTModelKey(resultSet.getString(1)); keyRef.setKeyName(resultSet.getString(2)); keyRef.setKeyValue(resultSet.getString(3)); keyRefList.add(keyRef); 177 } 178 179 return keyRefList; 180 } 181 finally 182 { 183 try 184 { 185 resultSet.close(); 186 statement.close(); 187 } 188 catch (Exception e) 189 { 190 } 191 } 192 } 193 194 202 public static void delete(String tModelKey, Connection connection) 203 throws java.sql.SQLException 204 { 205 PreparedStatement statement = null; 206 207 try 208 { 209 statement = connection.prepareStatement(deleteSQL); 211 statement.setString(1, tModelKey.toString()); 212 213 log.debug( 214 "delete from TMODEL_CATEGORY table:\n\n\t" 215 + deleteSQL 216 + "\n\t TMODEL_KEY=" 217 + tModelKey.toString() 218 + "\n"); 219 220 statement.executeUpdate(); 222 } 223 finally 224 { 225 try 226 { 227 statement.close(); 228 } 229 catch (Exception e) 230 { 231 } 232 } 233 } 234 } 235 | Popular Tags |