Skip to content

Commit

Permalink
Merge pull request #344 from kaneeldias/stage-1.2.1
Browse files Browse the repository at this point in the history
Patch release for JDBC 1.2.1
  • Loading branch information
kaneeldias authored Feb 3, 2022
2 parents b0e636b + 98b136e commit 8c9484c
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 14 deletions.
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
org = "ballerinax"
name = "java.jdbc"
version = "1.2.0"
version = "1.2.1"
authors = ["Ballerina"]
keywords = ["database", "client", "network", "SQL", "RDBMS", "JDBC"]
repository = "https://github.com/ballerina-platform/module-ballerinax-java.jdbc"
license = ["Apache-2.0"]
distribution = "slbeta6"

[[platform.java11.dependency]]
path = "../native/build/libs/java.jdbc-native-1.2.0.jar"
path = "../native/build/libs/java.jdbc-native-1.2.1.jar"

[[platform.java11.dependency]]
path = "./lib/sql-native-1.2.0.jar"
path = "./lib/sql-native-1.2.1.jar"
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "jdbc-compiler-plugin"
class = "io.ballerina.stdlib.java.jdbc.compiler.JDBCCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/java.jdbc-compiler-plugin-1.2.0.jar"
path = "../compiler-plugin/build/libs/java.jdbc-compiler-plugin-1.2.1.jar"
4 changes: 2 additions & 2 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "sql"
version = "1.2.0"
version = "1.2.1"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -364,7 +364,7 @@ modules = [
[[package]]
org = "ballerinax"
name = "java.jdbc"
version = "1.2.0"
version = "1.2.1"
dependencies = [
{org = "ballerina", name = "file"},
{org = "ballerina", name = "io"},
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

### Changed
- [Fix Compiler plugin crash when variable is passed for `sql:ConnectionPool`](https://github.com/ballerina-platform/ballerina-standard-library/issues/2536)

## [1.2.0] - 2021-12-13

### Changed
- Release module on top of Swan Lake Beta6 distribution

## [1.1.0] - 2021-11-20

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,17 @@ public void testSQLConnectionPoolFieldsInNewExpression() {
Assert.assertEquals(diagnostic.diagnosticInfo().messageFormat(), SQL_101.getMessage());
});
}

@Test
public void testSQLConnectionPoolFieldsInNewExpressionWVariables() {
Package currentPackage = loadPackage("sample3");
PackageCompilation compilation = currentPackage.getCompilation();
DiagnosticResult diagnosticResult = compilation.diagnosticResult();
List<Diagnostic> diagnosticErrorStream = diagnosticResult.diagnostics().stream()
.filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR))
.collect(Collectors.toList());
long availableErrors = diagnosticErrorStream.size();

Assert.assertEquals(availableErrors, 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
org = "jdbc_test"
name = "sample3"
version = "0.1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
//
// WSO2 Inc. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerinax/java.jdbc;

public function main() returns error? {

int connectionNum = 5;
int connectionNumInvalid = -5;

jdbc:Client dbClient1 = check new("url", connectionPool = {maxOpenConnections: connectionNum});
check dbClient1.close();

jdbc:Client dbClient2 = check new("url", (), (), {}, {maxOpenConnections: connectionNumInvalid});
check dbClient2.close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void perform(SyntaxNodeAnalysisContext ctx) {
ExpressionNode valueNode = ((SpecificFieldNode) field).valueExpr().get();
switch (name) {
case Constants.ConnectionPool.MAX_OPEN_CONNECTIONS:
int maxOpenConnections = Integer.parseInt(getTerminalNodeValue(valueNode));
int maxOpenConnections = Integer.parseInt(getTerminalNodeValue(valueNode, "1"));
if (maxOpenConnections < 1) {
DiagnosticInfo diagnosticInfo = new DiagnosticInfo(SQL_101.getCode(), SQL_101.getMessage(),
SQL_101.getSeverity());
Expand All @@ -110,7 +110,7 @@ public void perform(SyntaxNodeAnalysisContext ctx) {
}
break;
case Constants.ConnectionPool.MIN_IDLE_CONNECTIONS:
int minIdleConnection = Integer.parseInt(getTerminalNodeValue(valueNode));
int minIdleConnection = Integer.parseInt(getTerminalNodeValue(valueNode, "0"));
if (minIdleConnection < 0) {
DiagnosticInfo diagnosticInfo = new DiagnosticInfo(SQL_102.getCode(), SQL_102.getMessage(),
SQL_102.getSeverity());
Expand All @@ -120,7 +120,7 @@ public void perform(SyntaxNodeAnalysisContext ctx) {
}
break;
case Constants.ConnectionPool.MAX_CONNECTION_LIFE_TIME:
float maxConnectionTime = Float.parseFloat(getTerminalNodeValue(valueNode));
float maxConnectionTime = Float.parseFloat(getTerminalNodeValue(valueNode, "30"));
if (maxConnectionTime < 30) {
DiagnosticInfo diagnosticInfo = new DiagnosticInfo(SQL_103.getCode(), SQL_103.getMessage(),
SQL_103.getSeverity());
Expand All @@ -136,15 +136,16 @@ public void perform(SyntaxNodeAnalysisContext ctx) {
}
}

private String getTerminalNodeValue(Node valueNode) {
String value;
private String getTerminalNodeValue(Node valueNode, String defaultValue) {
String value = defaultValue;
if (valueNode instanceof BasicLiteralNode) {
value = ((BasicLiteralNode) valueNode).literalToken().text();
} else {
} else if (valueNode instanceof UnaryExpressionNode) {
UnaryExpressionNode unaryExpressionNode = (UnaryExpressionNode) valueNode;
value = unaryExpressionNode.unaryOperator() +
((BasicLiteralNode) unaryExpressionNode.expression()).literalToken().text();
}
// Currently we cannot process values from variables, this needs code flow analysis
return value.replaceAll(UNNECESSARY_CHARS_REGEX, "");
}

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=io.ballerina.stdlib
version=1.2.0
version=1.2.1

puppycrawlCheckstyleVersion=8.18
checkstyleToolVersion=7.8.2
Expand All @@ -12,7 +12,7 @@ testngVersion=7.4.0

ballerinaLangVersion=2.0.0-beta.6

stdlibSqlVersion=1.2.0
stdlibSqlVersion=1.2.1

stdlibIoVersion=1.1.0
stdlibRegexVersion=1.1.0
Expand Down

0 comments on commit 8c9484c

Please sign in to comment.