1 22 package org.jboss.mq.pm.jdbc2; 23 24 import java.sql.Connection ; 25 import java.sql.PreparedStatement ; 26 import java.sql.SQLException ; 27 28 import javax.jms.JMSException ; 29 30 import org.jboss.mq.SpyJMSException; 31 32 40 public class MSSQLPersistenceManager extends PersistenceManager 41 { 42 43 protected String CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION = "CREATE UNIQUE CLUSTERED INDEX JMS_MESSAGES_IDX ON JMS_MESSAGES (MESSAGEID, DESTINATION)"; 44 45 50 public MSSQLPersistenceManager() throws JMSException 51 { 52 } 53 54 55 synchronized protected void createSchema() throws JMSException 56 { 57 TransactionManagerStrategy tms = new TransactionManagerStrategy(); 58 tms.startTX(); 59 60 61 Connection c = null; 62 PreparedStatement stmt = null; 63 boolean threadWasInterrupted = Thread.interrupted(); 64 65 try 66 { 67 innerCreateSchema(c, stmt); 68 69 } 70 catch (SQLException e) 71 { 72 tms.setRollbackOnly(); 73 throw new SpyJMSException("Could not get a connection for jdbc2 table construction ", e); 74 } 75 finally 76 { 77 try 78 { 79 if (stmt != null) 80 stmt.close(); 81 } 82 catch (Throwable ignore) 83 { 84 } 85 stmt = null; 86 try 87 { 88 if (c != null) 89 c.close(); 90 } 91 catch (Throwable ignore) 92 { 93 } 94 c = null; 95 tms.endTX(); 96 97 if (threadWasInterrupted) 99 Thread.currentThread().interrupt(); 100 } 101 } 102 103 104 protected void innerCreateSchema(Connection c, PreparedStatement stmt) throws SQLException 105 { 106 107 if (createTables) 108 { 109 c = this.getConnection(); 110 111 boolean createdMessageTable = false; 112 try 113 { 114 stmt = c.prepareStatement(CREATE_MESSAGE_TABLE); 115 stmt.executeUpdate(); 116 createdMessageTable = true; 117 } 118 catch (SQLException e) 119 { 120 log.debug("Could not create table with SQL: " + CREATE_MESSAGE_TABLE, e); 121 } 122 finally 123 { 124 try 125 { 126 if (stmt != null) 127 stmt.close(); 128 } 129 catch (Throwable ignored) 130 { 131 log.trace("Ignored: " + ignored); 132 } 133 stmt = null; 134 } 135 136 if (createdMessageTable) 137 { 138 try 139 { 140 stmt = c.prepareStatement(CREATE_IDX_MESSAGE_TXOP_TXID); 141 stmt.executeUpdate(); 142 } 143 catch (SQLException e) 144 { 145 log.debug("Could not create index with SQL: " + CREATE_IDX_MESSAGE_TXOP_TXID, e); 146 } 147 finally 148 { 149 try 150 { 151 if (stmt != null) 152 stmt.close(); 153 } 154 catch (Throwable ignored) 155 { 156 log.trace("Ignored: " + ignored); 157 } 158 stmt = null; 159 } 160 try 161 { 162 stmt = c.prepareStatement(CREATE_IDX_MESSAGE_DESTINATION); 163 stmt.executeUpdate(); 164 } 165 catch (SQLException e) 166 { 167 log.debug("Could not create index with SQL: " + CREATE_IDX_MESSAGE_DESTINATION, e); 168 } 169 finally 170 { 171 try 172 { 173 if (stmt != null) 174 stmt.close(); 175 } 176 catch (Throwable ignored) 177 { 178 log.trace("Ignored: " + ignored); 179 } 180 stmt = null; 181 } 182 try 183 { 184 stmt = c.prepareStatement(CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION); 185 stmt.executeUpdate(); 186 } 187 catch (SQLException e) 188 { 189 log.debug("Could not create index with SQL: " + CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION, e); 190 } 191 finally 192 { 193 try 194 { 195 if (stmt != null) 196 stmt.close(); 197 } 198 catch (Throwable ignored) 199 { 200 log.trace("Ignored: " + ignored); 201 } 202 stmt = null; 203 } 204 } 205 206 try 207 { 208 stmt = c.prepareStatement(CREATE_TX_TABLE); 209 stmt.executeUpdate(); 210 } 211 catch (SQLException e) 212 { 213 log.debug("Could not create table with SQL: " + CREATE_TX_TABLE, e); 214 } 215 finally 216 { 217 try 218 { 219 if (stmt != null) 220 stmt.close(); 221 } 222 catch (Throwable ignored) 223 { 224 log.trace("Ignored: " + ignored); 225 } 226 stmt = null; 227 } 228 } 229 } 230 231 232 public void startService() throws Exception 233 { 234 CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION = sqlProperties.getProperty("CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION", CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION); 235 236 super.startService(); 237 } 238 239 240 } 241 | Popular Tags |