Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport PR 1473 fixes #1476

Merged
merged 3 commits into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 151 additions & 37 deletions integrations/cdi/jpa-cdi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@
<artifactId>helidon-integrations-cdi-eclipselink</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>helidon-integrations-cdi-hibernate</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.config</groupId>
<artifactId>helidon-microprofile-config-cdi</artifactId>
Expand Down Expand Up @@ -117,12 +122,12 @@
<artifactId>helidon-integrations-cdi-delegates</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>io.helidon.integrations.cdi</groupId>
<artifactId>helidon-integrations-cdi-reference-counted-context</artifactId>
<scope>compile</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -153,43 +158,18 @@
</plugin>
</plugins>
</pluginManagement>

<!--
Please note that the ordering of the following plugins
below is significant:

* maven-resources-plugin
* eclipselink-maven-plugin
* hibernate-enhance-maven-plugin
* maven-surefire-plugin
-->

<plugins>
<plugin>
<groupId>com.ethlo.persistence.tools</groupId>
<artifactId>eclipselink-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${version.lib.junit}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>weave</id>
<phase>process-test-classes</phase>
<goals>
<goal>weave</goal>
</goals>
<configuration>
<persistenceInfoLocation>${project.build.testOutputDirectory}</persistenceInfoLocation>
<source>${project.build.testOutputDirectory}</source>
<target>${project.build.testOutputDirectory}</target>
</configuration>
</execution>
<execution>
<id>modelgen</id>
<phase>generate-test-sources</phase>
<goals>
<goal>modelgen</goal>
</goals>
<configuration>
<source>${project.build.testSourceDirectory}</source>
<generatedSourcesDirectory>${project.build.directory}/generated-test-sources/apt</generatedSourcesDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
Expand Down Expand Up @@ -229,14 +209,148 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>Copy test classes to Eclipselink weaving area</id>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>process-test-classes</phase>
<configuration>
<resources>
<resource>
<directory>${project.build.testOutputDirectory}</directory>
<filtering>false</filtering>
</resource>
</resources>
<outputDirectory>${project.build.directory}/eclipselink/test-classes</outputDirectory>
<overwrite>true</overwrite>
</configuration>
</execution>
<execution>
<id>Copy test classes to Hibernate weaving area</id>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>process-test-classes</phase>
<configuration>
<resources>
<resource>
<directory>${project.build.testOutputDirectory}</directory>
<filtering>false</filtering>
</resource>
</resources>
<outputDirectory>${project.build.directory}/hibernate/test-classes</outputDirectory>
<overwrite>true</overwrite>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.ethlo.persistence.tools</groupId>
<artifactId>eclipselink-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${version.lib.junit}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>Statically weave JPA entities for Eclipselink</id>
<phase>process-test-classes</phase>
<goals>
<goal>weave</goal>
</goals>
<configuration>
<source>${project.build.directory}/eclipselink/test-classes</source>
<target>${project.build.directory}/eclipselink/test-classes</target>
<persistenceInfoLocation>${project.build.directory}/eclipselink/test-classes</persistenceInfoLocation>
</configuration>
</execution>
<execution>
<id>modelgen</id>
<phase>generate-test-sources</phase>
<goals>
<goal>modelgen</goal>
</goals>
<configuration>
<source>${project.build.testSourceDirectory}</source>
<generatedSourcesDirectory>${project.build.directory}/generated-test-sources/apt</generatedSourcesDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.hibernate.orm.tooling</groupId>
<artifactId>hibernate-enhance-maven-plugin</artifactId>
<executions>
<execution>
<id>Statically enhance JPA entities for Hibernate</id>
<phase>process-test-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
<configuration>
<base>${project.build.directory}/hibernate/test-classes</base>
<dir>${project.build.directory}/hibernate/test-classes</dir>
<failOnError>true</failOnError>
<enableAssociationManagement>true</enableAssociationManagement>
<enableDirtyTracking>true</enableDirtyTracking>
<enableExtendedEnhancement>true</enableExtendedEnhancement>
<enableLazyInitialization>true</enableLazyInitialization>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExclude>io.helidon.integrations.cdi:helidon-integrations-cdi-hibernate</classpathDependencyExclude>
<classpathDependencyExclude>org.hibernate:hibernate-core</classpathDependencyExclude>
</classpathDependencyExcludes>
<reportNameSuffix>eclipselink</reportNameSuffix>
<skip>true</skip>
<systemPropertyVariables>
<java.util.logging.config.file>${project.basedir}/src/test/logging.properties</java.util.logging.config.file>
</systemPropertyVariables>
<testClassesDirectory>${project.build.directory}/eclipselink/test-classes</testClassesDirectory>
</configuration>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<skip>false</skip>
</configuration>
</execution>
<execution>
<id>default-test</id>
<configuration>
<skip>false</skip>
</configuration>
</execution>
<execution>
<id>hibernate</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExclude>io.helidon.integrations.cdi:helidon-integrations-cdi-eclipselink</classpathDependencyExclude>
<classpathDependencyExclude>org.eclipse.persistence:org.eclipse.persistence.jpa</classpathDependencyExclude>
</classpathDependencyExcludes>
<reportNameSuffix>hibernate</reportNameSuffix>
<skip>false</skip>
<testClassesDirectory>${project.build.directory}/hibernate/test-classes</testClassesDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class ConditionallyCloseableConnection extends DelegatingConnection {
*/
@Override
public void close() throws SQLException {
if (!this.isClosed() && this.isCloseable()) {
if (this.isCloseable()) {
assert !this.isClosed();
this.reset();
super.close();
this.closed();
Expand Down Expand Up @@ -193,8 +194,9 @@ public final void setCloseable(final boolean closeable) {
* operation is actually going to take place.
*
* <p>The default implementation of this method calls {@link
* #setCloseable(boolean)} with {@code true} as a parameter
* value.</p>
* #setCloseable(boolean)} with {@code true} as a parameter value
* ensuring that the actual {@link Connection#close()} operation
* will not be blocked or reimplemented in any way.</p>
*
* <p>Overrides must not call the {@link #close()} method or
* undefined behavior will result.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ final class JtaDataSource extends AbstractDataSource implements Synchronization

private final DataSource delegate;

private final String dataSourceName;

private final TransactionManager transactionManager;


Expand All @@ -78,9 +80,11 @@ final class JtaDataSource extends AbstractDataSource implements Synchronization


JtaDataSource(final DataSource delegate,
final String dataSourceName,
final TransactionManager transactionManager) {
super();
this.delegate = Objects.requireNonNull(delegate);
this.dataSourceName = dataSourceName;
this.transactionManager = Objects.requireNonNull(transactionManager);
}

Expand Down Expand Up @@ -137,21 +141,29 @@ public void afterCompletion(final int status) {
break;
}

// Get all of the TransactionSpecificConnections we have
// released into the world via our getConnection() and
// getConnection(String, String) methods, and inform them that
// the transaction is over. Then remove them from the map
// since the transaction is over. These particular
// Connections out in the world will not participate in future
// JTA transactions, even if such transactions are started on
// this thread.
@SuppressWarnings("unchecked")
final Map<?, ? extends TransactionSpecificConnection> connectionMap =
final Map<?, ? extends TransactionSpecificConnection> myThreadLocalConnectionMap =
(Map<?, ? extends TransactionSpecificConnection>) CONNECTION_STORAGE.get().get(this);

if (connectionMap != null && !connectionMap.isEmpty()) {
final Collection<? extends TransactionSpecificConnection> connections = connectionMap.values();
assert connections != null;
if (myThreadLocalConnectionMap != null && !myThreadLocalConnectionMap.isEmpty()) {
final Collection<? extends TransactionSpecificConnection> myConnections = myThreadLocalConnectionMap.values();
assert myConnections != null;
try {
if (badStatusException != null) {
throw badStatusException;
} else {
complete(connections, consumer);
complete(myConnections, consumer);
}
} finally {
connections.clear();
myConnections.clear();
}
}
}
Expand All @@ -174,6 +186,15 @@ public void afterCompletion(final int status) {
* closed if a caller has requested their closing prior to this
* method executing.</p>
*
* <p>If a user has not requested their closing prior to this
* method executing, the {@link TransactionSpecificConnection}s
* will not be closed, but will become closeable by the end user
* (allowing them to be released back to any backing connection
* pool that might exist). They will no longer take part in any
* new JTA transactions from this point forward (a new {@link
* Connection} will have to be acquired while a JTA transaction is
* active for that behavior).</p>
*
* @param connections an {@link Iterable} of {@link
* TransactionSpecificConnection} instances; may be {@code null}
* in which case no action will be taken
Expand Down Expand Up @@ -457,7 +478,6 @@ private Connection getConnection(final String username,
if (status == Status.STATUS_ACTIVE) {
final Map<JtaDataSource, Map<Object, TransactionSpecificConnection>> connectionStorageMap = CONNECTION_STORAGE.get();
assert connectionStorageMap != null;
// @SuppressWarnings("unchecked")
Map<Object, TransactionSpecificConnection> myConnectionMap = connectionStorageMap.get(this);
if (myConnectionMap == null) {
myConnectionMap = new HashMap<>();
Expand All @@ -479,7 +499,7 @@ private Connection getConnection(final String username,
}
myConnectionMap.put(id, tsc);
} else {
tsc.resetCloseCalled();
tsc.setCloseCalled(false);
}
returnValue = tsc;
} else if (useZeroArgumentForm) {
Expand Down Expand Up @@ -525,7 +545,8 @@ private static final class TransactionSpecificConnection extends ConditionallyCl
private boolean closeCalled;

private TransactionSpecificConnection(final Connection delegate) throws SQLException {
super(delegate, false);
super(delegate, false /* not closeable */);
assert !this.isCloseable();
this.oldAutoCommit = this.getAutoCommit();
this.setAutoCommit(false);
}
Expand All @@ -536,16 +557,16 @@ private void restoreAutoCommit() throws SQLException {

@Override
public void close() throws SQLException {
this.closeCalled = true;
this.setCloseCalled(true);
super.close();
}

private boolean isCloseCalled() throws SQLException {
return this.closeCalled || this.isClosed();
}

private void resetCloseCalled() {
this.closeCalled = false;
private void setCloseCalled(final boolean closeCalled) {
this.closeCalled = closeCalled;
}

}
Expand Down
Loading