geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jarek Gawor <jga...@gmail.com>
Subject Re: svn commit: r958821 - in /geronimo/server/trunk/plugins: client/client-deployer/src/main/plan/ j2ee/j2ee-deployer/src/main/plan/ openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/ openjpa2/persisten
Date Tue, 03 Aug 2010 05:21:51 GMT
David,

Can you explain why look for persistence units for references in a
given module only? Shouldn't it be checking the module first and then
the application and then its parents?

Jarek

On Tue, Jun 29, 2010 at 12:42 AM,  <djencks@apache.org> wrote:
> Author: djencks
> Date: Tue Jun 29 04:42:13 2010
> New Revision: 958821
>
> URL: http://svn.apache.org/viewvc?rev=958821&view=rev
> Log:
> Only look in module and parents for persistence units.  Only look in module for persistence
units for refs.  Combine persistence unit and context ref builders.
>
> Added:
>    geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
  (contents, props changed)
>      - copied, changed from r958756, geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java
> Removed:
>    geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java
>    geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java
> Modified:
>    geronimo/server/trunk/plugins/client/client-deployer/src/main/plan/plan.xml
>    geronimo/server/trunk/plugins/j2ee/j2ee-deployer/src/main/plan/plan.xml
>    geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
>    geronimo/server/trunk/plugins/openjpa2/persistence-jpa20-deployer/src/main/plan/plan.xml
>
> Modified: geronimo/server/trunk/plugins/client/client-deployer/src/main/plan/plan.xml
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/client/client-deployer/src/main/plan/plan.xml?rev=958821&r1=958820&r2=958821&view=diff
> ==============================================================================
> --- geronimo/server/trunk/plugins/client/client-deployer/src/main/plan/plan.xml (original)
> +++ geronimo/server/trunk/plugins/client/client-deployer/src/main/plan/plan.xml Tue Jun
29 04:42:13 2010
> @@ -42,7 +42,7 @@
>                 <name>GBeanRefBuilder</name>
>             </pattern>
>             <pattern>
> -                <name>PersistenceUnitRefBuilder</name>
> +                <name>PersistenceRefBuilder</name>
>             </pattern>
>             <pattern>
>                 <name>ClientResourceRefBuilder</name>
>
> Modified: geronimo/server/trunk/plugins/j2ee/j2ee-deployer/src/main/plan/plan.xml
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/j2ee-deployer/src/main/plan/plan.xml?rev=958821&r1=958820&r2=958821&view=diff
> ==============================================================================
> --- geronimo/server/trunk/plugins/j2ee/j2ee-deployer/src/main/plan/plan.xml (original)
> +++ geronimo/server/trunk/plugins/j2ee/j2ee-deployer/src/main/plan/plan.xml Tue Jun 29
04:42:13 2010
> @@ -115,10 +115,7 @@
>                 <name>GBeanRefBuilder</name>
>             </pattern>
>             <pattern>
> -                <name>PersistenceContextRefBuilder</name>
> -            </pattern>
> -            <pattern>
> -                <name>PersistenceUnitRefBuilder</name>
> +                <name>PersistenceRefBuilder</name>
>             </pattern>
>             <pattern>
>                 <name>DataSourceBuilder</name>
>
> Copied: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
(from r958756, geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java)
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java?p2=geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java&p1=geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java&r1=958756&r2=958821&rev=958821&view=diff
> ==============================================================================
> --- geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java
(original)
> +++ geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
Tue Jun 29 04:42:13 2010
> @@ -32,21 +32,32 @@ import org.apache.geronimo.gbean.Abstrac
>  import org.apache.geronimo.gbean.GBeanData;
>  import org.apache.geronimo.gbean.annotation.GBean;
>  import org.apache.geronimo.gbean.annotation.ParamAttribute;
> +import org.apache.geronimo.j2ee.deployment.EARContext;
>  import org.apache.geronimo.j2ee.deployment.Module;
> +import org.apache.geronimo.j2ee.deployment.annotation.PersistenceContextAnnotationHelper;
>  import org.apache.geronimo.j2ee.deployment.annotation.PersistenceUnitAnnotationHelper;
>  import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
>  import org.apache.geronimo.kernel.GBeanNotFoundException;
>  import org.apache.geronimo.kernel.config.Configuration;
>  import org.apache.geronimo.kernel.repository.Environment;
>  import org.apache.geronimo.naming.deployment.AbstractNamingBuilder;
> +import org.apache.geronimo.naming.reference.PersistenceContextReference;
>  import org.apache.geronimo.naming.reference.PersistenceUnitReference;
>  import org.apache.geronimo.schema.NamespaceElementConverter;
>  import org.apache.geronimo.schema.SchemaConversionUtils;
>  import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
> +import org.apache.geronimo.xbeans.geronimo.naming.GerPersistenceContextRefDocument;
> +import org.apache.geronimo.xbeans.geronimo.naming.GerPersistenceContextRefType;
> +import org.apache.geronimo.xbeans.geronimo.naming.GerPersistenceContextTypeType;
>  import org.apache.geronimo.xbeans.geronimo.naming.GerPersistenceUnitRefDocument;
>  import org.apache.geronimo.xbeans.geronimo.naming.GerPersistenceUnitRefType;
> +import org.apache.geronimo.xbeans.geronimo.naming.GerPropertyType;
>  import org.apache.openejb.jee.JndiConsumer;
> +import org.apache.openejb.jee.PersistenceContextRef;
> +import org.apache.openejb.jee.PersistenceContextType;
> +import org.apache.openejb.jee.PersistenceRef;
>  import org.apache.openejb.jee.PersistenceUnitRef;
> +import org.apache.openejb.jee.Property;
>  import org.apache.xmlbeans.QNameSet;
>  import org.apache.xmlbeans.XmlObject;
>
> @@ -54,17 +65,19 @@ import org.apache.xmlbeans.XmlObject;
>  * @version $Rev$ $Date$
>  */
>  @GBean(j2eeType = NameFactory.MODULE_BUILDER)
> -public class PersistenceUnitRefBuilder extends AbstractNamingBuilder {
> +public class PersistenceRefBuilder extends AbstractNamingBuilder {
>     private static final QName PERSISTENCE_UNIT_REF_QNAME = new QName(JEE_NAMESPACE,
"persistence-unit-ref");
>     private static final QNameSet PERSISTENCE_UNIT_REF_QNAME_SET = QNameSet.singleton(PERSISTENCE_UNIT_REF_QNAME);
>     private static final QName GER_PERSISTENCE_UNIT_REF_QNAME = GerPersistenceUnitRefDocument.type.getDocumentElementName();
>     private static final QNameSet GER_PERSISTENCE_UNIT_REF_QNAME_SET = QNameSet.singleton(GER_PERSISTENCE_UNIT_REF_QNAME);
>     private static final Set PERSISTENCE_UNIT_INTERFACE_TYPES = Collections.singleton("org.apache.geronimo.persistence.PersistenceUnitGBean");
> +    private static final QName GER_PERSISTENCE_CONTEXT_REF_QNAME = GerPersistenceContextRefDocument.type.getDocumentElementName();
> +    private static final QNameSet GER_PERSISTENCE_CONTEXT_REF_QNAME_SET = QNameSet.singleton(GER_PERSISTENCE_CONTEXT_REF_QNAME);
>     private final AbstractNameQuery defaultPersistenceUnitAbstractNameQuery;
>     private final boolean strictMatching;
>
>
> -    public PersistenceUnitRefBuilder(@ParamAttribute(name = "defaultEnvironment")
Environment defaultEnvironment,
> +    public PersistenceRefBuilder(@ParamAttribute(name = "defaultEnvironment") Environment
defaultEnvironment,
>                                      @ParamAttribute(name = "defaultPersistenceUnitAbstractNameQuery")
AbstractNameQuery defaultPersistenceUnitAbstractNameQuery,
>                                      @ParamAttribute(name = "strictMatching")
boolean strictMatching) {
>         super(defaultEnvironment);
> @@ -73,22 +86,24 @@ public class PersistenceUnitRefBuilder e
>     }
>
>     protected boolean willMergeEnvironment(JndiConsumer specDD, XmlObject plan) throws
DeploymentException {
> -        if (specDD != null && specDD.getPersistenceUnitRef().size() >
0) {
> +        if (specDD != null && !specDD.getPersistenceUnitRef().isEmpty())
{
>             return true;
>         }
> -        return plan != null && plan.selectChildren(PersistenceUnitRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME_SET).length
> 0;
> +        return plan != null && plan.selectChildren(PersistenceRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME_SET).length
> 0;
>     }
>
> -    public void buildNaming(JndiConsumer specDD, XmlObject plan, Module module, Map
componentContext) throws DeploymentException {
> +    public void buildNaming(JndiConsumer specDD, XmlObject plan, Module module, Map<EARContext.Key,
Object> componentContext) throws DeploymentException {
>         Configuration localConfiguration = module.getEarContext().getConfiguration();
> -        // Discover and process any @PersistenceUnitRef annotations (if !metadata-complete)
> +        List<DeploymentException> problems = new ArrayList<DeploymentException>();
> +
> +        // Discover and process any @PersistenceUnitRef and @PersistenceContextRef
annotations (if !metadata-complete)
>         if (module.getClassFinder() != null) {
>             processAnnotations(specDD, module);
>         }
>
> +        //persistenceUnit refs
>         Collection<PersistenceUnitRef> specPersistenceUnitRefsUntyped = specDD.getPersistenceUnitRef();
>         Map<String, GerPersistenceUnitRefType> gerPersistenceUnitRefsUntyped
= getGerPersistenceUnitRefs(plan);
> -        List<DeploymentException> problems = new ArrayList<DeploymentException>();
>         for (PersistenceUnitRef persistenceUnitRef : specPersistenceUnitRefsUntyped)
{
>             try {
>                 String persistenceUnitRefName = persistenceUnitRef.getPersistenceUnitRefName().trim();
> @@ -99,32 +114,9 @@ public class PersistenceUnitRefBuilder e
>                 if (gerPersistenceUnitRef != null) {
>                     persistenceUnitNameQuery = findPersistenceUnit(gerPersistenceUnitRef);
>                     checkForGBean(localConfiguration, persistenceUnitNameQuery,
true);
> -                } else if (persistenceUnitRef.getPersistenceUnitName() != null
&& !persistenceUnitRef.getPersistenceUnitName().trim().isEmpty()) {
> -                    String persistenceUnitName = persistenceUnitRef.getPersistenceUnitName().trim();
> -                    persistenceUnitNameQuery = new AbstractNameQuery(null,
Collections.singletonMap("name", persistenceUnitName), PERSISTENCE_UNIT_INTERFACE_TYPES);
> -                    if (!checkForGBean(localConfiguration, persistenceUnitNameQuery,
strictMatching)) {
> -                        persistenceUnitName = "persistence/" + persistenceUnitName;
> -                        persistenceUnitNameQuery = new AbstractNameQuery(null,
Collections.singletonMap("name", persistenceUnitName), PERSISTENCE_UNIT_INTERFACE_TYPES);
> -                        checkForGBean(localConfiguration, persistenceUnitNameQuery,
true);
> -                    }
>                 } else {
> -                    persistenceUnitNameQuery = new AbstractNameQuery(null,
Collections.EMPTY_MAP, PERSISTENCE_UNIT_INTERFACE_TYPES);
> -                    Set<AbstractNameQuery> patterns = Collections.singleton(persistenceUnitNameQuery);
> -                    LinkedHashSet<GBeanData> gbeans = localConfiguration.findGBeanDatas(localConfiguration,
patterns);
> -                    persistenceUnitNameQuery = checkForDefaultPersistenceUnit(gbeans);
> -                    if (gbeans.isEmpty()) {
> -                        gbeans = localConfiguration.findGBeanDatas(patterns);
> -                        persistenceUnitNameQuery = checkForDefaultPersistenceUnit(gbeans);
> -
> -                        if (gbeans.isEmpty()) {
> -                            if (defaultPersistenceUnitAbstractNameQuery
== null) {
> -                                throw new DeploymentException("No default
PersistenceUnit specified, and none located");
> -                            }
> -                            persistenceUnitNameQuery = defaultPersistenceUnitAbstractNameQuery;
> -                        }
> -                    }
> +                    persistenceUnitNameQuery = findPersistenceUnitQuery(module,
localConfiguration, persistenceUnitRef);
>                 }
> -                checkForGBean(localConfiguration, persistenceUnitNameQuery,
true);
>
>                 PersistenceUnitReference reference = new PersistenceUnitReference(module.getConfigId(),
persistenceUnitNameQuery);
>
> @@ -134,31 +126,111 @@ public class PersistenceUnitRefBuilder e
>             }
>
>         }
> -
> -
>         for (GerPersistenceUnitRefType gerPersistenceUnitRef : gerPersistenceUnitRefsUntyped.values())
{
>             try {
>                 String PersistenceUnitRefName = gerPersistenceUnitRef.getPersistenceUnitRefName();
> -
>                 AbstractNameQuery persistenceUnitNameQuery = findPersistenceUnit(gerPersistenceUnitRef);
> -
>                 checkForGBean(localConfiguration, persistenceUnitNameQuery, true);
> -
>                 PersistenceUnitReference reference = new PersistenceUnitReference(module.getConfigId(),
persistenceUnitNameQuery);
> -
>                 put(PersistenceUnitRefName, reference, module.getJndiContext());
>             } catch (DeploymentException e) {
>                 problems.add(e);
>             }
> +        }
> +
> +
> +        //persistence context refs
> +        Collection<PersistenceContextRef> specPersistenceContextRefsUntyped
= specDD.getPersistenceContextRef();
> +        Map<String, GerPersistenceContextRefType> gerPersistenceContextRefsUntyped
= getGerPersistenceContextRefs(plan);
> +        for (PersistenceContextRef persistenceContextRef : specPersistenceContextRefsUntyped)
{
> +            try {
> +                String persistenceContextRefName = persistenceContextRef.getPersistenceContextRefName().trim();
> +
> +                addInjections(persistenceContextRefName, persistenceContextRef.getInjectionTarget(),
componentContext);
> +                PersistenceContextType persistenceContextType = persistenceContextRef.getPersistenceContextType();
> +                boolean transactionScoped = persistenceContextType == null ||
persistenceContextType.equals(PersistenceContextType.TRANSACTION);
> +
> +                List<Property> propertyTypes = persistenceContextRef.getPersistenceProperty();
> +                Map<String, String> properties = new HashMap<String,
String>();
> +                for (Property propertyType : propertyTypes) {
> +                    String key = propertyType.getName();
> +                    String value = propertyType.getValue();
> +                    properties.put(key, value);
> +                }
> +
> +                AbstractNameQuery persistenceUnitNameQuery;
> +                GerPersistenceContextRefType gerPersistenceContextRef = gerPersistenceContextRefsUntyped.remove(persistenceContextRefName);
> +                if (gerPersistenceContextRef != null) {
> +                    persistenceUnitNameQuery = findPersistenceUnit(gerPersistenceContextRef);
> +                    addProperties(gerPersistenceContextRef, properties);
> +                    checkForGBean(localConfiguration, persistenceUnitNameQuery,
true);
> +                } else {
> +                    persistenceUnitNameQuery = findPersistenceUnitQuery(module,
localConfiguration, persistenceContextRef);
> +                }
> +                PersistenceContextReference reference = new PersistenceContextReference(module.getConfigId(),
persistenceUnitNameQuery, transactionScoped, properties);
> +                put(persistenceContextRefName, reference, module.getJndiContext());
> +            } catch (DeploymentException e) {
> +                problems.add(e);
> +            }
> +        }
> +
> +        // Support persistence context refs that are mentioned only in the geronimo
plan
> +        for (GerPersistenceContextRefType gerPersistenceContextRef : gerPersistenceContextRefsUntyped.values())
{
> +            try {
> +                String persistenceContextRefName = gerPersistenceContextRef.getPersistenceContextRefName();
> +                GerPersistenceContextTypeType.Enum persistenceContextType =
gerPersistenceContextRef.getPersistenceContextType();
> +                boolean transactionScoped = persistenceContextType == null ||
!persistenceContextType.equals(GerPersistenceContextTypeType.EXTENDED);
> +                Map<String, String> properties = new HashMap<String,
String>();
> +                addProperties(gerPersistenceContextRef, properties);
> +                AbstractNameQuery persistenceUnitNameQuery = findPersistenceUnit(gerPersistenceContextRef);
> +                checkForGBean(localConfiguration, persistenceUnitNameQuery,
true);
> +                PersistenceContextReference reference = new PersistenceContextReference(module.getConfigId(),
persistenceUnitNameQuery, transactionScoped, properties);
> +                put(persistenceContextRefName, reference, module.getJndiContext());
> +            } catch (DeploymentException e) {
> +                problems.add(e);
> +            }
>
>         }
> +
>         if (!problems.isEmpty()) {
> -            //TODO make DeploymentException accept a list of exceptions as causes.
> -            throw new DeploymentException("At least one deployment problem:" +
problems);
> +            throw new DeploymentException("At least one deployment problem:",
problems);
>         }
>     }
>
> -    private AbstractNameQuery checkForDefaultPersistenceUnit(LinkedHashSet<GBeanData>
gbeans) throws DeploymentException {
> +    private AbstractNameQuery findPersistenceUnitQuery(Module module, Configuration
localConfiguration, PersistenceRef persistenceRef) throws DeploymentException {
> +        AbstractNameQuery persistenceUnitNameQuery;
> +        if (persistenceRef.getPersistenceUnitName() != null && !persistenceRef.getPersistenceUnitName().trim().isEmpty())
{
> +            String persistenceUnitName = persistenceRef.getPersistenceUnitName().trim();
> +            AbstractName childName = module.getEarContext().getNaming().createChildName(module.getModuleName(),
persistenceUnitName, NameFactory.PERSISTENCE_UNIT);
> +            persistenceUnitNameQuery = new AbstractNameQuery(null, childName.getName(),
PERSISTENCE_UNIT_INTERFACE_TYPES);
> +            if (!checkForGBean(localConfiguration, persistenceUnitNameQuery, strictMatching))
{
> +                persistenceUnitName = "persistence/" + persistenceUnitName;
> +                childName = module.getEarContext().getNaming().createChildName(module.getModuleName(),
persistenceUnitName, NameFactory.PERSISTENCE_UNIT);
> +                persistenceUnitNameQuery = new AbstractNameQuery(null, childName.getName(),
PERSISTENCE_UNIT_INTERFACE_TYPES);
> +                checkForGBean(localConfiguration, persistenceUnitNameQuery,
true);
> +            }
> +        } else {
> +            persistenceUnitNameQuery = new AbstractNameQuery(null, Collections.EMPTY_MAP,
PERSISTENCE_UNIT_INTERFACE_TYPES);
> +            Set<AbstractNameQuery> patterns = Collections.singleton(persistenceUnitNameQuery);
> +            LinkedHashSet<GBeanData> gbeans = localConfiguration.findGBeanDatas(localConfiguration,
patterns);
> +            persistenceUnitNameQuery = checkForDefaultPersistenceUnit(gbeans);
> +            if (gbeans.isEmpty()) {
> +                gbeans = localConfiguration.findGBeanDatas(patterns);
> +                persistenceUnitNameQuery = checkForDefaultPersistenceUnit(gbeans);
> +
> +                if (gbeans.isEmpty()) {
> +                    if (defaultPersistenceUnitAbstractNameQuery == null) {
> +                        throw new DeploymentException("No default PersistenceUnit
specified, and none located");
> +                    }
> +                    persistenceUnitNameQuery = defaultPersistenceUnitAbstractNameQuery;
> +                }
> +            }
> +        }
> +        checkForGBean(localConfiguration, persistenceUnitNameQuery, true);
> +        return persistenceUnitNameQuery;
> +    }
> +
> +    private static AbstractNameQuery checkForDefaultPersistenceUnit(LinkedHashSet<GBeanData>
gbeans) throws DeploymentException {
>         AbstractNameQuery persistenceUnitNameQuery = null;
>         for (java.util.Iterator it = gbeans.iterator(); it.hasNext();) {
>             GBeanData gbean = (GBeanData) it.next();
> @@ -176,14 +248,17 @@ public class PersistenceUnitRefBuilder e
>         return persistenceUnitNameQuery;
>     }
>
> -    private boolean checkForGBean(Configuration localConfiguration, AbstractNameQuery
persistenceUnitNameQuery, boolean complainIfMissing) throws DeploymentException {
> +    private static boolean checkForGBean(Configuration localConfiguration, AbstractNameQuery
persistenceQuery, boolean complainIfMissing) throws DeploymentException {
>         try {
> -            localConfiguration.findGBeanData(persistenceUnitNameQuery);
> +            localConfiguration.findGBeanData(persistenceQuery);
>             return true;
>         } catch (GBeanNotFoundException e) {
>             if (complainIfMissing || e.hasMatches()) {
> -                String reason = e.hasMatches() ? "More than one GBean reference
found." : "No GBean references found.";
> -                throw new DeploymentException("Could not resolve reference at
deploy time for query " + persistenceUnitNameQuery + ". " + reason, e);
> +                if (e.hasMatches()) {
> +                    throw new DeploymentException("More than one reference
at deploy time for query " + persistenceQuery + ". " + e.getMatches(), e);
> +                } else {
> +                    throw new DeploymentException("No references found at
deploy time for query " + persistenceQuery, e);
> +                }
>             }
>             return false;
>         }
> @@ -192,15 +267,16 @@ public class PersistenceUnitRefBuilder e
>     private void processAnnotations(JndiConsumer specDD, Module module) throws DeploymentException
{
>         // Process all the annotations for this naming builder type
>         PersistenceUnitAnnotationHelper.processAnnotations(specDD, module.getClassFinder());
> +        PersistenceContextAnnotationHelper.processAnnotations(specDD, module.getClassFinder());
>     }
>
> -    private AbstractNameQuery findPersistenceUnit(GerPersistenceUnitRefType gerPersistenceUnitRef)
{
> +    private AbstractNameQuery findPersistenceUnit(GerPersistenceUnitRefType gerPersistenceRef)
{
>         AbstractNameQuery persistenceUnitNameQuery;
> -        if (gerPersistenceUnitRef.isSetPersistenceUnitName()) {
> -            String persistenceUnitName = gerPersistenceUnitRef.getPersistenceUnitName();
> +        if (gerPersistenceRef.isSetPersistenceUnitName()) {
> +            String persistenceUnitName = gerPersistenceRef.getPersistenceUnitName();
>             persistenceUnitNameQuery = new AbstractNameQuery(null, Collections.singletonMap("name",
persistenceUnitName), PERSISTENCE_UNIT_INTERFACE_TYPES);
>         } else {
> -            GerPatternType gbeanLocator = gerPersistenceUnitRef.getPattern();
> +            GerPatternType gbeanLocator = gerPersistenceRef.getPattern();
>
>             persistenceUnitNameQuery = buildAbstractNameQuery(gbeanLocator, null,
null, PERSISTENCE_UNIT_INTERFACE_TYPES);
>         }
> @@ -208,7 +284,7 @@ public class PersistenceUnitRefBuilder e
>     }
>
>     public QNameSet getSpecQNameSet() {
> -        SchemaConversionUtils.registerNamespaceConversions(Collections.singletonMap(PersistenceUnitRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME.getLocalPart(),
new NamespaceElementConverter(PersistenceUnitRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME.getNamespaceURI())));
> +        SchemaConversionUtils.registerNamespaceConversions(Collections.singletonMap(PersistenceRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME.getLocalPart(),
new NamespaceElementConverter(PersistenceRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME.getNamespaceURI())));
>         return PERSISTENCE_UNIT_REF_QNAME_SET;
>     }
>
> @@ -219,7 +295,7 @@ public class PersistenceUnitRefBuilder e
>     private Map<String, GerPersistenceUnitRefType> getGerPersistenceUnitRefs(XmlObject
plan) throws DeploymentException {
>         Map<String, GerPersistenceUnitRefType> map = new HashMap<String,
GerPersistenceUnitRefType>();
>         if (plan != null) {
> -            List<GerPersistenceUnitRefType> refs = convert(plan.selectChildren(PersistenceUnitRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME_SET),
NAMING_CONVERTER, GerPersistenceUnitRefType.class, GerPersistenceUnitRefType.type);
> +            List<GerPersistenceUnitRefType> refs = convert(plan.selectChildren(PersistenceRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME_SET),
NAMING_CONVERTER, GerPersistenceUnitRefType.class, GerPersistenceUnitRefType.type);
>             for (GerPersistenceUnitRefType ref : refs) {
>                 map.put(ref.getPersistenceUnitRefName().trim(), ref);
>             }
> @@ -227,4 +303,38 @@ public class PersistenceUnitRefBuilder e
>         return map;
>     }
>
> +    private void addProperties(GerPersistenceContextRefType persistenceContextRef,
Map<String, String> properties) {
> +        GerPropertyType[] propertyTypes = persistenceContextRef.getPropertyArray();
> +        for (GerPropertyType propertyType : propertyTypes) {
> +            String key = propertyType.getKey();
> +            String value = propertyType.getValue();
> +            properties.put(key, value);
> +        }
> +    }
> +
> +    private Map<String, GerPersistenceContextRefType> getGerPersistenceContextRefs(XmlObject
plan) throws DeploymentException {
> +        Map<String, GerPersistenceContextRefType> map = new HashMap<String,
GerPersistenceContextRefType>();
> +        if (plan != null) {
> +            List<GerPersistenceContextRefType> refs = convert(plan.selectChildren(GER_PERSISTENCE_CONTEXT_REF_QNAME_SET),
NAMING_CONVERTER, GerPersistenceContextRefType.class, GerPersistenceContextRefType.type);
> +            for (GerPersistenceContextRefType ref : refs) {
> +                map.put(ref.getPersistenceContextRefName().trim(), ref);
> +            }
> +        }
> +        return map;
> +    }
> +
> +    private AbstractNameQuery findPersistenceUnit(GerPersistenceContextRefType persistenceContextRef)
{
> +        AbstractNameQuery persistenceUnitNameQuery;
> +        if (persistenceContextRef.isSetPersistenceUnitName()) {
> +            String persistenceUnitName = persistenceContextRef.getPersistenceUnitName();
> +            persistenceUnitNameQuery = new AbstractNameQuery(null, Collections.singletonMap("name",
persistenceUnitName), PERSISTENCE_UNIT_INTERFACE_TYPES);
> +        } else {
> +            GerPatternType gbeanLocator = persistenceContextRef.getPattern();
> +
> +            persistenceUnitNameQuery = buildAbstractNameQuery(gbeanLocator, null,
null, PERSISTENCE_UNIT_INTERFACE_TYPES);
> +        }
> +        return persistenceUnitNameQuery;
> +    }
> +
> +
>  }
>
> Propchange: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
> ------------------------------------------------------------------------------
>    svn:eol-style = native
>
> Propchange: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
> ------------------------------------------------------------------------------
>    svn:keywords = Date Revision
>
> Propchange: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceRefBuilder.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Modified: geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java?rev=958821&r1=958820&r2=958821&view=diff
> ==============================================================================
> --- geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
(original)
> +++ geronimo/server/trunk/plugins/openjpa2/geronimo-persistence-jpa20-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitBuilder.java
Tue Jun 29 04:42:13 2010
> @@ -23,6 +23,7 @@ import java.net.URL;
>  import java.util.ArrayList;
>  import java.util.Collection;
>  import java.util.HashMap;
> +import java.util.LinkedHashSet;
>  import java.util.List;
>  import java.util.Map;
>  import java.util.Properties;
> @@ -59,6 +60,8 @@ import org.apache.openejb.jee.JAXBContex
>  import org.apache.openejb.jee.JaxbJavaee;
>  import org.apache.openejb.jee.Persistence;
>  import org.apache.xbean.osgi.bundle.util.BundleResourceFinder;
> +import org.apache.xbean.osgi.bundle.util.DiscoveryRange;
> +import org.apache.xbean.osgi.bundle.util.ResourceDiscoveryFilter;
>  import org.apache.xmlbeans.QNameSet;
>  import org.apache.xmlbeans.XmlObject;
>  import org.osgi.framework.Bundle;
> @@ -72,18 +75,18 @@ import org.osgi.service.packageadmin.Pac
>  @GBean(j2eeType = NameFactory.MODULE_BUILDER)
>  public class PersistenceUnitBuilder implements ModuleBuilderExtension {
>
> -    private static final EARContext.Key<List<URL>> PERSISTENCE_URL_LIST_KEY
= new EARContext.Key<List<URL>>() {
> -
> -        @Override
> -        public List<URL> get(Map<EARContext.Key, Object> keyObjectMap)
{
> -            List<URL> list = (List<URL>) keyObjectMap.get(this);
> -            if (list == null) {
> -                list = new ArrayList<URL>();
> -                keyObjectMap.put(this, list);
> -            }
> -            return list;
> -        }
> -    };
> +//    private static final EARContext.Key<List<URL>> PERSISTENCE_URL_LIST_KEY
= new EARContext.Key<List<URL>>() {
> +//
> +//        @Override
> +//        public List<URL> get(Map<EARContext.Key, Object> keyObjectMap)
{
> +//            List<URL> list = (List<URL>) keyObjectMap.get(this);
> +//            if (list == null) {
> +//                list = new ArrayList<URL>();
> +//                keyObjectMap.put(this, list);
> +//            }
> +//            return list;
> +//        }
> +//    };
>
>     private static final QName PERSISTENCE_QNAME = new QName("http://java.sun.com/xml/ns/persistence",
"persistence");
>
> @@ -144,19 +147,31 @@ public class PersistenceUnitBuilder impl
>             throw new DeploymentException("Parse Persistence configuration file
failed", e);
>         }
>         try {
> -            URI moduleBaseURI = moduleContext.getBaseDir().toURI();
> -            Collection<String> manifestcp = module.getClassPath();
> -            manifestcp.add(module.getTargetPath());
> -//            URL[] urls = new URL[manifestcp.size()];
> -//            int i = 0;
> -//            for (String path : manifestcp) {
> -//                //TODO either this encoding is unnecessary or incomplete
> -//                path = path.replaceAll(" ", "%20");
> -//                URL url = moduleBaseURI.resolve(path).toURL();
> -//                urls[i++] = url;
> -//            }
> -            BundleResourceFinder finder = new BundleResourceFinder(packageAdmin,
bundle, "", "META-INF/persistence.xml");
> -            List<URL> knownPersistenceUrls = PERSISTENCE_URL_LIST_KEY.get(module.getRootEarContext().getGeneralData());
> +
> +            final Collection<String> manifestcp = new LinkedHashSet<String>();
> +            for (Module m = module; m != null; m = m.getParentModule()){
> +                manifestcp.addAll(m.getClassPath());
> +            }
> +            //should not be needed??
> +//            manifestcp.add(module.getTargetPath());
> +            BundleResourceFinder finder = new BundleResourceFinder(packageAdmin,
bundle, "", "META-INF/persistence.xml", new ResourceDiscoveryFilter() {
> +
> +                @Override
> +                public boolean rangeDiscoveryRequired(DiscoveryRange discoveryRange)
{
> +                    return discoveryRange == DiscoveryRange.BUNDLE_CLASSPATH
|| discoveryRange == DiscoveryRange.FRAGMENT_BUNDLES;
> +                }
> +
> +                @Override
> +                public boolean zipFileDiscoveryRequired(String s) {
> +                    return manifestcp.contains(s);
> +                }
> +
> +                @Override
> +                public boolean directoryDiscoveryRequired(String s) {
> +                    return manifestcp.contains(s);
> +                }
> +            });
> +//            List<URL> knownPersistenceUrls = PERSISTENCE_URL_LIST_KEY.get(module.getRootEarContext().getGeneralData());
>             final Map<URL, String> persistenceURLs = new HashMap<URL,
String>();
>             finder.find(new BundleResourceFinder.ResourceFinderCallback() {
>
> @@ -172,7 +187,7 @@ public class PersistenceUnitBuilder impl
>                     persistenceURLs.put(url, jarName);
>                 }
>             });
> -            persistenceURLs.keySet().removeAll(knownPersistenceUrls);
> +//            persistenceURLs.keySet().removeAll(knownPersistenceUrls);
>             if (raws.length > 0 || persistenceURLs.size() > 0) {
>                 EnvironmentBuilder.mergeEnvironments(module.getEnvironment(),
defaultEnvironment);
>             }
> @@ -189,7 +204,7 @@ public class PersistenceUnitBuilder impl
>                     in.close();
>                 }
>                 buildPersistenceUnits(persistence, overrides, module, persistenceLocation);
> -                knownPersistenceUrls.add(persistenceUrl);
> +//                knownPersistenceUrls.add(persistenceUrl);
>             }
>         } catch (Exception e) {
>             throw new DeploymentException("Could not look for META-INF/persistence.xml
files", e);
>
> Modified: geronimo/server/trunk/plugins/openjpa2/persistence-jpa20-deployer/src/main/plan/plan.xml
> URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openjpa2/persistence-jpa20-deployer/src/main/plan/plan.xml?rev=958821&r1=958820&r2=958821&view=diff
> ==============================================================================
> --- geronimo/server/trunk/plugins/openjpa2/persistence-jpa20-deployer/src/main/plan/plan.xml
(original)
> +++ geronimo/server/trunk/plugins/openjpa2/persistence-jpa20-deployer/src/main/plan/plan.xml
Tue Jun 29 04:42:13 2010
> @@ -44,21 +44,7 @@
>         </xml-attribute>
>     </gbean>
>     <!-- TODO possibly the ref builders only need a dependency on transaction -->
> -    <gbean name="PersistenceContextRefBuilder" class="org.apache.geronimo.persistence.builder.PersistenceContextRefBuilder">
> -        <xml-attribute name="defaultEnvironment">
> -            <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-${geronimoSchemaVersion}">
> -                <dependencies>
> -                    <dependency>
> -                        <groupId>org.apache.geronimo.configs</groupId>
> -                        <artifactId>openjpa2</artifactId>
> -                        <version>${version}</version>
> -                        <type>car</type>
> -                    </dependency>
> -                </dependencies>
> -            </environment>
> -        </xml-attribute>
> -    </gbean>
> -    <gbean name="PersistenceUnitRefBuilder" class="org.apache.geronimo.persistence.builder.PersistenceUnitRefBuilder">
> +    <gbean name="PersistenceRefBuilder" class="org.apache.geronimo.persistence.builder.PersistenceRefBuilder">
>         <xml-attribute name="defaultEnvironment">
>             <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-${geronimoSchemaVersion}">
>                 <dependencies>
>
>
>

Mime
View raw message