[jboss-cvs] JBossAS SVN: r62317 - in branches/Branch_4_2/server/src: main/org/jboss/ejb/txtimer and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Apr 13 06:39:22 EDT 2007


Author: dimitris at jboss.org
Date: 2007-04-13 06:39:22 -0400 (Fri, 13 Apr 2007)
New Revision: 62317

Added:
   branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePluginExt.java
Modified:
   branches/Branch_4_2/server/src/etc/deploy/ejb-deployer.xml
   branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePolicy.java
   branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePolicyMBean.java
   branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/GeneralPurposeDatabasePersistencePlugin.java
Log:
JBAS-4042, allow configuration of timers table name (and schema)

Modified: branches/Branch_4_2/server/src/etc/deploy/ejb-deployer.xml
===================================================================
--- branches/Branch_4_2/server/src/etc/deploy/ejb-deployer.xml	2007-04-13 10:38:46 UTC (rev 62316)
+++ branches/Branch_4_2/server/src/etc/deploy/ejb-deployer.xml	2007-04-13 10:39:22 UTC (rev 62317)
@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-
-<!-- The JBoss service configuration file for the EJB deployer service.
-$Id$
+<!--
+  The JBoss service configuration file for the EJB deployer service.
+  
+  $Id$
 -->
 <server>
 
@@ -26,16 +27,29 @@
     <attribute name="Delay">100</attribute>
   </mbean>
 
-  <!-- A persistence policy that does not persist the timer
+  <!-- A persistence policy that does not persist the timers
   <mbean code="org.jboss.ejb.txtimer.NoopPersistencePolicy" name="jboss.ejb:service=EJBTimerService,persistencePolicy=noop"/>
   -->
 
-  <!-- A persistence policy that persistes timers to a database -->
+  <!--
+    A persistence policy that persists timers to a database.
+    
+    The 2 supported db persistence plugins are:
+      org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin
+      org.jboss.ejb.txtimer.OracleDatabasePersistencePlugin
+      
+    The table name defaults to "TIMERS". It can be overriden using the
+    'TimersTable' attribute if the persistence plugin supports it.
+    When overriding the timers table, an optional schema can be specified
+    using the syntax [schema.]table
+  -->
   <mbean code="org.jboss.ejb.txtimer.DatabasePersistencePolicy" name="jboss.ejb:service=EJBTimerService,persistencePolicy=database">
-    <!-- DataSource JNDI name -->
+    <!-- DataSourceBinding ObjectName -->
     <depends optional-attribute-name="DataSource">jboss.jca:service=DataSourceBinding,name=DefaultDS</depends>
     <!-- The plugin that handles database persistence -->
     <attribute name="DatabasePersistencePlugin">org.jboss.ejb.txtimer.GeneralPurposeDatabasePersistencePlugin</attribute>
+    <!-- The timers table name -->
+    <attribute name="TimersTable">TIMERS</attribute>
   </mbean>
 
   <!-- ==================================================================== -->

Added: branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePluginExt.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePluginExt.java	                        (rev 0)
+++ branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePluginExt.java	2007-04-13 10:39:22 UTC (rev 62317)
@@ -0,0 +1,44 @@
+/*
+ * 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.ejb.txtimer;
+
+// $Id: DatabasePersistencePlugin.java 57209 2006-09-26 12:21:57Z dimitris at jboss.org $
+
+import java.sql.SQLException;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * An extension of DatabasePersistencePlugin that allows setting of the
+ * timers table name during initialization.
+ *
+ * @author Dimitris.Andreadis at jboss.org
+ * @version $Revision: 57209 $
+ */
+public interface DatabasePersistencePluginExt extends DatabasePersistencePlugin
+{
+   /**
+    * Initialize the plugin and set also the timers tablename
+    */
+   void init(MBeanServer server, ObjectName dataSource, String tableName) throws SQLException;
+}
\ No newline at end of file

Modified: branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePolicy.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePolicy.java	2007-04-13 10:38:46 UTC (rev 62316)
+++ branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePolicy.java	2007-04-13 10:39:22 UTC (rev 62317)
@@ -50,17 +50,20 @@
 public class DatabasePersistencePolicy extends ServiceMBeanSupport
    implements DatabasePersistencePolicyMBean
 {
-   // logging support
+   /** logging support */
    private static Logger log = Logger.getLogger(DatabasePersistencePolicy.class);
 
-   // The persistence plugin
+   /** The persistence plugin */
    private DatabasePersistencePlugin dbpPlugin;
 
-   // The service attributes
+   /** The datasource */
    private ObjectName dataSource;
+   /** The persistence plugin */
    private String dbpPluginClassName;
+   /** The timers table */
+   private String timersTable = "TIMERS";
 
-   // The persisted timers seen on startup
+   /** The persisted timers seen on startup */
    private List timersToRestore;
 
    /**
@@ -80,14 +83,29 @@
       }
 
       // init the plugin
-      dbpPlugin.init(server, dataSource);
+      if (dbpPlugin instanceof DatabasePersistencePluginExt)
+      {
+         // if using the extended plugin interface, initialize the timers table name
+         ((DatabasePersistencePluginExt)dbpPlugin).init(server, dataSource, timersTable);
+      }
+      else
+      {
+         dbpPlugin.init(server, dataSource);
+      }
 
+      // warn if timers table cannot be set
+      if (dbpPlugin.getTableName().equals(timersTable) == false)
+      {
+         log.warn("Database persistence plugin '" + dbpPluginClassName +
+               "' uses hardcoded timers table name: '" + dbpPlugin.getTableName());
+      }
+      
       // create the table if needed
       dbpPlugin.createTableIfNotExists();
    }
 
    /**
-    * Creates the timer in  persistent storage.
+    * Creates the timer in persistent storage.
     *
     * @param timerId          The timer id
     * @param timedObjectId    The timed object id
@@ -271,4 +289,20 @@
    {
       this.dbpPluginClassName = dbpPluginClass;
    }
+   
+   /**
+    * @jmx.managed-attribute
+    */
+   public String getTimersTable()
+   {
+      return timersTable;
+   }
+
+   /**
+    * @jmx.managed-attribute
+    */
+   public void setTimersTable(String timersTable)
+   {
+      this.timersTable = timersTable;
+   }   
 }

Modified: branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePolicyMBean.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePolicyMBean.java	2007-04-13 10:38:46 UTC (rev 62316)
+++ branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/DatabasePersistencePolicyMBean.java	2007-04-13 10:39:22 UTC (rev 62317)
@@ -21,10 +21,12 @@
  */
 package org.jboss.ejb.txtimer;
 
+import java.sql.SQLException;
+
 import javax.management.ObjectName;
 
 import org.jboss.mx.util.ObjectNameFactory;
-import org.jboss.system.Service;
+import org.jboss.system.ServiceMBean;
 
 /**
  * MBean interface.
@@ -34,31 +36,31 @@
  * @version $Revision$
  * @since 09-Sep-2004
  */
-public interface DatabasePersistencePolicyMBean extends Service, PersistencePolicy
+public interface DatabasePersistencePolicyMBean extends ServiceMBean, PersistencePolicy
 {
    /** The default object name */
-   static final ObjectName OBJECT_NAME = ObjectNameFactory.create("jboss.ejb:service=EJBTimerService,persistencePolicy=database");
+   ObjectName OBJECT_NAME = ObjectNameFactory.create("jboss.ejb:service=EJBTimerService,persistencePolicy=database");
 
    // Attributes ----------------------------------------------------
    
-   /**
-    * The used datasource
-    */
+   /** The used datasource */
    void setDataSource(ObjectName dataSource);   
    ObjectName getDataSource();
 
-   /**
-    * The used database persistence plugin class
-    */
+   /** The used database persistence plugin class */
    void setDatabasePersistencePlugin(String dbpPluginClass);   
    String getDatabasePersistencePlugin();
    
+   /** The timers table name */
+   void setTimersTable(String tableName);
+   String getTimersTable();
+   
    // Operations ----------------------------------------------------
    
    /**
     * Re-read the current persistent timers list,
     * clear the db of timers, and restore the timers.
     */
-   void resetAndRestoreTimers() throws java.sql.SQLException;
+   void resetAndRestoreTimers() throws SQLException;
 
 }

Modified: branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/GeneralPurposeDatabasePersistencePlugin.java
===================================================================
--- branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/GeneralPurposeDatabasePersistencePlugin.java	2007-04-13 10:38:46 UTC (rev 62316)
+++ branches/Branch_4_2/server/src/main/org/jboss/ejb/txtimer/GeneralPurposeDatabasePersistencePlugin.java	2007-04-13 10:39:22 UTC (rev 62317)
@@ -63,23 +63,43 @@
  * @version $Revision$
  * @since 23-Sep-2004
  */
-public class GeneralPurposeDatabasePersistencePlugin implements DatabasePersistencePlugin
+public class GeneralPurposeDatabasePersistencePlugin implements DatabasePersistencePluginExt
 {
-   // logging support
+   /** logging support */
    private static Logger log = Logger.getLogger(GeneralPurposeDatabasePersistencePlugin.class);
 
-   // The service attributes
+   /** The mbean server */
+   protected MBeanServer server;
+   
+   /** The service attributes */
    protected ObjectName dataSourceName;
 
-   // The mbean server
-   protected MBeanServer server;
-   // The data source the timers will be persisted to
+   /** The timers table name */
+   protected String tableName;
+   
+   /** The data source the timers will be persisted to */
    protected DataSource ds;
-   // datasource meta data
+   
+   /** datasource meta data */
    protected ObjectName metaDataName;
+   
    // default JDBC type code for binary data
    private int binarySqlType;
 
+   /**
+    * Initialize the plugin and set also the timers tablename
+    */
+   public void init(MBeanServer server, ObjectName dataSource, String tableName) throws SQLException
+   {
+      if (tableName == null)
+         throw new IllegalArgumentException("Timers tableName is null");
+      if (tableName.length() == 0)
+         throw new IllegalArgumentException("Timers tableName is empty");
+
+      this.tableName = tableName;
+      init(server, dataSource);
+   }
+   
    /** Initialize the plugin */
    public void init(MBeanServer server, ObjectName dataSourceName) throws SQLException
    {
@@ -337,7 +357,7 @@
    /** Get the timer table name */
    public String getTableName()
    {
-      return "TIMERS";
+      return tableName;
    }
 
    /** Get the timer ID column name */




More information about the jboss-cvs-commits mailing list