mirror of https://github.com/apache/openjpa.git
OPENJPA-506. Fixed behaviors for global listeners to get TCK working on trunk again. It turns out that global listeners and per-instance listeners are bound into the OpenJPA event framework differently.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@618821 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
024faa31d7
commit
3f439edc57
|
@ -488,6 +488,42 @@ public class LifecycleEventManager
|
||||||
((AttachListener) listener).afterAttach(ev);
|
((AttachListener) listener).afterAttach(ev);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case LifecycleEvent.AFTER_PERSIST_PERFORMED:
|
||||||
|
if (responds || listener instanceof PostPersistListener)
|
||||||
|
{
|
||||||
|
if (mock)
|
||||||
|
return Boolean.TRUE;
|
||||||
|
if (ev == null)
|
||||||
|
ev = new LifecycleEvent(source, rel, type);
|
||||||
|
((PostPersistListener) listener)
|
||||||
|
.afterPersistPerformed(ev);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LifecycleEvent.BEFORE_UPDATE:
|
||||||
|
case LifecycleEvent.AFTER_UPDATE_PERFORMED:
|
||||||
|
if (responds || listener instanceof UpdateListener) {
|
||||||
|
if (mock)
|
||||||
|
return Boolean.TRUE;
|
||||||
|
if (ev == null)
|
||||||
|
ev = new LifecycleEvent(source, rel, type);
|
||||||
|
if (type == LifecycleEvent.BEFORE_UPDATE)
|
||||||
|
((UpdateListener) listener).beforeUpdate(ev);
|
||||||
|
else
|
||||||
|
((UpdateListener) listener)
|
||||||
|
.afterUpdatePerformed(ev);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case LifecycleEvent.AFTER_DELETE_PERFORMED:
|
||||||
|
if (responds || listener instanceof PostDeleteListener){
|
||||||
|
if (mock)
|
||||||
|
return Boolean.TRUE;
|
||||||
|
if (ev == null)
|
||||||
|
ev = new LifecycleEvent(source, rel, type);
|
||||||
|
((PostDeleteListener) listener)
|
||||||
|
.afterDeletePerformed(ev);
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw new InvalidStateException(
|
throw new InvalidStateException(
|
||||||
_loc.get("unknown-lifecycle-event",
|
_loc.get("unknown-lifecycle-event",
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.openjpa.event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.1.0
|
||||||
|
*/
|
||||||
|
public interface PostDeleteListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receives notifications before an update is performed. Differs from
|
||||||
|
* {@link DeleteListener#afterDelete(LifecycleEvent)} in that the latter
|
||||||
|
* is called after the delete operation, whereas this is called after the
|
||||||
|
* delete statements have been sent to the data store.
|
||||||
|
*/
|
||||||
|
public void afterDeletePerformed(LifecycleEvent event);
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.openjpa.event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.1.0
|
||||||
|
*/
|
||||||
|
public interface PostPersistListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receives notifications after a persist operation has been written to the
|
||||||
|
* data store. Differs from {@link PersistListener#afterPersist} in that
|
||||||
|
* the latter is called at the end of the persist() operation itself, not
|
||||||
|
* after the flush.
|
||||||
|
*/
|
||||||
|
public void afterPersistPerformed(LifecycleEvent event);
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.openjpa.event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.1.0
|
||||||
|
*/
|
||||||
|
public interface UpdateListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receives notifications before an update is performed. Differs from
|
||||||
|
* {@link StoreListener#beforeStore} in that the latter is called for
|
||||||
|
* updated and new records, whereas this is only invoked for updated
|
||||||
|
* records.
|
||||||
|
*/
|
||||||
|
public void beforeUpdate(LifecycleEvent event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receives notifications before an update is performed. Differs from
|
||||||
|
* {@link StoreListener#afterStore} in that the latter is called for
|
||||||
|
* updated and new records, whereas this is only invoked for updated
|
||||||
|
* records, and that this is called after the record is actually flushed
|
||||||
|
* to the store.
|
||||||
|
*/
|
||||||
|
public void afterUpdatePerformed(LifecycleEvent event);
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.openjpa.persistence.callbacks;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.EntityListeners;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@EntityListeners(value = ListenerImpl.class)
|
||||||
|
public class EntityListenerEntity implements ListenerTestEntity {
|
||||||
|
@Id @GeneratedValue
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.openjpa.persistence.callbacks;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.EntityListeners;
|
||||||
|
|
||||||
|
import org.apache.openjpa.persistence.callbacks.ListenerImpl;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class GlobalListenerEntity implements ListenerTestEntity {
|
||||||
|
@Id @GeneratedValue
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.openjpa.persistence.callbacks;
|
||||||
|
|
||||||
|
import javax.persistence.PrePersist;
|
||||||
|
import javax.persistence.PostPersist;
|
||||||
|
import javax.persistence.PostLoad;
|
||||||
|
import javax.persistence.PreUpdate;
|
||||||
|
import javax.persistence.PostUpdate;
|
||||||
|
import javax.persistence.PreRemove;
|
||||||
|
import javax.persistence.PostRemove;
|
||||||
|
|
||||||
|
public class ListenerImpl {
|
||||||
|
|
||||||
|
static int prePersistCount;
|
||||||
|
static int postPersistCount;
|
||||||
|
static int preUpdateCount;
|
||||||
|
static int postUpdateCount;
|
||||||
|
static int preRemoveCount;
|
||||||
|
static int postRemoveCount;
|
||||||
|
static int postLoadCount;
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
public void prePersist(Object o) {
|
||||||
|
prePersistCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostPersist
|
||||||
|
public void postPersist(Object o) {
|
||||||
|
postPersistCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostLoad
|
||||||
|
public void postLoad(Object o) {
|
||||||
|
postLoadCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreUpdate
|
||||||
|
public void preUpdate(Object o) {
|
||||||
|
preUpdateCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostUpdate
|
||||||
|
public void postUpdate(Object o) {
|
||||||
|
postUpdateCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreRemove
|
||||||
|
public void preRemove(Object o) {
|
||||||
|
preRemoveCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostRemove
|
||||||
|
public void postRemove(Object o) {
|
||||||
|
postRemoveCount++;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.openjpa.persistence.callbacks;
|
||||||
|
|
||||||
|
public interface ListenerTestEntity {
|
||||||
|
|
||||||
|
public long getId();
|
||||||
|
|
||||||
|
public int getValue();
|
||||||
|
|
||||||
|
public void setValue(int val);
|
||||||
|
}
|
|
@ -0,0 +1,114 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.openjpa.persistence.callbacks;
|
||||||
|
|
||||||
|
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
||||||
|
import org.apache.openjpa.persistence.OpenJPAEntityManager;
|
||||||
|
|
||||||
|
public class TestEntityListeners extends SingleEMFTestCase {
|
||||||
|
|
||||||
|
public void setUp() {
|
||||||
|
setUp(CLEAR_TABLES);
|
||||||
|
ListenerImpl.prePersistCount = 0;
|
||||||
|
ListenerImpl.postPersistCount = 0;
|
||||||
|
ListenerImpl.preUpdateCount = 0;
|
||||||
|
ListenerImpl.postUpdateCount = 0;
|
||||||
|
ListenerImpl.preRemoveCount = 0;
|
||||||
|
ListenerImpl.postRemoveCount = 0;
|
||||||
|
ListenerImpl.postLoadCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getPersistenceUnitName() {
|
||||||
|
return "listener-pu";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testEntityListeners() {
|
||||||
|
helper(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGlobalListeners() {
|
||||||
|
helper(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void helper(boolean entityListeners) {
|
||||||
|
OpenJPAEntityManager em = emf.createEntityManager();
|
||||||
|
try {
|
||||||
|
em.getTransaction().begin();
|
||||||
|
ListenerTestEntity o;
|
||||||
|
if (entityListeners)
|
||||||
|
o = new EntityListenerEntity();
|
||||||
|
else
|
||||||
|
o = new GlobalListenerEntity();
|
||||||
|
em.persist(o);
|
||||||
|
|
||||||
|
assertStatus(1, 0, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
long id = o.getId();
|
||||||
|
em.close();
|
||||||
|
|
||||||
|
assertStatus(1, 1, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
em = emf.createEntityManager();
|
||||||
|
em.getTransaction().begin();
|
||||||
|
if (entityListeners)
|
||||||
|
o = em.find(EntityListenerEntity.class, id);
|
||||||
|
else
|
||||||
|
o = em.find(GlobalListenerEntity.class, id);
|
||||||
|
|
||||||
|
assertNotNull(o);
|
||||||
|
assertStatus(1, 1, 0, 0, 0, 0, 1);
|
||||||
|
|
||||||
|
o.setValue(o.getValue() + 1);
|
||||||
|
|
||||||
|
em.flush();
|
||||||
|
assertStatus(1, 1, 1, 1, 0, 0, 1);
|
||||||
|
|
||||||
|
em.remove(o);
|
||||||
|
assertStatus(1, 1, 1, 1, 1, 0, 1);
|
||||||
|
|
||||||
|
em.getTransaction().commit();
|
||||||
|
|
||||||
|
assertStatus(1, 1, 1, 1, 1, 1, 1);
|
||||||
|
|
||||||
|
em.close();
|
||||||
|
} finally {
|
||||||
|
if (em != null && em.getTransaction().isActive())
|
||||||
|
em.getTransaction().rollback();
|
||||||
|
if (em != null && em.isOpen())
|
||||||
|
em.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertStatus(
|
||||||
|
int prePersist, int postPersist,
|
||||||
|
int preUpdate, int postUpdate,
|
||||||
|
int preRemove, int postRemove,
|
||||||
|
int postLoad) {
|
||||||
|
assertEquals(prePersist, ListenerImpl.prePersistCount);
|
||||||
|
assertEquals(postPersist, ListenerImpl.postPersistCount);
|
||||||
|
assertEquals(preUpdate, ListenerImpl.preUpdateCount);
|
||||||
|
assertEquals(postUpdate, ListenerImpl.postUpdateCount);
|
||||||
|
assertEquals(preRemove, ListenerImpl.preRemoveCount);
|
||||||
|
assertEquals(postRemove, ListenerImpl.postRemoveCount);
|
||||||
|
assertEquals(postLoad, ListenerImpl.postLoadCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
-->
|
||||||
|
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
|
||||||
|
version="1.0">
|
||||||
|
<package>org.apache.openjpa.persistence.callbacks</package>
|
||||||
|
<entity class="EntityListenerEntity">
|
||||||
|
<exclude-default-listeners>true</exclude-default-listeners>
|
||||||
|
</entity>
|
||||||
|
<persistence-unit-metadata>
|
||||||
|
<persistence-unit-defaults>
|
||||||
|
<entity-listeners>
|
||||||
|
<entity-listener class="ListenerImpl">
|
||||||
|
</entity-listener>
|
||||||
|
</entity-listeners>
|
||||||
|
</persistence-unit-defaults>
|
||||||
|
</persistence-unit-metadata>
|
||||||
|
</entity-mappings>
|
|
@ -79,4 +79,14 @@
|
||||||
|
|
||||||
<persistence-unit name="empty-pu">
|
<persistence-unit name="empty-pu">
|
||||||
</persistence-unit>
|
</persistence-unit>
|
||||||
|
|
||||||
|
<persistence-unit name="listener-pu">
|
||||||
|
<mapping-file>META-INF/listener-orm.xml</mapping-file>
|
||||||
|
<class>org.apache.openjpa.persistence.callbacks.EntityListenerEntity</class>
|
||||||
|
<class>org.apache.openjpa.persistence.callbacks.GlobalListenerEntity</class>
|
||||||
|
<properties>
|
||||||
|
<property name="openjpa.jdbc.SynchronizeMappings"
|
||||||
|
value="buildSchema(ForeignKeys=true)"/>
|
||||||
|
</properties>
|
||||||
|
</persistence-unit>
|
||||||
</persistence>
|
</persistence>
|
||||||
|
|
|
@ -27,13 +27,16 @@ import org.apache.openjpa.event.LifecycleEvent;
|
||||||
import org.apache.openjpa.event.LifecycleEventManager;
|
import org.apache.openjpa.event.LifecycleEventManager;
|
||||||
import org.apache.openjpa.event.LoadListener;
|
import org.apache.openjpa.event.LoadListener;
|
||||||
import org.apache.openjpa.event.PersistListener;
|
import org.apache.openjpa.event.PersistListener;
|
||||||
import org.apache.openjpa.event.StoreListener;
|
import org.apache.openjpa.event.PostPersistListener;
|
||||||
|
import org.apache.openjpa.event.UpdateListener;
|
||||||
|
import org.apache.openjpa.event.PostDeleteListener;
|
||||||
import org.apache.openjpa.lib.util.Localizer;
|
import org.apache.openjpa.lib.util.Localizer;
|
||||||
import org.apache.openjpa.util.CallbackException;
|
import org.apache.openjpa.util.CallbackException;
|
||||||
|
|
||||||
class PersistenceListenerAdapter
|
class PersistenceListenerAdapter
|
||||||
implements LifecycleEventManager.ListenerAdapter, PersistListener,
|
implements LifecycleEventManager.ListenerAdapter, PersistListener,
|
||||||
LoadListener, StoreListener, DeleteListener {
|
PostPersistListener, LoadListener, UpdateListener, DeleteListener,
|
||||||
|
PostDeleteListener {
|
||||||
|
|
||||||
private static final Localizer _loc = Localizer.forPackage
|
private static final Localizer _loc = Localizer.forPackage
|
||||||
(PersistenceListenerAdapter.class);
|
(PersistenceListenerAdapter.class);
|
||||||
|
@ -83,6 +86,10 @@ class PersistenceListenerAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterPersist(LifecycleEvent event) {
|
public void afterPersist(LifecycleEvent event) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void afterPersistPerformed(LifecycleEvent event) {
|
||||||
makeCallback(event);
|
makeCallback(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,11 +101,11 @@ class PersistenceListenerAdapter
|
||||||
makeCallback(event);
|
makeCallback(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void beforeStore(LifecycleEvent event) {
|
public void beforeUpdate(LifecycleEvent event) {
|
||||||
makeCallback(event);
|
makeCallback(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterStore(LifecycleEvent event) {
|
public void afterUpdatePerformed(LifecycleEvent event) {
|
||||||
makeCallback(event);
|
makeCallback(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +114,10 @@ class PersistenceListenerAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterDelete(LifecycleEvent event) {
|
public void afterDelete(LifecycleEvent event) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void afterDeletePerformed(LifecycleEvent event) {
|
||||||
makeCallback(event);
|
makeCallback(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue