[jboss-cvs] JBossAS SVN: r61855 - in branches/Branch_4_2/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
Thu Mar 29 12:49:16 EDT 2007


Author: luc.texier at jboss.com
Date: 2007-03-29 12:49:15 -0400 (Thu, 29 Mar 2007)
New Revision: 61855

Added:
   branches/Branch_4_2/messaging/src/main/org/jboss/mq/sm/jdbc/MSSQLJDBCStateManager.java
Modified:
   branches/Branch_4_2/messaging/src/main/org/jboss/mq/pm/jdbc2/MSSQLPersistenceManager.java
   branches/Branch_4_2/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManager.java
Log:
JBAS-4260 updated JBossMQ's MSSQL pm and add MSSQL sm

Modified: branches/Branch_4_2/messaging/src/main/org/jboss/mq/pm/jdbc2/MSSQLPersistenceManager.java
===================================================================
--- branches/Branch_4_2/messaging/src/main/org/jboss/mq/pm/jdbc2/MSSQLPersistenceManager.java	2007-03-29 16:23:41 UTC (rev 61854)
+++ branches/Branch_4_2/messaging/src/main/org/jboss/mq/pm/jdbc2/MSSQLPersistenceManager.java	2007-03-29 16:49:15 UTC (rev 61855)
@@ -54,10 +54,6 @@
 
    synchronized protected void createSchema() throws JMSException
    {
-      TransactionManagerStrategy tms = new TransactionManagerStrategy();
-      tms.startTX();
-
-
       Connection c = null;
       PreparedStatement stmt = null;
       boolean threadWasInterrupted = Thread.interrupted();
@@ -69,7 +65,6 @@
       }
       catch (SQLException e)
       {
-         tms.setRollbackOnly();
          throw new SpyJMSException("Could not get a connection for jdbc2 table construction ", e);
       }
       finally
@@ -92,7 +87,6 @@
          {
          }
          c = null;
-         tms.endTX();
 
          // Restore the interrupted state of the thread
          if (threadWasInterrupted)

Modified: branches/Branch_4_2/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManager.java
===================================================================
--- branches/Branch_4_2/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManager.java	2007-03-29 16:23:41 UTC (rev 61854)
+++ branches/Branch_4_2/messaging/src/main/org/jboss/mq/sm/jdbc/JDBCStateManager.java	2007-03-29 16:49:15 UTC (rev 61855)
@@ -86,48 +86,48 @@
    protected TransactionManager tm;
 
    /** The sql properties */
-   private Properties sqlProperties = new Properties();
+   protected Properties sqlProperties = new Properties();
 
    /** Whether to create tables */
-   private boolean createTables = true;
+   protected boolean createTables = true;
 
    /** Create the user table */
-   private String CREATE_USER_TABLE = "CREATE TABLE JMS_USERS (USERID VARCHAR(32) NOT NULL, PASSWD VARCHAR(32) NOT NULL, CLIENTID VARCHAR(128),"
+   protected String CREATE_USER_TABLE = "CREATE TABLE JMS_USERS (USERID VARCHAR(32) NOT NULL, PASSWD VARCHAR(32) NOT NULL, CLIENTID VARCHAR(128),"
          + " PRIMARY KEY(USERID))";
 
    /** Create the role table */
-   private String CREATE_ROLE_TABLE = "CREATE TABLE JMS_ROLES (ROLEID VARCHAR(32) NOT NULL, USERID VARCHAR(32) NOT NULL,"
+   protected String CREATE_ROLE_TABLE = "CREATE TABLE JMS_ROLES (ROLEID VARCHAR(32) NOT NULL, USERID VARCHAR(32) NOT NULL,"
          + " PRIMARY KEY(USERID, ROLEID))";
 
-   private String CREATE_SUBSCRIPTION_TABLE = "CREATE TABLE JMS_SUBSCRIPTIONS (CLIENTID VARCHAR(128) NOT NULL, NAME VARCHAR(128) NOT NULL,"
+   protected String CREATE_SUBSCRIPTION_TABLE = "CREATE TABLE JMS_SUBSCRIPTIONS (CLIENTID VARCHAR(128) NOT NULL, NAME VARCHAR(128) NOT NULL,"
          + " TOPIC VARCHAR(255) NOT NULL, SELECTOR VARCHAR(255)," + " PRIMARY KEY(CLIENTID, NAME))";
 
    /** Get a subscription */
-   private String GET_SUBSCRIPTION = "SELECT TOPIC, SELECTOR FROM JMS_SUBSCRIPTIONS WHERE CLIENTID=? AND NAME=?";
+   protected String GET_SUBSCRIPTION = "SELECT TOPIC, SELECTOR FROM JMS_SUBSCRIPTIONS WHERE CLIENTID=? AND NAME=?";
 
    /** Get subscriptions for a topic */
-   private String GET_SUBSCRIPTIONS_FOR_TOPIC = "SELECT CLIENTID, NAME, SELECTOR FROM JMS_SUBSCRIPTIONS WHERE TOPIC=?";
+   protected String GET_SUBSCRIPTIONS_FOR_TOPIC = "SELECT CLIENTID, NAME, SELECTOR FROM JMS_SUBSCRIPTIONS WHERE TOPIC=?";
 
    /** Lock a subscription */
-   private String LOCK_SUBSCRIPTION = "SELECT TOPIC, SELECTOR FROM JMS_SUBSCRIPTIONS WHERE CLIENTID=? AND NAME=?";
+   protected String LOCK_SUBSCRIPTION = "SELECT TOPIC, SELECTOR FROM JMS_SUBSCRIPTIONS WHERE CLIENTID=? AND NAME=?";
 
    /** Insert a subscription */
-   private String INSERT_SUBSCRIPTION = "INSERT INTO JMS_SUBSCRIPTIONS (CLIENTID, NAME, TOPIC, SELECTOR) VALUES(?,?,?,?)";
+   protected String INSERT_SUBSCRIPTION = "INSERT INTO JMS_SUBSCRIPTIONS (CLIENTID, NAME, TOPIC, SELECTOR) VALUES(?,?,?,?)";
 
    /** Update a subscription */
-   private String UPDATE_SUBSCRIPTION = "UPDATE JMS_SUBSCRIPTIONS SET TOPIC=?, SELECTOR=? WHERE CLIENTID=? AND NAME=?";
+   protected String UPDATE_SUBSCRIPTION = "UPDATE JMS_SUBSCRIPTIONS SET TOPIC=?, SELECTOR=? WHERE CLIENTID=? AND NAME=?";
 
    /** Remove a subscription */
-   private String REMOVE_SUBSCRIPTION = "DELETE FROM JMS_SUBSCRIPTIONS WHERE CLIENTID=? AND NAME=?";
+   protected String REMOVE_SUBSCRIPTION = "DELETE FROM JMS_SUBSCRIPTIONS WHERE CLIENTID=? AND NAME=?";
 
    /** Get a user with the given client id */
-   private String GET_USER_BY_CLIENTID = "SELECT USERID, PASSWD, CLIENTID FROM JMS_USERS WHERE CLIENTID=?";
+   protected String GET_USER_BY_CLIENTID = "SELECT USERID, PASSWD, CLIENTID FROM JMS_USERS WHERE CLIENTID=?";
 
    /** Get a user with the given user id */
-   private String GET_USER = "SELECT PASSWD, CLIENTID FROM JMS_USERS WHERE USERID=?";
+   protected String GET_USER = "SELECT PASSWD, CLIENTID FROM JMS_USERS WHERE USERID=?";
 
    /** Populate tables with initial data */
-   private List POPULATE_TABLES = new ArrayList();
+   protected List POPULATE_TABLES = new ArrayList();
 
    public ObjectName getConnectionManager()
    {

Added: branches/Branch_4_2/messaging/src/main/org/jboss/mq/sm/jdbc/MSSQLJDBCStateManager.java
===================================================================
--- branches/Branch_4_2/messaging/src/main/org/jboss/mq/sm/jdbc/MSSQLJDBCStateManager.java	                        (rev 0)
+++ branches/Branch_4_2/messaging/src/main/org/jboss/mq/sm/jdbc/MSSQLJDBCStateManager.java	2007-03-29 16:49:15 UTC (rev 61855)
@@ -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