Search code examples
javaxodus

How to delete Entity Type with Xodus?


Here's my code to delete all entities for a given type:

@Override public boolean deleteEntities(String instance, final String storeName) { final boolean[] success = {false}; final PersistentEntityStore entityStore = manager.getPersistentEntityStore(xodusRoot, instance); try { entityStore.executeInTransaction(new StoreTransactionalExecutable() { @Override public void execute(@NotNull final StoreTransaction txn) { EntityIterable result = txn.getAll(storeName); final boolean[] hasError = {false}; for(Entity entity : result) { if(!entity.delete()) { hasError[0] = true; } } success[0] = !hasError[0]; } }); } finally { ////entityStore.close(); } return success[0]; }

Question:

  • Is this the right approach to delete all existing entities for a given entity type?
  • When this method is executed, all entities are indeed removed but the Enity type is sitll there, how to properly delete a enity type?

Solution

  • There is PersistentEntityStore#renameEntityType to rename entity type as part of a public api. To delete entity type at all you can use PersistentEntityStoreImpl#deleteEntityType. It's not a part of PersistentEntityStore api but method is public and you can use it.

    Also when you deleting entity type do not forget that you also need to clear all links points to entities of this type.