geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwo...@apache.org
Subject svn commit: r798212 - /geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA5/src/main/java/javax/persistence/Persistence.java
Date Mon, 27 Jul 2009 16:47:27 GMT
Author: dwoods
Date: Mon Jul 27 16:47:27 2009
New Revision: 798212

URL: http://svn.apache.org/viewvc?rev=798212&view=rev
Log:
GERONIMO-4410 - OPENJPA-1175 Implement PersistenceUtil and isLoaded methods on the provider

Modified:
    geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA5/src/main/java/javax/persistence/Persistence.java

Modified: geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA5/src/main/java/javax/persistence/Persistence.java
URL: http://svn.apache.org/viewvc/geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA5/src/main/java/javax/persistence/Persistence.java?rev=798212&r1=798211&r2=798212&view=diff
==============================================================================
--- geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA5/src/main/java/javax/persistence/Persistence.java
(original)
+++ geronimo/specs/branches/geronimo-jpa_2.0_spec-1.0-EA5/src/main/java/javax/persistence/Persistence.java
Mon Jul 27 16:47:27 2009
@@ -30,9 +30,11 @@
 import java.util.Map;
 import java.util.Set;
 
+import javax.persistence.spi.LoadState;
 import javax.persistence.spi.PersistenceProvider;
 import javax.persistence.spi.PersistenceProviderResolver;
 import javax.persistence.spi.PersistenceProviderResolverHolder;
+import javax.persistence.spi.ProviderUtil;
 
 /**
  * @version $Rev$ $Date$
@@ -161,13 +163,78 @@
      */
     private static class PersistenceUtilImpl implements PersistenceUtil {
 
+        /*
+         * Determines the load state of the attribute of an entity 
+         * @see javax.persistence.PersistenceUtil#isLoaded(java.lang.Object, java.lang.String)
+         */
             public boolean isLoaded(Object entity, String attributeName) {
-                // TODO Auto-generated dummy method stub
+                boolean isLoaded = true;
+
+                // Get the list of persistence providers from the resolver
+                PersistenceProviderResolver ppr = 
+                    PersistenceProviderResolverHolder.getPersistenceProviderResolver();
+                List<PersistenceProvider> pps = ppr.getPersistenceProviders();
+
+                // Iterate through the list using ProviderUtil.isLoadedWithoutReference()
+                for (PersistenceProvider pp : pps) {
+                    try {
+                        ProviderUtil pu = pp.getProviderUtil();                        
+                        LoadState ls = pu.isLoadedWithoutReference(entity, attributeName);
+                        if (ls == LoadState.LOADED)
+                            return true;
+                        if (ls == LoadState.NOT_LOADED)
+                            return false;
+                    }
+                    catch (Throwable t) {
+                        // JPA 1.0 providers will not implement the getProviderUtil
+                        // method.  Eat the exception and try the next provider.
+                    }
+                 }
+                // Iterate through the list a second time using ProviderUtil.isLoadedWithReference()
+                for (PersistenceProvider pp : pps) {
+                    try {
+                        ProviderUtil pu = pp.getProviderUtil();                        
+                        LoadState ls = pu.isLoadedWithoutReference(entity, attributeName);
+                        if (ls == LoadState.LOADED)
+                            return true;
+                        if (ls == LoadState.NOT_LOADED)
+                            return false;
+                    }
+                    catch (Throwable t) {
+                        // JPA 1.0 providers will not implement the getProviderUtil
+                        // method.  Eat the exception and try the next provider.
+                    }
+                 }
+                
+                // All providers returned a load state of unknown.  Return true.
                 return true;
             }
 
             public boolean isLoaded(Object entity) {
-                // TODO Auto-generated dummy method stub
+                // Get the list of persistence providers from the resolver
+                PersistenceProviderResolver ppr = 
+                    PersistenceProviderResolverHolder.getPersistenceProviderResolver();
+                List<PersistenceProvider> pps = ppr.getPersistenceProviders();
+
+                // Iterate through the list of providers, using ProviderUtil to
+                // determine the load state
+                for (PersistenceProvider pp : pps) {
+                    try {
+                        ProviderUtil pu = pp.getProviderUtil();
+                        LoadState ls = pu.isLoaded(entity);
+                        if (ls == LoadState.LOADED)
+                            return true;
+                        if (ls == LoadState.NOT_LOADED)
+                            return false;
+                        // Otherwise, load state is unknown.  Query the next provider.
+                    }
+                    catch (Throwable t) {
+                        // JPA 1.0 providers will not implement the getProviderUtil
+                        // method.  Eat the exception and try the next provider.
+                    }                   
+                }
+                
+                // All providers returned a load state of unknown.  Return true.
                 return true;
             }
     }



Mime
View raw message