Jump to content

How to implement cascading deletion in my trigger in java


Junior SIEMBE TIEGOUM

Recommended Posts

Hi,

Iam trying to delete records related to the one that the user is trying to delete because the primary key this table is a foreign key in other tables and I want that when this record is deleted, the others or the key of it migrated are deleted. For this I placed a trigger but I cannot inject an object from the UserServiceEventContext interface knowing that my trigger method has as a parameter an object of type: BeforeDeleteOccurrenceContext. I tried with the three types of injection but it does not work

Table Value

@EBXTablePath("Valeur")

public class ValeurEntity extends BaseEntity {

 

@EBXPath("codeRepertoire")

private String codeRepertoire;

 

@EBXTableId

@EBXPath("valeur")

private String codeValeur;

 

@EBXPath("descriptionCourte")

private String descriptionCourte;

}

 

Table ValueDescription

@EBXTablePath("DescriptionValeur")

public class DescriptionValeurEntity extends BaseEntity {

 

@EBXPath("codeRepertoire")

private String codeRepertoire;

 

@EBXPath("id")

private Integer id;

 

@EBXTableId

@EBXPath("idValeur")

private String idValeur;

 

@EBXTableId

@EBXPath("valeur")

private String codeValeur;

 

@EBXTableId

@EBXPath("codeLangue")

private String langue;

 

@EBXPath("descriptionCourt")

private String descriptionCourte;

}

And the DAO for entites

public abstract class BaseDAO extends BaseUtil {

private final Adaptation dataset;

private final Path tablePath;

private final UserServiceEventContext anEventContext;

 

protected BaseDAO(Adaptation dataset, UserServiceEventContext anEventContext) {

this.dataset = dataset;

this.anEventContext = anEventContext;

this.tablePath = this.setupTablePath();

}

.....

public void delete(List items, boolean triggerActivation) {

Procedure deleteProcedure = (procedureContext) -> {

procedureContext.setAllPrivileges(true);

procedureContext.setTriggerActivation(triggerActivation);

procedureContext.setBlockingConstraintsDisabled(!triggerActivation);

 

try {

Iterator var3 = items.iterator();

 

while(var3.hasNext()) {

T item = (BaseEntity)var3.next();

procedureContext.doDelete(item.getAdaptationName(), false);

}

} catch (Exception var5) {

var5.printStackTrace();

}

 

};

UserServiceTransaction transaction = this.anEventContext.createTransaction();

transaction.add(deleteProcedure);

transaction.execute();

}

.......

}

I was thinking that i can use this delete method on the DAO to find all DescriptionValues related to the Value that we need to delete and delete them. But i cannot because in don't know how to inject a UserServiceEventContext in my trigger

 

I try your solution but it doesn't work:

public class ValueTrigger extends TableTrigger {

....

@Override

public void handleBeforeDelete(BeforeDeleteOccurrenceContext aContext)

throws OperationException {

GDRMBeforeDeleteValidation.validate(aContext);

Session session = aContext.getSession();

Adaptation record = aContext.getAdaptationOccurrence();

if(session.getAttribute("ROOT_OF_CASCADE_DELETE") == null){

session.setAttribute("ROOT_OF_CASCADE_DELETE", record.getOccurrencePrimaryKey());

}

 

}

......

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...