[jboss-cvs] JBossAS SVN: r109999 - in trunk: connector/src/resources/deployers and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 17 12:55:17 EST 2010


Author: jaikiran
Date: 2010-12-17 12:55:17 -0500 (Fri, 17 Dec 2010)
New Revision: 109999

Added:
   trunk/connector/src/main/java/org/jboss/resource/deployers/AbstractDataSourceDeployer.java
   trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceResRefResourceProvider.java
   trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceResource.java
   trunk/connector/src/main/java/org/jboss/resource/deployers/EJBDataSourceDeployer.java
   trunk/connector/src/main/java/org/jboss/resource/deployers/WebDataSourceDeployer.java
Removed:
   trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceDeployer.java
Modified:
   trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceDeployerHelper.java
   trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceReferenceResourceProvider.java
   trunk/connector/src/resources/deployers/jca-deployers-jboss-beans.xml
   trunk/server/src/etc/deployers/switchboard-jboss-beans.xml
Log:
JBAS-8548 Remaining pieces of support for data-source reference in a Java EE component

Copied: trunk/connector/src/main/java/org/jboss/resource/deployers/AbstractDataSourceDeployer.java (from rev 109982, trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceDeployer.java)
===================================================================
--- trunk/connector/src/main/java/org/jboss/resource/deployers/AbstractDataSourceDeployer.java	                        (rev 0)
+++ trunk/connector/src/main/java/org/jboss/resource/deployers/AbstractDataSourceDeployer.java	2010-12-17 17:55:17 UTC (rev 109999)
@@ -0,0 +1,157 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.resource.deployers;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.javaee.spec.DataSourceMetaData;
+import org.jboss.metadata.javaee.spec.DataSourcesMetaData;
+import org.jboss.reloaded.naming.deployers.javaee.JavaEEComponentInformer;
+import org.jboss.resource.metadata.mcf.ConnectionPoolMetaData;
+import org.jboss.resource.metadata.mcf.DataSourceDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup;
+
+/**
+ * The DataSourceDeployer is designed to satisfy the EE6 specification
+ * requirement 5.17 where data-sources can be defined in the application.xml,
+ * ejb-jar.xml, web.xml and application-client.xml descriptors. The
+ * DataSourceDeployer simply reads the appropriate instances of meta data and
+ * translates each to the appropriate ManagedConnectionFactoryDeployment type which is in turn
+ * passed to the ManagedConnectionFactoryDeployer for real deployment.
+ * 
+ * @author Weston M. Price
+ * 
+ * 
+ */
+public abstract class AbstractDataSourceDeployer extends AbstractDeployer {
+
+	private static final Logger logger = Logger.getLogger(AbstractDataSourceDeployer.class);
+	
+	private JavaEEComponentInformer informer;
+	
+	public AbstractDataSourceDeployer() {
+		setStage(DeploymentStages.REAL);
+		
+		this.setOutput(ManagedConnectionFactoryDeploymentGroup.class);
+	}
+		
+
+	@Inject
+	public void setJavaEEComponentInformer(JavaEEComponentInformer informer)
+	{
+		this.informer = informer;
+	}
+	
+	@Override
+	public void deploy(DeploymentUnit unit) throws DeploymentException 
+	{
+		DataSourcesMetaData dsmd = this.getDataSources(unit);
+		if (dsmd == null)
+		{
+		   return;
+		}
+		Collection<DataSourceDeploymentMetaData> dataSourceDeployments = getDataSourceDeployments(dsmd, unit);
+		this.attachManagedConnectionFactories(unit, dataSourceDeployments);  
+	}
+	
+	protected abstract DataSourcesMetaData getDataSources(DeploymentUnit unit);
+
+	private Collection<DataSourceDeploymentMetaData> getDataSourceDeployments(DataSourcesMetaData dataSources, DeploymentUnit unit) 
+	{
+		Collection<DataSourceDeploymentMetaData> datasourceDeployments = new ArrayList<DataSourceDeploymentMetaData>();
+		
+		
+		for(String key: dataSources.keySet())
+		{
+		    DataSourceDeploymentMetaData depMd = null;
+			DataSourceMetaData dsmd = dataSources.get(key);
+			
+			if(dsmd.isTransactional())
+			{
+				depMd = DataSourceDeployerHelper.createTxnDeployment(dsmd);
+			}
+			else
+			{
+				depMd = DataSourceDeployerHelper.createNonTxnDeployment(dsmd);				
+			}
+			
+			
+			depMd.setJndiName(DataSourceDeployerHelper.normalizeJndiName(dsmd, unit, informer));
+			depMd.setUserName(dsmd.getUser());
+			depMd.setPassWord(dsmd.getPassword());
+			
+			if(dsmd.getIsolationLevel() != null)
+			{
+				depMd.setTransactionIsolation(dsmd.getIsolationLevel().toString());				
+			}
+												
+			ConnectionPoolMetaData cpmd = (ConnectionPoolMetaData)depMd;
+			
+			if(dsmd.getMinPoolSize() < 0)
+			{
+				cpmd.setMinSize(0);
+			}
+			else
+			{
+				cpmd.setMinSize(dsmd.getMinPoolSize());
+			}
+			
+			cpmd.setMaxSize(dsmd.getMaxPoolSize());
+			cpmd.setIdleTimeoutMinutes(dsmd.getMaxIdleTime() / 60);
+			if (dsmd.getLoginTimeout() > 0)
+			{
+			   cpmd.setBlockingTimeoutMilliSeconds(dsmd.getLoginTimeout() * 1000);
+			}
+			
+			datasourceDeployments.add(depMd);						
+			
+		}
+		
+				
+		return datasourceDeployments;
+	}
+	
+	private void attachManagedConnectionFactories(DeploymentUnit unit, Collection<DataSourceDeploymentMetaData> datasourceDeployments)
+	{
+	   DeploymentUnit nonComponentDU =  unit.isComponent() ? unit.getParent() : unit;
+	   ManagedConnectionFactoryDeploymentGroup managedConnectionFactories = nonComponentDU.getAttachment(ManagedConnectionFactoryDeploymentGroup.class);
+       if (managedConnectionFactories == null)
+       {
+          managedConnectionFactories = new ManagedConnectionFactoryDeploymentGroup();
+       }
+       
+       for (DataSourceDeploymentMetaData dataSourceDeployment : datasourceDeployments)
+       {
+          managedConnectionFactories.addManagedConnectionFactoryDeployment(dataSourceDeployment);
+       }
+       nonComponentDU.addAttachment(ManagedConnectionFactoryDeploymentGroup.class, managedConnectionFactories);
+	}
+
+	
+}

Deleted: trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceDeployer.java
===================================================================
--- trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceDeployer.java	2010-12-17 17:24:08 UTC (rev 109998)
+++ trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceDeployer.java	2010-12-17 17:55:17 UTC (rev 109999)
@@ -1,237 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt 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.resource.deployers;
-
-import org.jboss.beans.metadata.api.annotations.Inject;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.logging.Logger;
-import org.jboss.metadata.client.spec.ApplicationClientMetaData;
-import org.jboss.metadata.ear.spec.Ear60MetaData;
-import org.jboss.metadata.ear.spec.EarMetaData;
-import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
-import org.jboss.metadata.ejb.jboss.JBossMetaData;
-import org.jboss.metadata.javaee.spec.DataSourceMetaData;
-import org.jboss.metadata.javaee.spec.DataSourcesMetaData;
-import org.jboss.metadata.web.spec.WebMetaData;
-import org.jboss.reloaded.naming.deployers.javaee.JavaEEComponentInformer;
-import org.jboss.resource.metadata.mcf.ConnectionPoolMetaData;
-import org.jboss.resource.metadata.mcf.DataSourceDeploymentMetaData;
-import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup;
-
-/**
- * The DataSourceDeployer is designed to satisfy the EE6 specification
- * requirement 5.17 where data-sources can be defined in the application.xml,
- * ejb-jar.xml, web.xml and application-client.xml descriptors. The
- * DataSourceDeployer simply reads the appropriate instances of meta data and
- * translates each to the appropriate ManagedConnectionFactoryDeployment type which is in turn
- * passed to the ManagedConnectionFactoryDeployer for real deployment.
- * 
- * @author Weston M. Price
- * 
- * 
- */
-public class DataSourceDeployer extends AbstractDeployer {
-
-	private static final Logger logger = Logger.getLogger(DataSourceDeployer.class);
-	
-	private boolean isEARSupported = true;
-	private boolean isWARSupported = true;
-	private boolean isEJBSupported = true;
-	private boolean isCARSupported = true;
-
-	private JavaEEComponentInformer informer;
-	
-	public DataSourceDeployer() {
-		setStage(DeploymentStages.PRE_REAL);
-		addInput(EarMetaData.class);
-		addInput(WebMetaData.class);
-		addInput(ApplicationClientMetaData.class);
-		addInput(JBossMetaData.class);
-	}
-		
-	public boolean isEARSupported() {
-		return isEARSupported;
-	}
-
-	public void setEARSupported(boolean isEARSupported) {
-		this.isEARSupported = isEARSupported;
-	}
-
-	public boolean isWARSupported() {
-		return isWARSupported;
-	}
-
-	public void setWARSupported(boolean isWARSupported) {
-		this.isWARSupported = isWARSupported;
-	}
-
-	public boolean isEJBSupported() {
-		return isEJBSupported;
-	}
-
-	public void setEJBSupported(boolean isEJBSupported) {
-		this.isEJBSupported = isEJBSupported;
-	}
-
-	public boolean isCARSupported() {
-		return isCARSupported;
-	}
-
-	public void setCARSupported(boolean isCARSupported) {
-		this.isCARSupported = isCARSupported;
-	}
-	
-	@Inject
-	public void setJavaEEComponentInformer(JavaEEComponentInformer informer)
-	{
-		this.informer = informer;
-	}
-	
-	@Override
-	public void deploy(DeploymentUnit unit) throws DeploymentException 
-	{
-		DataSourcesMetaData dsmd = getDataSourcesMetaData(unit);
-		ManagedConnectionFactoryDeploymentGroup group = getMCFMetaData(dsmd, unit); 
-		unit.addAttachment(ManagedConnectionFactoryDeploymentGroup.class, group);
-	}
-
-	private ManagedConnectionFactoryDeploymentGroup getMCFMetaData(DataSourcesMetaData dataSources, DeploymentUnit unit) 
-	{
-		ManagedConnectionFactoryDeploymentGroup group = new ManagedConnectionFactoryDeploymentGroup();
-		DataSourceDeploymentMetaData depMd = null;
-		
-		for(String key: dataSources.keySet())
-		{
-			DataSourceMetaData dsmd = dataSources.get(key);
-			
-			if(dsmd.isTransactional())
-			{
-				depMd = DataSourceDeployerHelper.createTxnDeployment(dsmd);
-			}
-			else
-			{
-				depMd = DataSourceDeployerHelper.createNonTxnDeployment(dsmd);				
-			}
-			
-			
-			depMd.setJndiName(DataSourceDeployerHelper.normalizeJndiName(dsmd, unit, informer));
-			depMd.setUserName(dsmd.getUser());
-			depMd.setPassWord(dsmd.getPassword());
-			
-			if(dsmd.getIsolationLevel() != null)
-			{
-				depMd.setTransactionIsolation(dsmd.getIsolationLevel().toString());				
-			}
-												
-			ConnectionPoolMetaData cpmd = (ConnectionPoolMetaData)depMd;
-			
-			if(dsmd.getMinPoolSize() < 0)
-			{
-				cpmd.setMinSize(0);
-			}
-			else
-			{
-				cpmd.setMinSize(dsmd.getMinPoolSize());
-			}
-			
-			cpmd.setMaxSize(dsmd.getMaxPoolSize());
-			cpmd.setIdleTimeoutMinutes(dsmd.getMaxIdleTime() / 60);						
-			cpmd.setBlockingTimeoutMilliSeconds(dsmd.getLoginTimeout() * 1000);
-			
-			group.addManagedConnectionFactoryDeployment(depMd);						
-			
-		}
-		
-				
-		return group;
-	}
-
-	private DataSourcesMetaData getDataSourcesMetaData(DeploymentUnit du) 
-	{
-		DataSourcesMetaData candidates = new DataSourcesMetaData();
-		DataSourcesMetaData temp = null;
-		
-		WebMetaData wmd = du.getAttachment(WebMetaData.class);
-		
-		if(isWARSupported() && wmd != null && wmd.is30())
-		{
-			if(wmd.getJndiEnvironmentRefsGroup() != null)
-			{
-				temp = wmd.getJndiEnvironmentRefsGroup().getDataSources();
-				
-				if(temp != null && !temp.isEmpty())
-				{
-					candidates.addAll(temp);
-				}				
-			}
-		}
-		
-		EarMetaData emd = du.getAttachment(EarMetaData.class);
-		
-		if(isEARSupported() && (emd != null && emd.isEE6()))
-		{
-			if( ((Ear60MetaData)emd).getEarEnvironmentRefsGroup() != null)
-			{
-				temp = ((Ear60MetaData)emd).getEarEnvironmentRefsGroup().getDataSources();
-				
-				if(temp != null && !temp.isEmpty())
-				{
-					candidates.addAll(temp);
-				}
-			}
-			
-		}
-
-		JBossMetaData ebmd = du.getAttachment(JBossMetaData.class);
-
-		if(isEJBSupported() && (ebmd != null && ebmd.isEJB31()))
-		{
-			if(ebmd.getEnterpriseBeans() != null)
-			{
-				for(JBossEnterpriseBeanMetaData md: ebmd.getEnterpriseBeans())
-				{
-					temp = md.getDataSources();
-					
-					if(temp != null && !temp.isEmpty())
-					{
-						candidates.addAll(temp);
-					}
-				}
-				
-			}
-		
-		}
-
-		ApplicationClientMetaData acmd = du.getAttachment(ApplicationClientMetaData.class);
-		
-		if(isCARSupported() && acmd != null)
-		{
-			//TODO support application clients	
-		}
-		
-		return candidates;
-	}
-	
-}

Modified: trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceDeployerHelper.java
===================================================================
--- trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceDeployerHelper.java	2010-12-17 17:24:08 UTC (rev 109998)
+++ trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceDeployerHelper.java	2010-12-17 17:55:17 UTC (rev 109999)
@@ -52,34 +52,44 @@
 		
 	}
 	
-	public static String normalizeJndiName(DataSourceMetaData dsmd, DeploymentUnit unit, JavaEEComponentInformer informer)
-	{
-		return normalizeJndiName(dsmd.getName(), unit, informer);
-	}
+   public static String normalizeJndiName(DataSourceMetaData dsmd, DeploymentUnit unit, JavaEEComponentInformer informer)
+   {
+      // If it starts with some namespace (like java:comp, java:module, java:app or java:global)
+      // then return as is
+      String refName = dsmd.getName();
+      if (refName.startsWith("java:comp/") || refName.startsWith("java:module/") || refName.startsWith("java:app/")
+            || refName.startsWith("java:global/"))
+      {
+         return normalizeJndiName(refName, unit, informer);
+      }
+      else
+      {
+         // the reference name *doesn't* start with any namespace. So prefix a "env" before the
+         // name and return
+         return normalizeJndiName("env/" + refName, unit, informer);
+      }
+
+   }
 	
 	public static String normalizeJndiName(String dsJndiName, DeploymentUnit unit, JavaEEComponentInformer informer)
     {
         String jndiName = normalizeJndiName(dsJndiName);
-        StringBuffer results = new StringBuffer();
-        String dsName = null;
+        StringBuffer internalJndiName = new StringBuffer();
+        String dsName = jndiName;
         
         if(jndiName.indexOf("/") != -1 && scopes.contains(jndiName.substring(0, jndiName.indexOf("/"))))
         {                       
             dsName = jndiName.substring(jndiName.indexOf("/") + 1, jndiName.length());
-            
-            results.append("internal/" + informer.getApplicationName(unit) + "/" + informer.getModuleName(unit) + "/");
-            
-            if(informer.isJavaEEComponent(unit))
-            {
-                results.append(informer.getComponentName(unit) + "/");
-            }
-                        
-            return results.append(dsName).toString();
+        }
+        internalJndiName.append("internal/" + informer.getApplicationName(unit) + "/" + informer.getModuleName(unit) + "/");
         
+        if(informer.isJavaEEComponent(unit))
+        {
+            internalJndiName.append(informer.getComponentName(unit) + "/");
         }
+                    
+        return internalJndiName.append(dsName).toString();
         
-        
-        return jndiName;
     }
 	
 	

Modified: trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceReferenceResourceProvider.java
===================================================================
--- trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceReferenceResourceProvider.java	2010-12-17 17:24:08 UTC (rev 109998)
+++ trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceReferenceResourceProvider.java	2010-12-17 17:55:17 UTC (rev 109999)
@@ -21,11 +21,6 @@
  */
 package org.jboss.resource.deployers;
 
-import java.util.Collection;
-import java.util.Collections;
-
-import javax.naming.LinkRef;
-
 import org.jboss.beans.metadata.api.annotations.Inject;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.reloaded.naming.deployers.javaee.JavaEEComponentInformer;
@@ -71,7 +66,7 @@
       // convert it to internal JBoss specific jndi name
       // Note that the normalize method return a jndi name without an prefix but the DSDeployer binds to
       // java: prefix by default. So we prefix the java: to this returned normalized jndi name
-      String internalJndiNameWithoutNamespace = DataSourceDeployerHelper.normalizeJndiName(dsJndiName, unit.isComponent() ? unit.getParent() : unit, informer);
+      String internalJndiNameWithoutNamespace = DataSourceDeployerHelper.normalizeJndiName(dsJndiName, unit, informer);
       String targetJndiName = "java:/" + internalJndiNameWithoutNamespace;
       
       // the binder which binds to the internal JBoss specific jndi name
@@ -80,73 +75,4 @@
       // create and return the resource
       return new DataSourceResource(targetJndiName, binderName);
    }
-   
-   /**
-    * {@link Resource} for a data-source/@DataSourceDefinition reference
-    *
-    * @author Jaikiran Pai
-    * @version $Revision: $
-    */
-   private class DataSourceResource implements Resource
-   {
-
-      /**
-       * The LinkRef to internal JBoss specific jndi name of the datasource
-       */
-      private LinkRef target;
-      
-      /**
-       * The JBoss internal datasource binder which binds the datasource to an internal
-       * jndi name 
-       */
-      private String dataSourceBinderName;
-      
-      /**
-       * 
-       * @param internalJndiName JBoss specific internal jndi name for the datasource
-       * @param datasourceBinderName The binder which binds the datasource to the JBoss specific internal jndi name
-       */
-      DataSourceResource(String internalJndiName, String datasourceBinderName)
-      {
-         this.target = new LinkRef(internalJndiName);
-         this.dataSourceBinderName = datasourceBinderName;
-      }
-      
-      /**
-       * {@inheritDoc}
-       */
-      @Override
-      public Object getDependency()
-      {
-         // a LinkRef doesn't need to depend on anything *during bind time*
-         return null;
-      }
-
-      /**
-       * {@inheritDoc}
-       */
-      @Override
-      public Collection<?> getInvocationDependencies()
-      {
-         if (this.dataSourceBinderName == null || this.dataSourceBinderName.trim().isEmpty())
-         {
-            return null;
-         }
-         // this DataSourceResource, for lookup/invocation, depends on the binder which binds the datasource to internal
-         // JNDI name
-         return Collections.singleton(this.dataSourceBinderName);
-      }
-
-      /**
-       * {@inheritDoc}
-       */
-      @Override
-      public Object getTarget()
-      {
-         // return the LinkRef to internal JBoss specific jndi name of the datasource
-         return this.target;
-      }
-      
-   }
-
 }

Added: trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceResRefResourceProvider.java
===================================================================
--- trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceResRefResourceProvider.java	                        (rev 0)
+++ trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceResRefResourceProvider.java	2010-12-17 17:55:17 UTC (rev 109999)
@@ -0,0 +1,96 @@
+/*
+ * 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.resource.deployers;
+
+import org.jboss.beans.metadata.api.annotations.Inject;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
+import org.jboss.reloaded.naming.deployers.javaee.JavaEEComponentInformer;
+import org.jboss.switchboard.impl.resource.LinkRefResource;
+import org.jboss.switchboard.javaee.jboss.environment.JBossResourceRefType;
+import org.jboss.switchboard.mc.spi.MCBasedResourceProvider;
+import org.jboss.switchboard.spi.Resource;
+
+/**
+ * {@link MCBasedResourceProvider Resource provider} for res-ref of type javax.sql.DataSource
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class DataSourceResRefResourceProvider implements MCBasedResourceProvider<JBossResourceRefType>
+{
+
+   
+   private static Logger logger = Logger.getLogger(DataSourceResRefResourceProvider.class);
+   
+   /**
+    * JavaEE component informer
+    */
+   private JavaEEComponentInformer informer;
+
+   @Inject
+   public void setJavaEEComponentInformer(JavaEEComponentInformer informer)
+   {
+      this.informer = informer;
+   }
+   
+   @Override
+   public Class<JBossResourceRefType> getEnvironmentEntryType()
+   {
+      return JBossResourceRefType.class;
+   }
+
+   @Override
+   public Resource provide(DeploymentUnit unit, JBossResourceRefType resRef)
+   {
+      // let's check if there's any explicit jndi/mapped/lookup name
+      String lookupName = resRef.getLookupName();
+      if (lookupName != null && !lookupName.trim().isEmpty())
+      {
+         return new LinkRefResource(lookupName, null, resRef.isIgnoreDependency());
+      }
+
+      // now check mapped name
+      String mappedName = resRef.getMappedName();
+      if (mappedName != null && !mappedName.trim().isEmpty())
+      {
+         return new LinkRefResource(mappedName, null, resRef.isIgnoreDependency());
+      }
+      
+      // now check (JBoss specific) jndi name!
+      String jndiName = resRef.getJNDIName();
+      if (jndiName != null && !jndiName.trim().isEmpty())
+      {
+         return new LinkRefResource(jndiName, null, resRef.isIgnoreDependency());
+      }
+      String internalJndiNameWithoutNamespace = DataSourceDeployerHelper.normalizeJndiName(resRef.getName(), unit, informer);
+      String targetJndiName = "java:/" + internalJndiNameWithoutNamespace;
+      // the binder which binds to the internal JBoss specific jndi name
+      String binderName = "jboss.jca:name=" + internalJndiNameWithoutNamespace + ",service=DataSourceBinding";
+
+      logger.debug("No jndi-name/mapped-name/lookup specified for res-ref: " + resRef.getName() + " of type datasource. Will return a Resource which depends on datasource binder: " + binderName);
+
+      // create and return the resource
+      return new DataSourceResource(targetJndiName, binderName);   
+   }
+
+}

Added: trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceResource.java
===================================================================
--- trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceResource.java	                        (rev 0)
+++ trunk/connector/src/main/java/org/jboss/resource/deployers/DataSourceResource.java	2010-12-17 17:55:17 UTC (rev 109999)
@@ -0,0 +1,103 @@
+/*
+ * 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.resource.deployers;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.naming.LinkRef;
+
+import org.jboss.switchboard.spi.Resource;
+
+/**
+ * {@link Resource} for a data-source/@DataSourceDefinition reference
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class DataSourceResource implements Resource
+{
+
+   
+   /**
+    * The JBoss internal datasource binder which binds the datasource to an internal
+    * jndi name 
+    */
+   private String dataSourceBinderName;
+   
+   /**
+    * The internal JBoss specific jndi name of the datasource
+    */
+   private String targetJndiName;
+   
+   /**
+    * 
+    * @param internalJndiName JBoss specific internal jndi name for the datasource
+    * @param datasourceBinderName The binder which binds the datasource to the JBoss specific internal jndi name
+    */
+   public DataSourceResource(String internalJndiName, String datasourceBinderName)
+   {
+      this.targetJndiName = internalJndiName;
+      this.dataSourceBinderName = datasourceBinderName;
+   }
+   
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Object getDependency()
+   {
+      // a LinkRef doesn't need to depend on anything *during bind time*
+      return null;
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Collection<?> getInvocationDependencies()
+   {
+      if (this.dataSourceBinderName == null || this.dataSourceBinderName.trim().isEmpty())
+      {
+         return null;
+      }
+      // this DataSourceResource, for lookup/invocation, depends on the binder which binds the datasource to internal
+      // JNDI name
+      return Collections.singleton(this.dataSourceBinderName);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
+   @Override
+   public Object getTarget()
+   {
+      // return the LinkRef to internal JBoss specific jndi name of the datasource
+      return new LinkRef(this.targetJndiName);
+   }
+   
+   @Override
+   public String toString()
+   {
+      return "DataSourceResource[jndiname=" + this.targetJndiName + " ,binderName=" + this.dataSourceBinderName + "]";
+   }
+}

Added: trunk/connector/src/main/java/org/jboss/resource/deployers/EJBDataSourceDeployer.java
===================================================================
--- trunk/connector/src/main/java/org/jboss/resource/deployers/EJBDataSourceDeployer.java	                        (rev 0)
+++ trunk/connector/src/main/java/org/jboss/resource/deployers/EJBDataSourceDeployer.java	2010-12-17 17:55:17 UTC (rev 109999)
@@ -0,0 +1,78 @@
+/*
+ * 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.resource.deployers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorMetaData;
+import org.jboss.metadata.ejb.spec.InterceptorsMetaData;
+import org.jboss.metadata.javaee.spec.DataSourcesMetaData;
+
+/**
+ * Deployer for processing @DataSourceDefinition/data-source for EJB3 deployments
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class EJBDataSourceDeployer extends AbstractDataSourceDeployer
+{
+
+   public EJBDataSourceDeployer()
+   {
+      this.setInput(JBossEnterpriseBeanMetaData.class);
+      this.setComponentsOnly(true);
+   }
+   
+   @Override
+   protected DataSourcesMetaData getDataSources(DeploymentUnit unit)
+   {
+      JBossEnterpriseBeanMetaData enterpriseBean = unit.getAttachment(JBossEnterpriseBeanMetaData.class);
+      
+      if(!enterpriseBean.getJBossMetaData().isEJB31())
+      {
+         return null;
+      }
+      DataSourcesMetaData dataSources = new DataSourcesMetaData();
+      // datasources on the EJB
+      if (enterpriseBean.getDataSources() != null)
+      {
+         dataSources.addAll(enterpriseBean.getDataSources());
+      }
+      // datasources on the interceptors of the EJB
+      InterceptorsMetaData interceptors = JBossMetaData.getInterceptors(enterpriseBean.getEjbName(), enterpriseBean.getJBossMetaData());
+      if (interceptors != null)
+      {
+         for (InterceptorMetaData interceptor : interceptors)
+         {
+            if (interceptor == null || interceptor.getDataSources() == null)
+            {
+               continue;
+            }
+            dataSources.addAll(interceptor.getDataSources());
+         }
+      }
+      
+      return dataSources;
+   }
+
+}

Added: trunk/connector/src/main/java/org/jboss/resource/deployers/WebDataSourceDeployer.java
===================================================================
--- trunk/connector/src/main/java/org/jboss/resource/deployers/WebDataSourceDeployer.java	                        (rev 0)
+++ trunk/connector/src/main/java/org/jboss/resource/deployers/WebDataSourceDeployer.java	2010-12-17 17:55:17 UTC (rev 109999)
@@ -0,0 +1,54 @@
+/*
+ * 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.resource.deployers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.metadata.javaee.spec.DataSourcesMetaData;
+import org.jboss.metadata.web.jboss.JBossWebMetaData;
+
+/**
+ * Deployer for processing @DataSourceDefinition/data-source for web deployments
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class WebDataSourceDeployer extends AbstractDataSourceDeployer
+{
+
+   public WebDataSourceDeployer()
+   {
+      this.setInput(JBossWebMetaData.class);
+   }
+   
+   @Override
+   protected DataSourcesMetaData getDataSources(DeploymentUnit unit)
+   {
+      JBossWebMetaData jbosswebMetaData = unit.getAttachment(JBossWebMetaData.class);
+
+      if (!jbosswebMetaData.is30() || jbosswebMetaData.getJndiEnvironmentRefsGroup() == null)
+      {
+         return null;
+      }
+      return jbosswebMetaData.getJndiEnvironmentRefsGroup().getDataSources();
+   }
+
+}

Modified: trunk/connector/src/resources/deployers/jca-deployers-jboss-beans.xml
===================================================================
--- trunk/connector/src/resources/deployers/jca-deployers-jboss-beans.xml	2010-12-17 17:24:08 UTC (rev 109998)
+++ trunk/connector/src/resources/deployers/jca-deployers-jboss-beans.xml	2010-12-17 17:55:17 UTC (rev 109999)
@@ -183,12 +183,14 @@
    		<constructor><parameter><inject bean="PersistenceFactory" /></parameter></constructor>
    </bean>
 	
-	<!--  Deployer responsible for managing EE5.17 data source definitions -->
-   <bean name="DataSourceDeployer" class="org.jboss.resource.deployers.DataSourceDeployer">      
-   		<property name="CARSupported">false</property>   		
-   </bean>	
-
+	<!--  Deployer responsible for processing datasources in a EJB3 deployment (EE5.17 data source definitions) -->
+    <bean name="EJBDataSourceDeployer" class="org.jboss.resource.deployers.EJBDataSourceDeployer"/>      
+    <!--  Deployer responsible for processing datasources in a web deployment (EE5.17 data source definitions) -->
+    <bean name="WebDataSourceDeployer" class="org.jboss.resource.deployers.WebDataSourceDeployer"/>
+    
     <!--  ResourceProvider for @DataSourceDefinition/<data-source> (Java EE 6 Spec, section EE.5.17) -->
     <bean name="org.jboss.switchboard.DataSourceReferenceResourceProvider" class="org.jboss.resource.deployers.DataSourceReferenceResourceProvider"/>
+    <!--  ResourceProvider for resource-ref of type javax.sql.DataSource -->
+    <bean name="org.jboss.switchboard.DataSourceResRefResourceProvider" class="org.jboss.resource.deployers.DataSourceResRefResourceProvider"/>
     
 </deployment>

Modified: trunk/server/src/etc/deployers/switchboard-jboss-beans.xml
===================================================================
--- trunk/server/src/etc/deployers/switchboard-jboss-beans.xml	2010-12-17 17:24:08 UTC (rev 109998)
+++ trunk/server/src/etc/deployers/switchboard-jboss-beans.xml	2010-12-17 17:55:17 UTC (rev 109999)
@@ -104,6 +104,10 @@
                         </bean>
                     </value>
                 </entry>
+                <entry>
+                    <key>javax.sql.DataSource</key>
+                    <value><inject bean="org.jboss.switchboard.DataSourceResRefResourceProvider"/></value>
+                </entry>
             </map>           
         </property>
         <property name="fallbackResourceRefResourceProviders">



More information about the jboss-cvs-commits mailing list