[jboss-cvs] JBossAS SVN: r101062 - in projects/jboss-jca/trunk: common/src/main/java/org/jboss/jca/common/util and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 17 02:02:19 EST 2010


Author: smarlow at redhat.com
Date: 2010-02-17 02:02:19 -0500 (Wed, 17 Feb 2010)
New Revision: 101062

Added:
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/ConnectionFactoryBuilder.java
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/LocalApplicationServerJNDIHandler.java
   projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/LocalConnectionFactoryBuilder.java
Modified:
   projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java
Log:
JBJCA-274 set the Reference as required for the JNDI bind operation (otherwise we bind null value).

Added: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/ConnectionFactoryBuilder.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/ConnectionFactoryBuilder.java	                        (rev 0)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/api/ConnectionFactoryBuilder.java	2010-02-17 07:02:19 UTC (rev 101062)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.jca.common.api;
+
+import org.jboss.jca.fungal.deployers.DeployException;
+
+import javax.naming.Reference;
+import javax.resource.spi.ManagedConnectionFactory;
+
+/**
+ * Used for building the ConnectionFactory.  This is starting as a "simple as possible"
+ * interface based on current needs to build the ConnectionFactory (no remote case yet supported).
+ *
+ * @author <a href="mailto:smarlow at redhat.com">Scott Marlow</a>
+ */
+public interface ConnectionFactoryBuilder {
+
+   /**
+    * Return the CF Reference.  The ConnectionFactory can be obtained from the Reference.
+    * @return The reference
+    */
+   Reference getReference() throws DeployException;
+
+   /**
+    * specify the unique name of the connection factory builder  
+    * @param name
+    * @return this for convenience
+    */
+   ConnectionFactoryBuilder setName(String name);
+
+   /**
+    * Specify the managed connection factory.  Some implementation may ignore this call
+    * (e.g. because they will instead create the ManagedConnectionFactory on the fly).
+    * @param mcf is the managed connection factory to be used by connection factory.
+    * @return this for convenience
+    */
+   ConnectionFactoryBuilder setManagedConnectionFactory(ManagedConnectionFactory mcf);
+
+   /**
+    * @return the managed connection factory
+    */
+   Object getManagedConnectionFactory();
+
+   /**
+    * Specify the ConnectionFactory.  Some implementations may ignore this call
+    * (e.g. because they will instead create the ManagedConnectionFactory on the fly).
+    * @param cf is the connection factory that will be returned
+    * @return this for convenience
+    */
+   ConnectionFactoryBuilder setConnectionFactory(Object cf);
+
+   /**
+    * @return the connection factory
+    */
+   Object getConnectionFactory();
+
+
+}

Added: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/LocalApplicationServerJNDIHandler.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/LocalApplicationServerJNDIHandler.java	                        (rev 0)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/LocalApplicationServerJNDIHandler.java	2010-02-17 07:02:19 UTC (rev 101062)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.jca.common.util;
+
+import org.jboss.jca.common.api.ConnectionFactoryBuilder;
+import org.jboss.jca.fungal.deployers.DeployException;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+import java.util.Hashtable;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Local only support for connection factory
+ * TODO:  Add undeploy support to unregister CF builder
+ *
+ * @author <a href="mailto:smarlow at redhat.com">Scott Marlow</a>
+ */
+
+public class LocalApplicationServerJNDIHandler implements ObjectFactory {
+
+   private static ConcurrentHashMap<String, ConnectionFactoryBuilder> connectionFactories = new ConcurrentHashMap();
+
+   public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
+      Reference ref = (Reference)obj;
+      String className = (String)ref.get("class").getContent();
+      String cfname = (String)ref.get("name").getContent();
+      ConnectionFactoryBuilder cfb = connectionFactories.get(qualifiedName(cfname, className));
+      return cfb.getConnectionFactory();
+   }
+
+   /**
+    *
+    * @param name
+    * @param className
+    * @param cfb
+    * @throws DeployException if already registered and therefore deployed
+    */
+   public static void register(String name, String className, ConnectionFactoryBuilder cfb) throws DeployException {
+
+      if(null != connectionFactories.putIfAbsent(qualifiedName(name, className), cfb)) {
+         throw new DeployException("Deployment " + className + " failed, " + name +" is already deployed");
+      }
+   }
+
+   private static String qualifiedName(String name, String className) {
+      return className + "#" + name;
+   }
+
+}

Added: projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/LocalConnectionFactoryBuilder.java
===================================================================
--- projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/LocalConnectionFactoryBuilder.java	                        (rev 0)
+++ projects/jboss-jca/trunk/common/src/main/java/org/jboss/jca/common/util/LocalConnectionFactoryBuilder.java	2010-02-17 07:02:19 UTC (rev 101062)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.jca.common.util;
+
+import org.jboss.jca.common.api.ConnectionFactoryBuilder;
+import org.jboss.jca.fungal.deployers.DeployException;
+
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+import javax.resource.spi.ManagedConnectionFactory;
+
+/**
+ * Local only connection factory builder.
+ *
+ * @author <a href="mailto:smarlow at redhat.com">Scott Marlow</a>
+ */
+public class LocalConnectionFactoryBuilder implements ConnectionFactoryBuilder {
+
+   private ManagedConnectionFactory mcf;
+   private Object cf;
+   private String name;
+
+   public ConnectionFactoryBuilder setName(String name) {
+      this.name = name;
+      return this;
+   }
+
+   public Reference getReference() throws DeployException  {
+      String className = cf.getClass().getName();
+      String name = this.name;
+      Reference ref = new Reference(
+         cf.getClass().getName(),
+         new StringRefAddr("class",className),
+         LocalApplicationServerJNDIHandler.class.getName(),
+         null);
+      ref.add(new StringRefAddr("name", name ));
+      LocalApplicationServerJNDIHandler.register(name, className, this);
+      return ref;
+   }
+
+   public ConnectionFactoryBuilder setManagedConnectionFactory(ManagedConnectionFactory mcf) {
+      this.mcf = mcf;
+      return this;
+   }
+
+   public ManagedConnectionFactory getManagedConnectionFactory() {
+      return mcf;
+   }
+
+   public ConnectionFactoryBuilder setConnectionFactory(Object cf) {
+      this.cf = cf;
+      return this;
+   }
+
+   public Object getConnectionFactory() {
+      return cf;
+   }
+}

Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java	2010-02-17 06:36:28 UTC (rev 101061)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/RADeployer.java	2010-02-17 07:02:19 UTC (rev 101062)
@@ -1,6 +1,6 @@
 /*
  * JBoss, Home of Professional Open Source.
- * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2008-2010, 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.
  *
@@ -22,6 +22,8 @@
 
 package org.jboss.jca.deployers.fungal;
 
+import org.jboss.jca.common.api.ConnectionFactoryBuilder;
+import org.jboss.jca.common.util.LocalConnectionFactoryBuilder;
 import org.jboss.jca.core.api.CloneableBootstrapContext;
 import org.jboss.jca.core.connectionmanager.notx.NoTxConnectionManager;
 import org.jboss.jca.deployers.common.validator.Failure;
@@ -57,8 +59,6 @@
 
 import javax.naming.Context;
 import javax.naming.InitialContext;
-//import javax.naming.NamingException;
-import javax.naming.Reference;
 import javax.resource.Referenceable;
 import javax.resource.spi.BootstrapContext;
 import javax.resource.spi.ManagedConnectionFactory;
@@ -379,6 +379,8 @@
                         beanValidationObjects.add(mcf);
                         associationObjects.add(mcf);
 
+                        ConnectionFactoryBuilder cfb = getConnectionFactoryBuilder();
+
                         // ConnectionFactory
                         Object cf = mcf.createConnectionFactory(new NoTxConnectionManager());
 
@@ -399,7 +401,9 @@
                                  jndiNames = new ArrayList<String>(1);
 
                               String jndiName = f.getName().substring(0, f.getName().indexOf(".rar"));
-                              bindConnectionFactory(jndiName, (Serializable)cf);
+
+                              cfb.setManagedConnectionFactory(mcf).setConnectionFactory(cf).setName(jndiName);
+                              bindConnectionFactory(jndiName, (Serializable)cf, cfb);
                               jndiNames.add(JNDI_PREFIX + jndiName);
                            }
                            else
@@ -607,6 +611,10 @@
       }
    }
 
+   private ConnectionFactoryBuilder getConnectionFactoryBuilder() {
+      return new LocalConnectionFactoryBuilder();
+   }
+
    /**
     * Start the resource adapter
     * @param resourceAdapter The resource adapter
@@ -704,7 +712,7 @@
 
    /**
     * Get the URLs for the directory and all libraries located in the directory
-    * @param directrory The directory
+    * @param directory The directory
     * @return The URLs
     * @exception MalformedURLException MalformedURLException
     * @exception IOException IOException
@@ -736,20 +744,25 @@
     * Bind connection factory into JNDI
     * @param name The JNDI name
     * @param cf The connection factory
-    * @exception Thrown if an error occurs
+    * @exception Exception thrown if an error occurs
     */
-   private void bindConnectionFactory(String name, Serializable cf) throws Exception
+   private void bindConnectionFactory(String name, Serializable cf, ConnectionFactoryBuilder cfb) throws Exception
    {
       Context context = new InitialContext();
+      try {
 
-      Util.bind(context, JNDI_PREFIX + name, cf);
-      
-      Referenceable referenceable = (Referenceable)cf;
-      Reference ref = null;
+         Referenceable referenceable = (Referenceable)cf;
+         referenceable.setReference(cfb.getReference());
 
-      referenceable.setReference(ref);
+         Util.bind(context, JNDI_PREFIX + name, cf);
+
+      }
+      finally {
+         context.close();     // release connection
+      }
    }
 
+
    /**
     * Clone
     * @return The copy of the object




More information about the jboss-cvs-commits mailing list