[jboss-cvs] JBossAS SVN: r63253 - in branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq: sm/jdbc and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed May 30 09:52:15 EDT 2007


Author: luc.texier at jboss.com
Date: 2007-05-30 09:52:15 -0400 (Wed, 30 May 2007)
New Revision: 63253

Added:
   branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/pm/jdbc2/MSSQLPersistenceManager.java
   branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/sm/jdbc/MSSQLJDBCStateManager.java
Modified:
   branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManager.java
Log:
ASPATCH-219 updated MSSQL's jbossmq PM and SM

Added: branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/pm/jdbc2/MSSQLPersistenceManager.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/pm/jdbc2/MSSQLPersistenceManager.java	                        (rev 0)
+++ branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/pm/jdbc2/MSSQLPersistenceManager.java	2007-05-30 13:52:15 UTC (rev 63253)
@@ -0,0 +1,234 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mq.pm.jdbc2;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import javax.jms.JMSException;
+
+import org.jboss.mq.SpyJMSException;
+
+/**
+ * MSSQLPersistenceManager.<p>
+ *
+ * Based on http://jira.jboss.com/jira/browse/JBAS-2369
+ *
+ * @author <a href="luc.texier at jboss.com">Luc Texier</a>
+ * @version $Revision: 61854 $
+ */
+public class MSSQLPersistenceManager extends PersistenceManager
+{
+
+    protected String CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION = "CREATE UNIQUE CLUSTERED INDEX JMS_MESSAGES_IDX ON JMS_MESSAGES (MESSAGEID, DESTINATION)";
+
+   /**
+    * Create a new MSSQLPersistenceManager.
+    *
+    * @throws JMSException for any error
+    */
+   public MSSQLPersistenceManager() throws JMSException
+   {
+   }
+
+
+   synchronized protected void createSchema() throws JMSException
+   {
+      Connection c = null;
+      PreparedStatement stmt = null;
+      boolean threadWasInterrupted = Thread.interrupted();
+
+      try
+      {
+          innerCreateSchema(c, stmt);
+
+      }
+      catch (SQLException e)
+      {
+         throw new SpyJMSException("Could not get a connection for jdbc2 table construction ", e);
+      }
+      finally
+      {
+         try
+         {
+            if (stmt != null)
+               stmt.close();
+         }
+         catch (Throwable ignore)
+         {
+         }
+         stmt = null;
+         try
+         {
+            if (c != null)
+               c.close();
+         }
+         catch (Throwable ignore)
+         {
+         }
+         c = null;
+
+         // Restore the interrupted state of the thread
+         if (threadWasInterrupted)
+            Thread.currentThread().interrupt();
+      }
+   }
+
+
+    protected void innerCreateSchema(Connection c, PreparedStatement stmt) throws SQLException
+    {
+
+       if (createTables)
+       {
+          c = this.getConnection();
+
+          boolean createdMessageTable = false;
+          try
+          {
+             stmt = c.prepareStatement(CREATE_MESSAGE_TABLE);
+             stmt.executeUpdate();
+             createdMessageTable = true;
+          }
+          catch (SQLException e)
+          {
+             log.debug("Could not create table with SQL: " + CREATE_MESSAGE_TABLE, e);
+          }
+          finally
+          {
+             try
+             {
+                if (stmt != null)
+                   stmt.close();
+             }
+             catch (Throwable ignored)
+             {
+                log.trace("Ignored: " + ignored);
+             }
+             stmt = null;
+          }
+
+          if (createdMessageTable)
+          {
+             try
+             {
+                stmt = c.prepareStatement(CREATE_IDX_MESSAGE_TXOP_TXID);
+                stmt.executeUpdate();
+             }
+             catch (SQLException e)
+             {
+                log.debug("Could not create index with SQL: " + CREATE_IDX_MESSAGE_TXOP_TXID, e);
+             }
+             finally
+             {
+                try
+                {
+                   if (stmt != null)
+                      stmt.close();
+                }
+                catch (Throwable ignored)
+                {
+                   log.trace("Ignored: " + ignored);
+                }
+                stmt = null;
+             }
+             try
+             {
+                stmt = c.prepareStatement(CREATE_IDX_MESSAGE_DESTINATION);
+                stmt.executeUpdate();
+             }
+             catch (SQLException e)
+             {
+                log.debug("Could not create index with SQL: " + CREATE_IDX_MESSAGE_DESTINATION, e);
+             }
+             finally
+             {
+                try
+                {
+                   if (stmt != null)
+                      stmt.close();
+                }
+                catch (Throwable ignored)
+                {
+                   log.trace("Ignored: " + ignored);
+                }
+                stmt = null;
+             }
+              try
+              {
+                 stmt = c.prepareStatement(CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION);
+                 stmt.executeUpdate();
+              }
+              catch (SQLException e)
+              {
+                 log.debug("Could not create index with SQL: " + CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION, e);
+              }
+              finally
+              {
+                 try
+                 {
+                    if (stmt != null)
+                       stmt.close();
+                 }
+                 catch (Throwable ignored)
+                 {
+                    log.trace("Ignored: " + ignored);
+                 }
+                 stmt = null;
+              }
+          }
+
+          try
+          {
+             stmt = c.prepareStatement(CREATE_TX_TABLE);
+             stmt.executeUpdate();
+          }
+          catch (SQLException e)
+          {
+             log.debug("Could not create table with SQL: " + CREATE_TX_TABLE, e);
+          }
+          finally
+          {
+             try
+             {
+                if (stmt != null)
+                   stmt.close();
+             }
+             catch (Throwable ignored)
+             {
+                log.trace("Ignored: " + ignored);
+             }
+             stmt = null;
+          }
+       }
+   }
+
+
+   public void startService() throws Exception
+   {
+      CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION = sqlProperties.getProperty("CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION", CREATE_IDX_MESSAGE_MESSAGEID_DESTINATION);
+
+      super.startService();
+   }
+
+
+}

Modified: branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManager.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManager.java	2007-05-30 13:48:45 UTC (rev 63252)
+++ branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManager.java	2007-05-30 13:52:15 UTC (rev 63253)
@@ -48,7 +48,7 @@
  * @todo create indices
  * 
  * @author Adrian Brock (Adrian at jboss.org)
- * @author Ivelin Ivanov (ivelin at jboss.org)
+ * @author Ivelin Ivanov (ivelin at jboss.org) 
  * @version $Revision$
  */
 public class JDBCStateManager extends AbstractStateManager implements JDBCStateManagerMBean

Added: branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/sm/jdbc/MSSQLJDBCStateManager.java
===================================================================
--- branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/sm/jdbc/MSSQLJDBCStateManager.java	                        (rev 0)
+++ branches/JBoss_4_0_3_SP1_CP/messaging/src/main/org/jboss/mq/sm/jdbc/MSSQLJDBCStateManager.java	2007-05-30 13:52:15 UTC (rev 63253)
@@ -0,0 +1,167 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.mq.sm.jdbc;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.jms.InvalidClientIDException;
+import javax.jms.JMSException;
+import javax.jms.JMSSecurityException;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import javax.transaction.Status;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+import org.jboss.logging.Logger;
+import org.jboss.mq.DurableSubscriptionID;
+import org.jboss.mq.SpyJMSException;
+import org.jboss.mq.SpyTopic;
+import org.jboss.mq.sm.AbstractStateManager;
+import org.jboss.mq.sm.StateManager;
+import org.jboss.tm.TransactionManagerService;
+
+/**
+ * A state manager which does not create the table schema in a tx
+ *
+ * Based on http://jira.jboss.com/jira/browse/JBAS-4260
+ *
+ * @author Luc Texier (ltexier at redhat.com)
+ * @version $Revision$
+ */
+public class MSSQLJDBCStateManager extends JDBCStateManager
+{
+   static final Logger log = Logger.getLogger(MSSQLJDBCStateManager.class);
+
+   protected void initDB() throws Exception
+   {
+      CREATE_USER_TABLE = sqlProperties.getProperty("CREATE_USER_TABLE", CREATE_USER_TABLE);
+      CREATE_ROLE_TABLE = sqlProperties.getProperty("CREATE_ROLE_TABLE", CREATE_ROLE_TABLE);
+      CREATE_SUBSCRIPTION_TABLE = sqlProperties.getProperty("CREATE_SUBSCRIPTION_TABLE", CREATE_SUBSCRIPTION_TABLE);
+      GET_SUBSCRIPTION = sqlProperties.getProperty("GET_SUBSCRIPTION", GET_SUBSCRIPTION);
+      GET_SUBSCRIPTIONS_FOR_TOPIC = sqlProperties.getProperty("GET_SUBSCRIPTIONS_FOR_TOPIC",
+            GET_SUBSCRIPTIONS_FOR_TOPIC);
+      LOCK_SUBSCRIPTION = sqlProperties.getProperty("LOCK_SUBSCRIPTION", LOCK_SUBSCRIPTION);
+      INSERT_SUBSCRIPTION = sqlProperties.getProperty("INSERT_SUBSCRIPTION", INSERT_SUBSCRIPTION);
+      UPDATE_SUBSCRIPTION = sqlProperties.getProperty("UPDATE_SUBSCRIPTION", UPDATE_SUBSCRIPTION);
+      REMOVE_SUBSCRIPTION = sqlProperties.getProperty("REMOVE_SUBSCRIPTION", REMOVE_SUBSCRIPTION);
+      GET_USER_BY_CLIENTID = sqlProperties.getProperty("GET_USER_BY_CLIENTID", GET_USER_BY_CLIENTID);
+      GET_USER = sqlProperties.getProperty("GET_USER", GET_USER);
+
+      // Read the queries to populate the tables with initial data
+      for (Iterator i = sqlProperties.entrySet().iterator(); i.hasNext();)
+      {
+         Map.Entry entry = (Map.Entry) i.next();
+         String key = (String) entry.getKey();
+         if (key.startsWith("POPULATE.TABLES."))
+            POPULATE_TABLES.add(entry.getValue());
+      }
+
+      String createString = sqlProperties.getProperty("CREATE_TABLES_ON_START_UP");
+      if (createString == null)
+         createString = sqlProperties.getProperty("CREATE_TABLES_ON_STARTUP");
+      if (createString == null)
+         createTables = true;
+      else
+         createTables = createString.trim().equalsIgnoreCase("true");
+
+      if (createTables)
+      {
+         Connection connection = null;
+         connection = dataSource.getConnection();
+
+         try
+         {
+            PreparedStatement statement;
+            try
+            {
+               statement = connection.prepareStatement(CREATE_USER_TABLE);
+               statement.executeUpdate();
+            }
+            catch (SQLException ignored)
+            {
+               log.trace("Error creating table: " + CREATE_USER_TABLE, ignored);
+            }
+            try
+            {
+               statement = connection.prepareStatement(CREATE_ROLE_TABLE);
+               statement.executeUpdate();
+            }
+            catch (SQLException ignored)
+            {
+               log.trace("Error creating table: " + CREATE_ROLE_TABLE, ignored);
+            }
+            try
+            {
+               statement = connection.prepareStatement(CREATE_SUBSCRIPTION_TABLE);
+               statement.executeUpdate();
+            }
+            catch (SQLException ignored)
+            {
+               log.trace("Error creating table: " + CREATE_SUBSCRIPTION_TABLE, ignored);
+            }
+
+            Iterator iter = POPULATE_TABLES.iterator();
+            String nextQry = null;
+            while (iter.hasNext())
+            {
+               try
+               {
+                  nextQry = (String) iter.next();
+                  statement = connection.prepareStatement(nextQry);
+                  statement.execute();
+               }
+               catch (SQLException ignored)
+               {
+                  log.trace("Error populating tables: " + nextQry, ignored);
+               }
+            }
+         }
+         finally
+         {
+            try {
+               if(connection != null)
+                   connection.close();
+
+            }catch(SQLException sqle){
+                log.trace("Error when closing connection " +sqle);
+            }
+         }
+      }
+   }
+
+}




More information about the jboss-cvs-commits mailing list