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 TModelIdentifierTable 31 { 32 private static Log log = LogFactory.getLog(TModelIdentifierTable.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_IDENTIFIER ("); 46 sql.append("TMODEL_KEY,"); 47 sql.append("IDENTIFIER_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("IDENTIFIER_ID "); 61 sql.append("FROM TMODEL_IDENTIFIER "); 62 sql.append("WHERE TMODEL_KEY=? "); 63 sql.append("ORDER BY IDENTIFIER_ID"); 64 selectSQL = sql.toString(); 65 66 sql = new StringBuffer (100); 68 sql.append("DELETE FROM TMODEL_IDENTIFIER "); 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 identifierID = 0; identifierID < listSize; identifierID++) 96 { 97 KeyedReference keyRef = 98 (KeyedReference) keyRefs.elementAt(identifierID); 99 100 String tModelKeyValue = null; 102 if (keyRef.getTModelKey() != null) 103 tModelKeyValue = keyRef.getTModelKey().toString(); 104 105 statement.setInt(2, identifierID); 107 statement.setString(3, tModelKeyValue); 108 statement.setString(4, keyRef.getKeyName()); 109 statement.setString(5, keyRef.getKeyValue()); 110 111 log.debug( 112 "insert into TMODEL_IDENTIFIER table:\n\n\t" 113 + insertSQL 114 + "\n\t BUSINESS_KEY=" 115 + tModelKey.toString() 116 + "\n\t IDENTIFIER_ID=" 117 + identifierID 118 + "\n\t TMODEL_KEY_REF=" 119 + tModelKeyValue 120 + "\n\t KEY_NAME=" 121 + keyRef.getKeyName() 122 + "\n\t KEY_VALUE=" 123 + keyRef.getKeyValue() 124 + "\n"); 125 126 statement.executeUpdate(); 128 } 129 } 130 finally 131 { 132 try 133 { 134 statement.close(); 135 } 136 catch (Exception e) 137 { 138 } 139 } 140 } 141 142 149 public static Vector select(String tModelKey, Connection connection) 150 throws java.sql.SQLException 151 { 152 Vector keyRefList = new Vector (); 153 PreparedStatement statement = null; 154 ResultSet resultSet = null; 155 156 try 157 { 158 statement = connection.prepareStatement(selectSQL); 160 statement.setString(1, tModelKey.toString()); 161 162 log.debug( 163 "select from TMODEL_IDENTIFIER table:\n\n\t" 164 + selectSQL 165 + "\n\t TMODEL_KEY=" 166 + tModelKey.toString() 167 + "\n"); 168 169 resultSet = statement.executeQuery(); 171 while (resultSet.next()) 172 { 173 KeyedReference keyRef = new KeyedReference(); 174 keyRef.setTModelKey(resultSet.getString(1)); keyRef.setKeyName(resultSet.getString(2)); keyRef.setKeyValue(resultSet.getString(3)); keyRefList.add(keyRef); 178 } 179 180 return keyRefList; 181 } 182 finally 183 { 184 try 185 { 186 resultSet.close(); 187 statement.close(); 188 } 189 catch (Exception e) 190 { 191 } 192 } 193 } 194 195 203 public static void delete(String tModelKey, Connection connection) 204 throws java.sql.SQLException 205 { 206 PreparedStatement statement = null; 207 208 try 209 { 210 statement = connection.prepareStatement(deleteSQL); 212 statement.setString(1, tModelKey.toString()); 213 214 log.debug( 215 "delete from TMODEL_IDENTIFIER table:\n\n\t" 216 + deleteSQL 217 + "\n\t TMODEL_KEY=" 218 + tModelKey.toString() 219 + "\n"); 220 221 statement.executeUpdate(); 223 } 224 finally 225 { 226 try 227 { 228 statement.close(); 229 } 230 catch (Exception e) 231 { 232 } 233 } 234 } 235 } 236 | Popular Tags |