Aggiungere un listener alle istanze MessageInstance
package it.sistematica.isharedoc.persistence; import it.neverworks.data.EntityManager; import it.sistematica.isharedoc.model.instance.MessageInstance; import javax.annotation.Resource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; @Repository public class NumeraSchedeInstanceListener implements CustomInterceptor.Methods<MessageInstance> { private final static Logger logger = LoggerFactory.getLogger(NumeraSchedeInstanceListener.class); @Autowired public NumeraSchedeInstanceListener(CustomInterceptor ci) { ci.addInterceptor(MessageInstance.class, this); } @Resource EntityManager entities; @Override public void onAfterSave(MessageInstance instance) { } @Override public void onSave(MessageInstance entity) { } @Override public void onDelete(MessageInstance entity) { } }
Aggiungere un listener alle istanze ActivityInstance
Il procedimento è identico alla MessageInstance, basta sostituire MessageInstance con ActivityInstance.
Estendere l’istanza ActivityInstance
E’ possibile estendere la ActivityInstance o la MessageInstance per aggiungere attributi e metodi specifici all’oggetto hibernate.
In questo caso si dovrà creare un nuovo oggetto hibernate CabActivityInstance.java che estende ActivityInstance:
package it.sistematica.isharedoc.model.acea.instance; import it.neverworks.persistence.Listener; import it.neverworks.persistence.Listeners; import it.sistematica.isharedoc.model.instance.ActivityInstance; import it.sistematica.isharedoc.model.instance.ItemInstance; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Inheritance; import javax.persistence.InheritanceType; import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.Table; import javax.persistence.Transient; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; @Entity @Table( name = "CAB_INSTANCEACTIVITY" ) @PrimaryKeyJoinColumn( name = "IS_W_INSTANCE_ID" ) @Inheritance( strategy = InheritanceType.JOINED ) @Listener @Listeners({ "itemInstanceListener", "activityInstanceListener"}) @Cache( usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region="it.isharedoc.InstanceManagement" ) public class CabActivityInstance extends ActivityInstance implements Serializable { @Transient private static final long serialVersionUID = 0L; public CabActivityInstance() { this.type = "CabActivityInstance"; } @Override public Class<? extends ItemInstance> getInstanceClass() { return CabActivityInstance.class; } }
Al nuovo oggetto CabActivityInstance è possibile aggiungere dei listener come indicato nel paragrafo “Aggiungere un listener alle istanze MessageInstance”.