forked from jakartaee/persistence
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add EntityManager.runWithConnection()/callWithConnection()
see jakartaee#432
- Loading branch information
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
api/src/main/java/jakarta/persistence/ConnectionConsumer.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,40 @@ | ||
/* | ||
* Copyright (c) 2008, 2021 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 | ||
*/ | ||
|
||
// Contributors: | ||
// Gavin King - 3.2 | ||
|
||
|
||
package jakarta.persistence; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
/** | ||
* An executable action which makes use of a {@linkplain Connection JDBC connection}. | ||
* | ||
* @see ConnectionFunction | ||
* @see EntityManager#runWithConnection(ConnectionConsumer) | ||
* | ||
* @since 3.2 | ||
*/ | ||
@FunctionalInterface | ||
public interface ConnectionConsumer { | ||
/** | ||
* Execute the action using the given connection. | ||
* | ||
* @param connection the connection to use | ||
* | ||
* @throws SQLException if a problem occurs calling JDBC | ||
*/ | ||
void accept(Connection connection) throws SQLException; | ||
} |
43 changes: 43 additions & 0 deletions
43
api/src/main/java/jakarta/persistence/ConnectionFunction.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,43 @@ | ||
/* | ||
* Copyright (c) 2008, 2021 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 | ||
*/ | ||
|
||
// Contributors: | ||
// Gavin King - 3.2 | ||
|
||
|
||
package jakarta.persistence; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
/** | ||
* A function which makes use of a {@linkplain Connection JDBC connection} | ||
* to compute a result. | ||
* | ||
* @see ConnectionConsumer | ||
* @see EntityManager#callWithConnection(ConnectionFunction) | ||
* | ||
* @since 3.2 | ||
*/ | ||
@FunctionalInterface | ||
public interface ConnectionFunction<T> { | ||
/** | ||
* Compute a result using the given connection. | ||
* | ||
* @param connection the connection to use | ||
* | ||
* @return the result | ||
* | ||
* @throws SQLException if a problem occurs calling JDBC | ||
*/ | ||
T apply(Connection connection) throws SQLException; | ||
} |
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