preload
Sep 16

Open-Jacob (currently) does not support cascading deletes. Depending on the database used you could implement this at the database level but this would be no good idea since Open-Jacob itself keeps track of the data and could stumble when records are getting modified from another side.

Let’s assume the following database schema

relations

We want to be able to delete records from the tables hauptprf and/or teilprf. Therefore we need to  add some code to the classes HauptprfTableRecord and TeilprfTableRecord both attached to the respective tablealias.

HauptprfTableRecord

public void afterDeleteAction(IDataTableRecord tableRecord, IDataTransaction transaction) throws Exception
{
IDataTable hprdet = tableRecord.getAccessor().getTable(Hauptprfdet.NAME);
hprdet.qbeSetKeyValue(Hauptprfdet.hauptprf_key, tableRecord.getValue(“pkey”));
hprdet.fastDelete(transaction);

IDataTable hprdok = tableRecord.getAccessor().getTable(Hauptprfdok.NAME);
hprdok.qbeSetKeyValue(Hauptprfdok.hauptprf_key, tableRecord.getValue(“pkey”));
hprdok.fastDelete(transaction);

IDataTable hprgeb = tableRecord.getAccessor().getTable(Hauptprfgeb.NAME);
hprgeb.qbeSetKeyValue(Hauptprfgeb.hauptprf_key, tableRecord.getValue(“pkey”));
hprgeb.fastDelete(transaction);

IDataTable teilprf = tableRecord.getAccessor().getTable(Teilprf.NAME);
teilprf.qbeSetKeyValue(Teilprf.hauptprf_key, tableRecord.getValue(“pkey”));
teilprf.searchAndDelete(transaction);
}

TeilprfTableRecord

public void afterDeleteAction(IDataTableRecord tableRecord, IDataTransaction transaction) throws Exception
{
IDataTable teildet = tableRecord.getAccessor().getTable(Teilprfdet.NAME);
teildet.qbeSetKeyValue(Teilprfdet.teilprf_key, tableRecord.getValue(“pkey”));
teildet.fastDelete(transaction);

IDataTable teildok = tableRecord.getAccessor().getTable(Teilprfdok.NAME);
teildok.qbeSetKeyValue(Teilprfdok.teilprf_key, tableRecord.getValue(“pkey”));
teildok.fastDelete(transaction);

IDataTable colldat = tableRecord.getAccessor().getTable(Collecteddata.NAME);
colldat .qbeSetKeyValue(Collecteddata.teilprf_key, tableRecord.getValue(“pkey”));
colldat .fastDelete(transaction);
}

The only important thing is that fastDelete offers great performance but DOES NOT trigger any other hooks. Therefore deleting the teilprf data from the hauptprf  function contains the searchAndDelete function ! All the other delete operations can be done using fastDelete since the respective tables are the last in the hierarchy.

pixelstats trackingpixel

Leave a Reply

You must be logged in to post a comment.