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.SQLException ; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 import org.apache.juddi.datatype.publisher.Publisher; 26 27 30 public class PublisherTable 31 { 32 private static Log log = LogFactory.getLog(PublisherTable.class); 34 35 static String insertSQL = null; 36 static String selectSQL = null; 37 static String deleteSQL = null; 38 static String updateSQL = null; 39 static String verifyAdminSQL = null; 40 41 static 42 { 43 StringBuffer sql = null; 45 46 sql = new StringBuffer (150); 48 sql.append("INSERT INTO PUBLISHER ("); 49 sql.append("PUBLISHER_ID,"); 50 sql.append("PUBLISHER_NAME,"); 51 sql.append("EMAIL_ADDRESS,"); 52 sql.append("IS_ADMIN, "); 53 sql.append("IS_ENABLED) "); 54 sql.append("VALUES (?,?,?,?,?)"); 55 insertSQL = sql.toString(); 56 57 sql = new StringBuffer (200); 59 sql.append("SELECT "); 60 sql.append("PUBLISHER_NAME,"); 61 sql.append("EMAIL_ADDRESS,"); 62 sql.append("IS_ADMIN,"); 63 sql.append("IS_ENABLED "); 64 sql.append("FROM PUBLISHER "); 65 sql.append("WHERE PUBLISHER_ID=?"); 66 selectSQL = sql.toString(); 67 68 sql = new StringBuffer (200); 70 sql.append("DELETE FROM PUBLISHER "); 71 sql.append("WHERE PUBLISHER_ID=?"); 72 deleteSQL = sql.toString(); 73 74 sql = new StringBuffer (200); 76 sql.append("UPDATE PUBLISHER "); 77 sql.append("SET PUBLISHER_NAME=?,"); 78 sql.append("EMAIL_ADDRESS=?,"); 79 sql.append("IS_ADMIN=?,"); 80 sql.append("IS_ENABLED=? "); 81 sql.append("WHERE PUBLISHER_ID=?"); 82 updateSQL = sql.toString(); 83 } 84 85 92 public static void insert(Publisher publisher,Connection connection) 93 throws SQLException 94 { 95 if (publisher == null) 96 return; 98 PreparedStatement statement = null; 99 100 try 101 { 102 statement = connection.prepareStatement(insertSQL); 103 statement.setString(1,publisher.getPublisherID()); 104 statement.setString(2,publisher.getName()); 105 statement.setString(3,publisher.getEmailAddress()); 106 statement.setString(4,String.valueOf(publisher.isAdmin())); 107 statement.setString(5,String.valueOf(publisher.isEnabled())); 108 109 log.debug("insert into PUBLISHER table:\n\n\t" + insertSQL + 110 "\n\t PUBLISHER_ID=" + publisher.getPublisherID() + 111 "\n\t PUBLISHER_NAME=" + publisher.getName() + 112 "\n\t EMAIL_ADDRESS=" + publisher.getEmailAddress() + 113 "\n\t IS_ADMIN=" + publisher.isAdmin() + 114 "\n\t IS_ENABLED=" + publisher.isEnabled() + "\n"); 115 116 statement.executeUpdate(); 118 } 119 catch(SQLException sqlex) 120 { 121 log.error(sqlex.getMessage()); 122 throw sqlex; 123 } 124 finally 125 { 126 try { statement.close(); } catch (Exception e) { } 127 } 128 } 129 130 138 public static Publisher select(String publisherID,Connection connection) 139 throws SQLException 140 { 141 if (publisherID == null) 143 return null; 144 145 Publisher publisher = null; 146 PreparedStatement statement = null; 147 ResultSet resultSet = null; 148 149 try 150 { 151 statement = connection.prepareStatement(selectSQL); 152 statement.setString(1,publisherID); 153 154 log.debug("select from PUBLISHER table:\n\n\t" + selectSQL + 155 "\n\t PUBLISHER_ID=" + publisherID + "\n"); 156 157 resultSet = statement.executeQuery(); 158 if (resultSet.next()) 159 { 160 publisher = new Publisher(); 161 publisher.setPublisherID(publisherID); 162 publisher.setName(resultSet.getString(1)); publisher.setEmailAddress(resultSet.getString(2)); publisher.setAdminValue(resultSet.getString(3)); publisher.setEnabledValue(resultSet.getString(4)); } 167 168 return publisher; 169 } 170 catch(SQLException sqlex) 171 { 172 log.error(sqlex.getMessage()); 173 throw sqlex; 174 } 175 finally 176 { 177 try { resultSet.close(); } catch (Exception e) { } 178 try { statement.close(); } catch (Exception e) { } 179 } 180 } 181 182 189 public static void delete(String publisherID,Connection connection) 190 throws SQLException 191 { 192 PreparedStatement statement = null; 193 194 try 195 { 196 statement = connection.prepareStatement(deleteSQL); 198 statement.setString(1,publisherID); 199 200 log.debug("delete from PUBLISHER table:\n\n\t" + deleteSQL + 201 "\n\t PUBLISHER_ID=" + "\n"); 202 203 statement.executeUpdate(); 205 } 206 catch(SQLException sqlex) 207 { 208 log.error(sqlex.getMessage()); 209 throw sqlex; 210 } 211 finally 212 { 213 try { statement.close(); } catch (Exception e) { } 214 } 215 } 216 217 224 public static void update(Publisher publisher,Connection connection) 225 throws SQLException 226 { 227 PreparedStatement statement = null; 228 229 try 230 { 231 statement = connection.prepareStatement(updateSQL); 233 statement.setString(1,publisher.getName()); 234 statement.setString(2,publisher.getEmailAddress()); 235 statement.setString(3,String.valueOf(publisher.isAdmin())); 236 statement.setString(4,String.valueOf(publisher.isEnabled())); 237 statement.setString(5,publisher.getPublisherID()); 238 239 log.debug("update PUBLISHER table:\n\n\t" + updateSQL + 240 "\n\t PUBLISHER_NAME=" + publisher.getName() + 241 "\n\t EMAIL_ADDRESS=" + publisher.getEmailAddress() + 242 "\n\t IS_ADMIN=" + publisher.isAdmin() + 243 "\n\t IS_ENABLED=" + publisher.isEnabled() + 244 "\n\t PUBLISHER_ID=" + publisher.getPublisherID() + "\n"); 245 246 statement.executeUpdate(); 248 } 249 catch(SQLException sqlex) 250 { 251 log.error(sqlex.getMessage()); 252 throw sqlex; 253 } 254 finally 255 { 256 try { statement.close(); } catch (Exception e) { } 257 } 258 } 259 } | Popular Tags |