@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."); } }
@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."); }