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.sql.Timestamp ; 22 import java.util.Vector ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.juddi.datatype.OverviewDoc; 27 import org.apache.juddi.datatype.tmodel.TModel; 28 29 32 class TModelTable 33 { 34 private static Log log = LogFactory.getLog(TModelTable.class); 36 37 static String insertSQL = null; 38 static String deleteSQL = null; 39 static String updateSQL = null; 40 static String selectSQL = null; 41 static String selectByPublisherSQL = null; 42 static String verifyOwnershipSQL = null; 43 44 static 45 { 46 StringBuffer sql = null; 48 49 sql = new StringBuffer (150); 51 sql.append("INSERT INTO TMODEL ("); 52 sql.append("TMODEL_KEY,"); 53 sql.append("AUTHORIZED_NAME,"); 54 sql.append("PUBLISHER_ID,"); 55 sql.append("OPERATOR,"); 56 sql.append("NAME,"); 57 sql.append("OVERVIEW_URL,"); 58 sql.append("LAST_UPDATE) "); 59 sql.append("VALUES (?,?,?,?,?,?,?)"); 60 insertSQL = sql.toString(); 61 62 sql = new StringBuffer (100); 64 sql.append("DELETE FROM TMODEL "); 65 sql.append("WHERE TMODEL_KEY=?"); 66 deleteSQL = sql.toString(); 67 68 sql = new StringBuffer (100); 70 sql.append("UPDATE TMODEL "); 71 sql.append("SET DELETED='true' "); 72 sql.append("WHERE TMODEL_KEY=?"); 73 updateSQL = sql.toString(); 74 75 sql = new StringBuffer (200); 77 sql.append("SELECT "); 78 sql.append("AUTHORIZED_NAME,"); 79 sql.append("OPERATOR,"); 80 sql.append("NAME,"); 81 sql.append("OVERVIEW_URL,"); 82 sql.append("DELETED "); 83 sql.append("FROM TMODEL "); 84 sql.append("WHERE TMODEL_KEY=? "); 85 sql.append("AND DELETED IS NULL"); 86 selectSQL = sql.toString(); 87 88 sql = new StringBuffer (200); 90 sql.append("SELECT "); 91 sql.append("TMODEL_KEY,"); 92 sql.append("DELETED "); 93 sql.append("FROM TMODEL "); 94 sql.append("WHERE PUBLISHER_ID=? "); 95 sql.append("AND DELETED IS NULL"); 96 selectByPublisherSQL = sql.toString(); 97 98 sql = new StringBuffer (200); 100 sql.append("SELECT * "); 101 sql.append("FROM TMODEL "); 102 sql.append("WHERE TMODEL_KEY=? "); 103 sql.append("AND PUBLISHER_ID=? " ); 104 sql.append("AND DELETED IS NULL"); 105 verifyOwnershipSQL = sql.toString(); 106 } 107 108 116 public static void insert(TModel tModel,String publisherID,Connection connection) 117 throws java.sql.SQLException 118 { 119 PreparedStatement statement = null; 120 Timestamp timeStamp = new Timestamp (System.currentTimeMillis()); 121 122 String overviewURL = null; 123 if ((tModel.getOverviewDoc() != null) && (tModel.getOverviewDoc().getOverviewURL() != null)) 124 overviewURL = tModel.getOverviewDoc().getOverviewURL().getValue(); 125 126 try 127 { 128 statement = connection.prepareStatement(insertSQL); 129 statement.setString(1,tModel.getTModelKey().toString()); 130 statement.setString(2,tModel.getAuthorizedName()); 131 statement.setString(3,publisherID); 132 statement.setString(4,tModel.getOperator()); 133 statement.setString(5,tModel.getName()); 134 statement.setString(6,overviewURL); 135 statement.setTimestamp(7,timeStamp); 136 137 log.debug(insertSQL + 138 "\n\t TMODEL_KEY=" + tModel.getTModelKey().toString() + 139 "\n\t AUTHORIZED_NAME=" + tModel.getAuthorizedName() + 140 "\n\t PUBLISHER_ID=" + publisherID + 141 "\n\t OPERATOR=" + tModel.getOperator() + 142 "\n\t NAME=" + tModel.getName() + 143 "\n\t OVERVIEW_URL=" + overviewURL + 144 "\n\t LAST_UPDATE=" + timeStamp.getTime() + "\n"); 145 146 statement.executeUpdate(); 148 } 149 finally 150 { 151 try { 152 statement.close(); 153 } 154 catch (Exception e) { } 155 } 156 } 157 158 165 public static void delete(String tModelKey,Connection connection) 166 throws java.sql.SQLException 167 { 168 PreparedStatement statement = null; 169 170 try 171 { 172 statement = connection.prepareStatement(deleteSQL); 174 statement.setString(1,tModelKey.toString()); 175 176 log.debug(deleteSQL + 177 "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); 178 179 statement.executeUpdate(); 181 } 182 finally 183 { 184 try { 185 statement.close(); 186 } 187 catch (Exception e) { } 188 } 189 } 190 191 198 public static void markAsDeleted(String tModelKey,Connection connection) 199 throws java.sql.SQLException 200 { 201 PreparedStatement statement = null; 202 203 try 204 { 205 statement = connection.prepareStatement(updateSQL); 207 statement.setString(1,tModelKey.toString()); 208 209 log.debug(updateSQL + 210 "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); 211 212 statement.executeUpdate(); 214 } 215 finally 216 { 217 try { 218 statement.close(); 219 } 220 catch (Exception e) { } 221 } 222 } 223 224 231 public static TModel select(String tModelKey,Connection connection) 232 throws java.sql.SQLException 233 { 234 TModel tModel = null; 235 PreparedStatement statement = null; 236 ResultSet resultSet = null; 237 238 try 239 { 240 statement = connection.prepareStatement(selectSQL); 241 statement.setString(1,tModelKey.toString()); 242 243 log.debug(selectSQL + 244 "\n\t TMODEL_KEY=" + tModelKey.toString() + "\n"); 245 246 resultSet = statement.executeQuery(); 247 if (resultSet.next()) 248 { 249 tModel = new TModel(); 250 tModel.setTModelKey(tModelKey); 251 tModel.setAuthorizedName(resultSet.getString(1)); tModel.setOperator(resultSet.getString(2)); tModel.setName(resultSet.getString(3)); 255 OverviewDoc overviewDoc = new OverviewDoc(); 256 overviewDoc.setOverviewURL(resultSet.getString(4)); tModel.setOverviewDoc(overviewDoc); 258 } 259 260 return tModel; 261 } 262 finally 263 { 264 try { 265 resultSet.close(); 266 statement.close(); 267 } 268 catch (Exception e) { } 269 } 270 } 271 272 280 public static Vector selectByPublisherID(String publisherID,Connection connection) 281 throws java.sql.SQLException 282 { 283 Vector keyList = new Vector (); 284 PreparedStatement statement = null; 285 ResultSet resultSet = null; 286 287 try 288 { 289 statement = connection.prepareStatement(selectByPublisherSQL); 291 statement.setString(1,publisherID.toString()); 292 293 log.debug(selectByPublisherSQL + 294 "\n\t PUBLISHER_ID=" + publisherID + "\n"); 295 296 resultSet = statement.executeQuery(); 298 while (resultSet.next()) 299 keyList.add(resultSet.getString(1)); 301 return keyList; 302 } 303 finally 304 { 305 try { 306 resultSet.close(); 307 statement.close(); 308 } 309 catch (Exception e) { } 310 } 311 } 312 313 322 public static boolean verifyOwnership(String tModelKey,String publisherID,Connection connection) 323 throws java.sql.SQLException 324 { 325 if ((tModelKey == null) || (publisherID == null)) 326 return false; 327 328 boolean authorized = false; 329 PreparedStatement statement = null; 330 ResultSet resultSet = null; 331 332 try 333 { 334 statement = connection.prepareStatement(verifyOwnershipSQL); 335 statement.setString(1,tModelKey); 336 statement.setString(2,publisherID); 337 338 log.debug(verifyOwnershipSQL + 339 "\n\t TMODEL_KEY=" + tModelKey + 340 "\n\t PUBLISHER_ID=" + publisherID + "\n"); 341 342 resultSet = statement.executeQuery(); 343 if (resultSet.next()) 344 authorized = true; 345 346 return authorized; 347 } 348 finally 349 { 350 try { 351 resultSet.close(); 352 statement.close(); 353 } 354 catch (Exception e) { } 355 } 356 } 357 } 358 | Popular Tags |