How to implement referential integrity and cascading actions in liferay service xml file? -
i have requirement need implement ondelete cascade functionality liferay service builder. how can achieve in liferay?
first of all:
ondelete cascade not liferay service builder functionality. funtionality provided database.
next: liferay has premise, data processing , evaluation should done in code, , not in database.
having said that:
something similar ondelete cascade implement model listener. modellistener listening changes of model. (i know, misleading name ;) ) in model listener, implement onafterremove. in onafterremove goes code deletion of related records.
here small sample have written. code listening changes of group object, , tries delete referenced objectgeodata object, if there 1 present.
package de.osc.geodata.modellistener; import com.liferay.portal.modellistenerexception; import com.liferay.portal.kernel.exception.portalexception; import com.liferay.portal.kernel.exception.systemexception; import com.liferay.portal.kernel.log.log; import com.liferay.portal.kernel.log.logfactoryutil; import com.liferay.portal.kernel.search.indexerregistryutil; import com.liferay.portal.kernel.search.searchexception; import com.liferay.portal.model.basemodellistener; import com.liferay.portal.model.group; import com.liferay.portal.service.servicecontext; import de.osc.geodata.model.objectgeodata; import de.osc.geodata.service.objectgeodatalocalserviceutil; public class groupmodellistener extends basemodellistener<group> { private static final log log = logfactoryutil.getlog(groupmodellistener.class); @override public void onafterremove(group model) throws modellistenerexception { try { objectgeodata objectgeodata = objectgeodatalocalserviceutil.getobjectgeodata(model.getclassnameid(), model.getclasspk()); if (objectgeodata != null) { objectgeodatalocalserviceutil.deleteobjectgeodata(objectgeodata); } } catch (systemexception e) { log.warn("no geodataobject found in index.", e); } super.onafterremove(model); } }
Comments
Post a Comment