Author: steve.ebersole(a)jboss.com
Date: 2008-08-19 10:38:31 -0400 (Tue, 19 Aug 2008)
New Revision: 15113
Added:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/AbstractPreDatabaseOperationEvent.java
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/PreDeleteEvent.java
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/PreInsertEvent.java
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/PreUpdateEvent.java
Log:
HHH-3437 : re-add getSource() to events
Added:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/AbstractPreDatabaseOperationEvent.java
===================================================================
---
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/AbstractPreDatabaseOperationEvent.java
(rev 0)
+++
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/AbstractPreDatabaseOperationEvent.java 2008-08-19
14:38:31 UTC (rev 15113)
@@ -0,0 +1,101 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ *
+ */
+package org.hibernate.event;
+
+import java.io.Serializable;
+
+import org.hibernate.persister.entity.EntityPersister;
+
+/**
+ * Represents an operation we are about to perform against the database.
+ *
+ * @author Steve Ebersole
+ */
+public abstract class AbstractPreDatabaseOperationEvent extends AbstractEvent {
+ private final Object entity;
+ private final Serializable id;
+ private final EntityPersister persister;
+
+ /**
+ * Constructs an event containing the pertinent information.
+ *
+ * @param source The session from which the event originated.
+ * @param entity The entity to be invloved in the database operation.
+ * @param id The entity id to be invloved in the database operation.
+ * @param persister The entity's persister.
+ */
+ public AbstractPreDatabaseOperationEvent(
+ EventSource source,
+ Object entity,
+ Serializable id,
+ EntityPersister persister) {
+ super( source );
+ this.entity = entity;
+ this.id = id;
+ this.persister = persister;
+ }
+
+ /**
+ * Retrieves the entity involved in the database operation.
+ *
+ * @return The entity.
+ */
+ public Object getEntity() {
+ return entity;
+ }
+
+ /**
+ * The id to be used in the database operation.
+ *
+ * @return The id.
+ */
+ public Serializable getId() {
+ return id;
+ }
+
+ /**
+ * The persister for the {@link #getEntity entity}.
+ *
+ * @return The entity persister.
+ */
+ public EntityPersister getPersister() {
+ return persister;
+ }
+
+ /**
+ * Getter for property 'source'. This is the session from which the event
+ * originated.
+ * <p/>
+ * Some of the pre-* events had previous exposed the event source using
+ * getSource() because they had not originally extended from
+ * {@link AbstractEvent}.
+ *
+ * @return Value for property 'source'.
+ * @deprecated Use {@link #getSession} instead
+ */
+ public EventSource getSource() {
+ return getSession();
+ }
+}
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/PreDeleteEvent.java
===================================================================
---
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/PreDeleteEvent.java 2008-08-19
13:20:54 UTC (rev 15112)
+++
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/PreDeleteEvent.java 2008-08-19
14:38:31 UTC (rev 15113)
@@ -29,41 +29,43 @@
import org.hibernate.persister.entity.EntityPersister;
/**
- * Occurs before deleting an item from the datastore
+ * Represents a <tt>pre-delete</tt> event, which occurs just prior to
+ * performing the deletion of an entity from the database.
*
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class PreDeleteEvent extends AbstractEvent {
- private Object entity;
- private EntityPersister persister;
- private Serializable id;
+public class PreDeleteEvent extends AbstractPreDatabaseOperationEvent {
private Object[] deletedState;
-
- public Object getEntity() {
- return entity;
- }
- public Serializable getId() {
- return id;
- }
- public EntityPersister getPersister() {
- return persister;
- }
- public Object[] getDeletedState() {
- return deletedState;
- }
-
+
+ /**
+ *
+ * Constructs an event containing the pertinent information.
+ *
+ * @param entity The entity to be deleted.
+ * @param id The id to use in the deletion.
+ * @param deletedState The entity's state at deletion time.
+ * @param persister The entity's persister.
+ * @param source The session from which the event originated.
+ */
public PreDeleteEvent(
- Object entity,
+ Object entity,
Serializable id,
Object[] deletedState,
EntityPersister persister,
- EventSource source
- ) {
- super(source);
- this.entity = entity;
- this.persister = persister;
- this.id = id;
+ EventSource source) {
+ super( source, entity, id, persister );
this.deletedState = deletedState;
}
+ /**
+ * Getter for property 'deletedState'. This is the entity state at the
+ * time of deletion (useful for optomistic locking and such).
+ *
+ * @return Value for property 'deletedState'.
+ */
+ public Object[] getDeletedState() {
+ return deletedState;
+ }
+
}
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/PreInsertEvent.java
===================================================================
---
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/PreInsertEvent.java 2008-08-19
13:20:54 UTC (rev 15112)
+++
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/PreInsertEvent.java 2008-08-19
14:38:31 UTC (rev 15113)
@@ -29,39 +29,39 @@
import org.hibernate.persister.entity.EntityPersister;
/**
- * Occurs before inserting an item in the datastore
- *
+ * Represents a <tt>pre-insert</tt> event, which occurs just prior to
+ * performing the insert of an entity into the database.
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class PreInsertEvent extends AbstractEvent {
- private Object entity;
- private EntityPersister persister;
+public class PreInsertEvent extends AbstractPreDatabaseOperationEvent {
private Object[] state;
- private Serializable id;
+ /**
+ * Constructs an event containing the pertinent information.
+ *
+ * @param entity The entity to be inserted.
+ * @param id The id to use in the insertion.
+ * @param state The state to be inserted.
+ * @param persister The entity's persister.
+ * @param source The session from which the event originated.
+ */
public PreInsertEvent(
Object entity,
Serializable id,
Object[] state,
EntityPersister persister,
- EventSource source
- ) {
- super(source);
- this.entity = entity;
- this.id = id;
+ EventSource source) {
+ super( source, entity, id, persister );
this.state = state;
- this.persister = persister;
}
- public Object getEntity() {
- return entity;
- }
- public Serializable getId() {
- return id;
- }
- public EntityPersister getPersister() {
- return persister;
- }
+ /**
+ * Getter for property 'state'. These are the values to be inserted.
+ *
+ * @return Value for property 'state'.
+ */
public Object[] getState() {
return state;
}
Modified:
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/PreUpdateEvent.java
===================================================================
---
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/PreUpdateEvent.java 2008-08-19
13:20:54 UTC (rev 15112)
+++
core/branches/Branch_3_3/core/src/main/java/org/hibernate/event/PreUpdateEvent.java 2008-08-19
14:38:31 UTC (rev 15113)
@@ -29,46 +29,55 @@
import org.hibernate.persister.entity.EntityPersister;
/**
- * Occurs before updating the datastore
- *
+ * Represents a <tt>pre-update</tt> event, which occurs just prior to
+ * performing the update of an entity in the database.
+ *
* @author Gavin King
+ * @author Steve Ebersole
*/
-public class PreUpdateEvent extends AbstractEvent {
- private Object entity;
- private EntityPersister persister;
+public class PreUpdateEvent extends AbstractPreDatabaseOperationEvent {
private Object[] state;
private Object[] oldState;
- private Serializable id;
+ /**
+ * Constructs an event containing the pertinent information.
+ *
+ * @param entity The entity to be updated.
+ * @param id The id of the entity to use for updating.
+ * @param state The state to be updated.
+ * @param oldState The state of the entity at the time it was loaded from
+ * the database.
+ * @param persister The entity's persister.
+ * @param source The session from which the event originated.
+ */
public PreUpdateEvent(
Object entity,
Serializable id,
Object[] state,
Object[] oldState,
EntityPersister persister,
- EventSource source
- ) {
- super(source);
- this.entity = entity;
- this.id = id;
+ EventSource source) {
+ super( source, entity, id, persister );
this.state = state;
this.oldState = oldState;
- this.persister = persister;
}
- public Object getEntity() {
- return entity;
+ /**
+ * Retrieves the state to be used in the update.
+ *
+ * @return The current state.
+ */
+ public Object[] getState() {
+ return state;
}
- public Serializable getId() {
- return id;
- }
+
+ /**
+ * The old state of the entity at the time it was last loaded from the
+ * database; can be null in the case of detached entities.
+ *
+ * @return The loaded state, or null.
+ */
public Object[] getOldState() {
return oldState;
}
- public EntityPersister getPersister() {
- return persister;
- }
- public Object[] getState() {
- return state;
- }
}