0

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?
quarks
  • 33,478
  • 73
  • 290
  • 513

1 Answers1

1

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.

lehvolk
  • 233
  • 1
  • 4
  • Is there a batch delete method for links and entities? – quarks Sep 18 '18 at 06:50
  • No, it isn't. There is a refactoring which cleanup all broken links in entity store. Check out this config key jetbrains.exodus.entitystore.PersistentEntityStoreConfig#REFACTORING_HEAVY_LINKS. According to documentation it's not intended for public using but in case of troubleshooting or debugging it can be used. Keep in mind that there is a high level ORM-like framework for xodus - https://github.com/JetBrains/xodus-dnq there you could declare high level business model with cascade deletion operations for entities. – lehvolk Sep 18 '18 at 08:54
  • I wonder what will happen if this deleteEntityType method is called when there are existing entities, is this transactional? – quarks Sep 18 '18 at 22:17