如何在Intershop7中注册ORMObjectListener [英] How to register ORMObjectListener in Intershop7

查看:107
本文介绍了如何在Intershop7中注册ORMObjectListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Webshop实施中实现了几个自定义ORM对象,这些对象具有对Intershop Product系统对象的引用(依赖性).

We have implemented several custom ORM objects in our webshop implementation that have references (dependencies) to Intershop Product system object.

当用户尝试在后台删除某个产品时,这会引起问题,因为在我们的自定义对象中可能仍然存在对该产品的引用.自然地,删除从我们的自定义对象之一引用的产品会生成如下异常:

When a user tries to delete a certain product in back-office, it causes problems because references to that product may still exist in our custom objects. Naturally, deleting a product that is referenced from one of our custom objects generates an exception like this:

java.sql.SQLTransactionRollbackException: ORA-02091: transaction rolled back ORA-02292: integrity constraint (INTERSHOP.A1POSTPAIDPRICE_CO_002) violated - child record found  

我们已经发现,可以通过实现ORMObjectListener并重写objectDeleting方法来删除所有引用,然后再实际删除产品来解决此问题.

We have figured that we could solve that by implementing an ORMObjectListener and overriding objectDeleting method to delete all the references before the product actually gets deleted.

关于ORM层状态的Intershop食谱:

Intershop cookbook for ORM layer states:

实例必须为给定的ORM对象类型实现接口ORMObjectListener并在工厂注册.在创建,更改或删除给定类型的实例时,将调用侦听器."

"Instances must implement the interface ORMObjectListener for a given ORM object type and register at the factory. The listener is called when instances of the given type are created, changed or removed."

( https://support. intershop.com/kb/index.php/Display/2G3270#Cookbook-ORMLayer-Recipe:NotificationofPersistentObjectChanges )

但是,我们在工厂找不到用于注册收听者的食谱.我们需要做些什么来注册侦听器?

However, we cannot find a cookbook for registering the listener at the factory. What do we need to do to register the listener?

此外,如果在删除事件期间有一些更好的方法来处理对自定义对象的系统对象的依赖性,我欢迎您提出建议.

Also, if there is some better way for handling dependencies to system objects on our custom objects during delete event, I'm open to suggestions.

更新:

这是我到目前为止尝试过的侦听器类:

This is the listener class I have tried with so far:

public class ProductDeleteListener implements ORMObjectListener<ProductPO> {

  @Inject
  ProductPOFactory productPOFactory;

  /** The Constant LOGGER. */
  private static final Logger LOGGER = LoggerFactory.getLogger(ProductDeleteListener.class);

  public ProductDeleteListener() {
    productPOFactory.addObjectListener(this, new AttributeDescription[0]);
  }

  @Override
  public boolean isOldStateNeeded() {
    // TODO Auto-generated method stub
    return false;
  }

  @Override
  public void objectChanged(ProductPO object, Map<AttributeDescription, Object> previousValues) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("PRODUCT LISTENER TEST - CHANGE");
    }

  }

  @Override
  public void objectChanging(ProductPO object, Map<AttributeDescription, Object> previousValues) {
    // TODO Auto-generated method stub

  }

  @Override
  public void objectCreated(ProductPO object) {
    // TODO Auto-generated method stub

  }

  @Override
  public void objectCreating(ProductPO object) {
    // TODO Auto-generated method stub

  }

  @Override
  public void objectDeleted(ORMObjectKey objectKey) {
    // TODO Auto-generated method stub

  }

  @Override
  public void objectDeleting(ProductPO object) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("PRODUCT LISTENER TEST - PRE DELETE");
    }

  }

}

但是它不起作用.当对象更改或删除时,什么都不会记录.

But it is not working. Nothing gets logged when object changes or gets deleted.

推荐答案

除了Willem Evertse编写的内容外,您还需要将注册代码放在通过Intershop Component Framework实例化的类中.

In addition to what Willem Evertse wrote you need to place your registration code in a class that gets instantiated via Intershop Component Framework.

implementation.component:

<components xmlns="http://www.intershop.de/component/2010" scope="global">
<implementation name="ProductDeleteListenerRegistrar"
    class="your.fullqualifed.ProductDeleteRegistrar" start="start" stop="stop"></implementation>

instances.component:

<components xmlns="http://www.intershop.de/component/2010"> <instance name="ORMValidator" with="ORMValidator" scope="global"/></components>

您需要编写一个类,例如ProductDeleteRegistrar并提供启动方法,您可以在其中添加注册调用,例如Willem所述.至于停止方法,您需要安全地注销您的对象侦听器.确保两个方法都声明为同步.

You need to write a class, e.g. ProductDeleteRegistrar and provide start method in which you can add registration calls like Willem described. As for stop method you need to safely unregister your object listener. Make sure both methods are declared to be synchronized.

这篇关于如何在Intershop7中注册ORMObjectListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆