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 FindRelatedBusinessQuery 31 { 32 private static Log log = LogFactory.getLog(FindRelatedBusinessQuery.class); 34 35 static String selectSQL; 36 static String selectWithKeyedRefSQL; 37 38 static 39 { 40 StringBuffer sql = null; 41 42 sql = new StringBuffer (300); 44 sql.append("SELECT FROM_KEY,TO_KEY,TMODEL_KEY,KEY_NAME,KEY_VALUE "); 45 sql.append("FROM PUBLISHER_ASSERTION "); 46 sql.append("WHERE (FROM_KEY=? OR TO_KEY=?) "); 47 sql.append("AND FROM_CHECK='true' "); 48 sql.append("AND TO_CHECK='true'"); 49 selectSQL = sql.toString(); 50 51 sql = new StringBuffer (300); 53 sql.append("SELECT FROM_KEY,TO_KEY,TMODEL_KEY,KEY_NAME,KEY_VALUE "); 54 sql.append("FROM PUBLISHER_ASSERTION "); 55 sql.append("WHERE (FROM_KEY=? OR TO_KEY=?) "); 56 sql.append("AND TMODEL_KEY=? "); 57 sql.append("AND KEY_NAME=? "); 58 sql.append("AND KEY_VALUE=? "); 59 sql.append("AND FROM_CHECK='true' "); 60 sql.append("AND TO_CHECK='true'"); 61 selectWithKeyedRefSQL = sql.toString(); 62 } 63 64 74 public static Vector select(String businessKey,Connection connection) 75 throws java.sql.SQLException 76 { 77 Vector keysOut = new Vector (); 78 PreparedStatement statement = null; 79 ResultSet resultSet = null; 80 81 try 82 { 83 statement = connection.prepareStatement(selectSQL); 84 statement.setString(1,businessKey.toString()); 85 statement.setString(2,businessKey.toString()); 86 87 log.debug("select from PUBLISHER_ASSERTION table:\n\n\t" + selectSQL + 88 "\n\t FROM_KEY=" + businessKey+ 89 "\n\t TO_KEY=" + businessKey + "\n"); 90 91 resultSet = statement.executeQuery(); 92 while (resultSet.next()) 93 { 94 String fromKey = resultSet.getString(1); String toKey = resultSet.getString(2); 97 if (!fromKey.equalsIgnoreCase(businessKey)) 98 keysOut.addElement(fromKey); 99 else if (!toKey.equalsIgnoreCase(businessKey)) 100 keysOut.addElement(toKey); 101 } 102 103 return keysOut; 104 } 105 finally 106 { 107 try { 108 resultSet.close(); 109 } 110 catch (Exception e) 111 { 112 log.warn("An Exception was encountered while attempting to close " + 113 "the Find BusinessEntity ResultSet: "+e.getMessage(),e); 114 } 115 116 try { 117 statement.close(); 118 } 119 catch (Exception e) 120 { 121 log.warn("An Exception was encountered while attempting to close " + 122 "the Find BusinessEntity Statement: "+e.getMessage(),e); 123 } 124 } 125 } 126 127 138 public static Vector selectWithKeyedRef(String businessKey,KeyedReference keyedRef,Connection connection) 139 throws java.sql.SQLException 140 { 141 Vector keysOut = new Vector (); 142 PreparedStatement statement = null; 143 ResultSet resultSet = null; 144 145 try 146 { 147 statement = connection.prepareStatement(selectWithKeyedRefSQL); 148 statement.setString(1,businessKey); 149 statement.setString(2,businessKey); 150 statement.setString(3,keyedRef.getTModelKey()); 151 statement.setString(4,keyedRef.getKeyName()); 152 statement.setString(5,keyedRef.getKeyValue()); 153 154 log.debug("select from PUBLISHER_ASSERTION table:\n\n\t" + selectWithKeyedRefSQL + 155 "\n\t FROM_KEY=" + businessKey + 156 "\n\t TO_KEY=" + businessKey + 157 "\n\t TMODEL_KEY=" + keyedRef.getTModelKey() + 158 "\n\t KEY_NAME=" + keyedRef.getKeyName() + 159 "\n\t KEY_VALUE=" + keyedRef.getKeyValue() + "\n"); 160 161 resultSet = statement.executeQuery(); 162 while (resultSet.next()) 163 { 164 String fromKey = resultSet.getString(1); String toKey = resultSet.getString(2); 167 if (!fromKey.equalsIgnoreCase(businessKey)) 168 keysOut.addElement(fromKey); 169 else if (!toKey.equalsIgnoreCase(businessKey)) 170 keysOut.addElement(toKey); 171 } 172 173 if (keysOut.size() > 0) 174 log.info("select successful, at least one matching row was found"); 175 else 176 log.info("select executed successfully but no matching rows were found"); 177 178 return keysOut; 179 } 180 finally 181 { 182 try { 183 resultSet.close(); 184 } 185 catch (Exception e) 186 { 187 log.warn("An Exception was encountered while attempting to close " + 188 "the Find BusinessEntity ResultSet: "+e.getMessage(),e); 189 } 190 191 try { 192 statement.close(); 193 } 194 catch (Exception e) 195 { 196 log.warn("An Exception was encountered while attempting to close " + 197 "the Find BusinessEntity Statement: "+e.getMessage(),e); 198 } 199 } 200 } 201 } | Popular Tags |