diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9533ff3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,24 @@ +name: CI + +on: + push: + branches: + - 1.0.x + workflow_dispatch: + pull_request: + branches: + - 1.0.x + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Ballerina Build + uses: ballerina-platform/ballerina-action/@slalpha5 + with: + args: + build -c --skip-tests + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b3f4c6e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,26 @@ +name: Deployment + +on: + release: + types: [published] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Ballerina Build + uses: ballerina-platform/ballerina-action/@slalpha5 + with: + args: + build -c --skip-tests + - name: Ballerina Push + uses: ballerina-platform/ballerina-action/@slalpha5 + with: + args: + push + env: + BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }} + diff --git a/.gitignore b/.gitignore index a1c2a23..179819f 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,25 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* + +# Target folder of ballerina project +/target/* + +# resources folder +/resources/* + +# idea files +*.idea +*.iml + +# .ballerina files +*.ballerina + +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build + +# +*.log diff --git a/Ballerina.toml b/Ballerina.toml new file mode 100644 index 0000000..76df54a --- /dev/null +++ b/Ballerina.toml @@ -0,0 +1,16 @@ +[package] +org="ballerinax" +name="mssql.driver" +version="1.0.0" +authors=["Ballerina"] +keywords=["MSSQL", "SQL Server"] +repository="https://github.com/ballerina-platform/module-ballerinax-mssql.driver" +license=["Apache-2.0"] + +[[platform.java11.dependency]] +groupId = "com.microsoft.sqlserver" +artifactId = "mssql-jdbc" +version = "9.4.0.jre11" + +[build-options] +observabilityIncluded = true diff --git a/Package.md b/Package.md new file mode 100644 index 0000000..098277c --- /dev/null +++ b/Package.md @@ -0,0 +1,18 @@ +## Package overview + +This Package bundles the latest MSSQL driver so that the mssql connector can be used in ballerina projects easily. + +## Compatibility + +Ballerina Language Version **Swan Lake Alpha 5** +MSSQL Driver Version **9.4.0.jre11** + +## Usage + +To add the MSSQL driver dependency the project simply import the module as below, + +```ballerina +import ballerina/sql; +import ballerinax/mssql; +import ballerinax/mssql.driver as _; +``` \ No newline at end of file diff --git a/README.md b/README.md index 3ff663e..131c9c8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,45 @@ -# module-ballerinax-mssql.driver -Ballerina MSSQL DB Driver +Ballerina MSSQL Driver Library +=================== + +The MSSQL Driver library is one of the external library packages of the Ballerina language. + +This Package bundles the latest MSSQL driver so that the mssql connector can be used in ballerina projects easily. + +# Building from the Source +## Setting Up the Prerequisites + +1. Download and install Java SE Development Kit (JDK) version 11 (from one of the following locations). + + * [Oracle](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html) + + * [OpenJDK](https://adoptopenjdk.net/) + + > **Note:** Set the JAVA_HOME environment variable to the path name of the directory into which you installed JDK. + +2. Download and install [Ballerina SL Alpha 5](https://ballerina.io/). + +## Building the Source + +Execute the commands below to build from the source after installing Ballerina Swan Lake Alpha 5 version. + +1. To build the library: + ```shell script + bal build + ``` + +2. To build the module without the tests: + ```shell script + bal build --skip-tests + ``` +# Contributing to Ballerina +As an open source project, Ballerina welcomes contributions from the community. + +For more information, go to the [contribution guidelines](https://github.com/ballerina-platform/ballerina-lang/blob/main/CONTRIBUTING.md). + +# Code of Conduct +All contributors are encouraged to read the [Ballerina Code of Conduct](https://ballerina.io/code-of-conduct). + +# Useful Links +* Chat live with us via our [Slack channel](https://ballerina.io/community/slack/). +* Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag. \ No newline at end of file diff --git a/client.bal b/client.bal new file mode 100644 index 0000000..3fd1f38 --- /dev/null +++ b/client.bal @@ -0,0 +1,18 @@ +// 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 ballerina/jballerina.java as _; + diff --git a/tests/connection-init-test.bal b/tests/connection-init-test.bal new file mode 100644 index 0000000..30399ec --- /dev/null +++ b/tests/connection-init-test.bal @@ -0,0 +1,66 @@ +// 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 ballerina/sql; +import ballerinax/java.jdbc; +import ballerina/test; + +string url = "jdbc:sqlserver://localhost:1433;"; +string user = "sa"; +string password = "Test123#"; + +@test:Config { + groups: ["connection", "connection-init"] +} +function testWithURLParams() returns error? { + jdbc:Client dbClient = check new (url, user, password); + sql:Error? closeResult = dbClient.close(); + test:assertExactEquals(closeResult, (), "Initialising connection with params fails."); +} + +@test:Config { + groups: ["connection", "connection-init"] +} +function testWithConnectionPool() returns error? { + sql:ConnectionPool connectionPool = { + maxOpenConnections: 25, + maxConnectionLifeTime : 15, + minIdleConnections : 15 + }; + jdbc:Client dbClient = check new (url = url, user = user, password = password, connectionPool = connectionPool); + sql:Error? closeResult = dbClient.close(); + test:assertExactEquals(closeResult, (), "Initialising connection with option max connection pool fails."); + test:assertEquals(connectionPool.maxOpenConnections, 25, "Configured max connection config is wrong."); + test:assertEquals(connectionPool.maxConnectionLifeTime, 15, "Configured max connection life time second is wrong."); + test:assertEquals(connectionPool.minIdleConnections, 15, "Configured min idle connection is wrong."); +} + +@test:Config { + groups: ["connection", "connection-init"] +} +function testWithClosedClient1() returns error? { + jdbc:Client dbClient = check new (url = url, user = user, password = password); + sql:Error? closeResult = dbClient.close(); + test:assertExactEquals(closeResult, (), "Initialising connection with connection params fails."); + sql:ExecutionResult|sql:Error result = dbClient->execute(`CREATE TABLE test (id int)`); + if (result is sql:Error) { + string expectedErrorMessage = "SQL Client is already closed, hence further operations are not allowed"; + test:assertTrue(result.message().startsWith(expectedErrorMessage), + "Error message does not match, actual :\n'" + result.message() + "'\nExpected : \n" + expectedErrorMessage); + } else { + test:assertFail("Error expected"); + } +} +