Delete Concepts - learn-tibco-cep/tutorials GitHub Wiki

BE applications can delete persistent data by using a few different approaches. We describe common implementation of delete operations in this article.

Configured Expiration

Concepts can be configured in the CDD file to expire, and thus automatically deleted after a specified Time-To-Live (Concept TTL).

Events can also be configured to expire in the definition of individual events.

Retrieve and Then Delete A Concept

The most common way to delete a single concept is shown in function onDeleteConcept, which uses the following steps.

  • Acquire a lock by calling Cluster.DataGrid.Lock();
  • Retrieve a concept from cache or persistent store by calling Cluster.DataGrid.CacheLoadConceptByExtIdByUri();
  • Delete the loaded concept by calling Instance.deleteInstance().

Delete Concept by Primary Key

You may also use Store catalog functions to delete concepts from a persistent store by primary-key, which would be more efficient since it does not fetch all fields of a concept to the client process.

For example, the following code will delete a BookAuthorXref concept of a specified primary-key, which is a composite of 3 fields.

Concepts.BookAuthorXref con = Concepts.BookAuthorXref.BookAuthorXref(null, "/authors/OL6831580A", "/books/OL45532136M", 1);
Store.open("http://localhost:8181", "d_bookauthorxref");
Store.delete("http://localhost:8181", "d_bookauthorxref", con);
Instance.deleteInstance(con);

Note that you have to call deleteInstance() immediately so the concept containing only primary-key fields will not trigger rule evaluation cycle.

A better option to avoid unintended rule cycle is to use transient concept instance as follows.

Concepts.BookAuthorXref con = Instance.newTransientInstance("/Concepts/BookAuthorXref");
con.author_id = "/authors/OL6831580A";
con.book_id = "/books/OL45532136M";
con.book_version = 1;
Store.open("http://localhost:8181", "d_bookauthorxref");
Store.delete("http://localhost:8181", "d_bookauthorxref", con);

You may also call Store.deleteAll() to delete multiple concepts of given set of primary-keys.

However, this approach works only for concepts that explicitly specify one or more primary-key fields in the CDD file. The following code for deleting an Author does not work in the current release of BE 6.2.2, because the concept Author uses extId as its implicit primary-key.

Concept con = Instance.newInstance("/Concepts/Author", "/authors/OL884910A/10");
Store.open("http://localhost:8181", "d_bookauthorxref");
Store.delete("http://localhost:8181", "d_bookauthorxref", con);
Instance.deleteInstance(con);

Delete Query

You may delete bulk of concepts from Apache Ignite cache by using a native query. As shown in the function deleteRevisions, the following code deletes all Books of revision < 0 from Ignite cache.

String sql = "native-query: delete from be_gen_concepts_book where revision < 0";
Object list = Query.Util.executeInQuerySession("query-class", sql, null, false, -1);

Note, however, when the CDD specifies object default to use Limited Cache, cache queries will apply to only objects that are already loaded in the cache, which may not include all data in the persistent backing store.

To delete bulk of concepts from a persistent store based on a query filter, you may want to use CEP Store catalog functions as follows.

String sql = "delete from d_book where revision < 0";
long count = Store.executeUpdate("http://localhost:8181", sql);

Unfortunately, this does not work for ActiveSpaces stores in the current version of BE 6.2.2. In this tutorial, the function deleteRevisions uses an ActiveSpaces Java API to perform such delete operations, as implemented by a CustomFunction.

For RDBMS stores, you may simply use direct JDBC calls to perform bulk deletes, i.e., by using RDBMS catalog function Database.executeSQL().