usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [17/27] incubator-usergrid git commit: Removed concurrent annotations
Date Thu, 12 Feb 2015 22:28:36 GMT
Removed concurrent annotations

Refactored singleton to include transitive dependencies on initialization. Class rule order not guaranteed VM versions.


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

Branch: refs/heads/USERGRID-365
Commit: 1fbe3e54d27e1a9666626a55f2857654c957f8f9
Parents: e80df0d
Author: Todd Nine <tnine@apigee.com>
Authored: Thu Jan 22 17:04:18 2015 -0700
Committer: Todd Nine <tnine@apigee.com>
Committed: Thu Jan 22 17:04:18 2015 -0700

----------------------------------------------------------------------
 stack/core/pom.xml                              |    2 +-
 .../corepersistence/CpEntityManager.java        |  135 +-
 .../corepersistence/CpEntityManagerFactory.java |  137 +-
 .../usergrid/corepersistence/CpSetup.java       |  220 +--
 .../usergrid/corepersistence/GuiceFactory.java  |  157 +-
 .../usergrid/corepersistence/GuiceModule.java   |   45 +-
 .../usergrid/persistence/EntityManager.java     |  107 +-
 .../persistence/EntityManagerFactory.java       |   29 +-
 .../cassandra/EntityManagerFactoryImpl.java     |   28 +-
 .../cassandra/EntityManagerImpl.java            |   92 +-
 .../usergrid/persistence/cassandra/Setup.java   |   20 +
 .../persistence/cassandra/SetupImpl.java        |   27 +-
 .../OrganizationAlreadyExistsException.java     |   43 +
 .../main/resources/usergrid-core-context.xml    |   45 +-
 .../org/apache/usergrid/AbstractCoreIT.java     |   18 +-
 .../java/org/apache/usergrid/Application.java   |    3 +-
 .../org/apache/usergrid/CoreApplication.java    |   19 +-
 .../java/org/apache/usergrid/CoreITSetup.java   |    1 +
 .../org/apache/usergrid/CoreITSetupImpl.java    |   77 +-
 .../org/apache/usergrid/batch/AppArgsTest.java  |    3 -
 .../batch/BulkJobExecutionUnitTest.java         |    4 +-
 .../apache/usergrid/batch/BulkTestUtils.java    |    4 +-
 .../batch/ConcurrentSchedulerITSuite.java       |   47 -
 .../batch/ConcurrentSchedulerTestSuite.java     |   35 -
 .../usergrid/batch/UsergridJobFactoryTest.java  |    6 +-
 .../batch/job/AbstractSchedulerRuntimeIT.java   |    7 +-
 .../usergrid/batch/job/CountdownLatchJob.java   |    1 +
 .../usergrid/batch/job/DelayExecution.java      |    1 +
 .../usergrid/batch/job/DelayHeartbeat.java      |    1 +
 .../usergrid/batch/job/FailureJobExecution.java |    1 +
 .../usergrid/batch/job/OnlyOnceExceution.java   |    1 +
 .../job/OnlyOnceUnlockOnFailExceution.java      |    1 +
 .../usergrid/batch/job/SchedulerRuntime1IT.java |   30 +-
 .../usergrid/batch/job/SchedulerRuntime2IT.java |   42 +-
 .../usergrid/batch/job/SchedulerRuntime3IT.java |   11 +-
 .../usergrid/batch/job/SchedulerRuntime4IT.java |    9 +-
 .../usergrid/batch/job/SchedulerRuntime5IT.java |    9 +-
 .../usergrid/batch/job/SchedulerRuntime6IT.java |   11 +-
 .../usergrid/batch/job/SchedulerRuntime7IT.java |    9 +-
 .../usergrid/batch/job/SchedulerRuntime8IT.java |   15 +-
 .../batch/job/SchedulerRuntimeIntervalIT.java   |   21 +-
 .../usergrid/batch/job/TestJobListenerTest.java |    8 +-
 .../corepersistence/CpEntityMapUtilsTest.java   |   32 +-
 .../corepersistence/StaleIndexCleanupTest.java  |   59 +-
 .../migration/EntityDataMigrationIT.java        |   18 +-
 .../migration/EntityTypeMappingMigrationIT.java |   18 +-
 .../migration/GraphShardVersionMigrationIT.java |    9 +-
 .../migration/MigrationTestRule.java            |    1 -
 .../rx/AllEntitiesInSystemObservableIT.java     |    6 +-
 .../rx/ApplicationObservableTestIT.java         |    9 +-
 .../rx/EdgesFromSourceObservableIT.java         |    9 +-
 .../rx/EdgesToTargetObservableIT.java           |   12 +-
 .../rx/TargetIdObservableTestIT.java            |   14 +-
 .../count/BatchCountParallelismTest.java        |    7 +-
 .../usergrid/count/SimpleBatcherTest.java       |    1 +
 .../locking/cassandra/HectorLockManagerIT.java  |   11 +-
 .../SingleNodeLockTestSingleNode.java           |    1 +
 .../zookeeper/ZookeeperLockManagerTest.java     |    2 +-
 .../java/org/apache/usergrid/mq/MessagesIT.java |    4 +-
 .../org/apache/usergrid/mq/QueuePathsTest.java  |    3 +-
 .../usergrid/persistence/CollectionIT.java      |   17 +-
 .../usergrid/persistence/CoreSchemaManager.java |   39 +-
 .../apache/usergrid/persistence/CounterIT.java  |   27 +-
 .../usergrid/persistence/CountingMutatorIT.java |   12 +-
 .../persistence/EntityConnectionsIT.java        |   24 +-
 .../persistence/EntityDictionaryIT.java         |    7 +-
 .../usergrid/persistence/EntityManagerIT.java   |   42 +-
 .../apache/usergrid/persistence/EntityTest.java |    4 +-
 .../org/apache/usergrid/persistence/GeoIT.java  |   34 +-
 .../persistence/GeoQueryBooleanTest.java        |   36 +-
 .../apache/usergrid/persistence/IndexIT.java    |   12 +-
 .../usergrid/persistence/LargeEntityIT.java     |    9 +-
 .../usergrid/persistence/PathQueryIT.java       |   12 +-
 .../persistence/PerformanceEntityReadTest.java  |   15 +-
 .../PerformanceEntityRebuildIndexTest.java      |   43 +-
 .../persistence/PerformanceEntityWriteTest.java |    3 +-
 .../usergrid/persistence/PermissionsIT.java     |    7 +-
 .../apache/usergrid/persistence/QueryTest.java  |   12 +-
 .../usergrid/persistence/QueryUtilsTest.java    |    3 +-
 .../apache/usergrid/persistence/SchemaTest.java |    6 +-
 .../apache/usergrid/persistence/UtilsTest.java  |    4 +-
 .../cassandra/EntityManagerFactoryImplIT.java   |    3 +-
 .../cassandra/QueryProcessorTest.java           |   41 +-
 .../SimpleIndexShardLocatorImplTest.java        |    4 +-
 ...EntityLocationRefDistanceComparatorTest.java |    1 +
 .../query/AbstractIteratingQueryIT.java         | 1339 ----------------
 .../persistence/query/AllInCollectionIT.java    |   29 -
 .../persistence/query/AllInConnectionIT.java    |   29 -
 .../query/AllInConnectionNoTypeIT.java          |   54 -
 .../persistence/query/CollectionIoHelper.java   |   61 +
 .../persistence/query/ConnectionHelper.java     |   85 ++
 .../query/IntersectionTransitivePagingIT.java   |   17 +-
 .../query/IntersectionUnionPagingIT.java        |   27 +-
 .../usergrid/persistence/query/IoHelper.java    |   57 +
 .../persistence/query/IteratingQueryIT.java     | 1432 ++++++++++++++++++
 .../query/MultiOrderByCollectionIT.java         |   29 -
 .../MultiOrderByComplexUnionCollectionIT.java   |   29 -
 .../MultiOrderByComplexUnionConnectionIT.java   |   29 -
 .../query/MultiOrderByConnectionIT.java         |   32 -
 .../query/NotOrderByCollectionIT.java           |   29 -
 .../query/NotOrderByConnectionIT.java           |   29 -
 .../persistence/query/NotSubPropertyIT.java     |  157 +-
 ...gleOrderByBoundRangeScanAscCollectionIT.java |   29 -
 ...gleOrderByBoundRangeScanAscConnectionIT.java |   29 -
 ...leOrderByBoundRangeScanDescCollectionIT.java |   29 -
 ...leOrderByBoundRangeScanDescConnectionIT.java |   29 -
 ...eOrderByComplexIntersectionCollectionIT.java |   29 -
 ...eOrderByComplexIntersectionConnectionIT.java |   30 -
 .../SingleOrderByComplexUnionCollectionIT.java  |   29 -
 .../SingleOrderByComplexUnionConnectionIT.java  |   29 -
 .../SingleOrderByIntersectionCollectionIT.java  |   31 -
 .../SingleOrderByIntersectionConnectionIT.java  |   31 -
 .../SingleOrderByLessThanLimitCollectionIT.java |   29 -
 .../SingleOrderByLessThanLimitConnectionIT.java |   29 -
 .../SingleOrderByMaxLimitCollectionIT.java      |   30 -
 .../SingleOrderByMaxLimitConnectionIT.java      |   30 -
 ...SingleOrderByNoIntersectionCollectionIT.java |   29 -
 ...SingleOrderByNoIntersectionConnectionIT.java |   29 -
 .../query/SingleOrderByNotCollectionIT.java     |   29 -
 .../query/SingleOrderByNotConnectionIT.java     |   29 -
 ...OrderBySameRangeScanGreaterCollectionIT.java |   29 -
 ...OrderBySameRangeScanGreaterConnectionIT.java |   29 -
 ...meRangeScanGreaterThanEqualCollectionIT.java |   29 -
 ...gleOrderBySameRangeScanLessCollectionIT.java |   29 -
 ...gleOrderBySameRangeScanLessConnectionIT.java |   29 -
 ...ySameRangeScanLessThanEqualCollectionIT.java |   29 -
 ...ySameRangeScanLessThanEqualConnectionIT.java |   29 -
 .../query/ir/result/AbstractScanColumnTest.java |    1 +
 .../query/ir/result/InOrderIterator.java        |    9 +-
 .../ir/result/IntersectionIteratorTest.java     |    1 +
 .../ir/result/SubtractionIteratorTest.java      |    3 +-
 .../query/ir/result/UnionIteratorTest.java      |    3 +-
 .../system/UsergridSystemMonitorIT.java         |    2 -
 .../usergrid/utils/ImmediateCounterRule.java    |    4 +-
 .../apache/usergrid/utils/IndexUtilsTest.java   |    6 +-
 .../apache/usergrid/utils/UUIDUtilsTest.java    |    5 +-
 .../resources/usergrid-custom-test.properties   |   14 +-
 .../test/resources/usergrid-test-context.xml    |    6 +-
 .../usergrid/persistence/index/EntityIndex.java |   10 +-
 .../index/impl/ElasticSearchResource.java       |    5 +
 stack/pom.xml                                   |    5 -
 .../collection/DuplicateNameIT.java             |   67 +-
 .../notifications/NotificationsService.java     |    6 +-
 .../services/notifications/QueueListener.java   |    6 +-
 .../org/apache/usergrid/ServiceITSetupImpl.java |   21 +-
 .../apache/usergrid/management/EmailFlowIT.java |    7 +-
 .../usergrid/management/OrganizationIT.java     |    8 +-
 .../org/apache/usergrid/management/RoleIT.java  |    9 +-
 .../cassandra/ApplicationCreatorIT.java         |    8 +-
 .../management/cassandra/ExportServiceIT.java   |   24 +-
 .../cassandra/ManagementServiceIT.java          |   13 +-
 .../security/providers/FacebookProviderIT.java  |   10 +-
 .../providers/PingIdentityProviderIT.java       |    8 +-
 .../security/tokens/TokenServiceIT.java         |    9 +-
 .../usergrid/services/AbstractServiceIT.java    |    7 +-
 .../usergrid/services/ServiceRequestIT.java     |    7 +-
 .../usergrid/cassandra/CassandraResource.java   |    9 +-
 .../apache/usergrid/cassandra/Concurrent.java   |   31 -
 .../cassandra/ConcurrentJunitRunner.java        |   91 --
 .../usergrid/cassandra/ConcurrentSuite.java     |  117 --
 .../usergrid/cassandra/SpringResource.java      |   40 +-
 .../setup/ConcurrentProcessSingleton.java       |  124 ++
 .../usergrid/setup/SpringIntegrationRunner.java |   67 -
 .../org/apache/usergrid/setup/SystemSetup.java  |   90 --
 .../usergrid/cassandra/OkThisIsTheLastIT.java   |    2 -
 .../usergrid/cassandra/SpringResourceTest.java  |    1 -
 166 files changed, 3106 insertions(+), 4061 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1fbe3e54/stack/core/pom.xml
----------------------------------------------------------------------
diff --git a/stack/core/pom.xml b/stack/core/pom.xml
index 5d9da98..405b622 100644
--- a/stack/core/pom.xml
+++ b/stack/core/pom.xml
@@ -87,7 +87,7 @@
           <forkCount>${usergrid.it.forkCount}</forkCount>
           <threadCount>${usergrid.it.threads}</threadCount>
           <reuseForks>true</reuseForks>
-          <argLine>-Dtest.barrier.timestamp=${maven.build.timestamp} -Xmx${ug.heapmax} -Xms${ug.heapmin} -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -javaagent:${settings.localRepository}/com/github/stephenc/jamm/0.2.5/jamm-0.2.5.jar ${ug.argline}</argLine>
+          <argLine>-Dtest.barrier.timestamp=${maven.build.timestamp} -Dtest.clean.storage=true -Xmx${ug.heapmax} -Xms${ug.heapmin} -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -javaagent:${settings.localRepository}/com/github/stephenc/jamm/0.2.5/jamm-0.2.5.jar ${ug.argline}</argLine>
           <includes>
             <include>**/*IT.java</include>
             <include>**/*Test.java</include>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1fbe3e54/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 3ab767c..0f0d401 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
@@ -208,8 +208,8 @@ public class CpEntityManager implements EntityManager {
 
         applicationScope = CpNamingUtils.getApplicationScope( applicationId );
 
-        this.cass = this.emf.cass;
-        this.counterUtils = this.emf.counterUtils;
+        this.cass = this.emf.getCassandraService();
+        this.counterUtils = this.emf.getCounterUtils();
 
         // set to false for now
         this.skipAggregateCounters = false;
@@ -348,7 +348,7 @@ public class CpEntityManager implements EntityManager {
      */
     @Metered( group = "core", name = "EntityManager_create" )
     @TraceParticipant
-    public <A extends Entity> A create( String entityType, Class<A> entityClass, 
+    public <A extends Entity> A create( String entityType, Class<A> entityClass,
             Map<String, Object> properties, UUID importId ) throws Exception {
 
         UUID timestampUuid = importId != null ? importId : UUIDUtils.newTimeUUID();
@@ -526,12 +526,12 @@ public class CpEntityManager implements EntityManager {
         Id entityId = new SimpleId( entity.getUuid(), entity.getType() );
 
         if ( logger.isDebugEnabled() ) {
-            logger.debug( "Updating entity {}:{} from scope\n   app {}\n   owner {}\n   name {}", 
+            logger.debug( "Updating entity {}:{} from scope\n   app {}\n   owner {}\n   name {}",
                 new Object[] {
-                    entityId.getType(), 
-                    entityId.getUuid(), 
+                    entityId.getType(),
+                    entityId.getUuid(),
                     collectionScope.getApplication(),
-                    collectionScope.getOwner(), 
+                    collectionScope.getOwner(),
                     collectionScope.getName()
                 } );
         }
@@ -821,7 +821,7 @@ public class CpEntityManager implements EntityManager {
     }
 
 
-    private Iterable<EntityRef> getEntityRefsForUniqueProperty( 
+    private Iterable<EntityRef> getEntityRefsForUniqueProperty(
             String collName, String propName, String alias ) throws Exception {
 
         final Id id = getIdForUniqueEntityField( collName, propName, alias );
@@ -854,16 +854,16 @@ public class CpEntityManager implements EntityManager {
                 get( entityRef ).getType();
             }
             catch ( Exception e ) {
-                logger.error( "Unable to load entity " + entityRef.getType() 
+                logger.error( "Unable to load entity " + entityRef.getType()
                         + ":" + entityRef.getUuid(), e );
             }
             if ( entityRef == null ) {
-                throw new EntityNotFoundException( 
+                throw new EntityNotFoundException(
                         "Entity " + entityId.toString() + " cannot be verified" );
             }
             if ( ( entityType != null ) && !entityType.equalsIgnoreCase( entityRef.getType() ) ) {
                 throw new UnexpectedEntityTypeException(
-                        "Entity " + entityId + " is not the expected type, expected " 
+                        "Entity " + entityId + " is not the expected type, expected "
                                 + entityType + ", found " + entityRef.getType() );
             }
         }
@@ -880,7 +880,7 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public List<Entity> getPartialEntities( 
+    public List<Entity> getPartialEntities(
             Collection<UUID> ids, Collection<String> properties ) throws Exception {
         throw new UnsupportedOperationException( "Not supported yet." );
     }
@@ -895,7 +895,7 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public void setProperty( 
+    public void setProperty(
             EntityRef entityRef, String propertyName, Object propertyValue ) throws Exception {
 
         setProperty( entityRef, propertyName, propertyValue, false );
@@ -903,8 +903,8 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public void setProperty( EntityRef entityRef, String propertyName, Object propertyValue, 
-            boolean override ) throws Exception { 
+    public void setProperty( EntityRef entityRef, String propertyName, Object propertyValue,
+            boolean override ) throws Exception {
 
         if ( ( propertyValue instanceof String ) && ( ( String ) propertyValue ).equals( "" ) ) {
             propertyValue = null;
@@ -912,7 +912,7 @@ public class CpEntityManager implements EntityManager {
 
         Entity entity = get( entityRef );
 
-        propertyValue = Schema.getDefaultSchema().validateEntityPropertyValue( 
+        propertyValue = Schema.getDefaultSchema().validateEntityPropertyValue(
                 entity.getType(), propertyName, propertyValue );
 
         entity.setProperty( propertyName, propertyValue );
@@ -1017,7 +1017,7 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public void addToDictionary( EntityRef entityRef, String dictionaryName, 
+    public void addToDictionary( EntityRef entityRef, String dictionaryName,
             Object elementValue ) throws Exception {
 
         addToDictionary( entityRef, dictionaryName, elementValue, null );
@@ -1025,7 +1025,7 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public void addToDictionary( EntityRef entityRef, String dictionaryName, Object elementName, 
+    public void addToDictionary( EntityRef entityRef, String dictionaryName, Object elementName,
             Object elementValue ) throws Exception {
 
         if ( elementName == null ) {
@@ -1344,7 +1344,7 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public Entity createItemInCollection( EntityRef entityRef, String collectionName, 
+    public Entity createItemInCollection( EntityRef entityRef, String collectionName,
             String itemType, Map<String, Object> props ) throws Exception {
 
         return getRelationManager( entityRef ).createItemInCollection( collectionName, itemType, props );
@@ -1390,7 +1390,7 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public ConnectionRef createConnection( EntityRef connectingEntity, String pairedConnectionType, 
+    public ConnectionRef createConnection( EntityRef connectingEntity, String pairedConnectionType,
             EntityRef pairedEntity, String connectionType, EntityRef connectedEntityRef )
             throws Exception {
 
@@ -1417,7 +1417,7 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public ConnectionRef connectionRef( EntityRef connectingEntity, String pairedConnectionType, 
+    public ConnectionRef connectionRef( EntityRef connectingEntity, String pairedConnectionType,
             EntityRef pairedEntity, String connectionType, EntityRef connectedEntityRef ) throws Exception {
 
         return getRelationManager( connectingEntity )
@@ -1449,7 +1449,7 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public Results getConnectedEntities( EntityRef entityRef, String connectionType, 
+    public Results getConnectedEntities( EntityRef entityRef, String connectionType,
             String connectedEntityType, Level resultsLevel ) throws Exception {
 
         return getRelationManager( entityRef )
@@ -1458,7 +1458,7 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public Results getConnectingEntities( EntityRef entityRef, String connectionType, 
+    public Results getConnectingEntities( EntityRef entityRef, String connectionType,
             String connectedEntityType, Level resultsLevel ) throws Exception {
 
         return getRelationManager( entityRef )
@@ -1562,7 +1562,7 @@ public class CpEntityManager implements EntityManager {
     }
 
 
-    private Entity batchCreateRole( String roleName, String roleTitle, long inactivity, 
+    private Entity batchCreateRole( String roleName, String roleTitle, long inactivity,
             String propertyName, UUID ownerId, Map<String, Object> additionalProperties ) throws Exception {
 
         UUID timestampUuid = UUIDUtils.newTimeUUID();
@@ -1585,10 +1585,10 @@ public class CpEntityManager implements EntityManager {
 
         Mutator<ByteBuffer> batch = createMutator( cass.getApplicationKeyspace( applicationId ), be );
         CassandraPersistenceUtils.addInsertToMutator( batch, ENTITY_DICTIONARIES,
-                CassandraPersistenceUtils.key( ownerId, 
+                CassandraPersistenceUtils.key( ownerId,
                         Schema.DICTIONARY_ROLENAMES ), roleName, roleTitle, timestamp );
         CassandraPersistenceUtils.addInsertToMutator( batch, ENTITY_DICTIONARIES,
-                CassandraPersistenceUtils.key( ownerId, 
+                CassandraPersistenceUtils.key( ownerId,
                         Schema.DICTIONARY_ROLETIMES ), roleName, inactivity,
                 timestamp );
         CassandraPersistenceUtils.addInsertToMutator( batch, ENTITY_DICTIONARIES,
@@ -1607,7 +1607,7 @@ public class CpEntityManager implements EntityManager {
         permission = permission.toLowerCase();
         long timestamp = cass.createTimestamp();
         Mutator<ByteBuffer> batch = createMutator( cass.getApplicationKeyspace( applicationId ), be );
-        CassandraPersistenceUtils.addInsertToMutator( batch, ApplicationCF.ENTITY_DICTIONARIES, 
+        CassandraPersistenceUtils.addInsertToMutator( batch, ApplicationCF.ENTITY_DICTIONARIES,
             getRolePermissionsKey( roleName ), permission, ByteBuffer.allocate( 0 ), timestamp );
         CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
     }
@@ -1621,7 +1621,7 @@ public class CpEntityManager implements EntityManager {
         Mutator<ByteBuffer> batch = createMutator( cass.getApplicationKeyspace( applicationId ), be );
         for ( String permission : permissions ) {
             permission = permission.toLowerCase();
-            CassandraPersistenceUtils.addInsertToMutator( batch, ApplicationCF.ENTITY_DICTIONARIES, 
+            CassandraPersistenceUtils.addInsertToMutator( batch, ApplicationCF.ENTITY_DICTIONARIES,
                 getRolePermissionsKey( roleName ), permission, ByteBuffer.allocate( 0 ), timestamp);
         }
         CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
@@ -1629,7 +1629,7 @@ public class CpEntityManager implements EntityManager {
 
 
     private Object getRolePermissionsKey( String roleName ) {
-        return CassandraPersistenceUtils.key( 
+        return CassandraPersistenceUtils.key(
                 SimpleRoleRef.getIdForRoleName( roleName ), DICTIONARY_PERMISSIONS );
     }
 
@@ -1652,7 +1652,7 @@ public class CpEntityManager implements EntityManager {
         permission = permission.toLowerCase();
         long timestamp = cass.createTimestamp();
         Mutator<ByteBuffer> batch = createMutator( cass.getApplicationKeyspace( applicationId ), be);
-        CassandraPersistenceUtils.addDeleteToMutator( batch, ApplicationCF.ENTITY_DICTIONARIES, 
+        CassandraPersistenceUtils.addDeleteToMutator( batch, ApplicationCF.ENTITY_DICTIONARIES,
                 getRolePermissionsKey( roleName ), permission, timestamp );
         CassandraPersistenceUtils.batchExecute( batch, CassandraService.RETRY_COUNT );
     }
@@ -1661,7 +1661,7 @@ public class CpEntityManager implements EntityManager {
     @Override
     public Set<String> getRolePermissions( String roleName ) throws Exception {
         roleName = roleName.toLowerCase();
-        return cass.getAllColumnNames( cass.getApplicationKeyspace( applicationId ), 
+        return cass.getAllColumnNames( cass.getApplicationKeyspace( applicationId ),
                 ApplicationCF.ENTITY_DICTIONARIES, getRolePermissionsKey( roleName ) );
     }
 
@@ -1737,7 +1737,7 @@ public class CpEntityManager implements EntityManager {
     @Override
     public Set<String> getGroupRolePermissions( UUID groupId, String roleName ) throws Exception {
         roleName = roleName.toLowerCase();
-        return cass.getAllColumnNames( cass.getApplicationKeyspace( applicationId ), 
+        return cass.getAllColumnNames( cass.getApplicationKeyspace( applicationId ),
                 ApplicationCF.ENTITY_DICTIONARIES, getRolePermissionsKey( groupId, roleName ) );
     }
 
@@ -1780,7 +1780,7 @@ public class CpEntityManager implements EntityManager {
 
     @Override
     public Set<String> getUserPermissions( UUID userId ) throws Exception {
-        return cast(getDictionaryAsSet( 
+        return cast(getDictionaryAsSet(
                 new SimpleEntityRef( User.ENTITY_TYPE, userId ), Schema.DICTIONARY_PERMISSIONS ) );
     }
 
@@ -1861,7 +1861,7 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public void incrementAggregateCounters( UUID userId, UUID groupId, String category, 
+    public void incrementAggregateCounters( UUID userId, UUID groupId, String category,
             String counterName, long value ) {
 
         long cassandraTimestamp = cass.createTimestamp();
@@ -1869,14 +1869,14 @@ public class CpEntityManager implements EntityManager {
     }
 
 
-    private void incrementAggregateCounters( UUID userId, UUID groupId, String category, 
+    private void incrementAggregateCounters( UUID userId, UUID groupId, String category,
             String counterName, long value, long cassandraTimestamp ) {
 
         // TODO short circuit
         if ( !skipAggregateCounters ) {
             Mutator<ByteBuffer> m = createMutator( cass.getApplicationKeyspace( applicationId ), be );
 
-            counterUtils.batchIncrementAggregateCounters( m, applicationId, userId, groupId, null, 
+            counterUtils.batchIncrementAggregateCounters( m, applicationId, userId, groupId, null,
                     category, counterName, value, cassandraTimestamp / 1000, cassandraTimestamp );
 
             CassandraPersistenceUtils.batchExecute( m, CassandraService.RETRY_COUNT );
@@ -1885,15 +1885,15 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public Results getAggregateCounters( UUID userId, UUID groupId, String category, 
+    public Results getAggregateCounters( UUID userId, UUID groupId, String category,
             String counterName, CounterResolution resolution, long start, long finish, boolean pad ) {
-        return this.getAggregateCounters( 
+        return this.getAggregateCounters(
                 userId, groupId, null, category, counterName, resolution, start, finish, pad );
     }
 
 
     @Override
-    public Results getAggregateCounters( UUID userId, UUID groupId, UUID queueId, String category, 
+    public Results getAggregateCounters( UUID userId, UUID groupId, UUID queueId, String category,
         String counterName, CounterResolution resolution, long start, long finish, boolean pad ) {
 
         start = resolution.round( start );
@@ -2000,7 +2000,7 @@ public class CpEntityManager implements EntityManager {
                 }
             }
             CounterUtils.AggregateCounterSelection selection = selections.get( r.getKey() );
-            countSets.add( new AggregateCounterSet( selection.getName(), selection.getUserId(), 
+            countSets.add( new AggregateCounterSet( selection.getName(), selection.getUserId(),
                     selection.getGroupId(), selection.getCategory(), counters ) );
         }
 
@@ -2029,7 +2029,7 @@ public class CpEntityManager implements EntityManager {
             return new SimpleEntityRef( "user", identifier.getUUID() );
         }
         if ( identifier.isName() ) {
-            return this.getAlias( new SimpleEntityRef( 
+            return this.getAlias( new SimpleEntityRef(
                     Application.ENTITY_TYPE, applicationId ), "user", identifier.getName() );
         }
         if ( identifier.isEmail() ) {
@@ -2120,7 +2120,7 @@ public class CpEntityManager implements EntityManager {
         if ( !skipAggregateCounters ) {
             long timestamp = cass.createTimestamp();
             Mutator<ByteBuffer> m = createMutator( cass.getApplicationKeyspace( applicationId ), be );
-            counterUtils.batchIncrementAggregateCounters( 
+            counterUtils.batchIncrementAggregateCounters(
                     m, applicationId, userId, groupId, null, category, counters, timestamp );
 
             CassandraPersistenceUtils.batchExecute( m, CassandraService.RETRY_COUNT );
@@ -2149,7 +2149,7 @@ public class CpEntityManager implements EntityManager {
         final EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
 
         //convert to a string, that's what we store
-        final Id results = ecm.getIdField( new StringField( 
+        final Id results = ecm.getIdField( new StringField(
                 propertyName, propertyValue.toString() ) ).toBlocking() .lastOrDefault( null );
 
         return results;
@@ -2341,7 +2341,7 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public <A extends Entity> A batchCreate( Mutator<ByteBuffer> ignored, String entityType, 
+    public <A extends Entity> A batchCreate( Mutator<ByteBuffer> ignored, String entityType,
             Class<A> entityClass, Map<String, Object> properties, UUID importId, UUID timestampUuid )
             throws Exception {
 
@@ -2473,13 +2473,13 @@ public class CpEntityManager implements EntityManager {
         EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
 
         if ( logger.isDebugEnabled() ) {
-            logger.debug( "Writing entity {}:{} into scope\n   app {}\n   owner {}\n   name {} data {}", 
+            logger.debug( "Writing entity {}:{} into scope\n   app {}\n   owner {}\n   name {} data {}",
                 new Object[] {
-                    entity.getType(), 
-                    entity.getUuid(), 
+                    entity.getType(),
+                    entity.getUuid(),
                     collectionScope.getApplication(),
-                    collectionScope.getOwner(), 
-                    collectionScope.getName(), 
+                    collectionScope.getOwner(),
+                    collectionScope.getName(),
                     CpEntityMapUtils.toMap( cpEntity )
                 } );
             //
@@ -2551,7 +2551,7 @@ public class CpEntityManager implements EntityManager {
 
     private void incrementEntityCollection( String collection_name, long cassandraTimestamp ) {
         try {
-            incrementAggregateCounters( null, null, null, 
+            incrementAggregateCounters( null, null, null,
                     APPLICATION_COLLECTION + collection_name, ONE_COUNT, cassandraTimestamp );
         }
         catch ( Exception e ) {
@@ -2559,11 +2559,11 @@ public class CpEntityManager implements EntityManager {
                     new Object[] { collection_name, e } );
         }
         try {
-            incrementAggregateCounters( null, null, null, 
+            incrementAggregateCounters( null, null, null,
                     APPLICATION_ENTITIES, ONE_COUNT, cassandraTimestamp );
         }
         catch ( Exception e ) {
-            logger.error( "Unable to increment counter application.entities for collection: " 
+            logger.error( "Unable to increment counter application.entities for collection: "
                     + "{} with timestamp: {}",
                     new Object[] { collection_name, cassandraTimestamp, e } );
         }
@@ -2573,7 +2573,7 @@ public class CpEntityManager implements EntityManager {
     private void handleWriteUniqueVerifyException( Entity entity, WriteUniqueVerifyException wuve )
             throws DuplicateUniquePropertyExistsException {
 
-        // we may have multiple conflicts, but caller expects only one 
+        // we may have multiple conflicts, but caller expects only one
         Map<String, Field> violiations = wuve.getVioliations();
 
         if ( violiations != null ) {
@@ -2590,7 +2590,7 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public Mutator<ByteBuffer> batchSetProperty( Mutator<ByteBuffer> batch, EntityRef entity, 
+    public Mutator<ByteBuffer> batchSetProperty( Mutator<ByteBuffer> batch, EntityRef entity,
             String propertyName, Object propertyValue, UUID timestampUuid ) throws Exception {
 
         throw new UnsupportedOperationException( "Not supported yet." );
@@ -2598,8 +2598,8 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public Mutator<ByteBuffer> batchSetProperty( Mutator<ByteBuffer> batch, EntityRef entity, 
-            String propertyName, Object propertyValue, boolean force, boolean noRead, 
+    public Mutator<ByteBuffer> batchSetProperty( Mutator<ByteBuffer> batch, EntityRef entity,
+            String propertyName, Object propertyValue, boolean force, boolean noRead,
             UUID timestampUuid ) throws Exception {
 
         throw new UnsupportedOperationException( "Not supported yet." );
@@ -2607,7 +2607,7 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public Mutator<ByteBuffer> batchUpdateDictionary( Mutator<ByteBuffer> batch, EntityRef entity, 
+    public Mutator<ByteBuffer> batchUpdateDictionary( Mutator<ByteBuffer> batch, EntityRef entity,
             String dictionaryName, Object elementValue, Object elementCoValue,
             boolean removeFromDictionary, UUID timestampUuid )
             throws Exception {
@@ -2628,24 +2628,24 @@ public class CpEntityManager implements EntityManager {
                     batch, dictionaryName, elementValue, removeFromDictionary, timestampUuid );
         }
 
-        ApplicationCF dictionary_cf = entityHasDictionary 
+        ApplicationCF dictionary_cf = entityHasDictionary
                 ? ENTITY_DICTIONARIES : ENTITY_COMPOSITE_DICTIONARIES;
 
         if ( elementValue != null ) {
             if ( !removeFromDictionary ) {
                 // Set the new value
 
-                elementCoValue = CassandraPersistenceUtils.toStorableBinaryValue( 
+                elementCoValue = CassandraPersistenceUtils.toStorableBinaryValue(
                         elementCoValue, !entityHasDictionary );
 
                 CassandraPersistenceUtils.addInsertToMutator( batch, dictionary_cf,
                         CassandraPersistenceUtils.key( entity.getUuid(), dictionaryName ),
-                        entityHasDictionary ? elementValue : asList( elementValue ), 
+                        entityHasDictionary ? elementValue : asList( elementValue ),
                         elementCoValue, timestamp );
 
                 if ( !entityHasDictionary ) {
                     CassandraPersistenceUtils.addInsertToMutator( batch, ENTITY_DICTIONARIES,
-                            CassandraPersistenceUtils.key( entity.getUuid(), DICTIONARY_SETS ), 
+                            CassandraPersistenceUtils.key( entity.getUuid(), DICTIONARY_SETS ),
                             dictionaryName, null, timestamp );
                 }
             }
@@ -2661,18 +2661,18 @@ public class CpEntityManager implements EntityManager {
 
 
     @Override
-    public Mutator<ByteBuffer> batchUpdateDictionary( Mutator<ByteBuffer> batch, EntityRef entity, 
-            String dictionaryName, Object elementValue, boolean removeFromDictionary, 
+    public Mutator<ByteBuffer> batchUpdateDictionary( Mutator<ByteBuffer> batch, EntityRef entity,
+            String dictionaryName, Object elementValue, boolean removeFromDictionary,
             UUID timestampUuid )
             throws Exception {
 
-        return batchUpdateDictionary( batch, entity, dictionaryName, elementValue, null, 
+        return batchUpdateDictionary( batch, entity, dictionaryName, elementValue, null,
                 removeFromDictionary, timestampUuid );
     }
 
 
     @Override
-    public Mutator<ByteBuffer> batchUpdateProperties( Mutator<ByteBuffer> batch, EntityRef entity, 
+    public Mutator<ByteBuffer> batchUpdateProperties( Mutator<ByteBuffer> batch, EntityRef entity,
             Map<String, Object> properties, UUID timestampUuid ) throws Exception {
 
         throw new UnsupportedOperationException( "Not supported yet." );
@@ -2750,6 +2750,11 @@ public class CpEntityManager implements EntityManager {
         ei.initializeIndex();
     }
 
+    public void deleteIndex(){
+        EntityIndex ei = managerCache.getEntityIndex( applicationScope );
+        ei.deleteIndex();
+    }
+
 
     public static org.apache.usergrid.persistence.model.entity.Entity entityToCpEntity( Entity entity, UUID importId ) {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1fbe3e54/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 7016d3c..e49f46e 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
@@ -51,7 +51,6 @@ import org.apache.usergrid.persistence.cassandra.CounterUtils;
 import org.apache.usergrid.persistence.cassandra.Setup;
 import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.EntityCollectionManager;
-import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
 import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
 import org.apache.usergrid.persistence.core.migration.data.DataMigrationManager;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
@@ -59,16 +58,14 @@ import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
 import org.apache.usergrid.persistence.core.util.Health;
 import org.apache.usergrid.persistence.entities.Application;
 import org.apache.usergrid.persistence.exceptions.ApplicationAlreadyExistsException;
+import org.apache.usergrid.persistence.exceptions.DuplicateUniquePropertyExistsException;
+import org.apache.usergrid.persistence.exceptions.OrganizationAlreadyExistsException;
 import org.apache.usergrid.persistence.graph.Edge;
 import org.apache.usergrid.persistence.graph.GraphManager;
-import org.apache.usergrid.persistence.graph.GraphManagerFactory;
 import org.apache.usergrid.persistence.graph.SearchByEdgeType;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
-import org.apache.usergrid.persistence.index.AliasedEntityIndex;
 import org.apache.usergrid.persistence.index.EntityIndex;
-import org.apache.usergrid.persistence.index.EntityIndexFactory;
 import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.persistence.map.MapManagerFactory;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.utils.UUIDUtils;
@@ -89,8 +86,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
     private static final Logger logger = LoggerFactory.getLogger( CpEntityManagerFactory.class );
 
-    public static String IMPLEMENTATION_DESCRIPTION = "Core Persistence Entity Manager Factory 1.0";
-
     private ApplicationContext applicationContext;
 
     private Setup setup = null;
@@ -114,17 +109,36 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     private ManagerCache managerCache;
     private DataMigrationManager dataMigrationManager;
 
-    CassandraService cass;
-    CounterUtils counterUtils;
+    private CassandraService cassandraService;
+    private CounterUtils counterUtils;
+    private Injector injector;
 
 
     public CpEntityManagerFactory(
-            CassandraService cass, CounterUtils counterUtils) {
+            final CassandraService cassandraService, final CounterUtils counterUtils, final Injector injector) {
 
-        this.cass = cass;
+        this.cassandraService = cassandraService;
         this.counterUtils = counterUtils;
+        this.injector = injector;
+        this.managerCache = injector.getInstance( ManagerCache.class );
+        this.dataMigrationManager = injector.getInstance( DataMigrationManager.class );
+
+
+    }
+
+
+    public CounterUtils getCounterUtils() {
+        return counterUtils;
+    }
+
+
+    public CassandraService getCassandraService() {
+        return cassandraService;
+    }
 
 
+    public ManagerCache getManagerCache() {
+        return managerCache;
     }
 
 
@@ -149,25 +163,15 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     }
 
 
-    public ManagerCache getManagerCache() {
-
-        if ( managerCache == null ) {
-
-            // TODO: better solution for getting injector?
-            Injector injector = CpSetup.getInjector();
-
-            managerCache = injector.getInstance( ManagerCache.class );
-
-            dataMigrationManager = injector.getInstance( DataMigrationManager.class );
-        }
-        return managerCache;
-    }
-
-
-    @Override
-    public String getImpementationDescription() throws Exception {
-        return IMPLEMENTATION_DESCRIPTION;
-    }
+//    public ManagerCache getManagerCache() {
+//
+//        if ( managerCache == null ) {
+//            managerCache = injector.getInstance( ManagerCache.class );
+//
+//            dataMigrationManager = injector.getInstance( DataMigrationManager.class );
+//        }
+//        return managerCache;
+//    }
 
 
     @Override
@@ -187,7 +191,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         EntityManager em = new CpEntityManager();
         em.init( this, applicationId );
 
-        // only need to do this once 
+        // only need to do this once
         if ( !applicationIndexesCreated.contains( applicationId ) ) {
             em.createIndex();
             applicationIndexesCreated.add( applicationId );
@@ -251,9 +255,18 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
             // create new org because the specified one does not exist
             final String orgName = organizationName;
-            Entity orgInfo = em.create("organization", new HashMap<String, Object>() {{
-                put( PROPERTY_NAME, orgName );
-            }});
+
+            final Entity orgInfo;
+
+            try {
+                orgInfo = em.create( "organization", new HashMap<String, Object>() {{
+                    put( PROPERTY_NAME, orgName );
+                }} );
+            }
+            catch ( DuplicateUniquePropertyExistsException e ) {
+                throw new OrganizationAlreadyExistsException( orgName );
+            }
+
             em.refreshIndex();
             orgUuid = orgInfo.getUuid();
         }
@@ -266,7 +279,12 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
             put( "applicationUuid", appId );
             put( "organizationUuid", orgId );
         }};
-        Entity appInfo = em.create( "appinfo", appInfoMap );
+
+        try{
+             em.create( "appinfo", appInfoMap );
+        }catch(DuplicateUniquePropertyExistsException e){
+                       throw new ApplicationAlreadyExistsException( appName );
+                   }
         em.refreshIndex();
 
         // create application entity
@@ -460,7 +478,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
             propsEntity = EntityFactory.newEntity( UUIDUtils.newTimeUUID(), "propertymap");
         }
 
-        // intentionally going only one-level deep into fields and treating all 
+        // intentionally going only one-level deep into fields and treating all
         // values as strings because that is all we need for service properties
         for ( String key : properties.keySet() ) {
             propsEntity.setProperty( key, properties.get(key).toString() );
@@ -530,11 +548,11 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     @Override
     public void setApplicationContext( ApplicationContext applicationContext ) throws BeansException {
         this.applicationContext = applicationContext;
-        try {
-            setup();
-        } catch (Exception ex) {
-            logger.error("Error setting up EMF", ex);
-        }
+//        try {
+//            setup();
+//        } catch (Exception ex) {
+//            logger.error("Error setting up EMF", ex);
+//        }
     }
 
 
@@ -546,13 +564,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     }
 
 
-    /**
-     * @param managerCache the managerCache to set
-     */
-    public void setManagerCache(CpManagerCache managerCache) {
-        this.managerCache = managerCache;
-    }
-
 
     @Override
     public UUID getManagementAppId() {
@@ -574,7 +585,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
      */
     public Setup getSetup() {
         if ( setup == null ) {
-            setup = new CpSetup( this, cass );
+            setup = new CpSetup( this, cassandraService, injector );
         }
         return setup;
     }
@@ -609,17 +620,16 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
     private List<EntityIndex> getManagementIndexes() {
 
-        return Arrays.asList(
-            getManagerCache().getEntityIndex(
-                new ApplicationScopeImpl( new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application" ))),
+        return Arrays.asList( managerCache.getEntityIndex(
+                new ApplicationScopeImpl( new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application" ) ) ),
 
             // management app
-            getManagerCache().getEntityIndex(
-                new ApplicationScopeImpl( new SimpleId( getManagementAppId(), "application" ))),
+            managerCache
+                .getEntityIndex( new ApplicationScopeImpl( new SimpleId( getManagementAppId(), "application" ) ) ),
 
             // default app TODO: do we need this in two-dot-o
-            getManagerCache().getEntityIndex(
-                new ApplicationScopeImpl( new SimpleId( getDefaultAppId(), "application" ))));
+            managerCache
+                .getEntityIndex( new ApplicationScopeImpl( new SimpleId( getDefaultAppId(), "application" ) ) ) );
     }
 
 
@@ -703,7 +713,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
     @Override
     public void addIndex(final UUID applicationId,final String indexSuffix,final int shards,final int replicas){
-        EntityIndex entityIndex = getManagerCache().getEntityIndex(CpNamingUtils.getApplicationScope(applicationId));
+        EntityIndex entityIndex = managerCache.getEntityIndex(CpNamingUtils.getApplicationScope(applicationId));
         entityIndex.addIndex(indexSuffix, shards, replicas);
     }
 
@@ -711,13 +721,10 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     public Health getEntityStoreHealth() {
 
         // could use any collection scope here, does not matter
-        EntityCollectionManager ecm = getManagerCache().getEntityCollectionManager( 
-            new CollectionScopeImpl( 
-                new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application"),
-                new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application"),
-                "dummy"
-        ));
-                 
+        EntityCollectionManager ecm = managerCache.getEntityCollectionManager(
+            new CollectionScopeImpl( new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application" ),
+                new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application" ), "dummy" ) );
+
         return ecm.getHealth();
-    } 
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1fbe3e54/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
index 47f45fe..5efa4a8 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
@@ -17,23 +17,27 @@
 package org.apache.usergrid.corepersistence;
 
 
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.netflix.config.ConfigurationManager;
-import java.util.Properties;
 import java.util.UUID;
 
-import me.prettyprint.cassandra.service.CassandraHost;
-import me.prettyprint.hector.api.ddl.ComparatorType;
-import static me.prettyprint.hector.api.factory.HFactory.createColumnFamilyDefinition;
-import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.mq.cassandra.QueuesCF;
 import org.apache.usergrid.persistence.EntityManagerFactory;
 import org.apache.usergrid.persistence.cassandra.ApplicationCF;
-import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.getCfDefs;
 import org.apache.usergrid.persistence.cassandra.CassandraService;
+import org.apache.usergrid.persistence.cassandra.Setup;
+import org.apache.usergrid.persistence.core.migration.schema.MigrationException;
+import org.apache.usergrid.persistence.core.migration.schema.MigrationManager;
+import org.apache.usergrid.persistence.exceptions.ApplicationAlreadyExistsException;
+import org.apache.usergrid.persistence.exceptions.OrganizationAlreadyExistsException;
+
+import com.google.inject.Injector;
+
+import me.prettyprint.hector.api.ddl.ComparatorType;
+
+import static me.prettyprint.hector.api.factory.HFactory.createColumnFamilyDefinition;
+import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.getCfDefs;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.APPLICATIONS_CF;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.DEFAULT_APPLICATION;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.DEFAULT_ORGANIZATION;
@@ -45,14 +49,6 @@ import static org.apache.usergrid.persistence.cassandra.CassandraService.SYSTEM_
 import static org.apache.usergrid.persistence.cassandra.CassandraService.TOKENS_CF;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.USE_VIRTUAL_KEYSPACES;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.keyspaceForApplication;
-import org.apache.usergrid.persistence.cassandra.Setup;
-import org.apache.usergrid.persistence.core.migration.data.DataMigrationManager;
-import org.apache.usergrid.persistence.core.migration.schema.MigrationException;
-import org.apache.usergrid.persistence.core.migration.schema.MigrationManager;
-import org.apache.usergrid.persistence.entities.Application;
-import org.apache.usergrid.persistence.exceptions.ApplicationAlreadyExistsException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 
 /**
@@ -62,151 +58,105 @@ public class CpSetup implements Setup {
 
     private static final Logger logger = LoggerFactory.getLogger( CpSetup.class );
 
-    private static Injector injector = null;
-    private static EntityManagerFactory emf;
+
+    private final Injector injector;
+
 
     private final CassandraService cass;
 
+    private final EntityManagerFactory emf;
+
 
     /**
      * Instantiates a new setup object.
      *
      * @param emf the emf
      */
-    public CpSetup( EntityManagerFactory emf, CassandraService cass ) {
+    public CpSetup( final EntityManagerFactory emf, final CassandraService cassandraService, final Injector injector ) {
         this.emf = emf;
-        this.cass = cass;
-    }
-
-
-    public static Injector getInjector() {
-        if ( injector == null ) {
-            injector = Guice.createInjector( new GuiceModule( emf ) ); 
-        }
-        return injector;
+        this.cass = cassandraService;
+        this.injector = injector;
     }
 
 
     @Override
     public void init() throws Exception {
-        cass.init();
-
-        try {
-            logger.info("Loading Core Persistence properties");
-
-            String hostsString = "";
-            CassandraHost[] hosts = cass.getCassandraHostConfigurator().buildCassandraHosts();
-            if ( hosts.length == 0 ) {
-                throw new RuntimeException("Fatal error: no Cassandra hosts configured");
-            }
-            String sep = "";
-            for ( CassandraHost host : hosts ) {
-                if (StringUtils.isEmpty(host.getHost())) {
-                    throw new RuntimeException("Fatal error: Cassandra hostname cannot be empty");
-                }
-                hostsString = hostsString + sep + host.getHost();
-                sep = ",";
-            }
-
-            logger.info("hostsString: " + hostsString);
+        //a no op, creating the injector creates the connections
 
-            Properties cpProps = new Properties();
+    }
 
-            // Some Usergrid properties must be mapped to Core Persistence properties
-            cpProps.put("cassandra.hosts", hostsString);
-            cpProps.put("cassandra.port", hosts[0].getPort());
-            cpProps.put("cassandra.cluster_name", cass.getProperties().get("cassandra.cluster"));
 
-            String cassRemoteString = (String)cass.getProperties().get("cassandra.use_remote"); 
-            if ( cassRemoteString != null && cassRemoteString.equals("false")) {
-                cpProps.put("cassandra.embedded", "true");
-            } else {
-                cpProps.put("cassandra.embedded", "false");
-            }
+    public void createDefaultApplications() throws Exception {
 
-            cpProps.put("collections.keyspace.strategy.class", 
-                    cass.getProperties().get("cassandra.keyspace.strategy"));
+        setupSystemKeyspace();
 
-            cpProps.put("collections.keyspace.strategy.options",
-                    cass.getProperties().get("cassandra.keyspace.replication"));
+        setupStaticKeyspace();
 
+        //force the EMF creation of indexes before creating the default applications
+        emf.refreshIndex();
 
-            logger.debug("Set Cassandra properties for Core Persistence: " + cpProps.toString() );
 
-            // Make all Usergrid properties into Core Persistence config
-            cpProps.putAll( cass.getProperties() );
-            //logger.debug("All properties fed to Core Persistence: " + cpProps.toString() );
+        logger.info( "Setting up default applications" );
 
-            ConfigurationManager.loadProperties( cpProps );
+        try {
+            emf.initializeApplication( DEFAULT_ORGANIZATION, emf.getDefaultAppId(), DEFAULT_APPLICATION, null );
         }
-        catch ( Exception e ) {
-            throw new RuntimeException( "Fatal error loading configuration.", e );
+        catch ( ApplicationAlreadyExistsException ex ) {
+            logger.warn( "Application {}/{} already exists", DEFAULT_ORGANIZATION, DEFAULT_APPLICATION );
+        }
+        catch ( OrganizationAlreadyExistsException oaee ) {
+            logger.warn( "Organization {} already exists", DEFAULT_ORGANIZATION );
         }
 
-        Injector injector = CpSetup.getInjector();
-        MigrationManager m = injector.getInstance( MigrationManager.class );
         try {
-            m.migrate();
-        } catch (MigrationException ex) {
-            throw new RuntimeException("Error migrating Core Persistence", ex);
+            emf.initializeApplication( DEFAULT_ORGANIZATION, emf.getManagementAppId(), MANAGEMENT_APPLICATION, null );
+        }
+        catch ( ApplicationAlreadyExistsException ex ) {
+            logger.warn( "Application {}/{} already exists", DEFAULT_ORGANIZATION, MANAGEMENT_APPLICATION );
+        }
+        catch ( OrganizationAlreadyExistsException oaee ) {
+            logger.warn( "Organization {} already exists", DEFAULT_ORGANIZATION );
         }
-
-        setupSystemKeyspace();
-
-        setupStaticKeyspace();
-
-        //force the EMF creation of indexes before creating the default applications
-        emf.refreshIndex();
-
-        createDefaultApplications();
     }
 
 
-    public void createDefaultApplications() throws Exception {
-
-        logger.info("Setting up default applications");
-
+    /**
+     * Perform migration of the 2.0 code
+     */
+    private void migrate() {
+        MigrationManager m = injector.getInstance( MigrationManager.class );
         try {
-            emf.initializeApplication( DEFAULT_ORGANIZATION,
-                    emf.getDefaultAppId(), DEFAULT_APPLICATION, null );
-        } catch (ApplicationAlreadyExistsException ex) {
-            logger.warn("Application {}/{} already exists", 
-                    DEFAULT_ORGANIZATION, DEFAULT_APPLICATION);
+            m.migrate();
         }
-
-        try {
-            emf.initializeApplication( DEFAULT_ORGANIZATION,
-                    emf.getManagementAppId(), MANAGEMENT_APPLICATION, null );
-        } catch (ApplicationAlreadyExistsException ex) {
-            logger.warn("Application {}/{} already exists", 
-                    DEFAULT_ORGANIZATION, MANAGEMENT_APPLICATION);
+        catch ( MigrationException ex ) {
+            throw new RuntimeException( "Error migrating Core Persistence", ex );
         }
     }
 
 
-
-    
     @Override
     public void setupSystemKeyspace() throws Exception {
 
         logger.info( "Initialize system keyspace" );
 
-        cass.createColumnFamily( SYSTEM_KEYSPACE, createColumnFamilyDefinition( 
-                SYSTEM_KEYSPACE, APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
+        migrate();
 
-        cass.createColumnFamily( SYSTEM_KEYSPACE, createColumnFamilyDefinition( 
-                SYSTEM_KEYSPACE, PROPERTIES_CF, ComparatorType.BYTESTYPE ) );
+        cass.createColumnFamily( SYSTEM_KEYSPACE,
+            createColumnFamilyDefinition( SYSTEM_KEYSPACE, APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
 
-        cass.createColumnFamily( SYSTEM_KEYSPACE, createColumnFamilyDefinition( 
-                SYSTEM_KEYSPACE, TOKENS_CF, ComparatorType.BYTESTYPE ) );
+        cass.createColumnFamily( SYSTEM_KEYSPACE,
+            createColumnFamilyDefinition( SYSTEM_KEYSPACE, PROPERTIES_CF, ComparatorType.BYTESTYPE ) );
 
-        cass.createColumnFamily( SYSTEM_KEYSPACE, createColumnFamilyDefinition( 
-                SYSTEM_KEYSPACE, PRINCIPAL_TOKEN_CF, ComparatorType.UUIDTYPE ) );
+        cass.createColumnFamily( SYSTEM_KEYSPACE,
+            createColumnFamilyDefinition( SYSTEM_KEYSPACE, TOKENS_CF, ComparatorType.BYTESTYPE ) );
+
+        cass.createColumnFamily( SYSTEM_KEYSPACE,
+            createColumnFamilyDefinition( SYSTEM_KEYSPACE, PRINCIPAL_TOKEN_CF, ComparatorType.UUIDTYPE ) );
 
         logger.info( "System keyspace initialized" );
     }
 
-    
+
     /**
      * Initialize application keyspace.
      *
@@ -216,8 +166,9 @@ public class CpSetup implements Setup {
      * @throws Exception the exception
      */
 
-    public void setupApplicationKeyspace( 
-            final UUID applicationId, String applicationName ) throws Exception {
+    public void setupApplicationKeyspace( final UUID applicationId, String applicationName ) throws Exception {
+
+        migrate();
 
         // Need this legacy stuff for queues
 
@@ -225,18 +176,14 @@ public class CpSetup implements Setup {
 
             String app_keyspace = keyspaceForApplication( applicationId );
 
-            logger.info( "Creating application keyspace " + app_keyspace 
-                    + " for " + applicationName + " application" );
+            logger.info( "Creating application keyspace " + app_keyspace + " for " + applicationName + " application" );
 
-            cass.createColumnFamily( app_keyspace, 
-                createColumnFamilyDefinition( 
-                    SYSTEM_KEYSPACE, APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
+            cass.createColumnFamily( app_keyspace,
+                createColumnFamilyDefinition( SYSTEM_KEYSPACE, APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
 
-            cass.createColumnFamilies( app_keyspace, 
-                getCfDefs( ApplicationCF.class, app_keyspace ) );
+            cass.createColumnFamilies( app_keyspace, getCfDefs( ApplicationCF.class, app_keyspace ) );
 
-            cass.createColumnFamilies( app_keyspace, 
-                getCfDefs( QueuesCF.class, app_keyspace ) );
+            cass.createColumnFamilies( app_keyspace, getCfDefs( QueuesCF.class, app_keyspace ) );
         }
     }
 
@@ -244,6 +191,8 @@ public class CpSetup implements Setup {
     @Override
     public void setupStaticKeyspace() throws Exception {
 
+        migrate();
+
         // Need this legacy stuff for queues
 
         if ( USE_VIRTUAL_KEYSPACES ) {
@@ -251,33 +200,20 @@ public class CpSetup implements Setup {
             logger.info( "Creating static application keyspace " + STATIC_APPLICATION_KEYSPACE );
 
             cass.createColumnFamily( STATIC_APPLICATION_KEYSPACE,
-                    createColumnFamilyDefinition( STATIC_APPLICATION_KEYSPACE, APPLICATIONS_CF,
-                            ComparatorType.BYTESTYPE ) );
+                createColumnFamilyDefinition( STATIC_APPLICATION_KEYSPACE, APPLICATIONS_CF,
+                    ComparatorType.BYTESTYPE ) );
 
             cass.createColumnFamilies( STATIC_APPLICATION_KEYSPACE,
-                    getCfDefs( ApplicationCF.class, STATIC_APPLICATION_KEYSPACE ) );
+                getCfDefs( ApplicationCF.class, STATIC_APPLICATION_KEYSPACE ) );
 
             cass.createColumnFamilies( STATIC_APPLICATION_KEYSPACE,
-                    getCfDefs( QueuesCF.class, STATIC_APPLICATION_KEYSPACE ) );
+                getCfDefs( QueuesCF.class, STATIC_APPLICATION_KEYSPACE ) );
         }
     }
 
+
     @Override
     public boolean keyspacesExist() {
         return true;
     }
-
-    static class SystemDefaults {
-
-        private static final Application managementApp = 
-                new Application( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
-
-//        private static final Application defaultApp = 
-//                new Application( CpEntityManagerFactory.DEFAULT_APPLICATION_ID );
-
-        static {
-            managementApp.setName( MANAGEMENT_APPLICATION );
-//            defaultApp.setName( DEFAULT_APPLICATION );
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1fbe3e54/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
index 89f89a3..edbb1c9 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
@@ -1,4 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
 package org.apache.usergrid.corepersistence;
 
 
-public class GuiceFactory {}
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.FactoryBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+import org.apache.commons.lang.StringUtils;
+
+import org.apache.usergrid.persistence.cassandra.CassandraService;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Singleton;
+import com.netflix.config.ConfigurationManager;
+
+import me.prettyprint.cassandra.service.CassandraHost;
+
+
+/**
+ * Factory for configuring Guice then returning it
+ */
+@Singleton
+public class GuiceFactory implements FactoryBean<Injector>, ApplicationContextAware {
+
+    private static final Logger logger = LoggerFactory.getLogger( GuiceFactory.class );
+
+
+    private final CassandraService cass;
+
+    private final Properties systemProperties;
+
+
+    private ApplicationContext applicationContext;
+
+    private Injector injector;
+
+
+
+    public GuiceFactory( final CassandraService cass, final Properties systemProperties ) {
+        this.cass = cass;
+        this.systemProperties = systemProperties;
+    }
+
+
+    @Override
+    public Injector getObject() throws Exception {
+
+        if ( this.injector != null ) {
+            return injector;
+        }
+
+
+        try {
+
+            cass.init();
+            logger.info( "Loading Core Persistence properties" );
+
+            String hostsString = "";
+            CassandraHost[] hosts = cass.getCassandraHostConfigurator().buildCassandraHosts();
+            if ( hosts.length == 0 ) {
+                throw new RuntimeException( "Fatal error: no Cassandra hosts configured" );
+            }
+            String sep = "";
+            for ( CassandraHost host : hosts ) {
+                if ( StringUtils.isEmpty( host.getHost() ) ) {
+                    throw new RuntimeException( "Fatal error: Cassandra hostname cannot be empty" );
+                }
+                hostsString = hostsString + sep + host.getHost();
+                sep = ",";
+            }
+
+            logger.info( "hostsString: " + hostsString );
+
+            Properties cpProps = new Properties();
+
+            // Some Usergrid properties must be mapped to Core Persistence properties
+            cpProps.put( "cassandra.hosts", hostsString );
+            cpProps.put( "cassandra.port", hosts[0].getPort() );
+            cpProps.put( "cassandra.cluster_name", cass.getProperties().get( "cassandra.cluster" ) );
+
+            String cassRemoteString = ( String ) cass.getProperties().get( "cassandra.use_remote" );
+            if ( cassRemoteString != null && cassRemoteString.equals( "false" ) ) {
+                cpProps.put( "cassandra.embedded", "true" );
+            }
+            else {
+                cpProps.put( "cassandra.embedded", "false" );
+            }
+
+            cpProps.put( "collections.keyspace.strategy.class",
+                cass.getProperties().get( "cassandra.keyspace.strategy" ) );
+
+            cpProps.put( "collections.keyspace.strategy.options",
+                cass.getProperties().get( "cassandra.keyspace.replication" ) );
+
+
+            logger.debug( "Set Cassandra properties for Core Persistence: " + cpProps.toString() );
+
+            // Make all Usergrid properties into Core Persistence config
+            cpProps.putAll( cass.getProperties() );
+            cpProps.putAll( systemProperties );
+            //logger.debug("All properties fed to Core Persistence: " + cpProps.toString() );
+
+
+
+            ConfigurationManager.loadProperties( cpProps );
+        }
+        catch ( Exception e ) {
+            throw new RuntimeException( "Fatal error loading configuration.", e );
+        }
+
+        //this is seriously fugly, and needs removed
+        injector = Guice.createInjector( new GuiceModule( applicationContext ) );
+
+        return injector;
+    }
+
+
+    @Override
+    public Class<?> getObjectType() {
+        return Injector.class;
+    }
+
+
+    @Override
+    public boolean isSingleton() {
+        return true;
+    }
+
+
+    @Override
+    public void setApplicationContext( final ApplicationContext applicationContext ) throws BeansException {
+        this.applicationContext = applicationContext;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1fbe3e54/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
index bbf776f..699dfec 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
@@ -16,6 +16,7 @@
 package org.apache.usergrid.corepersistence;
 
 import com.google.inject.AbstractModule;
+import com.google.inject.Provider;
 import com.google.inject.multibindings.Multibinder;
 
 import org.apache.usergrid.corepersistence.migration.EntityDataMigration;
@@ -37,32 +38,35 @@ import org.apache.usergrid.persistence.map.guice.MapModule;
 import org.apache.usergrid.persistence.queue.guice.QueueModule;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
 
 
 /**
  * Guice Module that encapsulates Core Persistence.
  */
 public class GuiceModule  extends AbstractModule {
-    private static final Logger log = LoggerFactory.getLogger( GuiceModule.class );
 
-    private static final Logger logger = LoggerFactory.getLogger(GuiceModule.class);
-
-    private EntityManagerFactory emf;
+    /**
+     * TODO this is a circular dependency, and should be refactored
+     */
+    private LazyEntityManagerFactoryProvider lazyEntityManagerFactoryProvider;
 
     public static final String EVENTS_DISABLED = "corepersistence.events.disabled";
 
-    GuiceModule( EntityManagerFactory emf ) {
-        this.emf = emf;
+
+
+    public GuiceModule( final ApplicationContext context ) {
+        this.lazyEntityManagerFactoryProvider = new LazyEntityManagerFactoryProvider( context );
     }
 
     @Override
     protected void configure() {
 
-        if ( emf != null ) {
-            bind( EntityManagerFactory.class ).toInstance( emf );
-        }
 
-        install(new CommonModule());
+        //See TODO, this is fugly
+        bind(EntityManagerFactory.class).toProvider( lazyEntityManagerFactoryProvider );
+
+        install( new CommonModule());
         install(new CollectionModule());
         install(new GraphModule());
         install(new IndexModule());
@@ -92,4 +96,25 @@ public class GuiceModule  extends AbstractModule {
 
     }
 
+
+    /**
+     * TODO, this is a hack workaround due to the guice/spring EMF circular dependency
+     * Once the entity managers have been refactored and moved into guice, remove this dependency.
+     *
+     */
+    public static class LazyEntityManagerFactoryProvider implements Provider<EntityManagerFactory>{
+
+        private final ApplicationContext context;
+
+
+        public LazyEntityManagerFactoryProvider( final ApplicationContext context ) {this.context = context;}
+
+
+
+        @Override
+        public EntityManagerFactory get() {
+            return this.context.getBean( EntityManagerFactory.class );
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1fbe3e54/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index 6e571d1..d425b7a 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -89,7 +89,7 @@ public interface EntityManager {
      *
      * @throws Exception the exception
      */
-    public Entity create( UUID importId, String entityType, Map<String, Object> properties ) 
+    public Entity create( UUID importId, String entityType, Map<String, Object> properties )
             throws Exception;
 
     public void createApplicationCollection( String entityType ) throws Exception;
@@ -103,7 +103,7 @@ public interface EntityManager {
      * @param collectionName The name of the collection
      * @param aliasValue The value of the alias
      */
-    public EntityRef getAlias( EntityRef ownerRef, String collectionName, String aliasValue ) 
+    public EntityRef getAlias( EntityRef ownerRef, String collectionName, String aliasValue )
             throws Exception;
 
     public Map<String, EntityRef> getAlias( String aliasType, List<String> aliases ) throws Exception;
@@ -115,11 +115,11 @@ public interface EntityManager {
      * @param collectionName The name of the collection
      * @param aliases The alias property
      */
-    public Map<String, EntityRef> getAlias( EntityRef ownerRef, String collectionName, 
+    public Map<String, EntityRef> getAlias( EntityRef ownerRef, String collectionName,
             List<String> aliases ) throws Exception;
 
     /**
-     * Validates that the entity exists in the datastore meaning that it exists and the type has 
+     * Validates that the entity exists in the datastore meaning that it exists and the type has
      * been loaded if not already provided.
      *
      * @return an validated EntityRef or null.
@@ -142,7 +142,7 @@ public interface EntityManager {
      *
      * @return a list of entity objects.
      */
-    public Results get( Collection<UUID> entityIds, Class<? extends Entity> entityClass, 
+    public Results get( Collection<UUID> entityIds, Class<? extends Entity> entityClass,
             Level resultsLevel ) throws Exception;
 
     /**
@@ -150,7 +150,7 @@ public interface EntityManager {
      *
      * @return a list of entity objects.
      */
-    public Results get( Collection<UUID> entityIds, String entityType, 
+    public Results get( Collection<UUID> entityIds, String entityType,
         Class<? extends Entity> entityClass, Level resultsLevel ) throws Exception;
 
     public Results getEntities(List<UUID> ids, String type);
@@ -222,13 +222,13 @@ public interface EntityManager {
      *
      * @throws Exception the exception
      */
-    public void updateProperties( EntityRef entityRef, Map<String, Object> properties ) 
+    public void updateProperties( EntityRef entityRef, Map<String, Object> properties )
             throws Exception;
 
     public void deleteProperty( EntityRef entityRef, String propertyName ) throws Exception;
 
     /**
-     * Gets the values from an entity list property. Lists are a special type of entity property 
+     * Gets the values from an entity list property. Lists are a special type of entity property
      * that can contain an unordered set of non-duplicate values.
      *
      * @param entityRef an entity reference
@@ -238,11 +238,11 @@ public interface EntityManager {
      *
      * @throws Exception the exception
      */
-    public Set<Object> getDictionaryAsSet( EntityRef entityRef, String dictionaryName ) 
+    public Set<Object> getDictionaryAsSet( EntityRef entityRef, String dictionaryName )
             throws Exception;
 
     /**
-     * Adds the specified value to the named entity list property. Lists are a special type of 
+     * Adds the specified value to the named entity list property. Lists are a special type of
      * entity property that can contain an unordered set of non-duplicate values.
      *
      * @param entityRef an entity reference
@@ -251,26 +251,26 @@ public interface EntityManager {
      *
      * @throws Exception the exception
      */
-    public void addToDictionary( EntityRef entityRef, String dictionaryName, Object elementValue ) 
+    public void addToDictionary( EntityRef entityRef, String dictionaryName, Object elementValue )
             throws Exception;
 
-    public void addToDictionary( EntityRef entityRef, String dictionaryName, Object elementName, 
+    public void addToDictionary( EntityRef entityRef, String dictionaryName, Object elementName,
             Object elementValue ) throws Exception;
 
-    public void addSetToDictionary( EntityRef entityRef, String dictionaryName, 
+    public void addSetToDictionary( EntityRef entityRef, String dictionaryName,
             Set<?> elementValues ) throws Exception;
 
-    public void addMapToDictionary( EntityRef entityRef, String dictionaryName, 
+    public void addMapToDictionary( EntityRef entityRef, String dictionaryName,
             Map<?, ?> elementValues ) throws Exception;
 
-    public Map<Object, Object> getDictionaryAsMap( EntityRef entityRef, String dictionaryName ) 
+    public Map<Object, Object> getDictionaryAsMap( EntityRef entityRef, String dictionaryName )
             throws Exception;
 
-    public Object getDictionaryElementValue( EntityRef entityRef, String dictionaryName, 
+    public Object getDictionaryElementValue( EntityRef entityRef, String dictionaryName,
             String elementName ) throws Exception;
 
     /**
-     * Removes the specified value to the named entity list property. Lists are a special type of 
+     * Removes the specified value to the named entity list property. Lists are a special type of
      * entity property that can contain an unordered set of non-duplicate values.
      *
      * @param entityRef an entity reference
@@ -298,7 +298,7 @@ public interface EntityManager {
      *
      * @param entityRef an entity reference
      *
-     * @return a map of entity references to set of collection names for the entities and 
+     * @return a map of entity references to set of collection names for the entities and
      * collections that this entity is a member of.
      *
      * @throws Exception the exception
@@ -312,7 +312,7 @@ public interface EntityManager {
      * @param collectionName The collection name
      * @param entity The entity in the collection
      */
-    public boolean isCollectionMember( EntityRef owner, String collectionName, EntityRef entity ) 
+    public boolean isCollectionMember( EntityRef owner, String collectionName, EntityRef entity )
             throws Exception;
 
     /**
@@ -322,12 +322,12 @@ public interface EntityManager {
      * @param connectionName The collection name
      * @param entity The entity in the collection
      */
-    public boolean isConnectionMember( EntityRef owner, String connectionName, EntityRef entity ) 
+    public boolean isConnectionMember( EntityRef owner, String connectionName, EntityRef entity )
             throws Exception;
 
 
     /**
-     * Gets the collections for the specified entity. Collection for a given type are encoded 
+     * Gets the collections for the specified entity. Collection for a given type are encoded
      * in the schema, this method loads the entity type and returns the collections from the schema.
      *
      * @param entityRef an entity reference
@@ -391,20 +391,20 @@ public interface EntityManager {
      *
      * @throws Exception the exception
      */
-    public void removeFromCollection( EntityRef entityRef, String collectionName, EntityRef itemRef) 
+    public void removeFromCollection( EntityRef entityRef, String collectionName, EntityRef itemRef)
             throws Exception;
 
-    public Results searchCollection( EntityRef entityRef, String collectionName, Query query ) 
+    public Results searchCollection( EntityRef entityRef, String collectionName, Query query )
             throws Exception;
 
-    public Set<String> getCollectionIndexes( EntityRef entity, String collectionName ) 
+    public Set<String> getCollectionIndexes( EntityRef entity, String collectionName )
             throws Exception;
 
-    public void copyRelationships( EntityRef srcEntityRef, String srcRelationName, 
+    public void copyRelationships( EntityRef srcEntityRef, String srcRelationName,
             EntityRef dstEntityRef, String dstRelationName ) throws Exception;
 
     /**
-     * Connect the specified entity to another entity with the specified connection type. 
+     * Connect the specified entity to another entity with the specified connection type.
      * Connections are directional relationships that can be traversed in either direction.
      *
      * @throws Exception the exception
@@ -415,24 +415,24 @@ public interface EntityManager {
                                            EntityRef connectedEntityRef ) throws Exception;
 
     public ConnectionRef createConnection( EntityRef connectingEntity, String pairedConnectionType,
-                                           EntityRef pairedEntity, String connectionType, 
+                                           EntityRef pairedEntity, String connectionType,
                                            EntityRef connectedEntityRef ) throws Exception;
 
-    public ConnectionRef createConnection( 
+    public ConnectionRef createConnection(
             EntityRef connectingEntity, ConnectedEntityRef... connections )
             throws Exception;
 
     public ConnectionRef connectionRef( EntityRef connectingEntity, String connectionType,
                                         EntityRef connectedEntityRef ) throws Exception;
 
-    public ConnectionRef connectionRef( EntityRef connectingEntity, String pairedConnectionType, 
-            EntityRef pairedEntity, String connectionType, EntityRef connectedEntityRef ) 
+    public ConnectionRef connectionRef( EntityRef connectingEntity, String pairedConnectionType,
+            EntityRef pairedEntity, String connectionType, EntityRef connectedEntityRef )
             throws Exception;
 
     public ConnectionRef connectionRef( EntityRef connectingEntity, ConnectedEntityRef... connections );
 
     /**
-     * Disconnects two connected entities with the specified connection type. Connections are 
+     * Disconnects two connected entities with the specified connection type. Connections are
      * directional relationships that can be traversed in either direction.
      *
      * @throws Exception the exception
@@ -444,7 +444,7 @@ public interface EntityManager {
 
 
     /**
-     * Gets the entities of the specified type connected to the specified entity, optionally 
+     * Gets the entities of the specified type connected to the specified entity, optionally
      * matching the specified connection types and/or entity types. Returns a list of entity ids.
      *
      * @param entityId an entity reference
@@ -455,11 +455,11 @@ public interface EntityManager {
      *
      * @throws Exception the exception
      */
-    public Results getConnectedEntities( EntityRef entityRef, String connectionType, 
+    public Results getConnectedEntities( EntityRef entityRef, String connectionType,
             String connectedEntityType, Level resultsLevel ) throws Exception;
 
     /**
-     * Gets the entities connecting to this entity, optionally with the specified connection 
+     * Gets the entities connecting to this entity, optionally with the specified connection
      * type and/or entity type.
      * <p/>
      * e.g. "get users who have favorited this place"
@@ -472,7 +472,7 @@ public interface EntityManager {
      *
      * @throws Exception the exception
      */
-    public Results getConnectingEntities( EntityRef entityRef, String connectionType, 
+    public Results getConnectingEntities( EntityRef entityRef, String connectionType,
             String connectedEntityType, Level resultsLevel ) throws Exception;
 
     public Results getConnectingEntities( EntityRef entityRef, String connectionType,
@@ -551,13 +551,13 @@ public interface EntityManager {
 
     public Results getUsersInGroupRole( UUID groupId, String roleName, Level level ) throws Exception;
 
-    public void incrementAggregateCounters( UUID userId, UUID groupId, String category, 
+    public void incrementAggregateCounters( UUID userId, UUID groupId, String category,
             String counterName, long value );
 
-    public Results getAggregateCounters( UUID userId, UUID groupId, String category, 
+    public Results getAggregateCounters( UUID userId, UUID groupId, String category,
             String counterName, CounterResolution resolution, long start, long finish, boolean pad );
 
-    public Results getAggregateCounters( UUID userId, UUID groupId, UUID queueId, String category, 
+    public Results getAggregateCounters( UUID userId, UUID groupId, UUID queueId, String category,
             String counterName, CounterResolution resolution, long start, long finish, boolean pad );
 
     public Results getAggregateCounters( Query query ) throws Exception;
@@ -572,10 +572,10 @@ public interface EntityManager {
 
     public Map<String, Long> getApplicationCounters() throws Exception;
 
-    public void incrementAggregateCounters( 
+    public void incrementAggregateCounters(
             UUID userId, UUID groupId, String category, Map<String, Long> counters );
 
-    public boolean isPropertyValueUniqueForEntity( 
+    public boolean isPropertyValueUniqueForEntity(
             String entityType, String propertyName, Object propertyValue ) throws Exception;
 
     @Deprecated
@@ -610,8 +610,8 @@ public interface EntityManager {
     public void revokeGroupPermission( UUID groupId, String permission ) throws Exception;
 
 
-    <A extends Entity> A batchCreate(Mutator<ByteBuffer> m, String entityType, 
-            Class<A> entityClass, Map<String, Object> properties, 
+    <A extends Entity> A batchCreate(Mutator<ByteBuffer> m, String entityType,
+            Class<A> entityClass, Map<String, Object> properties,
             UUID importId, UUID timestampUuid) throws Exception;
     /**
      * Batch dictionary property.
@@ -626,15 +626,15 @@ public interface EntityManager {
      *
      * @throws Exception the exception
      */
-    Mutator<ByteBuffer> batchSetProperty(Mutator<ByteBuffer> batch, EntityRef entity, 
+    Mutator<ByteBuffer> batchSetProperty(Mutator<ByteBuffer> batch, EntityRef entity,
             String propertyName, Object propertyValue, UUID timestampUuid) throws Exception;
 
-    Mutator<ByteBuffer> batchSetProperty(Mutator<ByteBuffer> batch, EntityRef entity, 
-            String propertyName, Object propertyValue, boolean force, boolean noRead, 
+    Mutator<ByteBuffer> batchSetProperty(Mutator<ByteBuffer> batch, EntityRef entity,
+            String propertyName, Object propertyValue, boolean force, boolean noRead,
             UUID timestampUuid) throws Exception;
 
-    Mutator<ByteBuffer> batchUpdateDictionary(Mutator<ByteBuffer> batch, EntityRef entity, 
-            String dictionaryName, Object elementValue, Object elementCoValue, 
+    Mutator<ByteBuffer> batchUpdateDictionary(Mutator<ByteBuffer> batch, EntityRef entity,
+            String dictionaryName, Object elementValue, Object elementCoValue,
             boolean removeFromDictionary, UUID timestampUuid) throws Exception;
 
     /**
@@ -651,8 +651,8 @@ public interface EntityManager {
      *
      * @throws Exception the exception
      */
-    Mutator<ByteBuffer> batchUpdateDictionary(Mutator<ByteBuffer> batch, EntityRef entity, 
-            String dictionaryName, Object elementValue, 
+    Mutator<ByteBuffer> batchUpdateDictionary(Mutator<ByteBuffer> batch, EntityRef entity,
+            String dictionaryName, Object elementValue,
             boolean removeFromDictionary, UUID timestampUuid) throws Exception;
 
     /**
@@ -667,7 +667,7 @@ public interface EntityManager {
      *
      * @throws Exception the exception
      */
-    Mutator<ByteBuffer> batchUpdateProperties(Mutator<ByteBuffer> batch, 
+    Mutator<ByteBuffer> batchUpdateProperties(Mutator<ByteBuffer> batch,
             EntityRef entity, Map<String, Object> properties, UUID timestampUuid) throws Exception;
 
     Set<String> getDictionaryNames(EntityRef entity) throws Exception;
@@ -683,7 +683,7 @@ public interface EntityManager {
     /** @return the cass */
     CassandraService getCass();
 
-    /** 
+    /**
      * Refresh the applications index -- use sparingly.
      */
     void refreshIndex();
@@ -693,6 +693,11 @@ public interface EntityManager {
      */
     void createIndex();
 
+    /**
+    * Create the index, should ONLY ever be called the first time an application is created
+    */
+    void deleteIndex();
+
     public void init( EntityManagerFactory emf, UUID applicationId);
 
     /** For testing purposes */


Mime
View raw message