Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
java-version: ${{ matrix.java_version }}
distribution: 'zulu'
- name: Maven cache
uses: actions/cache@v2
uses: actions/cache@v4
env:
cache-name: maven-cache
with:
Expand Down
2 changes: 1 addition & 1 deletion ebean-datasource-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-datasource-parent</artifactId>
<groupId>io.ebean</groupId>
<version>9.3-SNAPSHOT</version>
<version>9.3-FOC4-SNAPSHOT</version>
</parent>

<artifactId>ebean-datasource-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,27 @@ default DataSourceBuilder initDatabaseForPlatform(String platform) {
*/
DataSourceBuilder loadSettings(Properties properties, String poolName);


/**
* When enabled, the datasource enforces a clean close. This means, if you close a possible dirty
* connection, that was not committed or rolled back, an exception is thrown.
* <p>
* When disabled, the situation is logged as warning.
* <p>
* This option has no effect on readonly or autocommit connections.
* <p>
* Note: It is recommended to enable this option in tests/test systems to find possible
* programming errors. See https://github.com/ebean-orm/ebean-datasource/issues/116 for details.
*/
DataSourceBuilder enforceCleanClose(boolean enforceCleanClose);

/**
* When <code>true</code>, an exception is thrown when a dirty connection is closed.
* <p>
* See {@link #enforceCleanClose(boolean)}.
*/
boolean enforceCleanClose();

/**
* The settings of the DataSourceBuilder. Provides getters/accessors
* to read the configured properties of this DataSourceBuilder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class DataSourceConfig implements DataSourceBuilder.Settings {
private String applicationName;
private boolean shutdownOnJvmExit;
private boolean validateOnHeartbeat = !System.getenv().containsKey("LAMBDA_TASK_ROOT");
private boolean enforceCleanClose;

@Override
public Settings settings() {
Expand Down Expand Up @@ -144,6 +145,7 @@ public DataSourceConfig copy() {
copy.initSql = initSql;
copy.alert = alert;
copy.listener = listener;
copy.enforceCleanClose = enforceCleanClose;
return copy;
}

Expand Down Expand Up @@ -798,6 +800,8 @@ private void loadSettings(ConfigPropertiesHelper properties) {
offline = properties.getBoolean("offline", offline);
shutdownOnJvmExit = properties.getBoolean("shutdownOnJvmExit", shutdownOnJvmExit);
validateOnHeartbeat = properties.getBoolean("validateOnHeartbeat", validateOnHeartbeat);
enforceCleanClose = properties.getBoolean("enforceCleanClose", enforceCleanClose);


String isoLevel = properties.get("isolationLevel", _isolationLevel(isolationLevel));
this.isolationLevel = _isolationLevel(isoLevel);
Expand Down Expand Up @@ -846,6 +850,17 @@ Map<String, String> parseCustom(String customProperties) {
return propertyMap;
}

@Override
public DataSourceBuilder enforceCleanClose(boolean enforceCleanClose) {
this.enforceCleanClose = enforceCleanClose;
return this;
}

@Override
public boolean enforceCleanClose() {
return enforceCleanClose;
}

/**
* Return the isolation level description from the associated Connection int value.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ static DataSourceBuilder builder() {
*/
SQLException dataSourceDownReason();

int forceTrim(int trimCount);

/**
* Set a new maximum size.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,37 @@
*/
public interface DataSourcePoolListener {

/**
* Called before a connection has been created
*/
default void onBeforeCreateConnection() {}

/**
* Called after a connection has been created
*/
default void onAfterCreateConnection(Connection connection) {}

/**
* Called before a connection has been retrieved from the connection pool
*/
default void onBeforeBorrowConnection() {}

/**
* Called after a connection has been retrieved from the connection pool
*/
void onAfterBorrowConnection(Connection connection);
default void onAfterBorrowConnection(Connection connection) {}

/**
* Called before a connection will be put back to the connection pool
*/
void onBeforeReturnConnection(Connection connection);
default void onBeforeReturnConnection(Connection connection) {}

/**
* Called after a connection will be put back to the connection pool
*/
default void onAfterReturnConnection() {}

default void onBeforeCloseConnection(Connection connection) {}

default void onAfterCloseConnection() {}
}
20 changes: 17 additions & 3 deletions ebean-datasource/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.ebean</groupId>
<artifactId>ebean-datasource-parent</artifactId>
<version>9.3-SNAPSHOT</version>
<version>9.3-FOC4-SNAPSHOT</version>
</parent>

<artifactId>ebean-datasource</artifactId>
Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-datasource-api</artifactId>
<version>9.3-SNAPSHOT</version>
<version>9.3-FOC4-SNAPSHOT</version>
</dependency>

<dependency>
Expand All @@ -29,7 +29,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test-containers</artifactId>
<version>7.3</version>
<version>7.6</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -76,6 +76,20 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>11.5.9.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>3.5.1</version>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.ebean.datasource.pool;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* A buffer especially designed for Busy PooledConnections.
Expand Down Expand Up @@ -82,9 +84,10 @@ boolean remove(PooledConnection pc) {
}

/**
* Close connections that should be considered leaked.
* Remove connections that should be considered leaked.
*/
void closeBusyConnections(long leakTimeMinutes) {
List<PooledConnection> removeBusyConnections(long leakTimeMinutes) {
List<PooledConnection> busyConnections = null;
long olderThanTime = System.currentTimeMillis() - (leakTimeMinutes * 60000);
Log.debug("Closing busy connections using leakTimeMinutes {0}", leakTimeMinutes);
for (int i = 0; i < slots.length; i++) {
Expand All @@ -98,20 +101,14 @@ void closeBusyConnections(long leakTimeMinutes) {
} else {
slots[i] = null;
--size;
closeBusyConnection(pc);
if (busyConnections == null) {
busyConnections = new ArrayList<>();
}
busyConnections.add(pc);
}
}
}
}

private void closeBusyConnection(PooledConnection pc) {
try {
Log.warn("DataSource closing busy connection? {0}", pc.fullDescription());
System.out.println("CLOSING busy connection: " + pc.fullDescription());
pc.closeConnectionFully(false);
} catch (Exception ex) {
Log.error("Error when closing potentially leaked connection " + pc.description(), ex);
}
return busyConnections;
}

/**
Expand Down
Loading