You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/12/03 20:59:12 UTC
[02/50] [abbrv] incubator-usergrid git commit: Refactored generation
of collection scope to be re-usable with CpNamingUtils for consistency across
modules
Refactored generation of collection scope to be re-usable with CpNamingUtils for consistency across modules
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/364a6ea6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/364a6ea6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/364a6ea6
Branch: refs/heads/two-dot-o-events
Commit: 364a6ea6737194a1dd266b6d0e89abb4a40ddf96
Parents: 9ed7964
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Nov 20 14:24:03 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Nov 20 14:24:03 2014 -0700
----------------------------------------------------------------------
.../corepersistence/CpEntityManager.java | 44 ++++++--------------
.../corepersistence/CpEntityManagerFactory.java | 2 +-
.../corepersistence/CpRelationManager.java | 35 ++++------------
.../corepersistence/util/CpNamingUtils.java | 19 +++++++++
4 files changed, 41 insertions(+), 59 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/364a6ea6/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 e2f67e8..e6b8bce 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
@@ -131,6 +131,7 @@ import static me.prettyprint.hector.api.factory.HFactory.createCounterSliceQuery
import static me.prettyprint.hector.api.factory.HFactory.createMutator;
import static org.apache.commons.lang.StringUtils.capitalize;
import static org.apache.commons.lang.StringUtils.isBlank;
+import static org.apache.usergrid.corepersistence.util.CpNamingUtils.getCollectionScopeNameFromEntityType;
import static org.apache.usergrid.persistence.Schema.COLLECTION_ROLES;
import static org.apache.usergrid.persistence.Schema.COLLECTION_USERS;
import static org.apache.usergrid.persistence.Schema.DICTIONARY_PERMISSIONS;
@@ -372,13 +373,9 @@ public class CpEntityManager implements EntityManager {
}
Id id = new SimpleId( entityRef.getUuid(), entityRef.getType() );
- String collectionName = CpNamingUtils.getCollectionScopeNameFromEntityType( entityRef.getType() );
- CollectionScope collectionScope =
- new CollectionScopeImpl( getApplicationScope().getApplication(), getApplicationScope().getApplication(),
- collectionName );
+ CollectionScope collectionScope = getCollectionScopeNameFromEntityType(applicationScope.getApplication(), entityRef.getType());
- EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
// if ( !UUIDUtils.isTimeBased( id.getUuid() ) ) {
// throw new IllegalArgumentException(
@@ -457,13 +454,10 @@ public class CpEntityManager implements EntityManager {
String type = Schema.getDefaultSchema().getEntityType( entityClass );
Id id = new SimpleId( entityId, type );
- String collectionName = CpNamingUtils.getCollectionScopeNameFromEntityType( type );
- CollectionScope collectionScope =
- new CollectionScopeImpl( getApplicationScope().getApplication(), getApplicationScope().getApplication(),
- collectionName );
- EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
+ CollectionScope collectionScope = getCollectionScopeNameFromEntityType(applicationScope.getApplication(), type);
+
// if ( !UUIDUtils.isTimeBased( id.getUuid() ) ) {
// throw new IllegalArgumentException(
@@ -522,9 +516,8 @@ public class CpEntityManager implements EntityManager {
public void update( Entity entity ) throws Exception {
// first, update entity index in its own collection scope
- CollectionScope collectionScope =
- new CollectionScopeImpl( getApplicationScope().getApplication(), getApplicationScope().getApplication(),
- CpNamingUtils.getCollectionScopeNameFromEntityType( entity.getType() ) );
+
+ CollectionScope collectionScope = getCollectionScopeNameFromEntityType(applicationScope.getApplication(), entity.getType());
EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
Id entityId = new SimpleId( entity.getUuid(), entity.getType() );
@@ -590,9 +583,7 @@ public class CpEntityManager implements EntityManager {
private Observable deleteAsync( EntityRef entityRef ) throws Exception {
- CollectionScope collectionScope =
- new CollectionScopeImpl( getApplicationScope().getApplication(), getApplicationScope().getApplication(),
- CpNamingUtils.getCollectionScopeNameFromEntityType( entityRef.getType() ) );
+ CollectionScope collectionScope =getCollectionScopeNameFromEntityType(applicationScope.getApplication(), entityRef.getType() );
EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
@@ -639,7 +630,7 @@ public class CpEntityManager implements EntityManager {
// deindex from default index scope
IndexScope defaultIndexScope = new IndexScopeImpl( getApplicationScope().getApplication(),
- CpNamingUtils.getCollectionScopeNameFromEntityType( entityRef.getType() ) );
+ getCollectionScopeNameFromEntityType( entityRef.getType() ) );
batch.deindex( defaultIndexScope, entity );
@@ -1010,15 +1001,10 @@ public class CpEntityManager implements EntityManager {
@Override
public void deleteProperty( EntityRef entityRef, String propertyName ) throws Exception {
-
- String collectionName = CpNamingUtils.getCollectionScopeNameFromEntityType( entityRef.getType() );
-
- CollectionScope collectionScope =
- new CollectionScopeImpl( getApplicationScope().getApplication(), getApplicationScope().getApplication(),
- collectionName );
+ CollectionScope collectionScope = getCollectionScopeNameFromEntityType(getApplicationScope().getApplication(), entityRef.getType());
IndexScope defaultIndexScope = new IndexScopeImpl( getApplicationScope().getApplication(),
- CpNamingUtils.getCollectionScopeNameFromEntityType( entityRef.getType() ) );
+ getCollectionScopeNameFromEntityType( entityRef.getType() ) );
EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
EntityIndex ei = managerCache.getEntityIndex( getApplicationScope() );
@@ -2187,10 +2173,7 @@ public class CpEntityManager implements EntityManager {
private Id getIdForUniqueEntityField( final String collectionName, final String propertyName,
final Object propertyValue ) {
- CollectionScope collectionScope =
- new CollectionScopeImpl( applicationScope.getApplication(), applicationScope.getApplication(),
- CpNamingUtils.getCollectionScopeNameFromEntityType( collectionName ) );
-
+ CollectionScope collectionScope = getCollectionScopeNameFromEntityType(applicationScope.getApplication(), collectionName);
final EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
@@ -2514,9 +2497,8 @@ public class CpEntityManager implements EntityManager {
org.apache.usergrid.persistence.model.entity.Entity cpEntity = entityToCpEntity( entity, importId );
// prepare to write and index Core Persistence Entity into default scope
- CollectionScope collectionScope =
- new CollectionScopeImpl( applicationScope.getApplication(), applicationScope.getApplication(),
- CpNamingUtils.getCollectionScopeNameFromEntityType( eType ) );
+ CollectionScope collectionScope = getCollectionScopeNameFromEntityType(applicationScope.getApplication(), eType);
+
EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
if ( logger.isDebugEnabled() ) {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/364a6ea6/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index e07bb00..82e80a5 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -541,7 +541,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
public long performEntityCount() {
//TODO, this really needs to be a task that writes this data somewhere since this will get
//progressively slower as the system expands
- return AllEntitiesInSystemObservable.getAllEntitiesInSystem( managerCache ).longCount().toBlocking().last();
+ return AllEntitiesInSystemObservable.getAllEntitiesInSystem( managerCache, 1000 ).longCount().toBlocking().last();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/364a6ea6/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index 8514504..dcb4ba1 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -120,6 +120,7 @@ import rx.functions.Func1;
import static java.util.Arrays.asList;
import static me.prettyprint.hector.api.factory.HFactory.createMutator;
+import static org.apache.usergrid.corepersistence.util.CpNamingUtils.getCollectionScopeNameFromEntityType;
import static org.apache.usergrid.persistence.Schema.COLLECTION_ROLES;
import static org.apache.usergrid.persistence.Schema.DICTIONARY_CONNECTED_ENTITIES;
import static org.apache.usergrid.persistence.Schema.DICTIONARY_CONNECTED_TYPES;
@@ -219,10 +220,7 @@ public class CpRelationManager implements RelationManager {
this.indexBucketLocator = indexBucketLocator; // TODO: this also
// load the Core Persistence version of the head entity as well
- this.headEntityScope = new CollectionScopeImpl(
- this.applicationScope.getApplication(),
- this.applicationScope.getApplication(),
- CpNamingUtils.getCollectionScopeNameFromEntityType( headEntity.getType() ) );
+ this.headEntityScope = getCollectionScopeNameFromEntityType(applicationScope.getApplication(), headEntity.getType());
if ( logger.isDebugEnabled() ) {
logger.debug( "Loading head entity {}:{} from scope\n app {}\n owner {}\n name {}",
@@ -606,10 +604,7 @@ public class CpRelationManager implements RelationManager {
public Entity addToCollection( String collName, EntityRef itemRef, boolean connectBack )
throws Exception {
- CollectionScope memberScope = new CollectionScopeImpl(
- applicationScope.getApplication(),
- applicationScope.getApplication(),
- CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ) );
+ CollectionScope memberScope = getCollectionScopeNameFromEntityType(applicationScope.getApplication(), itemRef.getType());
Id entityId = new SimpleId( itemRef.getUuid(), itemRef.getType() );
org.apache.usergrid.persistence.model.entity.Entity memberEntity =
@@ -642,10 +637,7 @@ public class CpRelationManager implements RelationManager {
}
// load the new member entity to be added to the collection from its default scope
- CollectionScope memberScope = new CollectionScopeImpl(
- applicationScope.getApplication(),
- applicationScope.getApplication(),
- CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ) );
+ CollectionScope memberScope = getCollectionScopeNameFromEntityType(applicationScope.getApplication(), itemRef.getType());
//TODO, this double load should disappear once events are in
Id entityId = new SimpleId( itemRef.getUuid(), itemRef.getType() );
@@ -797,11 +789,7 @@ public class CpRelationManager implements RelationManager {
}
// load the entity to be removed to the collection
- CollectionScope memberScope = new CollectionScopeImpl(
- this.applicationScope.getApplication(),
- this.applicationScope.getApplication(),
- CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ) );
- EntityCollectionManager memberMgr = managerCache.getEntityCollectionManager( memberScope );
+ CollectionScope memberScope = getCollectionScopeNameFromEntityType(applicationScope.getApplication(), itemRef.getType());
if ( logger.isDebugEnabled() ) {
logger.debug( "Loading entity to remove from collection "
@@ -1017,10 +1005,7 @@ public class CpRelationManager implements RelationManager {
ConnectionRefImpl connection = new ConnectionRefImpl( headEntity, connectionType, connectedEntityRef );
- CollectionScope targetScope = new CollectionScopeImpl(
- applicationScope.getApplication(),
- applicationScope.getApplication(),
- CpNamingUtils.getCollectionScopeNameFromEntityType( connectedEntityRef.getType() ) );
+ CollectionScope targetScope = getCollectionScopeNameFromEntityType(applicationScope.getApplication(), connectedEntityRef.getType());
if ( logger.isDebugEnabled() ) {
logger.debug("createConnection(): "
@@ -1249,12 +1234,8 @@ public class CpRelationManager implements RelationManager {
String connectionType = connectionRef.getConnectedEntity().getConnectionType();
- CollectionScope targetScope = new CollectionScopeImpl(
- applicationScope.getApplication(),
- applicationScope.getApplication(),
- CpNamingUtils.getCollectionScopeNameFromEntityType( connectedEntityRef.getType()) );
-
- EntityCollectionManager targetEcm = managerCache.getEntityCollectionManager( targetScope );
+ CollectionScope targetScope = getCollectionScopeNameFromEntityType( applicationScope.getApplication(),
+ connectedEntityRef.getType() );
if ( logger.isDebugEnabled() ) {
logger.debug( "Deleting connection '{}' from source {}:{} \n to target {}:{}",
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/364a6ea6/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
index 6fb35a3..684b6e0 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
@@ -22,6 +22,8 @@ package org.apache.usergrid.corepersistence.util;
import java.util.UUID;
import org.apache.usergrid.persistence.Schema;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
import org.apache.usergrid.persistence.entities.Application;
@@ -70,6 +72,23 @@ public class CpNamingUtils {
public static String TYPES_BY_UUID_MAP = "zzz_typesbyuuid_zzz";
+ /**
+ * Generate a collection scope for a collection within the application's Id for the given type
+ * @param applicationId The applicationId that owns this entity
+ * @param type The type in the collection
+ * @return The collectionScope
+ */
+ public static CollectionScope getCollectionScopeNameFromEntityType(final Id applicationId, final String type){
+ return
+ new CollectionScopeImpl( applicationId, applicationId,
+ getCollectionScopeNameFromEntityType( type ) );
+ }
+
+ /**
+ * Get the collection name from the entity/id type
+ * @param type
+ * @return
+ */
public static String getCollectionScopeNameFromEntityType( String type ) {
String csn = EDGE_COLL_SUFFIX + Schema.defaultCollectionName( type );
return csn.toLowerCase();