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.OverviewDoc; 26 import org.apache.juddi.datatype.binding.InstanceDetails; 27 import org.apache.juddi.datatype.binding.InstanceParms; 28 import org.apache.juddi.datatype.binding.TModelInstanceInfo; 29 30 33 class TModelInstanceInfoTable 34 { 35 private static Log log = LogFactory.getLog(TModelInstanceInfoTable.class); 37 38 static String insertSQL = null; 39 static String selectSQL = null; 40 static String deleteSQL = null; 41 42 static { 43 StringBuffer sql = null; 45 46 sql = new StringBuffer (150); 48 sql.append("INSERT INTO TMODEL_INSTANCE_INFO ("); 49 sql.append("BINDING_KEY,"); 50 sql.append("TMODEL_INSTANCE_INFO_ID,"); 51 sql.append("TMODEL_KEY, "); 52 sql.append("OVERVIEW_URL,"); 53 sql.append("INSTANCE_PARMS) "); 54 sql.append("VALUES (?,?,?,?,?)"); 55 insertSQL = sql.toString(); 56 57 sql = new StringBuffer (200); 59 sql.append("SELECT "); 60 sql.append("TMODEL_KEY,"); 61 sql.append("OVERVIEW_URL,"); 62 sql.append("INSTANCE_PARMS, "); 63 sql.append("TMODEL_INSTANCE_INFO_ID "); 64 sql.append("FROM TMODEL_INSTANCE_INFO "); 65 sql.append("WHERE BINDING_KEY=? "); 66 sql.append("ORDER BY TMODEL_INSTANCE_INFO_ID"); 67 selectSQL = sql.toString(); 68 69 sql = new StringBuffer (100); 71 sql.append("DELETE FROM TMODEL_INSTANCE_INFO "); 72 sql.append("WHERE BINDING_KEY=?"); 73 deleteSQL = sql.toString(); 74 } 75 76 84 public static void insert( 85 String bindingKey, 86 Vector infoList, 87 Connection connection) 88 throws java.sql.SQLException 89 { 90 if ((infoList == null) || (infoList.size() == 0)) 91 return; 93 PreparedStatement statement = null; 94 95 try 96 { 97 statement = connection.prepareStatement(insertSQL); 98 statement.setString(1, bindingKey.toString()); 99 100 int listSize = infoList.size(); 101 for (int infoID = 0; infoID < listSize; infoID++) 102 { 103 String tModelKey = null; 104 String overURL = null; 105 String instParms = null; 106 107 TModelInstanceInfo info = 108 (TModelInstanceInfo) infoList.elementAt(infoID); 109 if (info.getTModelKey() != null) 110 tModelKey = info.getTModelKey().toString(); 111 112 InstanceDetails details = info.getInstanceDetails(); 113 if (details != null) 114 { 115 if (details.getOverviewDoc() != null) 116 overURL = details.getOverviewDoc().getOverviewURLString(); 117 118 if (details.getInstanceParms() != null) 119 instParms = details.getInstanceParms().getValue(); 120 } 121 122 statement.setInt(2, infoID); 124 statement.setString(3, tModelKey); 125 statement.setString(4, overURL); 126 statement.setString(5, instParms); 127 128 log.debug( 129 "insert into TMODEL_INSTANCE_INFO table:\n\n\t" 130 + insertSQL 131 + "\n\t BINDING_KEY=" 132 + bindingKey.toString() 133 + "\n\t TMODEL_INSTANCE_INFO_ID=" 134 + infoID 135 + "\n\t TMODEL_KEY=" 136 + tModelKey 137 + "\n\t OVERVIEW_URL=" 138 + overURL 139 + "\n\t INSTANCE_PARMS=" 140 + instParms 141 + "\n"); 142 143 statement.executeUpdate(); 144 } 145 } 146 finally 147 { 148 try 149 { 150 statement.close(); 151 } 152 catch (Exception e) 153 { 154 } 155 } 156 } 157 158 165 public static Vector select(String bindingKey, Connection connection) 166 throws java.sql.SQLException 167 { 168 Vector infoList = new Vector (); 169 PreparedStatement statement = null; 170 ResultSet resultSet = null; 171 172 try 173 { 174 statement = connection.prepareStatement(selectSQL); 176 statement.setString(1, bindingKey.toString()); 177 178 log.debug( 179 "select from TMODEL_INSTANCE_INFO table:\n\n\t" 180 + selectSQL 181 + "\n\t BINDING_KEY=" 182 + bindingKey.toString() 183 + "\n"); 184 185 resultSet = statement.executeQuery(); 187 188 while (resultSet.next()) 189 { 190 String tModelKey = resultSet.getString(1); String overURL = resultSet.getString(2); String instParms = resultSet.getString(3); 194 if (tModelKey != null) 195 { 196 TModelInstanceInfo info = new TModelInstanceInfo(); 197 info.setTModelKey(tModelKey); 198 199 OverviewDoc overviewDoc = null; 200 if (overURL != null) 201 { 202 overviewDoc = new OverviewDoc(); 203 overviewDoc.setOverviewURL(overURL); 204 } 205 206 InstanceParms instanceParms = null; 207 if (instParms != null) 208 { 209 instanceParms = new InstanceParms(); 210 instanceParms.setText(instParms); 211 } 212 213 InstanceDetails details = null; 214 if ((overviewDoc != null) || (instanceParms != null)) 215 { 216 details = new InstanceDetails(); 217 details.setOverviewDoc(overviewDoc); 218 details.setInstanceParms(instanceParms); 219 info.setInstanceDetails(details); 220 } 221 222 infoList.add(info); 223 } 224 } 225 226 return infoList; 227 } 228 finally 229 { 230 try 231 { 232 resultSet.close(); 233 statement.close(); 234 } 235 catch (Exception e) 236 { 237 } 238 } 239 } 240 241 249 public static void delete(String bindingKey, Connection connection) 250 throws java.sql.SQLException 251 { 252 PreparedStatement statement = null; 253 254 try 255 { 256 statement = connection.prepareStatement(deleteSQL); 258 statement.setString(1, bindingKey.toString()); 259 260 log.debug( 261 "delete from TMODEL_INSTANCE_INFO table:\n\n\t" 262 + deleteSQL 263 + "\n\t BINDING_KEY=" 264 + bindingKey.toString() 265 + "\n"); 266 267 statement.executeUpdate(); 269 } 270 finally 271 { 272 try 273 { 274 statement.close(); 275 } 276 catch (Exception e) 277 { 278 } 279 } 280 } 281 } 282 | Popular Tags |