001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.mq.pm.jdbc2;
023:
024: import java.sql.Connection;
025: import java.sql.PreparedStatement;
026: import java.sql.SQLException;
027:
028: import javax.jms.JMSException;
029:
030: import org.jboss.mq.SpyJMSException;
031:
032: /**
033: * MSSQLPersistenceManager.<p>
034: *
035: * Based on http://jira.jboss.com/jira/browse/JBAS-2369
036: *
037: * @author <a href="luc.texier@jboss.com">Luc Texier</a>
038: * @version $Revision: 61855 $
039: */
040: public class MSSQLPersistenceManager extends PersistenceManager {
041:
042: protected String CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION = "CREATE UNIQUE CLUSTERED INDEX JMS_MESSAGES_IDX ON JMS_MESSAGES (MESSAGEID, DESTINATION)";
043:
044: /**
045: * Create a new MSSQLPersistenceManager.
046: *
047: * @throws JMSException for any error
048: */
049: public MSSQLPersistenceManager() throws JMSException {
050: }
051:
052: synchronized protected void createSchema() throws JMSException {
053: Connection c = null;
054: PreparedStatement stmt = null;
055: boolean threadWasInterrupted = Thread.interrupted();
056:
057: try {
058: innerCreateSchema(c, stmt);
059:
060: } catch (SQLException e) {
061: throw new SpyJMSException(
062: "Could not get a connection for jdbc2 table construction ",
063: e);
064: } finally {
065: try {
066: if (stmt != null)
067: stmt.close();
068: } catch (Throwable ignore) {
069: }
070: stmt = null;
071: try {
072: if (c != null)
073: c.close();
074: } catch (Throwable ignore) {
075: }
076: c = null;
077:
078: // Restore the interrupted state of the thread
079: if (threadWasInterrupted)
080: Thread.currentThread().interrupt();
081: }
082: }
083:
084: protected void innerCreateSchema(Connection c,
085: PreparedStatement stmt) throws SQLException {
086:
087: if (createTables) {
088: c = this .getConnection();
089:
090: boolean createdMessageTable = false;
091: try {
092: stmt = c.prepareStatement(CREATE_MESSAGE_TABLE);
093: stmt.executeUpdate();
094: createdMessageTable = true;
095: } catch (SQLException e) {
096: log.debug("Could not create table with SQL: "
097: + CREATE_MESSAGE_TABLE, e);
098: } finally {
099: try {
100: if (stmt != null)
101: stmt.close();
102: } catch (Throwable ignored) {
103: log.trace("Ignored: " + ignored);
104: }
105: stmt = null;
106: }
107:
108: if (createdMessageTable) {
109: try {
110: stmt = c
111: .prepareStatement(CREATE_IDX_MESSAGE_TXOP_TXID);
112: stmt.executeUpdate();
113: } catch (SQLException e) {
114: log.debug("Could not create index with SQL: "
115: + CREATE_IDX_MESSAGE_TXOP_TXID, e);
116: } finally {
117: try {
118: if (stmt != null)
119: stmt.close();
120: } catch (Throwable ignored) {
121: log.trace("Ignored: " + ignored);
122: }
123: stmt = null;
124: }
125: try {
126: stmt = c
127: .prepareStatement(CREATE_IDX_MESSAGE_DESTINATION);
128: stmt.executeUpdate();
129: } catch (SQLException e) {
130: log.debug("Could not create index with SQL: "
131: + CREATE_IDX_MESSAGE_DESTINATION, e);
132: } finally {
133: try {
134: if (stmt != null)
135: stmt.close();
136: } catch (Throwable ignored) {
137: log.trace("Ignored: " + ignored);
138: }
139: stmt = null;
140: }
141: try {
142: stmt = c
143: .prepareStatement(CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION);
144: stmt.executeUpdate();
145: } catch (SQLException e) {
146: log.debug("Could not create index with SQL: "
147: + CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION,
148: e);
149: } finally {
150: try {
151: if (stmt != null)
152: stmt.close();
153: } catch (Throwable ignored) {
154: log.trace("Ignored: " + ignored);
155: }
156: stmt = null;
157: }
158: }
159:
160: try {
161: stmt = c.prepareStatement(CREATE_TX_TABLE);
162: stmt.executeUpdate();
163: } catch (SQLException e) {
164: log.debug("Could not create table with SQL: "
165: + CREATE_TX_TABLE, e);
166: } finally {
167: try {
168: if (stmt != null)
169: stmt.close();
170: } catch (Throwable ignored) {
171: log.trace("Ignored: " + ignored);
172: }
173: stmt = null;
174: }
175: }
176: }
177:
178: public void startService() throws Exception {
179: CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION = sqlProperties
180: .getProperty(
181: "CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION",
182: CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION);
183:
184: super.startService();
185: }
186:
187: }
|