Skip to content

Commit

Permalink
Merge pull request #591 from niveathika/update4
Browse files Browse the repository at this point in the history
Sync update4 branch with master
  • Loading branch information
niveathika authored Nov 29, 2022
2 parents addd057 + 29217cc commit 1b9a683
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 43 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
branches:
- master
- 2201.[0-9]+.x
- update4

jobs:
ubuntu-build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
branches:
- master
paths:
- 'docs/spec'
- 'docs/spec/**'

jobs:
update_specs:
Expand Down
6 changes: 3 additions & 3 deletions ballerina/connection-pool.bal
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ configurable int minIdleConnections = 15;
# Includes both idle and in-use connections. The default value is 15. This can be changed through
# the configuration API with the `ballerina.sql.maxOpenConnections` key
# + maxConnectionLifeTime - The maximum lifetime (in seconds) of a connection in the pool. The default value is 1800
# seconds (30 minutes). This can be changed through the configuration API with the
# `ballerina.sql.maxConnectionLifeTime` key. A value of 0 indicates an unlimited maximum
# lifetime (infinite lifetime)
# seconds (30 minutes). A value of 0 indicates an unlimited maximum lifetime (infinite lifetime).
# The minimum allowed value is 30 seconds. This can be changed through the configuration API
# with the `ballerina.sql.maxConnectionLifeTime` key.
# + minIdleConnections - The minimum number of idle connections that the pool tries to maintain. The default value
# is the same as `maxOpenConnections` and it can be changed through the configuration
# API with the `ballerina.sql.minIdleConnections` key
Expand Down
3 changes: 2 additions & 1 deletion ballerina/tests/connection-init-test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ function testWithConnectionPoolNegative() returns error? {
};
err = new (url = connectDB, user = user, password = password, connectionPool = connectionPool);
if err is error {
test:assertEquals(err.message(), "Error in SQL connector configuration: ConnectionPool field 'maxConnectionLifeTime' cannot be less than 30s.");
test:assertEquals(err.message(), "Error in SQL connector configuration: ConnectionPool field " +
"'maxConnectionLifeTime' can either be 0 or greater than or equal to 30.");
} else {
test:assertFail("Connection should fail with negative value");
}
Expand Down
4 changes: 3 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- [Remove SQL_901 diagnostic hint](https://github.com/ballerina-platform/ballerina-standard-library/issues/3609)

## [1.6.0]
## [1.6.0] - 2022-11-29

### Changed
- [Updated API Docs](https://github.com/ballerina-platform/ballerina-standard-library/issues/3463)
- [Fix unable to set unlimited lifetime (0) to ballerina.sql.maxConnectionLifeTime](https://github.com/ballerina-platform/ballerina-standard-library/issues/3657)
- [Improve error message on client connection failure](https://github.com/ballerina-platform/ballerina-standard-library/issues/3648)

## [1.5.0] - 2022-09-08

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,27 @@ public void testInvalidConnectionParamConfig() {
.collect(Collectors.toList());
long availableErrors = errorDiagnosticsList.size();

Assert.assertEquals(availableErrors, 4);
Assert.assertEquals(availableErrors, 5);

DiagnosticInfo maxOpenConnectionZero = errorDiagnosticsList.get(0).diagnosticInfo();
Assert.assertEquals(maxOpenConnectionZero.code(), SQLDiagnosticsCodes.SQL_101.getCode());
Assert.assertEquals(maxOpenConnectionZero.messageFormat(),
"invalid value: expected value is greater than one");
Assert.assertEquals(maxOpenConnectionZero.messageFormat(), SQLDiagnosticsCodes.SQL_101.getMessage());

DiagnosticInfo maxConnectionLifeTime = errorDiagnosticsList.get(1).diagnosticInfo();
Assert.assertEquals(maxConnectionLifeTime.code(), SQLDiagnosticsCodes.SQL_103.getCode());
Assert.assertEquals(maxConnectionLifeTime.messageFormat(),
"invalid value: expected value is greater than or equal to 30");
Assert.assertEquals(maxConnectionLifeTime.messageFormat(), SQLDiagnosticsCodes.SQL_103.getMessage());

DiagnosticInfo minIdleConnections = errorDiagnosticsList.get(2).diagnosticInfo();
Assert.assertEquals(minIdleConnections.code(), SQLDiagnosticsCodes.SQL_102.getCode());
Assert.assertEquals(minIdleConnections.messageFormat(),
"invalid value: expected value is greater than zero");
Assert.assertEquals(minIdleConnections.messageFormat(), SQLDiagnosticsCodes.SQL_102.getMessage());

DiagnosticInfo maxOpenConnectionNegative = errorDiagnosticsList.get(3).diagnosticInfo();
Assert.assertEquals(maxOpenConnectionNegative.code(), SQLDiagnosticsCodes.SQL_101.getCode());
Assert.assertEquals(maxOpenConnectionNegative.messageFormat(),
"invalid value: expected value is greater than one");
Assert.assertEquals(maxOpenConnectionNegative.messageFormat(), SQLDiagnosticsCodes.SQL_101.getMessage());

DiagnosticInfo maxConnectionLifeTimeNegative = errorDiagnosticsList.get(4).diagnosticInfo();
Assert.assertEquals(maxConnectionLifeTimeNegative.code(), SQLDiagnosticsCodes.SQL_103.getCode());
Assert.assertEquals(maxConnectionLifeTimeNegative.messageFormat(), SQLDiagnosticsCodes.SQL_103.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@ public function main() {
minIdleConnections: 0
};

ConnectionPool pool5 = {
sql:ConnectionPool pool5 = {
maxConnectionLifeTime: 0
};

ConnectionPool pool6 = {
connection: 0
};

sql:ConnectionPool pool7 = {
maxConnectionLifeTime: -5
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public enum SQLDiagnosticsCodes {
SQL_101("SQL_101", "invalid value: expected value is greater than one", ERROR),
SQL_102("SQL_102", "invalid value: expected value is greater than zero", ERROR),
SQL_103("SQL_103", "invalid value: expected value is greater than or equal to 30", ERROR),
SQL_103("SQL_103", "invalid value: expected value is either 0 or greater than or equal to 30", ERROR),

// Out parameter return type validations diagnostics
SQL_201("SQL_201", "invalid value: expected value is array", ERROR),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void perform(SyntaxNodeAnalysisContext ctx) {
break;
case Constants.ConnectionPool.MAX_CONNECTION_LIFE_TIME:
float maxConnectionTime = Float.parseFloat(getTerminalNodeValue(valueNode, "30"));
if (maxConnectionTime < 30) {
if (maxConnectionTime < 0 || (maxConnectionTime > 0 && maxConnectionTime < 30)) {
DiagnosticInfo diagnosticInfo = new DiagnosticInfo(SQL_103.getCode(), SQL_103.getMessage(),
SQL_103.getSeverity());
ctx.reportDiagnostic(
Expand Down
36 changes: 18 additions & 18 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@ ballerinaLangVersion=2201.4.0-20221104-003000-4b73c40e

# Direct Dependencies
# Level 01
stdlibIoVersion=1.3.1-20221013-104400-2228262
stdlibRegexVersion=1.3.1-20221012-141600-b6ec370
stdlibTimeVersion=2.2.3-20221013-110700-b1911b4
stdlibIoVersion=1.3.1
stdlibRegexVersion=1.3.1
stdlibTimeVersion=2.2.3

# Level 02
stdlibLogVersion=2.5.0-20221022-095900-123270e
stdlibOsVersion=1.5.0-20221021-114000-e41fc65
stdlibLogVersion=2.5.0
stdlibOsVersion=1.5.0

# Level 03
stdlibFileVersion=1.5.0-20221024-132900-beb9113
stdlibFileVersion=1.5.0

# Ballerinax Observer
observeVersion=1.0.5
observeInternalVersion=1.0.4

# Transitive Dependencies
# Level 01
stdlibConstraintVersion=1.0.1-20221012-153500-b7200cb
stdlibUrlVersion=2.2.3-20221012-145800-3753746
stdlibConstraintVersion=1.0.1
stdlibUrlVersion=2.2.3

# Level 02
stdlibCryptoVersion=2.3.0-20221021-111000-c691a43
stdlibTaskVersion=2.3.0-20221021-110900-987dd04
stdlibCryptoVersion=2.3.0
stdlibTaskVersion=2.3.0

# Level 03
stdlibCacheVersion=3.3.0-20221022-095100-c8edb87
stdlibMimeVersion=2.5.0-20221024-153000-72349b8
stdlibUuidVersion=1.4.0-20221021-123700-e798cd1
stdlibCacheVersion=3.3.0
stdlibMimeVersion=2.5.0
stdlibUuidVersion=1.4.0

# Level 04
stdlibAuthVersion=2.5.0-20221024-165000-28c7088
stdlibJwtVersion=2.5.0-20221024-160700-f5f0b5d
stdlibOAuth2Version=2.5.0-20221024-164100-e99fca0
stdlibAuthVersion=2.5.0
stdlibJwtVersion=2.5.0
stdlibOAuth2Version=2.5.0

# Level 05
stdlibHttpVersion=2.5.0-20221024-180400-6edb755
stdlibHttpVersion=2.5.0

# Level 06
stdlibTransactionVersion=1.3.0-20221024-190700-b39c1bc
stdlibTransactionVersion=1.3.0
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.ballerina.stdlib.sql.exception.ApplicationError;
import io.ballerina.stdlib.sql.transaction.SQLTransactionContext;
import io.ballerina.stdlib.sql.utils.ErrorGenerator;
import io.ballerina.stdlib.sql.utils.Utils;

import java.sql.Connection;
import java.sql.SQLException;
Expand Down Expand Up @@ -195,8 +196,11 @@ public static Connection getConnection(boolean isInTrx, TransactionResourceManag
conn = ((SQLTransactionContext) txContext).getConnection();
}
} catch (SQLException e) {
// The SQLException thrown here sometimes (by Hikari) does not contain adequate information to determine the
// actual cause of the connection failure. Hence, we would need to find and return the root cause.
SQLException rootSQLException = Utils.getRootSQLException(e);
throw new SQLException("error while getting the connection for " + Constants.CONNECTOR_NAME + ". "
+ e.getMessage(), e.getSQLState(), e.getErrorCode());
+ rootSQLException.getMessage(), rootSQLException.getSQLState(), rootSQLException.getErrorCode());
}
return conn;
}
Expand Down Expand Up @@ -328,13 +332,13 @@ private HikariDataSource buildNonXADataSource(SQLDatasourceParams sqlDatasourceP

Object connLifeTimeSec = sqlDatasourceParams.connectionPool
.get(Constants.ConnectionPool.MAX_CONNECTION_LIFE_TIME);
BDecimal connLifeTime = (BDecimal) connLifeTimeSec;
if (connLifeTime.floatValue() < 30) {
double connLifeTime = ((BDecimal) connLifeTimeSec).floatValue();
if (connLifeTime < 0 || (connLifeTime > 0 && connLifeTime < 30)) {
// Here if the connection life time is minimum 30s, the default value will be used
throw new ApplicationError(
"ConnectionPool field 'maxConnectionLifeTime' cannot be less than 30s.");
throw new ApplicationError("ConnectionPool field 'maxConnectionLifeTime' can either be 0 " +
"or greater than or equal to 30.");
}
long connLifeTimeMS = Double.valueOf(connLifeTime.floatValue() * 1000).longValue();
long connLifeTimeMS = Double.valueOf(connLifeTime * 1000).longValue();
config.setMaxLifetime(connLifeTimeMS);

int minIdleConnections = sqlDatasourceParams.connectionPool
Expand Down
12 changes: 12 additions & 0 deletions native/src/main/java/io/ballerina/stdlib/sql/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1337,4 +1337,16 @@ private static BMapInitialValueEntry[] getInitialValueEntries(Map<String, Object
}
return entries;
}

public static SQLException getRootSQLException(SQLException e) {
SQLException rootSQLException = e;
Throwable t = e.getCause();
while (t != null) {
if (t instanceof SQLException) {
rootSQLException = (SQLException) t;
}
t = t.getCause();
}
return rootSQLException;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
{
"name": "org.hsqldb.jdbc.JDBCCommonDataSource",
"methods": [
{
"name": "setLoginTimeout",
"parameterTypes": [
"int"
]
},
{
"name": "setPassword",
"parameterTypes": [
"java.lang.String"
]
},
{
"name": "setUrl",
"parameterTypes": [
"java.lang.String"
]
},
{
"name": "setUser",
"parameterTypes": [
"java.lang.String"
]
}
]
},
{
"name": "org.hsqldb.jdbc.JDBCDataSource",
"queryAllPublicMethods": true,
"methods": [
{
"name": "<init>",
"parameterTypes": []
}
]
},
{
"name": "org.hsqldb.jdbc.JDBCDriver"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"bundles": [
{
"name": "org.hsqldb.resources.sql-state-messages",
"locales": [
""
]
}
]
}

0 comments on commit 1b9a683

Please sign in to comment.