-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #1240: SessionEventListener: add pre/post flush() events - backpo…
…rt from master (#2178) * Fix #1240: SessionEventListener: add pre/post flush() events (#1978) - added preFlushUnitOfWork/postFlushUnitOfWork events - removed preCommitUnitOfWork event from flush in UnitOfWorkImpl - added unitTests for flush events Signed-off-by: Patrick Schmitt <[email protected]> (cherry picked from commit 5db018c)
- Loading branch information
Showing
13 changed files
with
228 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...src/it/java/org/eclipse/persistence/testing/tests/unitofwork/PostFlushUnitOfWorkTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.tests.unitofwork; | ||
|
||
import org.eclipse.persistence.sessions.SessionEvent; | ||
import org.eclipse.persistence.sessions.SessionEventAdapter; | ||
import org.eclipse.persistence.sessions.UnitOfWork; | ||
import org.eclipse.persistence.testing.framework.TestErrorException; | ||
|
||
public class PostFlushUnitOfWorkTest extends UnitOfWorkEventTest { | ||
@Override | ||
public void setup() { | ||
super.setup(); | ||
setDescription("Test the postFlushUnitOfWork Event"); | ||
SessionEventAdapter tvAdapter = new SessionEventAdapter() { | ||
// Listen for PostFlushUnitOfWorkEvents | ||
|
||
@Override | ||
public void postFlushUnitOfWork(SessionEvent event) { | ||
setEventTriggered(true); | ||
} | ||
}; | ||
getSession().getEventManager().addListener(tvAdapter); | ||
} | ||
|
||
@Override | ||
public void test() { | ||
UnitOfWork tvUnitOfWork = getSession().acquireUnitOfWork(); | ||
tvUnitOfWork.writeChanges(); | ||
} | ||
|
||
@Override | ||
public void verify() { | ||
if (!isEventTriggered()) { | ||
throw new TestErrorException("The preFlushUnitOfWork event was not triggered."); | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
.../src/it/java/org/eclipse/persistence/testing/tests/unitofwork/PreFlushUnitOfWorkTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
package org.eclipse.persistence.testing.tests.unitofwork; | ||
|
||
import org.eclipse.persistence.sessions.SessionEvent; | ||
import org.eclipse.persistence.sessions.SessionEventAdapter; | ||
import org.eclipse.persistence.sessions.UnitOfWork; | ||
import org.eclipse.persistence.testing.framework.TestErrorException; | ||
|
||
public class PreFlushUnitOfWorkTest extends UnitOfWorkEventTest { | ||
@Override | ||
public void setup() { | ||
super.setup(); | ||
setDescription("Test the preFlushUnitOfWork Event"); | ||
SessionEventAdapter tvAdapter = new SessionEventAdapter() { | ||
// Listen for PreFlushUnitOfWorkEvents | ||
|
||
@Override | ||
public void preFlushUnitOfWork(SessionEvent event) { | ||
setEventTriggered(true); | ||
} | ||
}; | ||
getSession().getEventManager().addListener(tvAdapter); | ||
} | ||
|
||
@Override | ||
public void test() { | ||
UnitOfWork tvUnitOfWork = getSession().acquireUnitOfWork(); | ||
tvUnitOfWork.writeChanges(); | ||
} | ||
|
||
@Override | ||
public void verify() { | ||
if (!isEventTriggered()) { | ||
throw new TestErrorException("The preFlushUnitOfWork event was not triggered."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.