usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [2/9] incubator-usergrid git commit: Look up app by name from EntityCollectionManager instead of using search.
Date Mon, 06 Apr 2015 20:50:50 GMT
Look up app by name from EntityCollectionManager instead of using search.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/fdd71930
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/fdd71930
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/fdd71930

Branch: refs/heads/USERGRID-533-create-app-test
Commit: fdd719306a3937e2cd0916c03494ccdb3ece66d1
Parents: 721e385
Author: Dave Johnson <dmjohnson@apigee.com>
Authored: Fri Apr 3 15:35:25 2015 -0400
Committer: Dave Johnson <dmjohnson@apigee.com>
Committed: Fri Apr 3 15:35:25 2015 -0400

----------------------------------------------------------------------
 .../corepersistence/ApplicationIdCacheImpl.java | 51 +++++++++-----------
 .../corepersistence/CpEntityManager.java        |  6 +++
 2 files changed, 29 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fdd71930/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
index 379f306..ebd7798 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
@@ -20,20 +20,23 @@
 package org.apache.usergrid.corepersistence;
 
 
-import java.util.UUID;
-import java.util.concurrent.ExecutionException;
-
-import org.apache.usergrid.corepersistence.util.CpNamingUtils;
-import org.apache.usergrid.persistence.*;
-
-import com.google.common.base.Optional;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.utils.UUIDUtils;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityManagerFactory;
+import org.apache.usergrid.persistence.Schema;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.field.StringField;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import rx.Observable;
+
+import java.util.UUID;
 
 
 /**
@@ -48,6 +51,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
      * Cache the pointer to our root entity manager for reference
      */
     private final EntityManager rootEm;
+    private final CpEntityManagerFactory emf;
 
     private final LoadingCache<String, UUID> appCache =
         CacheBuilder.newBuilder().maximumSize( 10000 ).build( new CacheLoader<String,
UUID>() {
@@ -59,6 +63,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
 
 
     public ApplicationIdCacheImpl(final EntityManagerFactory emf) {
+        this.emf = (CpEntityManagerFactory)emf;
         this.rootEm = emf.getEntityManager( emf.getManagementAppId());
     }
 
@@ -81,35 +86,25 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
      */
     private UUID fetchApplicationId( final String applicationName ) {
 
-        UUID value = null;
+        final UUID value;
+
+        EntityCollectionManager ecm = emf.getManagerCache().getEntityCollectionManager(
+            new ApplicationScopeImpl( new SimpleId( CpNamingUtils.SYSTEM_APP_ID, Schema.TYPE_APPLICATION
) ) );
 
         try {
             if ( rootEm.getApplication() == null ) {
                 return null;
             }
         } catch ( Exception e ) {
-            logger.error("Error looking up app", e);
+            logger.error("Error looking up management app", e);
         }
 
         try {
-            Query q = Query.fromQL( Schema.PROPERTY_NAME + " = '" + applicationName.toLowerCase()
+ "'" );
-
-            Results results = rootEm.searchCollection(
-                rootEm.getApplicationRef(), CpNamingUtils.APPLICATION_INFOS, q);
-
-            if ( !results.isEmpty() ) {
+            final Observable<Id> idObs = ecm.getIdField(
+                Schema.TYPE_APPLICATION, new StringField( Schema.PROPERTY_NAME, applicationName
));
 
-                Entity entity = results.iterator().next();
-                Object uuidObject = entity.getProperty(Schema.PROPERTY_APPLICATION_ID);
-
-                if (uuidObject instanceof UUID) {
-                    value = (UUID) uuidObject;
-                } else {
-                    value = UUIDUtils.tryExtractUUID(
-                        entity.getProperty(Schema.PROPERTY_APPLICATION_ID).toString());
-                }
-
-            }
+            Id id = idObs.toBlocking().lastOrDefault(null);
+            value = id.getUuid();
 
             logger.debug("Loaded    for key {} value {}", applicationName, value );
             return value;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fdd71930/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index efdad6d..2ae9e64 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -2304,6 +2304,12 @@ public class CpEntityManager implements EntityManager {
         //convert to a string, that's what we store
         final Id results = ecm.getIdField( new StringField(
                 propertyName, propertyValue.toString() ) ).toBlocking() .lastOrDefault( null
);
+
+//        final Id results = ecm.getIdField(
+//            Inflector.getInstance().singularize( collectionName ),
+//            new StringField( propertyName, propertyValue.toString() )
+//        ).toBlocking() .lastOrDefault( null );
+
         return results;
     }
 


Mime
View raw message