Java Mailing List Archive

http://www.gg3721.com/

Home » Hibernate Commits List »

[hibernate-commits] Hibernate SVN: r15114 -
 core/trunk/core/src/main/java/org/hibernate/event.

hibernate-commits

2008-08-19


Author LoginPost Reply
Author: steve.ebersole@(protected)
Date: 2008-08-19 10:40:53 -0400 (Tue, 19 Aug 2008)
New Revision: 15114

Added:
 core/trunk/core/src/main/java/org/hibernate/event/AbstractPreDatabaseOperationEvent.java
Modified:
 core/trunk/core/src/main/java/org/hibernate/event/PreDeleteEvent.java
 core/trunk/core/src/main/java/org/hibernate/event/PreInsertEvent.java
 core/trunk/core/src/main/java/org/hibernate/event/PreUpdateEvent.java
Log:
HHH-3437 : re-add getSource() on events

Added: core/trunk/core/src/main/java/org/hibernate/event/AbstractPreDatabaseOperationEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/AbstractPreDatabaseOperationEvent.java                  (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/event/AbstractPreDatabaseOperationEvent.java  2008-08-19 14:40:53 UTC (rev 15114)
@@(protected) @@
+/*
+ * 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 {@(protected)}.
+   *
+   * @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
+   * {@(protected)}.
+   *
+   * @return Value for property 'source'.
+   * @deprecated Use {@(protected)
+   */
+  public EventSource getSource() {
+    return getSession();
+  }
+}

Modified: core/trunk/core/src/main/java/org/hibernate/event/PreDeleteEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PreDeleteEvent.java  2008-08-19 14:38:31 UTC (rev 15113)
+++ core/trunk/core/src/main/java/org/hibernate/event/PreDeleteEvent.java  2008-08-19 14:40:53 UTC (rev 15114)
@@(protected) @@
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/trunk/core/src/main/java/org/hibernate/event/PreInsertEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PreInsertEvent.java  2008-08-19 14:38:31 UTC (rev 15113)
+++ core/trunk/core/src/main/java/org/hibernate/event/PreInsertEvent.java  2008-08-19 14:40:53 UTC (rev 15114)
@@(protected) @@
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/trunk/core/src/main/java/org/hibernate/event/PreUpdateEvent.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/event/PreUpdateEvent.java  2008-08-19 14:38:31 UTC (rev 15113)
+++ core/trunk/core/src/main/java/org/hibernate/event/PreUpdateEvent.java  2008-08-19 14:40:53 UTC (rev 15114)
@@(protected) @@
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;
-  }
}

_______________________________________________
hibernate-commits mailing list
hibernate-commits@(protected)
https://lists.jboss.org/mailman/listinfo/hibernate-commits
©2008 gg3721.com - Jax Systems, LLC, U.S.A.