KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mq > pm > jdbc2 > MSSQLPersistenceManager


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mq.pm.jdbc2;
23
24 import java.sql.Connection JavaDoc;
25 import java.sql.PreparedStatement JavaDoc;
26 import java.sql.SQLException JavaDoc;
27
28 import javax.jms.JMSException JavaDoc;
29
30 import org.jboss.mq.SpyJMSException;
31
32 /**
33  * MSSQLPersistenceManager.<p>
34  *
35  * Based on http://jira.jboss.com/jira/browse/JBAS-2369
36  *
37  * @author <a HREF="luc.texier@jboss.com">Luc Texier</a>
38  * @version $Revision: 42605 $
39  */

40 public class MSSQLPersistenceManager extends PersistenceManager
41 {
42
43     protected String JavaDoc CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION = "CREATE UNIQUE CLUSTERED INDEX JMS_MESSAGES_IDX ON JMS_MESSAGES (MESSAGEID, DESTINATION)";
44
45    /**
46     * Create a new MSSQLPersistenceManager.
47     *
48     * @throws JMSException for any error
49     */

50    public MSSQLPersistenceManager() throws JMSException JavaDoc
51    {
52    }
53
54
55    synchronized protected void createSchema() throws JMSException JavaDoc
56    {
57       TransactionManagerStrategy tms = new TransactionManagerStrategy();
58       tms.startTX();
59
60
61       Connection JavaDoc c = null;
62       PreparedStatement JavaDoc stmt = null;
63       boolean threadWasInterrupted = Thread.interrupted();
64
65       try
66       {
67           innerCreateSchema(c, stmt);
68
69       }
70       catch (SQLException JavaDoc 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 JavaDoc ignore)
83          {
84          }
85          stmt = null;
86          try
87          {
88             if (c != null)
89                c.close();
90          }
91          catch (Throwable JavaDoc ignore)
92          {
93          }
94          c = null;
95          tms.endTX();
96
97          // Restore the interrupted state of the thread
98
if (threadWasInterrupted)
99             Thread.currentThread().interrupt();
100       }
101    }
102
103
104     protected void innerCreateSchema(Connection JavaDoc c, PreparedStatement JavaDoc stmt) throws SQLException JavaDoc
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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc ignored)
223              {
224                 log.trace("Ignored: " + ignored);
225              }
226              stmt = null;
227           }
228        }
229    }
230
231
232    public void startService() throws Exception JavaDoc
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