Skip to content

Commit 8c45eeb

Browse files
committed
refactorings to the AbstractEvent hierarchy
1. delete unused class SaveOrUpdateEvent 2. introduce AbstractPostDatabaseOperationEvent for consistency 3. DirtyCheckEvent should no longer extend FlushEvent
1 parent b383801 commit 8c45eeb

18 files changed

+134
-234
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.event.spi;
6+
7+
import org.hibernate.engine.spi.SessionFactoryImplementor;
8+
import org.hibernate.persister.entity.EntityPersister;
9+
10+
/**
11+
* Represents an operation successfully executed by the database.
12+
*
13+
* @author Gavin King
14+
*
15+
* @since 7
16+
*/
17+
public abstract class AbstractPostDatabaseOperationEvent extends AbstractEvent {
18+
19+
private final Object entity;
20+
private final Object id;
21+
private final EntityPersister persister;
22+
23+
/**
24+
* Constructs an event containing the pertinent information.
25+
*
26+
* @param source The session from which the event originated.
27+
* @param entity The entity to be involved in the database operation.
28+
* @param id The entity id to be involved in the database operation.
29+
* @param persister The entity's persister.
30+
*/
31+
public AbstractPostDatabaseOperationEvent(
32+
EventSource source,
33+
Object entity,
34+
Object id,
35+
EntityPersister persister) {
36+
super( source );
37+
this.entity = entity;
38+
this.id = id;
39+
this.persister = persister;
40+
}
41+
42+
/**
43+
* Retrieves the entity involved in the database operation.
44+
*
45+
* @return The entity.
46+
*/
47+
public Object getEntity() {
48+
return entity;
49+
}
50+
51+
/**
52+
* The id to be used in the database operation.
53+
*
54+
* @return The id.
55+
*/
56+
public Object getId() {
57+
return id;
58+
}
59+
60+
/**
61+
* The persister for the entity.
62+
*
63+
* @return The entity persister.
64+
*/
65+
public EntityPersister getPersister() {
66+
return persister;
67+
}
68+
69+
/**
70+
* The factory which owns the persister for the entity.
71+
*
72+
* @return The factory
73+
*/
74+
@Override
75+
public SessionFactoryImplementor getFactory() {
76+
return persister.getFactory();
77+
}
78+
}

hibernate-core/src/main/java/org/hibernate/event/spi/AbstractPreDatabaseOperationEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import org.hibernate.persister.entity.EntityPersister;
99

1010
/**
11-
* Represents an operation we are about to perform against the database.
11+
* Represents an operation that is about to be executed by the database.
1212
*
1313
* @author Steve Ebersole
1414
*/

hibernate-core/src/main/java/org/hibernate/event/spi/AutoFlushEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
import java.util.Set;
88

9-
/** Defines an event class for the auto-flushing of a session.
9+
/**
10+
* Event class for {@link org.hibernate.FlushMode#AUTO automatic}
11+
* stateful session flush.
1012
*
1113
* @author Steve Ebersole
1214
*/

hibernate-core/src/main/java/org/hibernate/event/spi/ClearEvent.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
package org.hibernate.event.spi;
66

77
/**
8-
* An event for {@link org.hibernate.Session#clear()} listening
8+
* Event class for {@link org.hibernate.Session#clear}.
99
*
1010
* @author Steve Ebersole
11+
*
12+
* @see org.hibernate.Session#clear
1113
*/
1214
public class ClearEvent extends AbstractEvent {
13-
/**
14-
* Constructs an event from the given event session.
15-
*
16-
* @param source The session event source.
17-
*/
1815
public ClearEvent(EventSource source) {
1916
super( source );
2017
}

hibernate-core/src/main/java/org/hibernate/event/spi/DeleteEvent.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,27 @@
55
package org.hibernate.event.spi;
66

77
/**
8-
* Defines an event class for the deletion of an entity.
8+
* Event class for {@link org.hibernate.Session#remove}.
9+
*
10+
* @apiNote This class predates JPA, and today should
11+
* really be named {@code RemoveEvent}.
912
*
1013
* @author Steve Ebersole
14+
*
15+
* @see org.hibernate.Session#remove
1116
*/
1217
public class DeleteEvent extends AbstractEvent {
1318
private final Object object;
1419
private String entityName;
1520
private boolean cascadeDeleteEnabled;
16-
// TODO: The removeOrphan concept is a temporary "hack" for HHH-6484. This should be removed once action/task
17-
// ordering is improved.
21+
// TODO: The removeOrphan concept is a temporary "hack" for HHH-6484.
22+
// This should be removed once action/task ordering is improved.
1823
private boolean orphanRemovalBeforeUpdates;
1924

20-
/**
21-
* Constructs a new DeleteEvent instance.
22-
*
23-
* @param object The entity to be deleted.
24-
* @param source The session from which the delete event was generated.
25-
*/
2625
public DeleteEvent(Object object, EventSource source) {
2726
super(source);
2827
if (object == null) {
29-
throw new IllegalArgumentException(
30-
"attempt to create delete event with null entity"
31-
);
28+
throw new IllegalArgumentException( "attempt to create delete event with null entity" );
3229
}
3330
this.object = object;
3431
}

hibernate-core/src/main/java/org/hibernate/event/spi/DirtyCheckEvent.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
*/
55
package org.hibernate.event.spi;
66

7+
78
/**
8-
* Defines an event class for the dirty-checking of a session.
9+
* Event class for {@link org.hibernate.Session#isDirty}.
910
*
1011
* @author Steve Ebersole
12+
*
13+
* @see org.hibernate.Session#isDirty
1114
*/
12-
public class DirtyCheckEvent extends FlushEvent {
15+
public class DirtyCheckEvent extends AbstractEvent {
1316
private boolean dirty;
1417

1518
public DirtyCheckEvent(EventSource source) {

hibernate-core/src/main/java/org/hibernate/event/spi/EvictEvent.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
package org.hibernate.event.spi;
66

77
/**
8-
* Defines an event class for the evicting of an entity.
8+
* Event class for {@link org.hibernate.Session#evict}
9+
* and {@link org.hibernate.Session#detach}.
910
*
1011
* @author Steve Ebersole
12+
*
13+
* @see org.hibernate.Session#evict
14+
* @see org.hibernate.Session#detach
1115
*/
1216
public class EvictEvent extends AbstractEvent {
1317

hibernate-core/src/main/java/org/hibernate/event/spi/FlushEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
package org.hibernate.event.spi;
66

77
/**
8-
* Defines an event class for the flushing of a session.
8+
* Event class for stateful session flush.
99
*
1010
* @author Steve Ebersole
11+
*
12+
* @see org.hibernate.Session#flush
1113
*/
1214
public class FlushEvent extends AbstractEvent {
1315
private int numberOfEntitiesProcessed;

hibernate-core/src/main/java/org/hibernate/event/spi/LockEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import org.hibernate.LockOptions;
1010

1111
/**
12-
* Defines an event class for the locking of an entity.
12+
* Event class for {@link org.hibernate.Session#lock}.
1313
*
1414
* @author Steve Ebersole
15+
*
16+
* @see org.hibernate.Session#lock
1517
*/
1618
public class LockEvent extends AbstractEvent {
1719

hibernate-core/src/main/java/org/hibernate/event/spi/MergeEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
package org.hibernate.event.spi;
66

77
/**
8-
* An event class for merge() and saveOrUpdateCopy()
8+
* Event class for {@link org.hibernate.Session#merge}.
99
*
1010
* @author Gavin King
11+
*
12+
* @see org.hibernate.Session#merge
1113
*/
1214
public class MergeEvent extends AbstractEvent {
1315

0 commit comments

Comments
 (0)