Author: rmannibucau
Date: Sun Jul 31 20:28:48 2011
New Revision: 1152629

URL: http://svn.apache.org/viewvc?rev=1152629&view=rev
Log:
@Repository: if there is only one persistence context in the app using it by 
default

Modified:
    
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java

Modified: 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=1152629&r1=1152628&r2=1152629&view=diff
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
 (original)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java
 Sun Jul 31 20:28:48 2011
@@ -693,17 +693,26 @@ public class Assembler extends Assembler
                 for (String repository : ejbJar.repositories) {
                     try {
                         Class<?> proxied = classLoader.loadClass(repository);
-                        // TODO: move it in config
+
+                        // TODO: move it in config?
                         Repository annotation = 
proxied.getAnnotation(Repository.class);
                         PersistenceContext pc = annotation.context();
+                        String unitName = pc.unitName();
+                        if ("".equals(pc.unitName())) {
+                            if (appInfo.persistenceUnits.size() == 1) {
+                                unitName = 
appInfo.persistenceUnits.iterator().next().name;
+                            } else {
+                                throw new OpenEJBException("specify a unit 
name for repository " + repository);
+                            }
+                        }
 
                         // create the em
                         Context context = 
SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext();
                         EntityManagerFactory factory;
                         try {
-                            factory = (EntityManagerFactory) 
context.lookup(units.get(pc.unitName()));
+                            factory = (EntityManagerFactory) 
context.lookup(units.get(unitName));
                         } catch (NamingException e) {
-                            throw new OpenEJBException("PersistenceUnit '" + 
pc.unitName() + "' not found");
+                            throw new OpenEJBException("PersistenceUnit '" + 
unitName + "' not found");
                         }
                         Map<String, String> properties = new 
LinkedHashMap<String, String>();
                         for (PersistenceProperty property : pc.properties()) {
@@ -720,7 +729,9 @@ public class Assembler extends Assembler
                         if (jndi == null || jndi.isEmpty()) {
                             jndi = "openejb/Repository/" + repository;
                         }
-                        containerSystemContext.bind(jndi, proxy); // TODO in a 
better way
+
+                        // TODO in a better way
+                        containerSystemContext.bind(jndi, proxy);
                         repositoryNames.add(jndi);
                         logger.info("Bound @Repository " + repository + " to " 
+ jndi);
                         appContext.getGlobalJndiContext().bind("global/" + 
jndi, proxy);


Reply via email to