Example #1
0
 @Override
 public <T> void delete(T instance) {
   AbstractInstanceManager<EntityId, Entity> entityInstanceManager =
       sessionContext.getEntityInstanceManager();
   AbstractInstanceManager<RelationId, Relation> relationInstanceManager =
       sessionContext.getRelationInstanceManager();
   DatastoreSession<
           EntityId,
           Entity,
           EntityMetadata,
           EntityDiscriminator,
           RelationId,
           Relation,
           RelationMetadata,
           RelationDiscriminator,
           PropertyMetadata>
       datastoreSession = sessionContext.getDatastoreSession();
   if (entityInstanceManager.isInstance(instance)) {
     Entity entity = entityInstanceManager.getDatastoreType(instance);
     sessionContext.getInstanceListenerService().preDelete(instance);
     datastoreSession.getDatastoreEntityManager().deleteEntity(entity);
     entityInstanceManager.removeInstance(instance);
     entityInstanceManager.closeInstance(instance);
     sessionContext.getInstanceListenerService().postDelete(instance);
   } else if (relationInstanceManager.isInstance(instance)) {
     Relation relation = relationInstanceManager.getDatastoreType(instance);
     sessionContext.getInstanceListenerService().preDelete(instance);
     datastoreSession.getDatastoreRelationManager().deleteRelation(relation);
     relationInstanceManager.removeInstance(instance);
     relationInstanceManager.closeInstance(instance);
     sessionContext.getInstanceListenerService().postDelete(instance);
   } else {
     throw new XOException(instance + " is not a managed XO instance.");
   }
 }
Example #2
0
 /**
  * Create a new {@link CompositeObject} instance using an example.
  *
  * @param type The interface the property type shall implement.
  * @param types Additional interfaces the entity type shall implement.
  * @param exampleEntity The example instance.
  * @return The {@link CompositeObject} instance.
  */
 private CompositeObject createByExample(
     Class<?> type,
     Class<?>[] types,
     Map<PrimitivePropertyMethodMetadata<PropertyMetadata>, Object> exampleEntity) {
   TypeMetadataSet<EntityTypeMetadata<EntityMetadata>> effectiveTypes =
       getEffectiveTypes(type, types);
   Set<EntityDiscriminator> entityDiscriminators =
       sessionContext.getMetadataProvider().getEntityDiscriminators(effectiveTypes);
   DatastoreSession<
           EntityId,
           Entity,
           EntityMetadata,
           EntityDiscriminator,
           RelationId,
           Relation,
           RelationMetadata,
           RelationDiscriminator,
           PropertyMetadata>
       datastoreSession = sessionContext.getDatastoreSession();
   Entity entity =
       datastoreSession
           .getDatastoreEntityManager()
           .createEntity(effectiveTypes, entityDiscriminators, exampleEntity);
   AbstractInstanceManager<EntityId, Entity> entityInstanceManager =
       sessionContext.getEntityInstanceManager();
   CompositeObject instance = entityInstanceManager.createInstance(entity);
   sessionContext.getInstanceListenerService().postCreate(instance);
   return instance;
 }
Example #3
0
 @Override
 public <T, M> CompositeObject migrate(
     T instance,
     MigrationStrategy<T, M> migrationStrategy,
     Class<M> targetType,
     Class<?>... targetTypes) {
   AbstractInstanceManager<EntityId, Entity> entityInstanceManager =
       sessionContext.getEntityInstanceManager();
   Entity entity = entityInstanceManager.getDatastoreType(instance);
   DatastoreSession<
           EntityId,
           Entity,
           EntityMetadata,
           EntityDiscriminator,
           RelationId,
           Relation,
           RelationMetadata,
           RelationDiscriminator,
           PropertyMetadata>
       datastoreSession = sessionContext.getDatastoreSession();
   Set<EntityDiscriminator> entityDiscriminators =
       datastoreSession.getDatastoreEntityManager().getEntityDiscriminators(entity);
   MetadataProvider<EntityMetadata, EntityDiscriminator, RelationMetadata, RelationDiscriminator>
       metadataProvider = sessionContext.getMetadataProvider();
   TypeMetadataSet<EntityTypeMetadata<EntityMetadata>> types =
       metadataProvider.getTypes(entityDiscriminators);
   TypeMetadataSet<EntityTypeMetadata<EntityMetadata>> effectiveTargetTypes =
       getEffectiveTypes(targetType, targetTypes);
   Set<EntityDiscriminator> targetEntityDiscriminators =
       metadataProvider.getEntityDiscriminators(effectiveTargetTypes);
   datastoreSession
       .getDatastoreEntityManager()
       .migrateEntity(
           entity, types, entityDiscriminators, effectiveTargetTypes, targetEntityDiscriminators);
   entityInstanceManager.removeInstance(instance);
   CompositeObject migratedInstance = entityInstanceManager.updateInstance(entity);
   if (migrationStrategy != null) {
     migrationStrategy.migrate(instance, migratedInstance.as(targetType));
   }
   entityInstanceManager.closeInstance(instance);
   return migratedInstance;
 }
Example #4
0
 @Override
 public <T, Id> Id getId(T instance) {
   AbstractInstanceManager<EntityId, Entity> entityInstanceManager =
       sessionContext.getEntityInstanceManager();
   AbstractInstanceManager<RelationId, Relation> relationInstanceManager =
       sessionContext.getRelationInstanceManager();
   if (entityInstanceManager.isInstance(instance)) {
     Entity entity = entityInstanceManager.getDatastoreType(instance);
     return (Id)
         sessionContext.getDatastoreSession().getDatastoreEntityManager().getEntityId(entity);
   } else if (relationInstanceManager.isInstance(instance)) {
     Relation relation = relationInstanceManager.getDatastoreType(instance);
     return (Id)
         sessionContext
             .getDatastoreSession()
             .getDatastoreRelationManager()
             .getRelationId(relation);
   }
   throw new XOException(instance + " is not a managed XO instance.");
 }