[jboss-cvs] JBossAS SVN: r75382 - in projects/jpa/trunk/deployers/src: test/java/org/jboss/jpa/deployers/test/common and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jul 4 05:58:19 EDT 2008
Author: wolfc
Date: 2008-07-04 05:58:19 -0400 (Fri, 04 Jul 2008)
New Revision: 75382
Added:
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/DataSourceDependencyResolver.java
projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/SimpleDataSourceDependencyResolver.java
Modified:
projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java
projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/deployment/DeploymentTestCase.xml
Log:
DataSourceDependencyResolver externalizes the naming conventions of a DataSource
Added: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/DataSourceDependencyResolver.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/DataSourceDependencyResolver.java (rev 0)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/DataSourceDependencyResolver.java 2008-07-04 09:58:19 UTC (rev 75382)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jpa.deployers;
+
+/**
+ * Find the bean name that supplies the given DataSource. Not that
+ * this bean might not be available yet.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface DataSourceDependencyResolver
+{
+ /**
+ * @param jndiName the jndiName of the DataSource
+ * @return the bean name of the DataSource
+ */
+ String resolveDataSourceSupplier(String jndiName);
+}
Modified: projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java
===================================================================
--- projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java 2008-07-04 09:56:46 UTC (rev 75381)
+++ projects/jpa/trunk/deployers/src/main/java/org/jboss/jpa/deployers/PersistenceUnitDeployer.java 2008-07-04 09:58:19 UTC (rev 75382)
@@ -28,6 +28,7 @@
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import org.jboss.beans.metadata.api.annotations.Inject;
import org.jboss.beans.metadata.api.annotations.MapValue;
import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
import org.jboss.beans.metadata.spi.BeanMetaData;
@@ -50,6 +51,8 @@
private static final Logger log = Logger.getLogger(PersistenceUnitDeployer.class);
private Properties defaultPersistenceProperties;
+
+ private DataSourceDependencyResolver dataSourceDependencyResolver;
public PersistenceUnitDeployer()
{
@@ -61,6 +64,33 @@
addOutput(BeanMetaData.class);
}
+ private void addDependencies(BeanMetaDataBuilder builder, PersistenceUnitMetaData metaData)
+ {
+ Properties props = defaultPersistenceProperties;
+ if (!props.containsKey("jboss.no.implicit.datasource.dependency"))
+ {
+ if (metaData.getJtaDataSource() != null)
+ {
+ String ds = metaData.getJtaDataSource();
+ builder.addDependency(dataSourceDependencyResolver.resolveDataSourceSupplier(ds));
+ }
+ if (metaData.getNonJtaDataSource() != null)
+ {
+ String ds = metaData.getNonJtaDataSource();
+ builder.addDependency(dataSourceDependencyResolver.resolveDataSourceSupplier(ds));
+ }
+ }
+ for (Object prop : props.keySet())
+ {
+ String property = (String) prop;
+ if (property.startsWith("jboss.depends"))
+ {
+ builder.addDependency(props.get(property));
+ }
+ }
+
+ }
+
@Override
public void deploy(DeploymentUnit unit, PersistenceUnitMetaData metaData) throws DeploymentException
{
@@ -82,6 +112,7 @@
AbstractBeanMetaData beanMetaData = new AbstractBeanMetaData(name, PersistenceUnitDeployment.class.getName());
BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(beanMetaData);
builder.setConstructorValue(pu);
+ addDependencies(builder, metaData);
unit.addAttachment(BeanMetaData.class, builder.getBeanMetaData());
}
@@ -91,6 +122,12 @@
}
}
+ @Inject
+ public void setDataSourceDependencyResolver(DataSourceDependencyResolver resolver)
+ {
+ this.dataSourceDependencyResolver = resolver;
+ }
+
@MapValue(keyClass=String.class, value={}, valueClass=String.class)
public void setDefaultPersistenceProperties(Properties p)
{
Added: projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/SimpleDataSourceDependencyResolver.java
===================================================================
--- projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/SimpleDataSourceDependencyResolver.java (rev 0)
+++ projects/jpa/trunk/deployers/src/test/java/org/jboss/jpa/deployers/test/common/SimpleDataSourceDependencyResolver.java 2008-07-04 09:58:19 UTC (rev 75382)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.jpa.deployers.test.common;
+
+import org.jboss.jpa.deployers.DataSourceDependencyResolver;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleDataSourceDependencyResolver implements DataSourceDependencyResolver
+{
+ public String resolveDataSourceSupplier(String jndiName)
+ {
+ return "DerbyService";
+ }
+}
Modified: projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/deployment/DeploymentTestCase.xml
===================================================================
--- projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/deployment/DeploymentTestCase.xml 2008-07-04 09:56:46 UTC (rev 75381)
+++ projects/jpa/trunk/deployers/src/test/resources/org/jboss/jpa/deployers/test/deployment/DeploymentTestCase.xml 2008-07-04 09:58:19 UTC (rev 75382)
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="urn:jboss:bean-deployer:2.0">
+ <bean name="DataSourceDependencyResolver" class="org.jboss.jpa.deployers.test.common.SimpleDataSourceDependencyResolver"/>
+
<bean name="PersistenceParsingDeployer" class="org.jboss.jpa.deployers.PersistenceParsingDeployer"/>
<bean name="PersistenceDeployer" class="org.jboss.jpa.deployers.PersistenceDeployer"/>
More information about the jboss-cvs-commits
mailing list