| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Hibernate
Revision: 15114
Author: steve.ebersole@jboss.com
Date: 19 Aug 2008 10:40:53
Changes:HHH-3437 : re-add getSource() on events
Files:| ... | ...@@ -29,41 +29,43 @@ | |
| 29 | 29 | import org.hibernate.persister.entity.EntityPersister; |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | * Occurs before deleting an item from the datastore | |
| 32 | * Represents a <tt>pre-delete</tt> event, which occurs just prior to | |
| 33 | * performing the deletion of an entity from the database. | |
| 33 | 34 | * |
| 34 | 35 | * @author Gavin King |
| 36 | * @author Steve Ebersole | |
| 35 | 37 | */ |
| 36 | public class PreDeleteEvent extends AbstractEvent { | |
| 37 | private Object entity; | |
| 38 | private EntityPersister persister; | |
| 39 | private Serializable id; | |
| 38 | public class PreDeleteEvent extends AbstractPreDatabaseOperationEvent { | |
| 40 | 39 | private Object[] deletedState; |
| 41 | ||
| 42 | public Object getEntity() { | |
| 43 | return entity; | |
| 44 | } | |
| 45 | public Serializable getId() { | |
| 46 | return id; | |
| 47 | } | |
| 48 | public EntityPersister getPersister() { | |
| 49 | return persister; | |
| 50 | } | |
| 51 | public Object[] getDeletedState() { | |
| 52 | return deletedState; | |
| 53 | } | |
| 54 | ||
| 40 | ||
| 41 | /** | |
| 42 | * | |
| 43 | * Constructs an event containing the pertinent information. | |
| 44 | * | |
| 45 | * @param entity The entity to be deleted. | |
| 46 | * @param id The id to use in the deletion. | |
| 47 | * @param deletedState The entity's state at deletion time. | |
| 48 | * @param persister The entity's persister. | |
| 49 | * @param source The session from which the event originated. | |
| 50 | */ | |
| 55 | 51 | public PreDeleteEvent( |
| 56 | Object entity, | |
| 52 | Object entity, | |
| 57 | 53 | Serializable id, |
| 58 | 54 | Object[] deletedState, |
| 59 | 55 | EntityPersister persister, |
| 60 | EventSource source | |
| 61 | ) { | |
| 62 | super(source); | |
| 63 | this.entity = entity; | |
| 64 | this.persister = persister; | |
| 65 | this.id = id; | |
| 56 | EventSource source) { | |
| 57 | super( source, entity, id, persister ); | |
| 66 | 58 | this.deletedState = deletedState; |
| 67 | 59 | } |
| 68 | 60 | |
| 61 | /** | |
| 62 | * Getter for property 'deletedState'. This is the entity state at the | |
| 63 | * time of deletion (useful for optomistic locking and such). | |
| 64 | * | |
| 65 | * @return Value for property 'deletedState'. | |
| 66 | */ | |
| 67 | public Object[] getDeletedState() { | |
| 68 | return deletedState; | |
| 69 | } | |
| 70 | ||
| 69 | 71 | } |
| ... | ...@@ -29,46 +29,55 @@ | |
| 29 | 29 | import org.hibernate.persister.entity.EntityPersister; |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | * Occurs before updating the datastore | |
| 33 | * | |
| 32 | * Represents a <tt>pre-update</tt> event, which occurs just prior to | |
| 33 | * performing the update of an entity in the database. | |
| 34 | * | |
| 34 | 35 | * @author Gavin King |
| 36 | * @author Steve Ebersole | |
| 35 | 37 | */ |
| 36 | public class PreUpdateEvent extends AbstractEvent { | |
| 37 | private Object entity; | |
| 38 | private EntityPersister persister; | |
| 38 | public class PreUpdateEvent extends AbstractPreDatabaseOperationEvent { | |
| 39 | 39 | private Object[] state; |
| 40 | 40 | private Object[] oldState; |
| 41 | private Serializable id; | |
| 42 | 41 | |
| 42 | /** | |
| 43 | * Constructs an event containing the pertinent information. | |
| 44 | * | |
| 45 | * @param entity The entity to be updated. | |
| 46 | * @param id The id of the entity to use for updating. | |
| 47 | * @param state The state to be updated. | |
| 48 | * @param oldState The state of the entity at the time it was loaded from | |
| 49 | * the database. | |
| 50 | * @param persister The entity's persister. | |
| 51 | * @param source The session from which the event originated. | |
| 52 | */ | |
| 43 | 53 | public PreUpdateEvent( |
| 44 | 54 | Object entity, |
| 45 | 55 | Serializable id, |
| 46 | 56 | Object[] state, |
| 47 | 57 | Object[] oldState, |
| 48 | 58 | EntityPersister persister, |
| 49 | EventSource source | |
| 50 | ) { | |
| 51 | super(source); | |
| 52 | this.entity = entity; | |
| 53 | this.id = id; | |
| 59 | EventSource source) { | |
| 60 | super( source, entity, id, persister ); | |
| 54 | 61 | this.state = state; |
| 55 | 62 | this.oldState = oldState; |
| 56 | this.persister = persister; | |
| 57 | 63 | } |
| 58 | 64 | |
| 59 | public Object getEntity() { | |
| 60 | return entity; | |
| 61 | } | |
| 62 | public Serializable getId() { | |
| 63 | return id; | |
| 65 | /** | |
| 66 | * Retrieves the state to be used in the update. | |
| 67 | * | |
| 68 | * @return The current state. | |
| 69 | */ | |
| 70 | public Object[] getState() { | |
| 71 | return state; | |
| 64 | 72 | } |
| 73 | ||
| 74 | /** | |
| 75 | * The old state of the entity at the time it was last loaded from the | |
| 76 | * database; can be null in the case of detached entities. | |
| 77 | * | |
| 78 | * @return The loaded state, or null. | |
| 79 | */ | |
| 65 | 80 | public Object[] getOldState() { |
| 66 | 81 | return oldState; |
| 67 | 82 | } |
| 68 | public EntityPersister getPersister() { | |
| 69 | return persister; | |
| 70 | } | |
| 71 | public Object[] getState() { | |
| 72 | return state; | |
| 73 | } | |
| 74 | 83 | } |
| ... | ...@@ -29,39 +29,39 @@ | |
| 29 | 29 | import org.hibernate.persister.entity.EntityPersister; |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | * Occurs before inserting an item in the datastore | |
| 33 | * | |
| 32 | * Represents a <tt>pre-insert</tt> event, which occurs just prior to | |
| 33 | * performing the insert of an entity into the database. | |
| 34 | * | |
| 34 | 35 | * @author Gavin King |
| 36 | * @author Steve Ebersole | |
| 35 | 37 | */ |
| 36 | public class PreInsertEvent extends AbstractEvent { | |
| 37 | private Object entity; | |
| 38 | private EntityPersister persister; | |
| 38 | public class PreInsertEvent extends AbstractPreDatabaseOperationEvent { | |
| 39 | 39 | private Object[] state; |
| 40 | private Serializable id; | |
| 41 | 40 | |
| 41 | /** | |
| 42 | * Constructs an event containing the pertinent information. | |
| 43 | * | |
| 44 | * @param entity The entity to be inserted. | |
| 45 | * @param id The id to use in the insertion. | |
| 46 | * @param state The state to be inserted. | |
| 47 | * @param persister The entity's persister. | |
| 48 | * @param source The session from which the event originated. | |
| 49 | */ | |
| 42 | 50 | public PreInsertEvent( |
| 43 | 51 | Object entity, |
| 44 | 52 | Serializable id, |
| 45 | 53 | Object[] state, |
| 46 | 54 | EntityPersister persister, |
| 47 | EventSource source | |
| 48 | ) { | |
| 49 | super(source); | |
| 50 | this.entity = entity; | |
| 51 | this.id = id; | |
| 55 | EventSource source) { | |
| 56 | super( source, entity, id, persister ); | |
| 52 | 57 | this.state = state; |
| 53 | this.persister = persister; | |
| 54 | 58 | } |
| 55 | 59 | |
| 56 | public Object getEntity() { | |
| 57 | return entity; | |
| 58 | } | |
| 59 | public Serializable getId() { | |
| 60 | return id; | |
| 61 | } | |
| 62 | public EntityPersister getPersister() { | |
| 63 | return persister; | |
| 64 | } | |
| 60 | /** | |
| 61 | * Getter for property 'state'. These are the values to be inserted. | |
| 62 | * | |
| 63 | * @return Value for property 'state'. | |
| 64 | */ | |
| 65 | 65 | public Object[] getState() { |
| 66 | 66 | return state; |
| 67 | 67 | } |
| ... | ...@@ -0,0 +1,101 @@ | |
| 1 | /* | |
| 2 | * Hibernate, Relational Persistence for Idiomatic Java | |
| 3 | * | |
| 4 | * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as | |
| 5 | * indicated by the @author tags or express copyright attribution | |
| 6 | * statements applied by the authors. All third-party contributions are | |
| 7 | * distributed under license by Red Hat Middleware LLC. | |
| 8 | * | |
| 9 | * This copyrighted material is made available to anyone wishing to use, modify, | |
| 10 | * copy, or redistribute it subject to the terms and conditions of the GNU | |
| 11 | * Lesser General Public License, as published by the Free Software Foundation. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
| 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | |
| 16 | * for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU Lesser General Public License | |
| 19 | * along with this distribution; if not, write to: | |
| 20 | * Free Software Foundation, Inc. | |
| 21 | * 51 Franklin Street, Fifth Floor | |
| 22 | * Boston, MA 02110-1301 USA | |
| 23 | * | |
| 24 | */ | |
| 25 | package org.hibernate.event; | |
| 26 | ||
| 27 | import java.io.Serializable; | |
| 28 | ||
| 29 | import org.hibernate.persister.entity.EntityPersister; | |
| 30 | ||
| 31 | /** | |
| 32 | * Represents an operation we are about to perform against the database. | |
| 33 | * | |
| 34 | * @author Steve Ebersole | |
| 35 | */ | |
| 36 | public abstract class AbstractPreDatabaseOperationEvent extends AbstractEvent { | |
| 37 | private final Object entity; | |
| 38 | private final Serializable id; | |
| 39 | private final EntityPersister persister; | |
| 40 | ||
| 41 | /** | |
| 42 | * Constructs an event containing the pertinent information. | |
| 43 | * | |
| 44 | * @param source The session from which the event originated. | |
| 45 | * @param entity The entity to be invloved in the database operation. | |
| 46 | * @param id The entity id to be invloved in the database operation. | |
| 47 | * @param persister The entity's persister. | |
| 48 | */ | |
| 49 | public AbstractPreDatabaseOperationEvent( | |
| 50 | EventSource source, | |
| 51 | Object entity, | |
| 52 | Serializable id, | |
| 53 | EntityPersister persister) { | |
| 54 | super( source ); | |
| 55 | this.entity = entity; | |
| 56 | this.id = id; | |
| 57 | this.persister = persister; | |
| 58 | } | |
| 59 | ||
| 60 | /** | |
| 61 | * Retrieves the entity involved in the database operation. | |
| 62 | * | |
| 63 | * @return The entity. | |
| 64 | */ | |
| 65 | public Object getEntity() { | |
| 66 | return entity; | |
| 67 | } | |
| 68 | ||
| 69 | /** | |
| 70 | * The id to be used in the database operation. | |
| 71 | * | |
| 72 | * @return The id. | |
| 73 | */ | |
| 74 | public Serializable getId() { | |
| 75 | return id; | |
| 76 | } | |
| 77 | ||
| 78 | /** | |
| 79 | * The persister for the {@link #getEntity entity}. | |
| 80 | * | |
| 81 | * @return The entity persister. | |
| 82 | */ | |
| 83 | public EntityPersister getPersister() { | |
| 84 | return persister; | |
| 85 | } | |
| 86 | ||
| 87 | /** | |
| 88 | * Getter for property 'source'. This is the session from which the event | |
| 89 | * originated. | |
| 90 | * <p/> | |
| 91 | * Some of the pre-* events had previous exposed the event source using | |
| 92 | * getSource() because they had not originally extended from | |
| 93 | * {@link AbstractEvent}. | |
| 94 | * | |
| 95 | * @return Value for property 'source'. | |
| 96 | * @deprecated Use {@link #getSession} instead | |
| 97 | */ | |
| 98 | public EventSource getSource() { | |
| 99 | return getSession(); | |
| 100 | } | |
| 101 | } |