├── .github
└── workflows
│ ├── linux-dev.yml
│ ├── linux-release.yml
│ ├── mac-dev.yml
│ ├── mac-release.yml
│ └── windows.yml
├── .gitignore
├── README.md
├── build_dev.sh
├── docs
├── allclasses-frame.html
├── allclasses-noframe.html
├── constant-values.html
├── deprecated-list.html
├── help-doc.html
├── index-files
│ ├── index-1.html
│ ├── index-10.html
│ ├── index-11.html
│ ├── index-12.html
│ ├── index-13.html
│ ├── index-14.html
│ ├── index-15.html
│ ├── index-16.html
│ ├── index-17.html
│ ├── index-18.html
│ ├── index-19.html
│ ├── index-2.html
│ ├── index-20.html
│ ├── index-3.html
│ ├── index-4.html
│ ├── index-5.html
│ ├── index-6.html
│ ├── index-7.html
│ ├── index-8.html
│ └── index-9.html
├── index.html
├── org
│ └── monetdb
│ │ └── monetdbe
│ │ ├── MonetBlob.html
│ │ ├── MonetCallableStatement.html
│ │ ├── MonetClob.html
│ │ ├── MonetColumn.html
│ │ ├── MonetConnection.html
│ │ ├── MonetDatabaseMetaData.html
│ │ ├── MonetDriver.html
│ │ ├── MonetNative.html
│ │ ├── MonetParameterMetaData.html
│ │ ├── MonetPreparedStatement.html
│ │ ├── MonetResultSet.html
│ │ ├── MonetResultSetMetaData.html
│ │ ├── MonetStatement.html
│ │ ├── MonetTypes.html
│ │ ├── MonetWrapper.html
│ │ ├── package-frame.html
│ │ ├── package-summary.html
│ │ └── package-tree.html
├── overview-tree.html
├── package-list
├── script.js
└── stylesheet.css
├── example
├── ComplexTypes.java
├── ConnectionTypes.java
├── HelloWorld.java
├── InsertAndQuery.java
├── JDBC_API_Tester.java
├── Metadata.java
├── MgBench.java
├── Movies.java
├── MultiConnections.java
├── MultiThreadAccess.java
├── PreparedQueries.java
├── RemoteConnectionTests.java
├── SimpleTypes.java
├── Taxi.java
├── TestMonetDBeJava.java
└── UpdateCount.java
├── java
├── META-INF
│ └── services
│ │ └── java.sql.Driver
├── pom.xml
└── src
│ ├── main
│ └── java
│ │ └── org
│ │ └── monetdb
│ │ └── monetdbe
│ │ ├── MonetBlob.java
│ │ ├── MonetCallableStatement.java
│ │ ├── MonetClob.java
│ │ ├── MonetColumn.java
│ │ ├── MonetConnection.java
│ │ ├── MonetDatabaseMetaData.java
│ │ ├── MonetDriver.java
│ │ ├── MonetNative.java
│ │ ├── MonetParameterMetaData.java
│ │ ├── MonetPreparedStatement.java
│ │ ├── MonetResultSet.java
│ │ ├── MonetResultSetMetaData.java
│ │ ├── MonetStatement.java
│ │ ├── MonetTypes.java
│ │ └── MonetWrapper.java
│ └── test
│ └── java
│ └── test
│ ├── AllTests.java
│ ├── RunTestsApp.java
│ ├── Test_01_OpenAndCloseConnection.java
│ ├── Test_02_CloseConnectionTwice.java
│ ├── Test_03_AutoCommit.java
│ ├── Test_04_SimpleInsertAndQueryStatements.java
│ ├── Test_05_BasicInsertAndQueryStatements.java
│ ├── Test_06_ComplexInsertAndQueryStatements.java
│ ├── Test_07_SimplePreparedStatements.java
│ ├── Test_08_ComplexPreparedStatements.java
│ ├── Test_09_LoadAndQueryTaxi.java
│ ├── Test_10_MetaData.java
│ ├── Test_11_ConcurrentConnections.java
│ ├── Test_12_BatchesAndJoinsMovies.java
│ ├── Test_13_Schema.java
│ ├── Test_14_MultipleResultSet.java
│ ├── Test_15_Transactions.java
│ ├── Test_16_MixedOrderStatements.java
│ ├── Test_17_QueryInThread.java
│ ├── Test_18_Multithreaded_Connection.java
│ ├── Test_19_ParameterMetadata.java
│ ├── Test_20_PreparedResultMetadata.java
│ ├── Test_21_ConnectionOptions.java
│ ├── Test_22_GetObject.java
│ └── Test_23_LogFile.java
├── native
├── jni
│ ├── monetdbe-java-native.c
│ └── org_monetdb_monetdbe_MonetNative.h
└── pom.xml
└── run_dev.sh
/.github/workflows/linux-dev.yml:
--------------------------------------------------------------------------------
1 | name: Linux CI - Dev build (Docker default and Aug2024)
2 | on: [push, workflow_dispatch, pull_request]
3 |
4 | jobs:
5 | linux_docker_dev_build:
6 | name: linux_docker_dev_build
7 | runs-on: ubuntu-latest
8 | strategy:
9 | matrix:
10 | branch: [default, Aug2024, Dec2023]
11 | container: monetdb/dev-builds:${{ matrix.branch }}
12 | steps:
13 | - name: Checkout
14 | uses: actions/checkout@v4
15 | with:
16 | ref: "master"
17 | - name: Set up JDK 2.1
18 | uses: actions/setup-java@v4
19 | with:
20 | distribution: 'temurin'
21 | java-version: '21'
22 | cache: 'maven'
23 | cache-dependency-path: '*/pom.xml'
24 | - name: Setup Maven
25 | uses: stCarolas/setup-maven@v4
26 | - name: Build native part
27 | run: cd native; mvn clean install -DMonetDB_dir=/usr/local
28 | - name: Build java part
29 | run: cd java; mvn clean install
30 | - name: Run example class (SimpleTypes)
31 | run: $GITHUB_WORKSPACE/run_dev.sh SimpleTypes
32 |
33 | #- name: Install packages
34 | #run: apt-get install wget
35 | #- name: Set up test environment
36 | #run: |
37 | #mkdir -p $GITHUB_WORKSPACE/testdata/taxi $GITHUB_WORKSPACE/testdata/localdb
38 | #wget -O testdata/taxi/yellow_tripdata_2016-01.csv https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2016-01.csv
39 | #linux_manual_dev_build:
40 | # name: linux_manual_dev_build
41 | # runs-on: ubuntu-latest
42 | # steps:
43 | # - uses: actions/checkout@v2
44 | # - name: Set up JDK 1.8
45 | # uses: actions/setup-java@v1
46 | # with:
47 | # java-version: 1.8
48 | # - name: Setup Maven
49 | # uses: stCarolas/setup-maven@v4
50 | # - name: Get monetdb
51 | # run: |
52 | # hg clone http://dev.monetdb.org/hg/MonetDB/
53 | # - name: Compile and install MonetDB
54 | # run: |
55 | # cd MonetDB
56 | # mkdir build MonetDB-default
57 | # cd build
58 | # pwd
59 | # cmake ../ -DCMAKE_INSTALL_PREFIX=/home/runner/work/MonetDBe-Java/MonetDBe-Java/MonetDB/MonetDB-default/ -DPY3INTEGRATION=OFF -DWITH_CRYPTO=OFF -DCMAKE_BUILD_TYPE=Release -DASSERT=OFF -DRINTEGRATION=OFF -DINT128=ON -DSTRICT=OFF
60 | # make install
61 | # cd ../../
62 | # - name: Build with Maven
63 | # run: $GITHUB_WORKSPACE/build_dev.sh /home/runner/work/MonetDBe-Java/MonetDBe-Java/MonetDB/MonetDB-default
64 | # - name: Run example class (SimpleTypes)
65 | # run: $GITHUB_WORKSPACE/run_dev.sh SimpleTypes
66 |
--------------------------------------------------------------------------------
/.github/workflows/linux-release.yml:
--------------------------------------------------------------------------------
1 | name: ManyLinux CI - Release Slim and Fat Jar
2 | on: [workflow_dispatch]
3 |
4 | jobs:
5 | linux_jars:
6 | name: manylinux_jars
7 | runs-on: ubuntu-latest
8 | strategy:
9 | fail-fast: false
10 | matrix:
11 | container: ["monetdb/dev-builds:default_manylinux","monetdb/dev-builds:Aug2024_manylinux","monetdb/dev-builds:Dec2023_manylinux"]
12 | artifact: ["slim","fat"]
13 | include:
14 | - container: "monetdb/dev-builds:default_manylinux"
15 | artifact: "slim"
16 | mdb_version: "default"
17 | - container: "monetdb/dev-builds:default_manylinux"
18 | artifact: "fat"
19 | mdb_version: "default"
20 | - container: "monetdb/dev-builds:Aug2024_manylinux"
21 | artifact: "slim"
22 | mdb_version: "Aug2024"
23 | - container: "monetdb/dev-builds:Aug2024_manylinux"
24 | artifact: "fat"
25 | mdb_version: "Aug2024"
26 | - container: "monetdb/dev-builds:Dec2023_manylinux"
27 | artifact: "slim"
28 | mdb_version: "Dec2023"
29 | - container: "monetdb/dev-builds:Dec2023_manylinux"
30 | artifact: "fat"
31 | mdb_version: "Dec2023"
32 | container:
33 | image: ${{ matrix.container }}
34 | env:
35 | MDBE_JAVA_VERSION: "1.11-SNAPSHOT"
36 | MONETDB_INSTALL: /usr/local
37 | MDB_VERSION: ${{ matrix.mdb_version }}
38 | steps:
39 | - name: Checkout
40 | uses: actions/checkout@v3
41 | with:
42 | ref: "master"
43 |
44 | #Set global environment variables
45 | - name: Env variables (slim jar)
46 | if: ${{ matrix.artifact == 'slim' }}
47 | run: |
48 | echo "MVN_FLAGS=linux-slim" >> $GITHUB_ENV
49 | echo "ARTIFACT=monetdbe-java-${{ env.MDBE_JAVA_VERSION }}-linux-slim.jar" >> $GITHUB_ENV
50 | echo "M2_REPO=/root/.m2/repository/monetdb/monetdbe-java/${{ env.MDBE_JAVA_VERSION }}" >> $GITHUB_ENV+
51 | - name: Env variables (fat jar)
52 | if: ${{ matrix.artifact == 'fat' }}
53 | run: |
54 | echo "MVN_FLAGS=linux-slim,linux-fat" >> $GITHUB_ENV
55 | echo "ARTIFACT=monetdbe-java-${{ env.MDBE_JAVA_VERSION }}-linux-fat.jar" >> $GITHUB_ENV
56 | echo "M2_REPO=/root/.m2/repository/monetdb/monetdbe-java/${{ env.MDBE_JAVA_VERSION }}" >> $GITHUB_ENV
57 |
58 | #Java, maven, gpg and patchelf setup; set up test env
59 | - name: Set up JDK 1.8 and maven settings.xml
60 | uses: actions/setup-java@v1
61 | with:
62 | java-version: 1.8
63 | server-id: ossrh
64 | server-username: MVN_DEPLOY_USERNAME
65 | server-password: MVN_DEPLOY_PASSWORD
66 | gpg-passphrase: MVN_GPG_PASSPHRASE
67 | settings-path: /root/.m2/
68 | - name: Setup Maven
69 | uses: stCarolas/setup-maven@v4
70 | with:
71 | maven-version: 3.6.3
72 | - name: Install packages
73 | run: yum install -y patchelf chrpath wget
74 | #- name: Import GPG private key for maven release (for sign-maven-plugin)
75 | # run: |
76 | # touch /root/.m2/sign-key.asc
77 | # echo -e "${{ secrets.MVN_GPG_PRIVATE_KEY_SIMPLIFY }}" > /root/.m2/sign-key.asc
78 | - name: Set up test environment
79 | run: |
80 | mkdir -p $GITHUB_WORKSPACE/testdata/taxi $GITHUB_WORKSPACE/testdata/localdb
81 | wget -O testdata/taxi/yellow_tripdata_2016-01.csv https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2016-01.csv
82 | #Install native library; collect library dependencies
83 | - name: Install native library (libmonetdbe-java.dylib)
84 | run: |
85 | cd native
86 | mvn clean install -DMonetDB_dir=$MONETDB_INSTALL -P linux-release --no-transfer-progress
87 | cd ..
88 | - name: Collect direct dependencies
89 | run: |
90 | mkdir collect_libs
91 | cp $MONETDB_LIBS/libbat.so.?? $MONETDB_LIBS/libmapi.so.?? $MONETDB_LIBS/libmonetdb5.so.?? $MONETDB_LIBS/libmonetdbe.so.? $MONETDB_LIBS/libmonetdbsql.so.?? $MONETDB_LIBS/libstream.so.?? collect_libs
92 | env:
93 | MONETDB_LIBS: ${{ env.MONETDB_INSTALL }}/lib64
94 | - name: Change rpath of MonetDB libraries to package
95 | run: |
96 | ldd $GITHUB_WORKSPACE/collect_libs/*
97 | for file in $GITHUB_WORKSPACE/collect_libs/*; do chrpath -r \$\ORIGIN/. $file; done
98 | ldd $GITHUB_WORKSPACE/collect_libs/*
99 | - name: Collect transitive dependencies (only for fat jar)
100 | if: ${{ matrix.artifact == 'fat' }}
101 | run: cp /lib64/libz.so.1 /lib64/libpcre.so.1 collect_libs
102 |
103 | #Package jar, test and deploy
104 | - name: Compile Java, package into jar, do unit tests and deploy
105 | run: |
106 | cd java
107 | mvn clean install -DCOLLECT_LIBS=$GITHUB_WORKSPACE/collect_libs -P ${{ env.MVN_FLAGS }} --no-transfer-progress
108 | cd ..
109 | env:
110 | MVN_DEPLOY_USERNAME: monetdb
111 | MVN_DEPLOY_PASSWORD: ${{ secrets.MVN_DEPLOY_PASSWORD }}
112 | MVN_GPG_PRIVATE_KEY: ${{ secrets.MVN_GPG_PRIVATE_KEY }}
113 | MVN_GPG_PASSPHRASE: ${{ secrets.MVN_GPG_PASSPHRASE }}
114 |
115 | #Run example and publish jar
116 | - name: Run example class (SimpleTypes)
117 | run: |
118 | javac -cp ${{env.M2_REPO}}/${{env.ARTIFACT}} example/SimpleTypes.java
119 | java -cp ${{env.M2_REPO}}/${{env.ARTIFACT}}:example/ SimpleTypes
120 |
121 | - name: Publish error log
122 | if: ${{ failure() }}
123 | uses: actions/upload-artifact@v2
124 | with:
125 | name: hs_err.log
126 | path: /__w/MonetDBe-Java/MonetDBe-Java/hs_err_pid*.log
127 | - name: Publish Linux jar
128 | uses: actions/upload-artifact@v2
129 | if: always()
130 | with:
131 | name: ${{ env.MDB_VERSION }}-${{env.ARTIFACT}}
132 | path: ${{env.M2_REPO}}/${{env.ARTIFACT}}
133 |
--------------------------------------------------------------------------------
/.github/workflows/mac-dev.yml:
--------------------------------------------------------------------------------
1 | name: MacOS CI - Dev build (from Homebrew)
2 | on: [push, workflow_dispatch, pull_request]
3 |
4 | jobs:
5 | mac_brew_dev_build:
6 | name: mac_brew_dev_build
7 | runs-on: macos-latest
8 | steps:
9 | - uses: actions/checkout@v4
10 | with:
11 | ref: "master"
12 | - name: Set up JDK 2.1
13 | uses: actions/setup-java@v4
14 | with:
15 | distribution: 'temurin'
16 | java-version: '21'
17 | cache: 'maven'
18 | cache-dependency-path: '*/pom.xml'
19 | - name: Setup Maven
20 | uses: stCarolas/setup-maven@v4
21 | - name: Install monetdb through brew
22 | run: brew install monetdb
23 | #- name: Set up test environment
24 | #run: |
25 | # mkdir -p $GITHUB_WORKSPACE/testdata/taxi $GITHUB_WORKSPACE/testdata/localdb
26 | # wget -O testdata/taxi/yellow_tripdata_2016-01.csv https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2016-01.csv
27 | - name: Build native part
28 | run: cd native; mvn clean install -DMonetDB_dir=/opt/homebrew
29 | - name: Build java part
30 | run: cd java; mvn clean install
31 | #- name: Build with Maven and test
32 | #run: $GITHUB_WORKSPACE/build_dev.sh /usr/local false
33 | - name: Run example class (SimpleTypes)
34 | run: $GITHUB_WORKSPACE/run_dev.sh SimpleTypes
35 | mac_manual_dev_build:
36 | name: mac_manual_dev_build
37 | runs-on: macos-latest
38 | steps:
39 | - uses: actions/checkout@v4
40 | - name: Set up JDK 2.1
41 | uses: actions/setup-java@v4
42 | with:
43 | distribution: 'temurin'
44 | java-version: '21'
45 | cache: 'maven'
46 | cache-dependency-path: '*/pom.xml'
47 | - name: Setup Maven
48 | uses: stCarolas/setup-maven@v4
49 | - name: Get brew bison
50 | run: brew install bison
51 | - name: Get monetdb
52 | run: git clone https://github.com/MonetDB/MonetDB
53 | - name: Compile and install MonetDB
54 | run: |
55 | export CMAKE_LIBRARY_PATH="/opt/homebrew/opt/bison/lib"
56 | export PATH="/opt/homebrew/opt/bison/bin/:$PATH"
57 | export LDFLAGS="-L/opt/homebrew/opt/bison/lib/"
58 | cd MonetDB
59 | mkdir build MonetDB-default
60 | cd build
61 | cmake ../ -DCMAKE_INSTALL_PREFIX=/Users/runner/work/MonetDBe-Java/MonetDBe-Java/MonetDB/MonetDB-default/ -DPY3INTEGRATION=OFF -DCMAKE_BUILD_TYPE=Release -DASSERT=OFF -DRINTEGRATION=OFF
62 | make install
63 | cd ../../
64 | #- name: Set up test environment
65 | #run: |
66 | #mkdir -p $GITHUB_WORKSPACE/testdata/taxi $GITHUB_WORKSPACE/testdata/localdb
67 | #wget -O testdata/taxi/yellow_tripdata_2016-01.csv https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2016-01.csv
68 | - name: Build native part
69 | run: cd native; mvn clean install -DMonetDB_dir=$GITHUB_WORKSPACE/MonetDB/MonetDB-default/
70 | - name: Build java part
71 | run: cd java; mvn clean install
72 |
73 | #- name: Build with Maven and test
74 | #run: $GITHUB_WORKSPACE/build_dev.sh $GITHUB_WORKSPACE/MonetDB/MonetDB-default/ false
75 | - name: Run example class (SimpleTypes)
76 | run: $GITHUB_WORKSPACE/run_dev.sh SimpleTypes
77 |
--------------------------------------------------------------------------------
/.github/workflows/windows.yml:
--------------------------------------------------------------------------------
1 | name: Windows CI - Release Jar
2 | on: [workflow_dispatch]
3 |
4 | jobs:
5 | windows_build:
6 | name: windows_build
7 | runs-on: windows-2019
8 | strategy:
9 | fail-fast: false
10 | matrix:
11 | mdb_version: ["Jan2022","Jul2021"]
12 | env:
13 | MDBE_JAVA_VERSION: "1.11-SNAPSHOT"
14 | MDB_VERSION: ${{ matrix.mdb_version }}
15 | steps:
16 | - uses: actions/checkout@v2
17 |
18 | #Set global environment variables
19 | - name: Env variables
20 | run: |
21 | echo "ARTIFACT=monetdbe-java-${{ env.MDBE_JAVA_VERSION }}-windows.jar" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
22 | echo "M2_REPO=C:\Users\runneradmin\.m2\repository\monetdb\monetdbe-java\${{ env.MDBE_JAVA_VERSION }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
23 |
24 | #Java, maven, gpg and dependencies setup; set up test env
25 | - name: Set up JDK 1.8
26 | uses: actions/setup-java@v1
27 | with:
28 | java-version: 1.8
29 | server-id: ossrh
30 | server-username: MVN_DEPLOY_USERNAME
31 | server-password: MVN_DEPLOY_PASSWORD
32 | gpg-passphrase: MVN_GPG_PASSPHRASE
33 | - name: Setup Maven
34 | uses: stCarolas/setup-maven@v4
35 | with:
36 | maven-version: 3.6.3
37 | - name: Setup VC tools
38 | uses: ilammy/msvc-dev-cmd@v1
39 | - name: Import GPG private key for maven release
40 | id: import_gpg
41 | uses: crazy-max/ghaction-import-gpg@v3
42 | with:
43 | gpg-private-key: ${{ secrets.MVN_GPG_PRIVATE_KEY }}
44 | passphrase: ${{ secrets.MVN_GPG_PASSPHRASE }}
45 | - name: Install vcpkg packages
46 | uses: lukka/run-vcpkg@v5
47 | with:
48 | vcpkgArguments: --triplet x64-windows libiconv openssl libxml2 pcre zlib getopt bzip2 curl
49 | vcpkgGitCommitId: e803bf11296d8e7900dafb41e7b1224778d33dc6
50 | appendedCacheKey: ${{ hashFiles(env.vcpkgResponseFile) }}
51 | - name: Install Bison/Flex
52 | run: choco install -y winflexbison
53 | - name: Set up test environment
54 | run: |
55 | Set-Location D:\a\MonetDBe-Java\MonetDBe-Java
56 | md testdata\taxi
57 | md testdata\localdb
58 | iwr -outf testdata\taxi\yellow_tripdata_2016-01.csv https://s3.amazonaws.com/nyc-tlc/trip+data/yellow_tripdata_2016-01.csv
59 |
60 | #Download and install MonetDB
61 | - name: Get monetdb
62 | run: |
63 | Set-Location c:\
64 | curl.exe https://www.monetdb.org/hg/MonetDB/archive/${{ env.MDB_VERSION }}.zip -O
65 | unzip.exe ${{ env.MDB_VERSION }}.zip
66 | - name: Compile and install MonetDB
67 | run: |
68 | mkdir c:\MonetDB-${{ env.MDB_VERSION }}\build
69 | Set-Location c:\MonetDB-${{ env.MDB_VERSION }}\build
70 |
71 | cmake -G "Visual Studio 16 2019" `
72 | -A x64 `
73 | -DCMAKE_TOOLCHAIN_FILE=D:\a\MonetDBe-Java\MonetDBe-Java\vcpkg\scripts\buildsystems\vcpkg.cmake `
74 | -DCMAKE_INSTALL_PREFIX=C:\MonetDB-${{ env.MDB_VERSION }} `
75 | -DTESTING=OFF `
76 | -DCMAKE_BUILD_TYPE=Release `
77 | -DASSERT=OFF `
78 | -DODBC=false `
79 | -DPY3INTEGRATION=OFF `
80 | -DINT128=ON `
81 | ..
82 | cmake --build . --target ALL_BUILD --parallel 8 --config Release
83 | cmake --build . --target INSTALL --config Release
84 |
85 | #Install native library, collect libraries, package jar, test and deploy
86 | - name: Install native library, collect libraries, package jar, test and deploy
87 | if: ${{ matrix.mdb_version == 'Jan2022' }}
88 | run: |
89 | Set-Location D:\a\MonetDBe-Java\MonetDBe-Java\native
90 | mvn clean install "-DMonetDB_dir=C:\MonetDB-${{ env.MDB_VERSION }}" --no-transfer-progress
91 | Set-Location D:\a\MonetDBe-Java\MonetDBe-Java\java
92 | mvn clean deploy "-DMonetDB_dir=C:\MonetDB-${{ env.MDB_VERSION }}" "-DVCPKG_ROOT=$Env:VCPKG_ROOT" -P release,release-sign --no-transfer-progress
93 | env:
94 | MVN_DEPLOY_USERNAME: monetdb
95 | MVN_DEPLOY_PASSWORD: ${{ secrets.MVN_DEPLOY_PASSWORD }}
96 | MVN_GPG_PRIVATE_KEY: ${{ secrets.MVN_GPG_PRIVATE_KEY }}
97 | MVN_GPG_PASSPHRASE: ${{ secrets.MVN_GPG_PASSPHRASE }}
98 |
99 | #Install native library, collect libraries, package jar, test and install
100 | - name: Install native library, collect libraries, package jar, test and install
101 | if: ${{ matrix.mdb_version != 'Jan2022' }}
102 | run: |
103 | Set-Location D:\a\MonetDBe-Java\MonetDBe-Java\native
104 | mvn clean install "-DMonetDB_dir=C:\MonetDB-${{ env.MDB_VERSION }}" --no-transfer-progress
105 | Set-Location D:\a\MonetDBe-Java\MonetDBe-Java\java
106 | mvn clean install "-DMonetDB_dir=C:\MonetDB-${{ env.MDB_VERSION }}" "-DVCPKG_ROOT=$Env:VCPKG_ROOT" --no-transfer-progress
107 |
108 | #Run example and publish jar
109 | - name: Run example class (ComplexTypes)
110 | run: |
111 | Set-Location D:\a\MonetDBe-Java\MonetDBe-Java\example
112 | javac -cp ${{ env.M2_REPO }}\${{ env.ARTIFACT }} ComplexTypes.java
113 | java -classpath ".\;${{ env.M2_REPO }}\${{ env.ARTIFACT }}" ComplexTypes
114 | - name: Publish Windows jar
115 | uses: actions/upload-artifact@v2
116 | if: always()
117 | with:
118 | name: ${{ env.MDB_VERSION }}-${{ env.ARTIFACT }}
119 | path: ${{ env.M2_REPO }}\${{ env.ARTIFACT }}
120 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | release-libs
2 | other/apidocs/
3 | testdata
4 | scripts
5 | other
6 | run_release.sh
7 |
8 | # Compiled class file
9 | *.class
10 |
11 | # Log file
12 | *.log
13 |
14 | # BlueJ files
15 | *.ctxt
16 |
17 | # Mobile Tools for Java (J2ME)
18 | .mtj.tmp/
19 |
20 | # Package Files #
21 | *.jar
22 | *.war
23 | *.nar
24 | *.ear
25 | *.zip
26 | *.tar.gz
27 | *.rar
28 |
29 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
30 | hs_err_pid*
31 |
32 |
33 | *.iml
34 | */.DS_STORE
35 | .DS_STORE
36 | temp/
37 | .settings/
38 | .project
39 | .classpath
40 | build/
41 | target/
42 | .vscode
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
52 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
53 |
54 | # User-specific stuff
55 | .idea/**/workspace.xml
56 | .idea/**/tasks.xml
57 | .idea/**/usage.statistics.xml
58 | .idea/**/dictionaries
59 | .idea/**/shelf
60 |
61 | # Generated files
62 | .idea/**/contentModel.xml
63 |
64 | # Sensitive or high-churn files
65 | .idea/**/dataSources/
66 | .idea/**/dataSources.ids
67 | .idea/**/dataSources.local.xml
68 | .idea/**/sqlDataSources.xml
69 | .idea/**/dynamic.xml
70 | .idea/**/uiDesigner.xml
71 | .idea/**/dbnavigator.xml
72 |
73 | # Gradle
74 | .idea/**/gradle.xml
75 | .idea/**/libraries
76 |
77 | # Gradle and Maven with auto-import
78 | # When using Gradle or Maven with auto-import, you should exclude module files,
79 | # since they will be recreated, and may cause churn. Uncomment if using
80 | # auto-import.
81 | # .idea/artifacts
82 | # .idea/compiler.xml
83 | # .idea/jarRepositories.xml
84 | # .idea/modules.xml
85 | # .idea/*.iml
86 | # .idea/modules
87 | # *.iml
88 | # *.ipr
89 |
90 | # CMake
91 | cmake-build-*/
92 |
93 | # Mongo Explorer plugin
94 | .idea/**/mongoSettings.xml
95 |
96 | # File-based project format
97 | *.iws
98 |
99 | # IntelliJ
100 | out/
101 |
102 | # mpeltonen/sbt-idea plugin
103 | .idea_modules/
104 |
105 | # JIRA plugin
106 | atlassian-ide-plugin.xml
107 |
108 | # Cursive Clojure plugin
109 | .idea/replstate.xml
110 |
111 | # Crashlytics plugin (for Android Studio and IntelliJ)
112 | com_crashlytics_export_strings.xml
113 | crashlytics.properties
114 | crashlytics-build.properties
115 | fabric.properties
116 |
117 | # Editor-based Rest Client
118 | .idea/httpRequests
119 |
120 | # Android studio 3.1+ serialized cache file
121 | .idea/caches/build_file_checksums.ser
122 |
--------------------------------------------------------------------------------
/build_dev.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if [ $# -eq 0 ]; then
4 | echo "No MonetDB installation directory provided"
5 | exit 1
6 | fi
7 |
8 | if [ $# -eq 2 ]; then
9 | if [ "$2" == "true" ] || [ "$2" == "false" ]; then
10 | skipTests="-DskipTests=${2}"
11 | else
12 | echo "The second argument (whether to skip tests) must be true or false"
13 | fi
14 | fi
15 |
16 | echo "Building native library"
17 | cd native
18 | mvn clean install -DMonetDB_dir=$1
19 | echo "Building dev jar"
20 | cd ../java
21 | mvn clean install $skipTests
22 | cd ..
23 | echo "Done!"
24 |
25 | #Clean up local test db
26 | if [ -n "$skipTests" ] && [ "$2" == "false" ]; then
27 | rm -rf ../testdata/localdb/*
28 | fi
29 |
--------------------------------------------------------------------------------
/docs/allclasses-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | All Classes
7 |
8 |
9 |
10 |
11 |
12 | All Classes
13 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/docs/allclasses-noframe.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | All Classes
7 |
8 |
9 |
10 |
11 |
12 | All Classes
13 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/docs/constant-values.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Constant Field Values
7 |
8 |
9 |
10 |
11 |
12 |
22 |
25 |
26 |
42 |
69 |
70 |
77 |
78 |
79 |
80 |
org.monetdb.*
81 |
82 | -
83 |
84 | org.monetdb.monetdbe.MonetDriver
85 |
86 | Modifier and Type |
87 | Constant Field |
88 | Value |
89 |
90 |
91 |
92 |
93 |
94 | static final java.lang.String |
95 | FILEURL |
96 | "jdbc:monetdb:file:" |
97 |
98 |
99 |
100 |
101 | static final java.lang.String |
102 | MAPIURL |
103 | "mapi:monetdb:" |
104 |
105 |
106 |
107 |
108 | static final java.lang.String |
109 | MEMORYURL |
110 | "jdbc:monetdb:memory:" |
111 |
112 |
113 |
114 |
115 | static final java.lang.String |
116 | MONETURL |
117 | "jdbc:monetdb:" |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
141 |
142 |
143 | - Prev
144 | - Next
145 |
146 |
150 |
153 |
154 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
--------------------------------------------------------------------------------
/docs/deprecated-list.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Deprecated List
7 |
8 |
9 |
10 |
11 |
12 |
22 |
25 |
26 |
42 |
69 |
70 |
77 |
99 |
100 |
116 |
117 |
118 | - Prev
119 | - Next
120 |
121 |
125 |
128 |
129 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/docs/index-files/index-10.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | J-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
25 |
26 |
42 |
69 |
70 | A B C D E F G H I J L M N O P R S T U W
71 |
72 |
73 |
J
74 |
75 | - jdbcCompliant() - Method in class org.monetdb.monetdbe.MonetDriver
76 | -
77 |
Reports whether this driver is a genuine JDBC Compliant™ driver.
78 |
79 |
80 |
A B C D E F G H I J L M N O P R S T U W
81 |
82 |
98 |
125 |
126 |
127 |
128 |
--------------------------------------------------------------------------------
/docs/index-files/index-14.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | O-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
25 |
26 |
42 |
69 |
70 | A B C D E F G H I J L M N O P R S T U W
71 |
72 |
73 |
O
74 |
75 | - org.monetdb.monetdbe - package org.monetdb.monetdbe
76 | -
77 | - othersDeletesAreVisible(int) - Method in class org.monetdb.monetdbe.MonetDatabaseMetaData
78 | -
79 | - othersInsertsAreVisible(int) - Method in class org.monetdb.monetdbe.MonetDatabaseMetaData
80 | -
81 | - othersUpdatesAreVisible(int) - Method in class org.monetdb.monetdbe.MonetDatabaseMetaData
82 | -
83 | - ownDeletesAreVisible(int) - Method in class org.monetdb.monetdbe.MonetDatabaseMetaData
84 | -
85 | - ownInsertsAreVisible(int) - Method in class org.monetdb.monetdbe.MonetDatabaseMetaData
86 | -
87 | - ownUpdatesAreVisible(int) - Method in class org.monetdb.monetdbe.MonetDatabaseMetaData
88 | -
89 |
90 |
A B C D E F G H I J L M N O P R S T U W
91 |
92 |
108 |
135 |
136 |
137 |
138 |
--------------------------------------------------------------------------------
/docs/index-files/index-2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | B-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
25 |
26 |
42 |
69 |
70 | A B C D E F G H I J L M N O P R S T U W
71 |
72 |
73 |
B
74 |
75 | - batch - Variable in class org.monetdb.monetdbe.MonetStatement
76 | -
77 |
Batched SQL queries to execute
78 |
79 | - beforeFirst() - Method in class org.monetdb.monetdbe.MonetResultSet
80 | -
81 |
Moves the cursor to the front of this ResultSet object, just before the first row.
82 |
83 |
84 |
A B C D E F G H I J L M N O P R S T U W
85 |
86 |
102 |
129 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/docs/index-files/index-20.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | W-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
25 |
26 |
42 |
69 |
70 | A B C D E F G H I J L M N O P R S T U W
71 |
72 |
73 |
W
74 |
75 | - wasNull() - Method in class org.monetdb.monetdbe.MonetCallableStatement
76 | -
77 |
Feature not supported.
78 |
79 | - wasNull() - Method in class org.monetdb.monetdbe.MonetResultSet
80 | -
81 |
Reports whether the last column read had a value of SQL NULL.
82 |
83 |
84 |
A B C D E F G H I J L M N O P R S T U W
85 |
86 |
102 |
129 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/docs/index-files/index-6.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | F-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
25 |
26 |
42 |
69 |
70 | A B C D E F G H I J L M N O P R S T U W
71 |
72 |
73 |
F
74 |
75 | - FILEURL - Static variable in class org.monetdb.monetdbe.MonetDriver
76 | -
77 |
The prefix to a file database URL
78 |
79 | - findColumn(String) - Method in class org.monetdb.monetdbe.MonetResultSet
80 | -
81 |
Maps the given ResultSet column label to its ResultSet column index.
82 |
83 | - first() - Method in class org.monetdb.monetdbe.MonetResultSet
84 | -
85 |
Moves the cursor to the first row in this ResultSet object.
86 |
87 | - free() - Method in class org.monetdb.monetdbe.MonetBlob
88 | -
89 |
This method frees the Blob object and releases the resources that
90 | it holds.
91 |
92 | - free() - Method in class org.monetdb.monetdbe.MonetClob
93 | -
94 |
This method frees the Clob object and releases the resources the
95 | resources that it holds.
96 |
97 |
98 |
A B C D E F G H I J L M N O P R S T U W
99 |
100 |
116 |
143 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/docs/index-files/index-8.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | H-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
25 |
26 |
42 |
69 |
70 | A B C D E F G H I J L M N O P R S T U W
71 |
72 |
73 |
H
74 |
75 | - hexStrToByteArray(String) - Static method in class org.monetdb.monetdbe.MonetBlob
76 | -
77 |
78 |
A B C D E F G H I J L M N O P R S T U W
79 |
80 |
96 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Generated Documentation (Untitled)
7 |
60 |
61 |
72 |
73 |
--------------------------------------------------------------------------------
/docs/org/monetdb/monetdbe/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | org.monetdb.monetdbe
7 |
8 |
9 |
10 |
11 |
12 |
13 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/docs/org/monetdb/monetdbe/package-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | org.monetdb.monetdbe Class Hierarchy
7 |
8 |
9 |
10 |
11 |
12 |
22 |
25 |
26 |
42 |
69 |
70 |
73 |
74 |
Class Hierarchy
75 |
76 | - java.lang.Object
77 |
78 | - org.monetdb.monetdbe.MonetBlob (implements java.sql.Blob)
79 | - org.monetdb.monetdbe.MonetClob (implements java.sql.Clob)
80 | - org.monetdb.monetdbe.MonetColumn
81 | - org.monetdb.monetdbe.MonetDriver (implements java.sql.Driver)
82 | - org.monetdb.monetdbe.MonetNative
83 | - org.monetdb.monetdbe.MonetTypes
84 | - org.monetdb.monetdbe.MonetWrapper (implements java.sql.Wrapper)
85 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
123 |
124 |
125 | - Prev
126 | - Next
127 |
128 |
132 |
135 |
136 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
--------------------------------------------------------------------------------
/docs/overview-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Class Hierarchy
7 |
8 |
9 |
10 |
11 |
12 |
22 |
25 |
26 |
42 |
69 |
70 |
77 |
78 |
Class Hierarchy
79 |
80 | - java.lang.Object
81 |
82 | - org.monetdb.monetdbe.MonetBlob (implements java.sql.Blob)
83 | - org.monetdb.monetdbe.MonetClob (implements java.sql.Clob)
84 | - org.monetdb.monetdbe.MonetColumn
85 | - org.monetdb.monetdbe.MonetDriver (implements java.sql.Driver)
86 | - org.monetdb.monetdbe.MonetNative
87 | - org.monetdb.monetdbe.MonetTypes
88 | - org.monetdb.monetdbe.MonetWrapper (implements java.sql.Wrapper)
89 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
127 |
128 |
129 | - Prev
130 | - Next
131 |
132 |
136 |
139 |
140 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
--------------------------------------------------------------------------------
/docs/package-list:
--------------------------------------------------------------------------------
1 | org.monetdb.monetdbe
2 |
--------------------------------------------------------------------------------
/docs/script.js:
--------------------------------------------------------------------------------
1 | function show(type)
2 | {
3 | count = 0;
4 | for (var key in methods) {
5 | var row = document.getElementById(key);
6 | if ((methods[key] & type) != 0) {
7 | row.style.display = '';
8 | row.className = (count++ % 2) ? rowColor : altColor;
9 | }
10 | else
11 | row.style.display = 'none';
12 | }
13 | updateTabs(type);
14 | }
15 |
16 | function updateTabs(type)
17 | {
18 | for (var value in tabs) {
19 | var sNode = document.getElementById(tabs[value][0]);
20 | var spanNode = sNode.firstChild;
21 | if (value == type) {
22 | sNode.className = activeTableTab;
23 | spanNode.innerHTML = tabs[value][1];
24 | }
25 | else {
26 | sNode.className = tableTab;
27 | spanNode.innerHTML = "" + tabs[value][1] + "";
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/example/ComplexTypes.java:
--------------------------------------------------------------------------------
1 | import org.monetdb.monetdbe.MonetBlob;
2 |
3 | import java.sql.*;
4 | import java.util.Arrays;
5 | import java.util.Properties;
6 |
7 | public class ComplexTypes {
8 | private static void createAndInsert(Connection c) {
9 | try {
10 | Statement s = c.createStatement();
11 |
12 | System.out.println("Create table");
13 | s.execute("CREATE TABLE complex (bd numeric, s string, b blob, d date, t time, ts timestamp);");
14 |
15 | System.out.println("Insert into\n");
16 | s.execute("INSERT INTO complex VALUES " +
17 | "(34589.54,'hello','12ff803F',current_date,current_time,current_timestamp), " +
18 | "(34012933.888,'world','0000803F',str_to_date('23-09-1987', '%d-%m-%Y'),str_to_time('11:40:30', '%H:%M:%S'),str_to_timestamp('23-09-1987 11:40', '%d-%m-%Y %H:%M')), " +
19 | "(666.666,'bye','ffffffff',str_to_date('23-09-1990', '%d-%m-%Y'),str_to_time('11:40:35', '%H:%M:%S'),str_to_timestamp('23-09-1990 11:40', '%d-%m-%Y %H:%M'))," +
20 | "(NULL,NULL,NULL,NULL,NULL,NULL);");
21 | } catch (SQLException e) {
22 | e.printStackTrace();
23 | }
24 | }
25 |
26 | private static void insertNulls (Connection c) {
27 | try {
28 | System.out.println("Inserting NULL values");
29 |
30 | PreparedStatement p = c.prepareStatement("INSERT INTO complex VALUES (?,?,?,?,?,?);");
31 | p.setNull(1,Types.NUMERIC);
32 | p.setNull(2,Types.VARCHAR);
33 | p.setNull(3,Types.BLOB);
34 | p.setNull(4,Types.DATE);
35 | p.setNull(5,Types.TIME);
36 | p.setNull(6,Types.TIMESTAMP);
37 |
38 | p.execute();
39 |
40 | } catch (SQLException e) {
41 | e.printStackTrace();
42 | }
43 | }
44 |
45 | private static void queryDB(Connection c) {
46 | try {
47 | System.out.println("Querying complex types");
48 | Statement s = c.createStatement();
49 | s.executeQuery("SELECT * FROM complex;");
50 | ResultSet rs = s.getResultSet();
51 | System.out.println("Select resultSet: ");
52 | rs.beforeFirst();
53 | while (rs.next()) {
54 | System.out.println("Row " + rs.getRow());
55 | System.out.println("BigDecimal " + rs.getBigDecimal(1));
56 | System.out.println("String: " + rs.getString(2));
57 | Blob b = rs.getBlob(3);
58 | if (b == null)
59 | System.out.println("Blob: null");
60 | else
61 | System.out.println("Blob: " + Arrays.toString(b.getBytes(1,(int)b.length())));
62 | System.out.println("Date: " + rs.getDate(4));
63 | System.out.println("Time: " + rs.getTime(5));
64 | System.out.println("Timestamp: " + rs.getTimestamp(6));
65 | System.out.println();
66 | }
67 | } catch (SQLException e) {
68 | e.printStackTrace();
69 | }
70 | }
71 |
72 | private static void concurrentAcess (Connection c) {
73 |
74 | }
75 |
76 | public static void main(String[] args) {
77 | try {
78 | Properties p = new Properties();
79 | //p.setProperty("logfile","/Users/bernardo/Monet/MonetDBe-Java/log.txt");
80 | Connection c = DriverManager.getConnection("jdbc:monetdb:memory:", p);
81 | Statement st = c.createStatement();
82 | ResultSet rs;
83 | //st.execute("CALL logging.setadapter('basic');");
84 | //st.execute("CALL logging.setflushlevel('debug');");
85 | //st.execute("call logging.setcomplevel('algo', 'debug');");
86 | if ((rs = st.getResultSet()) == null)
87 | System.out.println("Update count: " + st.getUpdateCount());
88 | else
89 | System.out.println("RS: " + rs.getObject(1));
90 |
91 | System.out.println("Opened connection");
92 |
93 | createAndInsert(c);
94 | insertNulls(c);
95 | queryDB(c);
96 |
97 | c.close();
98 | System.out.println("Closed connection");
99 | } catch (SQLException e) {
100 | e.printStackTrace();
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/example/ConnectionTypes.java:
--------------------------------------------------------------------------------
1 | import java.sql.Connection;
2 | import java.sql.DriverManager;
3 | import java.sql.SQLException;
4 |
5 | public class ConnectionTypes {
6 | public static void main(String[] args) {
7 | //In-Memory DB
8 | String urlMemory = "jdbc:monetdb:memory:";
9 | //Local Persistent DB
10 | String urlLocal = "jdbc:monetdb:file:/tmp/test/";
11 | //Remote Proxy DB (needs to have a server running)
12 | String urlProxy = "mapi:monetdb://localhost:50000/test";
13 |
14 | //Connecting to in-memory DB
15 | try {
16 | Connection memoryConnection = DriverManager.getConnection(urlMemory,null);
17 |
18 | if (memoryConnection != null) {
19 | System.out.println("Successful connection to in-memory database.");
20 | memoryConnection.close();
21 | }
22 | } catch (SQLException e) {
23 | e.printStackTrace();
24 | System.out.println("In-memory database connection failure.");
25 | }
26 |
27 | //Connecting to a local persistent DB
28 | try {
29 | Connection localConnection = DriverManager.getConnection(urlLocal,null);
30 |
31 | if (localConnection != null) {
32 | System.out.println("Successful connection to local persistent database.");
33 | localConnection.close();
34 | }
35 | } catch (SQLException e) {
36 | e.printStackTrace();
37 | System.out.println("Local persistent connection failure.");
38 | }
39 |
40 | //Connecting to a remote proxy DB
41 | try {
42 | Connection proxyConnection = DriverManager.getConnection(urlProxy,null);
43 |
44 | if (proxyConnection != null) {
45 | System.out.println("Successful connection to a remote proxy database.");
46 | proxyConnection.close();
47 | }
48 | } catch (SQLException e) {
49 | e.printStackTrace();
50 | System.out.println("Remote proxy database connection failure.");
51 | }
52 |
53 | //Connecting to in-memory DB with auto-commit turned off
54 | try {
55 | Connection memoryConnection = DriverManager.getConnection(urlMemory.concat("?autocommit=false"),null);
56 |
57 | if (memoryConnection != null) {
58 | boolean ac = memoryConnection.getAutoCommit();
59 | System.out.println("In-memory database with autocommit off returns: " + ac + " (should be false)");
60 | memoryConnection.close();
61 | }
62 | } catch (SQLException e) {
63 | e.printStackTrace();
64 | System.out.println("In-memory database connection failure.");
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/example/HelloWorld.java:
--------------------------------------------------------------------------------
1 | import java.sql.Connection;
2 | import java.sql.DriverManager;
3 | import java.sql.SQLException;
4 |
5 | public class HelloWorld {
6 | public static void main(String[] args) {
7 | Connection conn = null;
8 | try {
9 | //In-memory database
10 | conn = DriverManager.getConnection("jdbc:monetdb:memory:",null);
11 | } catch (SQLException e) {
12 | e.printStackTrace();
13 | }
14 |
15 | if (conn == null) {
16 | System.out.println("Could not connect to memory database");
17 | return;
18 | }
19 |
20 | System.out.println("Hello world, we have a lift off!\nMonetDB/e has been started");
21 |
22 | try {
23 | //Close connection
24 | conn.close();
25 | } catch (SQLException e) {
26 | e.printStackTrace();
27 | }
28 |
29 | System.out.println("Hello World, we have safely returned");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/example/InsertAndQuery.java:
--------------------------------------------------------------------------------
1 | import java.sql.*;
2 |
3 | public class InsertAndQuery {
4 | public static void main(String[] args) {
5 | Connection conn = null;
6 | try {
7 | //In-memory database
8 | conn = DriverManager.getConnection("jdbc:monetdb:memory:",null);
9 | } catch (SQLException e) {
10 | e.printStackTrace();
11 | }
12 |
13 | if (conn == null) {
14 | System.out.println("Could not connect to memory database");
15 | return;
16 | }
17 |
18 |
19 | try {
20 | //Create table and insert values
21 | Statement s = conn.createStatement();
22 | System.out.println("Creating table and inserting values.");
23 | s.executeUpdate("CREATE TABLE example (b BOOLEAN, i INTEGER, s STRING);");
24 | s.executeUpdate("INSERT INTO example VALUES (false,3,'hello'), (true,500,'world'),(false,-1,NULL);");
25 |
26 | //Query table
27 | ResultSet rs = s.executeQuery("SELECT * FROM example;");
28 |
29 | System.out.println("Fetched values:");
30 | //Fetch results
31 | while (rs.next()) {
32 | System.out.println("Bool: " + rs.getBoolean(1));
33 | System.out.println("Int: " + rs.getInt(2));
34 | System.out.println("String: " + rs.getString(3) + "\n");
35 | }
36 |
37 | conn.close();
38 | } catch (SQLException e) {
39 | e.printStackTrace();
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/example/Metadata.java:
--------------------------------------------------------------------------------
1 | import java.sql.*;
2 |
3 | public class Metadata {
4 |
5 | static void printResult(ResultSet rs, int start, int end) throws SQLException {
6 | while(rs.next()) {
7 | for (int i =start; i <= end; i++) {
8 | System.out.print(rs.getObject(i) + "\t");
9 | }
10 | System.out.println();
11 | }
12 | System.out.println("\n");
13 | }
14 |
15 | static void databaseMetadataGet (DatabaseMetaData dbMeta) throws SQLException {
16 | ResultSet rs;
17 | rs = dbMeta.getProcedures(null,null,null);
18 | System.out.println("Procedures: ");
19 | printResult(rs,1,8);
20 |
21 | rs = dbMeta.getProcedureColumns(null,null,null,null);
22 | System.out.println("Procedure Columns: ");
23 | printResult(rs,1,20);
24 |
25 | rs = dbMeta.getTables(null,null,null,null);
26 | System.out.println("Tables: ");
27 | printResult(rs,1,4);
28 |
29 | rs = dbMeta.getSchemas(null,null);
30 | System.out.println("Schemas: ");
31 | printResult(rs,1,2);
32 |
33 | rs = dbMeta.getColumns(null,null,null,null);
34 | System.out.println("Columns: ");
35 | printResult(rs,1,23);
36 |
37 | rs = dbMeta.getColumnPrivileges(null,null,null,null);
38 | System.out.println("Columns Privileges: ");
39 | printResult(rs,1,8);
40 |
41 | rs = dbMeta.getTablePrivileges(null,null,null);
42 | System.out.println("Table Privileges: ");
43 | printResult(rs,1,7);
44 |
45 | rs = dbMeta.getPrimaryKeys(null,null,null);
46 | System.out.println("Primary Keys: ");
47 | printResult(rs,1,6);
48 |
49 | rs = dbMeta.getImportedKeys(null,null,null);
50 | System.out.println("Imported Keys: ");
51 | printResult(rs,1,14);
52 |
53 | rs = dbMeta.getTypeInfo();
54 | System.out.println("Type info: ");
55 | printResult(rs,1,18);
56 |
57 | rs = dbMeta.getIndexInfo(null,null,null, false, false);
58 | System.out.println("Index info: ");
59 | printResult(rs,1,13);
60 |
61 | rs = dbMeta.getFunctions(null,null,null);
62 | System.out.println("Functions: ");
63 | printResult(rs,1,6);
64 |
65 | rs = dbMeta.getFunctionColumns(null,null,null,null);
66 | System.out.println("Function Columns: ");
67 | printResult(rs,1,17);
68 | }
69 |
70 | static void databaseMetadata (Connection conn) throws SQLException {
71 | DatabaseMetaData dbMeta = conn.getMetaData();
72 | ResultSet rs;
73 |
74 | System.out.println("Keywords: " + dbMeta.getSQLKeywords());
75 | System.out.println("Numeric functions: " + dbMeta.getNumericFunctions());
76 | System.out.println("String functions: " + dbMeta.getStringFunctions());
77 | System.out.println("System functions: " + dbMeta.getSystemFunctions());
78 | System.out.println("Timedate functions: " + dbMeta.getTimeDateFunctions());
79 |
80 | rs = dbMeta.getTableTypes();
81 | System.out.println("Table types: ");
82 | while(rs.next()) {
83 | System.out.println("\t" + rs.getObject(1));
84 | }
85 |
86 |
87 | databaseMetadataGet(dbMeta);
88 |
89 | rs = dbMeta.getClientInfoProperties();
90 | System.out.println("ClientInfoProperties: ");
91 | printResult(rs,1,4);
92 |
93 | }
94 |
95 | static void resultsetMetadata (Connection conn) throws SQLException {
96 | Statement s = conn.createStatement();
97 | ResultSet rs = s.executeQuery("SELECT 1, 'hey', 200000000000, 912387.3232;");
98 | ResultSetMetaData rsMeta = rs.getMetaData();
99 |
100 | int i = 1;
101 |
102 | while (rs.next()) {
103 | System.out.println("Value: " + rs.getObject(i));
104 | System.out.println("Name: " + rsMeta.getColumnName(i));
105 | System.out.println("SQL Type: " + rsMeta.getColumnType(i));
106 | System.out.println("Monet Type: " + rsMeta.getColumnTypeName(i));
107 | System.out.println("Java Type: " + rsMeta.getColumnClassName(i));
108 | System.out.println("Size: " + rsMeta.getColumnDisplaySize(i));
109 | i++;
110 | }
111 | }
112 |
113 | static void parameterMetadata (Connection conn) throws SQLException {
114 | //TODO
115 | }
116 |
117 | public static void main(String[] args) {
118 | Connection conn = null;
119 | try {
120 | //In-memory database
121 | conn = DriverManager.getConnection("jdbc:monetdb:memory:", null);
122 |
123 | resultsetMetadata(conn);
124 | databaseMetadata(conn);
125 | parameterMetadata(conn);
126 | } catch (SQLException e) {
127 | e.printStackTrace();
128 | }
129 |
130 |
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/example/Movies.java:
--------------------------------------------------------------------------------
1 | import java.sql.*;
2 |
3 | public class Movies {
4 | private static void loadMovies(Connection conn) throws SQLException {
5 | String[] titles = {"Iron Man", "The Incredible Hulk", "Iron Man 2", "Thor", "Captain America: The First Avenger", "The Avengers", "Iron Man 3", "Captain America: The Winter Soldier", "Avengers: Age of Ultron", "Captain America: Civil War", "Doctor Strange", "Black Panther", "Avengers: Infinity War"};
6 | int[] years = {2008, 2008, 2010, 2011, 2011, 2012, 2013, 2014, 2015, 2016, 2016, 2018, 2018};
7 |
8 | //Using a Prepared Statement, we can reuse a query for multiple parameters
9 | PreparedStatement ps = conn.prepareStatement("INSERT INTO Movies (title, \"year\") VALUES (?,?)");
10 |
11 | for (int i = 0; i < titles.length; i++) {
12 | ps.setString(1, titles[i]);
13 | ps.setInt(2, years[i]);
14 | //Using addBatch, we can store multiple input parameters, which can then be executed at once
15 | ps.addBatch();
16 | }
17 | //Inserts all batched movies
18 | ps.executeBatch();
19 | }
20 |
21 | private static void queryMovies(Statement s) throws SQLException {
22 | ResultSet rs = s.executeQuery("SELECT * FROM Movies;");
23 | while (rs.next()) {
24 | System.out.println("Id: " + rs.getInt(1) + " / Title: " + rs.getString(2) + " / Year: " + rs.getInt(3));
25 | }
26 |
27 | rs = s.executeQuery("SELECT * FROM Movies ORDER BY \"year\" DESC;");
28 | while (rs.next()) {
29 | System.out.println("Id: " + rs.getInt(1) + " / Title: " + rs.getString(2) + " / Year: " + rs.getInt(3));
30 | }
31 | }
32 |
33 | private static void loadActors(Connection conn) throws SQLException {
34 | String[] first_name = {"Robert","Chris","Scarlett","Samuel L.","Benedict","Brie","Chadwick"};
35 | String[] last_name = {"Downey Jr.", "Evans", "Johansson", "Jackson", "Cumberbatch", "Larson", "Boseman"};
36 | String[] character = {"Iron Man", "Captain America", "Black Widow", "Nick Fury", "Dr. Strange", "Captain Marvel", "Black Panther"};
37 | int[] age = {53, 37, 33, 69, 42, 29, 40};
38 |
39 | PreparedStatement ps = conn.prepareStatement("INSERT INTO Actors (first_name, last_name, \"character\", age) VALUES (?,?,?,?);");
40 |
41 | for (int i = 0; i < age.length; i++) {
42 | ps.setString(1, first_name[i]);
43 | ps.setString(2, last_name[i]);
44 | ps.setString(3, character[i]);
45 | ps.setInt(4, age[i]);
46 | ps.addBatch();
47 | }
48 | ps.executeBatch();
49 |
50 | int[] actors = {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 7, 7, 7};
51 | int[] movies = {1, 2, 3, 6, 7, 9, 10, 13, 5, 6, 8, 9, 10, 13, 3, 6, 8, 9, 10, 13, 1, 3, 4, 5, 6, 8, 9, 13, 11, 13, 10, 12, 13};
52 | ps = conn.prepareStatement("INSERT INTO MovieActors (movie_id, actor_id) VALUES (?,?);");
53 |
54 | for (int i = 0; i < actors.length; i++) {
55 | ps.setInt(1, movies[i]);
56 | ps.setInt(2, actors[i]);
57 | ps.addBatch();
58 | }
59 | ps.executeBatch();
60 | }
61 |
62 | private static void queryActorMovies(Statement s) throws SQLException {
63 | ResultSet rs = s.executeQuery("SELECT Movies.title, Movies.\"year\", Actors.first_name, Actors.\"character\" FROM MovieActors JOIN Movies ON MovieActors.movie_id = Movies.id JOIN Actors ON MovieActors.actor_id = Actors.id;");
64 | while (rs.next()) {
65 | System.out.println("Movie Title: " + rs.getString(1) + " / Movie Year: " + rs.getInt(2) + " / Actor First Name: " + rs.getString(3) + " / Actor Character: " + rs.getString(4));
66 | }
67 | }
68 |
69 | public static void main(String[] args) {
70 | String db = "/tmp/movies";
71 | Connection conn = null;
72 | try {
73 | //Local database
74 | conn = DriverManager.getConnection("jdbc:monetdb:file:" + db, null);
75 | } catch (SQLException e) {
76 | e.printStackTrace();
77 | }
78 |
79 | if (conn == null) {
80 | System.out.println("Could not connect to local database");
81 | return;
82 | }
83 |
84 | try {
85 | Statement s = conn.createStatement();
86 |
87 | //Here we create a primary key, and use "NOT NULL" to prevent inserting invalid data
88 | s.executeUpdate("CREATE TABLE Movies (id SERIAL, title STRING NOT NULL, \"year\" INTEGER NOT NULL);");
89 | loadMovies(conn);
90 | queryMovies(s);
91 |
92 | s.executeUpdate("CREATE TABLE Actors (id SERIAL, first_name TEXT NOT NULL, last_name TEXT NOT NULL, \"character\" TEXT NOT NULL, age REAL NOT NULL);");
93 | s.executeUpdate("CREATE TABLE MovieActors (id SERIAL, movie_id INTEGER NOT NULL, actor_id INTEGER NOT NULL);");
94 | loadActors(conn);
95 |
96 | queryActorMovies(s);
97 |
98 | conn.close();
99 | } catch (SQLException e) {
100 | e.printStackTrace();
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/example/MultiConnections.java:
--------------------------------------------------------------------------------
1 | import java.sql.*;
2 |
3 | public class MultiConnections {
4 | public static void main(String[] args) {
5 | Connection conn1 = null;
6 | Statement s1 = null;
7 | try {
8 | //Local database
9 | conn1 = DriverManager.getConnection("jdbc:monetdb:file:/tmp/db1",null);
10 | } catch (SQLException e) {
11 | e.printStackTrace();
12 | }
13 |
14 | if (conn1 == null) {
15 | System.out.println("Could not connect to db1");
16 | return;
17 | }
18 | System.out.println("Connected to db1");
19 |
20 | try {
21 | s1 = conn1.createStatement();
22 | s1.executeUpdate("CREATE TABLE db1 (i INTEGER);");
23 | s1.executeUpdate("INSERT INTO db1 VALUES (1),(2);");
24 |
25 | ResultSet rs1 = s1.executeQuery("SELECT * FROM db1;");
26 | System.out.println("Results from connection 1");
27 | while (rs1.next()) {
28 | System.out.println("Int: " + rs1.getInt(1));
29 | }
30 | } catch (SQLException e) {
31 | e.printStackTrace();
32 | }
33 |
34 | //Connection to same database
35 | Connection conn2 = null;
36 | Statement s2 = null;
37 | try {
38 | conn2 = DriverManager.getConnection("jdbc:monetdb:file:/tmp/db1",null);
39 | } catch (SQLException e) {
40 | e.printStackTrace();
41 | }
42 |
43 | if (conn2 == null) {
44 | System.out.println("Could not connect to db2");
45 | return;
46 | }
47 | System.out.println("Connected to db1 through connection 2");
48 |
49 | try {
50 | s2 = conn2.createStatement();
51 |
52 | System.out.println("Results from connection 2");
53 | ResultSet rs2 = s2.executeQuery("SELECT * FROM db1;");
54 | while (rs2.next()) {
55 | System.out.println("Int: " + rs2.getInt(1));
56 | }
57 | } catch (SQLException e) {
58 | e.printStackTrace();
59 | }
60 |
61 | //Connection 1 can still be used
62 | try {
63 | ResultSet rs1Sum = s1.executeQuery("SELECT sum(i) FROM db1;");
64 | System.out.println("Results from connection 1 (again)");
65 | while (rs1Sum.next()) {
66 | System.out.println("Sum: " + rs1Sum.getInt(1));
67 | }
68 | } catch (SQLException e) {
69 | e.printStackTrace();
70 | }
71 |
72 |
73 | //Connecting to another database
74 | Connection conn3 = null;
75 | try {
76 | conn3 = DriverManager.getConnection("jdbc:monetdb:file:/tmp/db2",null);
77 | } catch (SQLException e) {
78 | e.printStackTrace();
79 | }
80 |
81 | if (conn3 == null) {
82 | System.out.println("Could not connect to db2 through connection 3");
83 | return;
84 | }
85 | System.out.println("Connected to db2 through connection 3");
86 |
87 | try {
88 | Statement s3 = conn3.createStatement();
89 | s3.executeUpdate("CREATE TABLE db2 (i INTEGER);");
90 | s3.executeUpdate("INSERT INTO db2 VALUES (30),(40);");
91 |
92 | ResultSet rs3 = s3.executeQuery("SELECT * FROM db2;");
93 | System.out.println("Results from connection 3");
94 | while (rs3.next()) {
95 | System.out.println("Int: " + rs3.getInt(1));
96 | }
97 | } catch (SQLException e) {
98 | e.printStackTrace();
99 | }
100 |
101 | //Connection 1 can still be used
102 | try {
103 | ResultSet rs1sum = s1.executeQuery("SELECT sum(i) FROM db1;");
104 | System.out.println("Results from connection 1 (once more)");
105 | while (rs1sum.next()) {
106 | System.out.println("Sum: " + rs1sum.getInt(1));
107 | }
108 |
109 | s1.execute("DROP TABLE db1;");
110 | s2.execute("DROP TABLE db1;");
111 |
112 | System.out.println("Closing all connections");
113 | conn1.close();
114 | conn2.close();
115 | conn3.close();
116 | } catch (SQLException e) {
117 | e.printStackTrace();
118 | }
119 |
120 |
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/example/MultiThreadAccess.java:
--------------------------------------------------------------------------------
1 | import java.sql.*;
2 | import java.util.concurrent.ExecutorService;
3 | import java.util.concurrent.Executors;
4 |
5 | class MultiThreadRun implements Runnable {
6 | String url;
7 | boolean log;
8 | String tableName;
9 | String threadName;
10 | int threadNum;
11 | Connection c;
12 |
13 | public MultiThreadRun(String url, boolean log, int threadNum) {
14 | this.log = log;
15 | this.tableName = "a_" + threadNum;
16 | this.threadName = Thread.currentThread().getName();
17 | this.threadNum = threadNum;
18 | if (log)
19 | this.url = url + "?logfile=/Users/bernardo/Monet/MonetDBe-Java/logfile";
20 | else
21 | this.url = url;
22 | }
23 |
24 | public MultiThreadRun(Connection c, int threadNum) {
25 | this.threadNum = threadNum;
26 | this.tableName = "a_" + threadNum;
27 | this.threadName = Thread.currentThread().getName();
28 | this.c = c;
29 | }
30 |
31 | @Override
32 | public void run() {
33 | System.out.println("Running thread " + threadName + "." + threadNum);
34 | try {
35 | if (this.c == null) {
36 | System.out.println("Thread " + threadName + "." + threadNum + ":Starting new connection");
37 | this.c = DriverManager.getConnection(this.url);
38 | }
39 | Statement stat = c.createStatement();
40 |
41 | if (log) {
42 | stat.execute("CALL logging.setflushlevel('debug');");
43 | stat.execute("CALL logging.setlayerlevel('MDB_ALL','debug')");
44 | }
45 |
46 | ResultSet rs = null;
47 | System.out.println("Thread " + threadName + "." + threadNum + ": Create table " + tableName);
48 | stat.execute("CREATE TABLE " + tableName + " (a INT)");
49 | System.out.println("Thread " + threadName + "." + threadNum + ": Insert into");
50 | stat.execute("INSERT INTO " + tableName + " VALUES (1)");
51 | System.out.println("Thread " + threadName + "." + threadNum + ": Query");
52 | rs = stat.executeQuery("SELECT * FROM " + tableName);
53 | while(rs.next())
54 | System.out.println("Thread " + threadName + "." + threadNum + ": " + tableName + " -> " + rs.getObject(1));
55 |
56 |
57 | rs = stat.executeQuery("SELECT * FROM a_0");
58 | while(rs.next())
59 | System.out.println("Thread " + threadName + "." + threadNum + ": a_0 -> " + rs.getObject(1));
60 | System.out.println("Thread " + threadName + "." + threadNum + ": Closing connection");
61 | c.close();
62 | } catch (SQLException e) {
63 | e.printStackTrace();
64 | }
65 |
66 | }
67 | }
68 |
69 | public class MultiThreadAccess {
70 | public static void main(String[] args) {
71 | boolean useSameConnection = false;
72 |
73 | String urlMemory = "jdbc:monetdb:memory:";
74 | String urlFile = "jdbc:monetdb:file:/tmp/test/";
75 | Connection c = null;
76 |
77 | int n = 2;
78 | ExecutorService executor = Executors.newFixedThreadPool(n);
79 | try {
80 | if (useSameConnection)
81 | c = DriverManager.getConnection(urlMemory);
82 | } catch (SQLException e) {
83 | e.printStackTrace();
84 | }
85 |
86 | for (int i = 0; i < n; i++) {
87 | Runnable t = null;
88 | if (useSameConnection)
89 | t = new MultiThreadRun(c,i);
90 | else
91 | t = new MultiThreadRun(urlMemory,false,i);
92 |
93 | executor.execute(t);
94 | }
95 | executor.shutdown();
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/example/SimpleTypes.java:
--------------------------------------------------------------------------------
1 | import org.monetdb.monetdbe.MonetResultSet;
2 |
3 | import java.sql.*;
4 | import java.util.Properties;
5 |
6 | public class SimpleTypes {
7 | private static void createAndInsert(Connection c) {
8 | try {
9 | Statement s = c.createStatement();
10 |
11 | System.out.println("Create table");
12 | s.execute("CREATE TABLE simpleT (b boolean, s smallint, i int, l bigint, r real, f float);");
13 |
14 | System.out.println("Insert into\n");
15 | s.execute("INSERT INTO simpleT VALUES " +
16 | "(true, 2, 3, 5, 1.0, 1.66), " +
17 | "(true, 4, 6, 10, 2.5, 3.643), " +
18 | "(false, 8, 12, 20, 25.25, 372.325), " +
19 | "(false, 16, 24, 40, 255.255, 2434.432)," +
20 | "(false, null, 1, 1, 1, null);");
21 | } catch (SQLException e) {
22 | e.printStackTrace();
23 | }
24 | }
25 |
26 | private static void dropTable(Connection c) {
27 | try {
28 | Statement s = c.createStatement();
29 | s.execute("DROP TABLE simpleT;");
30 | System.out.println("Drop count: " + s.getUpdateCount());
31 | } catch (SQLException e) {
32 | e.printStackTrace();
33 | }
34 | }
35 |
36 | private static void queryDB(Connection c) {
37 | try {
38 | Statement s = c.createStatement();
39 | s.executeQuery("SELECT * FROM simpleT;");
40 | ResultSet rs = s.getResultSet();
41 | System.out.println("Select resultSet (" + ((MonetResultSet)rs).getRowsNumber() + " rows and " + ((MonetResultSet)rs).getColumnsNumber() + " columns): ");
42 | rs.beforeFirst();
43 | while (rs.next()) {
44 | System.out.println("Row " + rs.getRow());
45 | System.out.println("Bool: " + rs.getBoolean(1));
46 | System.out.println("Short: " + rs.getShort(2));
47 | System.out.println("Int: " + rs.getInt(3));
48 | System.out.println("Long: " + rs.getLong(4));
49 | System.out.println("Float: " + rs.getFloat(5));
50 | System.out.println("Double: " + rs.getDouble(6));
51 | System.out.println();
52 | }
53 | } catch (SQLException e) {
54 | e.printStackTrace();
55 | }
56 | }
57 |
58 | public static void main(String[] args) {
59 | try {
60 | Connection c = DriverManager.getConnection("jdbc:monetdb:memory:", new Properties());
61 | //Connection c = DriverManager.getConnection("mapi:monetdb://localhost:50000/test", new Properties());
62 |
63 | System.out.println("Opened connection");
64 |
65 | createAndInsert(c);
66 | queryDB(c);
67 | dropTable(c);
68 |
69 | c.close();
70 | System.out.println("Closed connection");
71 | } catch (SQLException e) {
72 | e.printStackTrace();
73 | }
74 | }
75 | }
--------------------------------------------------------------------------------
/example/UpdateCount.java:
--------------------------------------------------------------------------------
1 | import java.sql.Connection;
2 | import java.sql.DriverManager;
3 | import java.sql.PreparedStatement;
4 | import java.sql.ResultSet;
5 | import java.sql.SQLException;
6 | import java.sql.Statement;
7 | import java.sql.Types;
8 |
9 | public class UpdateCount {
10 | private static void updateCount(String connectionUrl, int loop) {
11 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
12 |
13 | try (Statement statement = conn.createStatement()) {
14 | statement.executeUpdate("CREATE TABLE updateCount (b BOOLEAN, i INTEGER, s STRING);");
15 |
16 | int i = 0;
17 | while (i < loop) {
18 | try (PreparedStatement p = conn.prepareStatement("INSERT INTO updateCount VALUES (?, ?, ?);")) {
19 | p.setBoolean(1, true);
20 | p.setInt(2, 10);
21 | p.setString(3, "Hello world");
22 | p.executeUpdate();
23 | }
24 | /*try (Statement s = conn.createStatement()) {
25 | s.executeUpdate("INSERT INTO updateCount VALUES (false, 15, 'hello');");
26 | }*/
27 | i++;
28 | }
29 | System.out.println("Inserted " + i + " non-null values");
30 |
31 | i=0;
32 |
33 | while (i < loop) {
34 | try (PreparedStatement p = conn.prepareStatement("INSERT INTO updateCount VALUES (?, ?, ?);")) {
35 | p.setNull(1, Types.BOOLEAN);
36 | p.setNull(2, Types.INTEGER);
37 | p.setNull(3, Types.VARCHAR);
38 | p.executeUpdate();
39 | }
40 | i++;
41 | }
42 | System.out.println("Inserted " + i + " null values");
43 |
44 | // Clean up
45 | int result = statement.executeUpdate("DROP TABLE updateCount;");
46 | System.out.println("Affected rows (should be " + loop*2 + "): " + result);
47 | }
48 |
49 | } catch (SQLException e) {
50 | e.printStackTrace();
51 | }
52 | }
53 |
54 | public static void main(String[] args) {
55 | updateCount("jdbc:monetdb:memory:", 5);
56 | updateCount("jdbc:monetdb:file:" + System.getProperty("user.dir") + "/testdata/localdb", 5);
57 | }
58 | }
--------------------------------------------------------------------------------
/java/META-INF/services/java.sql.Driver:
--------------------------------------------------------------------------------
1 | org.monetdb.monetdbe.MonetDriver
--------------------------------------------------------------------------------
/java/src/main/java/org/monetdb/monetdbe/MonetParameterMetaData.java:
--------------------------------------------------------------------------------
1 | package org.monetdb.monetdbe;
2 |
3 | import java.sql.ParameterMetaData;
4 | import java.sql.SQLException;
5 | import java.sql.SQLFeatureNotSupportedException;
6 |
7 | /**
8 | * A {@link ParameterMetaData} suitable for the MonetDB embedded database.
9 | *
10 | * An object that can be used to get information about the types and properties for each parameter marker in a PreparedStatement object.
11 | */
12 | public class MonetParameterMetaData extends MonetWrapper implements ParameterMetaData {
13 | /** Number of parameters */
14 | protected final int parameterCount;
15 | /** The MonetDB types of the parameters as integers */
16 | protected final int[] types;
17 | /** The MonetDB types of the parameters as strings */
18 | protected final String[] monetTypes;
19 | /** The JDBC SQL types of the parameters */
20 | protected final int[] sqlTypes;
21 | /** The name of the Java classes corresponding to the parameters */
22 | private final String[] javaTypes;
23 | /** Digits for parameters */
24 | protected int[] digits;
25 | /** Scales for parameters */
26 | protected int[] scale;
27 |
28 | /** Constructor from types returned from the PREPARE step of a reusable query
29 | *
30 | * @param parameterCount Number of parameters in PreparedQuery
31 | * @param monetdbeTypes Array of types of parameters in PreparedQuery (monetdbe.h types)
32 | * @param digits Precision of parameters
33 | * @param scale Scale of parameters
34 | **/
35 | MonetParameterMetaData(int parameterCount, int[] monetdbeTypes, int[] digits, int[] scale) {
36 | this.parameterCount = parameterCount;
37 | this.types = monetdbeTypes;
38 | this.monetTypes = new String[parameterCount];
39 | this.sqlTypes = new int[parameterCount];
40 | this.javaTypes = new String[parameterCount];
41 | if (digits != null && scale != null) {
42 | this.digits = digits;
43 | this.scale = scale;
44 | }
45 |
46 | for(int i = 0; i < parameterCount; i++ ) {
47 | this.monetTypes[i] = MonetTypes.getMonetTypeString(monetdbeTypes[i]);
48 | this.sqlTypes[i] = MonetTypes.getSQLTypeFromMonet(monetdbeTypes[i]);
49 | this.javaTypes[i] = MonetTypes.getClassForMonetType(monetdbeTypes[i]).getName();
50 | }
51 | }
52 |
53 | /**
54 | * Retrieves the number of parameters in the PreparedStatement object for which this ParameterMetaData object contains information.
55 | *
56 | * @return the number of parameters
57 | */
58 | @Override
59 | public int getParameterCount() throws SQLException {
60 | return parameterCount;
61 | }
62 |
63 | /**
64 | * Retrieves whether null values are allowed in the designated parameter.
65 | * Currently not supported.
66 | *
67 | * @param param Parameter number (starts at 1)
68 | * @return the nullability status of the given parameter; one of ParameterMetaData.parameterNoNulls,
69 | * ParameterMetaData.parameterNullable, or ParameterMetaData.parameterNullableUnknown
70 | */
71 | @Override
72 | public int isNullable(int param) throws SQLException {
73 | return ParameterMetaData.parameterNullableUnknown;
74 | }
75 |
76 | /**
77 | * Retrieves whether values for the designated parameter can be signed numbers.
78 | *
79 | * @param param Parameter number (starts at 1)
80 | * @return true if so; false otherwise
81 | */
82 | @Override
83 | public boolean isSigned(int param) throws SQLException {
84 | return MonetTypes.isSigned(getParameterType(param));
85 | }
86 |
87 | /**
88 | * Retrieves the designated parameter's specified column size. The returned value represents the maximum column size for the given parameter.
89 | *
90 | * @param param Parameter number (starts at 1)
91 | * @return precision
92 | */
93 | @Override
94 | public int getPrecision(int param) throws SQLException {
95 | try {
96 | return digits[param-1];
97 | } catch (IndexOutOfBoundsException e) {
98 | throw new SQLException("columnIndex out of bounds");
99 | }
100 | }
101 |
102 | /**
103 | * Retrieves the designated parameter's number of digits to right of the decimal point. 0 is returned for data types where the scale is not applicable.
104 | *
105 | * @param param Parameter number (starts at 1)
106 | * @return scale
107 | */
108 | @Override
109 | public int getScale(int param) throws SQLException {
110 | try {
111 | return scale[param-1];
112 | } catch (IndexOutOfBoundsException e) {
113 | throw new SQLException("columnIndex out of bounds");
114 | }
115 | }
116 |
117 | /**
118 | * Retrieves the designated parameter's SQL type.
119 | *
120 | * @param param Parameter number (starts at 1)
121 | * @return SQL type from java.sql.Types
122 | * @throws SQLException if the column parameter is out of bounds
123 | */
124 | @Override
125 | public int getParameterType(int param) throws SQLException {
126 | try {
127 | return sqlTypes[param-1];
128 | } catch (IndexOutOfBoundsException e) {
129 | throw new SQLException("columnIndex out of bounds");
130 | }
131 | }
132 |
133 | /**
134 | * Retrieves the designated parameter's MonetDBe type name as a String.
135 | *
136 | * @param param Parameter number (starts at 1)
137 | * @return MonetDBe type
138 | * @throws SQLException if the column parameter is out of bounds
139 | */
140 | @Override
141 | public String getParameterTypeName(int param) throws SQLException {
142 | //MonetDB type
143 | try {
144 | return monetTypes[param-1];
145 | } catch (IndexOutOfBoundsException e) {
146 | throw new SQLException("columnIndex out of bounds");
147 | }
148 | }
149 |
150 | /**
151 | * Returns the fully-qualified name of the Java class whose instances are manufactured if the method
152 | * ResultSet.getObject is called to retrieve a value from the column.
153 | *
154 | * @param param Parameter number (starts at 1)
155 | * @return the fully-qualified name of the class in the Java programming language that would be used by the method
156 | * ResultSet.getObject to retrieve the value in the specified column
157 | * @throws SQLException if the column parameter is out of bounds
158 | */
159 | @Override
160 | public String getParameterClassName(int param) throws SQLException {
161 | //Java class
162 | try {
163 | return javaTypes[param-1];
164 | } catch (IndexOutOfBoundsException e) {
165 | throw new SQLException("columnIndex out of bounds");
166 | }
167 | }
168 |
169 | /**
170 | * Retrieves the designated parameter's mode. MonetDB doesn't support OUT parameters, so we return
171 | * ParameterMetaData.parameterModeIn always.
172 | *
173 | * @param param Parameter number (starts at 1)
174 | * @return ParameterMetaData.parameterModeIn
175 | */
176 | @Override
177 | public int getParameterMode(int param) throws SQLException {
178 | return ParameterMetaData.parameterModeIn;
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/java/src/main/java/org/monetdb/monetdbe/MonetWrapper.java:
--------------------------------------------------------------------------------
1 | package org.monetdb.monetdbe;
2 |
3 | import java.sql.SQLException;
4 |
5 | /**
6 | * A Wrapper class which provide the ability to retrieve the delegate instance
7 | * when the instance in question is in fact a proxy class.
8 | *
9 | * The wrapper pattern is employed by many JDBC driver implementations to provide
10 | * extensions beyond the traditional JDBC API that are specific to a data source.
11 | * Developers may wish to gain access to these resources that are wrapped (the delegates)
12 | * as proxy class instances representing the the actual resources.
13 | * This class contains a standard mechanism to access these wrapped resources
14 | * represented by their proxy, to permit direct access to the resource delegates.
15 | *
16 | * @author Fabian Groffen, Martin van Dinther
17 | * @version 1.1
18 | */
19 | public class MonetWrapper implements java.sql.Wrapper {
20 | /**
21 | * Returns true if this either implements the interface argument or
22 | * is directly or indirectly a wrapper for an object that does.
23 | * Returns false otherwise. If this implements the interface then
24 | * return true, else if this is a wrapper then return the result of
25 | * recursively calling isWrapperFor
on the wrapped object.
26 | * If this does not implement the interface and is not a wrapper, return
27 | * false. This method should be implemented as a low-cost operation
28 | * compared to unwrap
so that callers can use this method to avoid
29 | * expensive unwrap
calls that may fail.
30 | * If this method returns true then calling unwrap
with the same argument should succeed.
31 | *
32 | * @param iface a Class defining an interface.
33 | * @return true if this implements the interface or directly or indirectly wraps an object that does.
34 | * @throws SQLException if an error occurs while determining whether this is a wrapper
35 | * for an object with the given interface.
36 | * @since 1.6
37 | */
38 | @Override
39 | public boolean isWrapperFor(final Class> iface) throws SQLException {
40 | return iface != null && iface.isAssignableFrom(getClass());
41 | }
42 |
43 | /**
44 | * Returns an object that implements the given interface to allow
45 | * access to non-standard methods, or standard methods not exposed by the proxy.
46 | * The result may be either the object found to implement the interface
47 | * or a proxy for that object.
48 | * If the receiver implements the interface then the result is the receiver
49 | * or a proxy for the receiver.
50 | * If the receiver is a wrapper and the wrapped object implements the interface
51 | * then the result is the wrapped object or a proxy for the wrapped object.
52 | * Otherwise return the result of calling unwrap
recursively on
53 | * the wrapped object or a proxy for that result.
54 | * If the receiver is not a wrapper and does not implement the interface,
55 | * then an SQLException
is thrown.
56 | *
57 | * @param iface A Class defining an interface that the result must implement.
58 | * @return an object that implements the interface. May be a proxy for the actual implementing object.
59 | * @throws SQLException If no object found that implements the interface
60 | * @since 1.6
61 | */
62 | @Override
63 | @SuppressWarnings("unchecked")
64 | public T unwrap(final Class iface) throws SQLException {
65 | if (isWrapperFor(iface)) {
66 | return (T) this;
67 | }
68 | throw new SQLException("Cannot unwrap to interface: " + (iface != null ? iface.getName() : ""), "0A000");
69 | }
70 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/AllTests.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import org.junit.runner.RunWith;
4 | import org.junit.runners.Suite;
5 | import org.junit.runners.Suite.SuiteClasses;
6 |
7 | //Oct2020 fails Test 21 (Timeout not reached), Test 22 (BigDecimal isn't scaled), Test 18 (Oct2020 does not support the new way of multithreaded connection?), plus some tests fail with "unable to drop table x"
8 | //Jul2021 passes all the tests except Test 22 (BigDecimal isn't scaled), but Tests 19 and 20 have to be modified
9 |
10 | //Jan2022 passes all the tests (memory and file databases)
11 | //Jan2022 remote connection errors:
12 | // 04 -> update count error
13 | // 05 -> update count error
14 | // 06 -> update count error
15 | // 07 -> update count error
16 | // 08 -> update count error
17 | // 12 -> batchPreparedQuery parameter 2 not bound to value -> monetdbe thinks there is an extra timestamp parameter to bind
18 | // 16 -> update count error
19 | // 17 -> update count error
20 | // 18 -> CORRECT: crashes if run through junit framework, but the multithreaded code works fine (RemoteConnectionTests example)
21 | // 19 -> PreparedStatement getParameterCount is wrong -> monetdbe thinks there is an extra timestamp parameter to bind
22 | // 21 -> MALException:mal.interpreter:HYT00!Query aborted due to session timeout // Timeout: 2000 Execution time: 3
23 | // 22 -> scale is not being set on DECIMAL; update count error
24 | @RunWith(Suite.class)
25 | @SuiteClasses({ Test_01_OpenAndCloseConnection.class, Test_02_CloseConnectionTwice.class, Test_03_AutoCommit.class,
26 | Test_04_SimpleInsertAndQueryStatements.class, Test_05_BasicInsertAndQueryStatements.class,
27 | Test_06_ComplexInsertAndQueryStatements.class, Test_07_SimplePreparedStatements.class,
28 | Test_08_ComplexPreparedStatements.class, Test_09_LoadAndQueryTaxi.class, Test_10_MetaData.class,
29 | Test_11_ConcurrentConnections.class, Test_12_BatchesAndJoinsMovies.class, Test_13_Schema.class,
30 | //Test_14_MultipleResultSet.class,
31 | Test_15_Transactions.class, Test_16_MixedOrderStatements.class, Test_17_QueryInThread.class,
32 | Test_18_Multithreaded_Connection.class, Test_19_ParameterMetadata.class, Test_20_PreparedResultMetadata.class,
33 | Test_21_ConnectionOptions.class, Test_22_GetObject.class})
34 | public class AllTests {
35 |
36 | protected static final String MEMORY_CONNECTION = "jdbc:monetdb:memory:";
37 | //Maven runs tests from the java directory, testdata folder should be on the root of the repo
38 | protected static final String LOCAL_CONNECTION = "jdbc:monetdb:file:" + System.getProperty("user.dir") + "/../testdata/localdb";
39 | //protected static final String LOCAL_CONNECTION = "jdbc:monetdb:file:./testdata/localdb";
40 | protected static final String PROXY_CONNECTION = "mapi:monetdb://localhost:50000/test";
41 |
42 | protected static final String[] CONNECTIONS = { MEMORY_CONNECTION, LOCAL_CONNECTION };
43 |
44 | protected static final String AUTOCOMMIT_FALSE_PARM = "?autocommit=false";
45 |
46 | //Maven runs tests from the java directory, testdata folder should be on the root of the repo
47 | protected static final String TAXI_CSV = System.getProperty("user.dir") + "/../testdata/taxi/yellow_tripdata_2016-01.csv";
48 | //protected static final String TAXI_CSV = "./testdata/taxi/yellow_tripdata_2016-01.csv";
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/java/src/test/java/test/RunTestsApp.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | public class RunTestsApp {
4 |
5 | public static void main(String[] args) {
6 | ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
7 |
8 | new Test_01_OpenAndCloseConnection().openAndCloseConnection();
9 | new Test_02_CloseConnectionTwice().closeConnectionTwice();
10 | new Test_03_AutoCommit().autoCommit();
11 | new Test_04_SimpleInsertAndQueryStatements().simpleInsertAndQueryStatements();
12 | new Test_05_BasicInsertAndQueryStatements().basicInsertAndQueryStatements();
13 | new Test_06_ComplexInsertAndQueryStatements().complexInsertAndQueryStatements();
14 | new Test_07_SimplePreparedStatements().simplePreparedStatements();
15 | new Test_08_ComplexPreparedStatements().complexPreparedStatements();
16 | new Test_09_LoadAndQueryTaxi().loadAndQueryTaxi();
17 | new Test_10_MetaData().metaData();
18 | new Test_11_ConcurrentConnections().concurrentConnections();
19 | new Test_12_BatchesAndJoinsMovies().batchesAndJoinsMovies();
20 | new Test_13_Schema().schema();
21 | // new Test_14_MultipleResultSet().multipleResultSet();
22 | new Test_15_Transactions().transactions();
23 | new Test_16_MixedOrderStatements().mixedOrderStatements();
24 | new Test_17_QueryInThread().queryInThread();
25 | new Test_18_Multithreaded_Connection().multithreadedConnection();
26 | new Test_19_ParameterMetadata().parameterMetadata();
27 | new Test_20_PreparedResultMetadata().preparedResultMetadata();
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_01_OpenAndCloseConnection.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertFalse;
4 | import static org.junit.Assert.assertNotNull;
5 | import static org.junit.Assert.assertTrue;
6 | import static org.junit.Assert.fail;
7 |
8 | import java.sql.Connection;
9 | import java.sql.DriverManager;
10 | import java.sql.SQLException;
11 | import java.util.stream.Stream;
12 |
13 | import org.junit.Test;
14 |
15 | public class Test_01_OpenAndCloseConnection {
16 |
17 | @Test
18 | public void openAndCloseConnection() {
19 | Stream.of(AllTests.CONNECTIONS).forEach(this::openAndCloseConnection);
20 | }
21 |
22 | private void openAndCloseConnection(String connectionUrl) {
23 | try {
24 |
25 | @SuppressWarnings("resource")
26 | Connection conn = DriverManager.getConnection(connectionUrl, null);
27 |
28 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
29 | assertFalse(conn.isClosed());
30 |
31 | // MonetDB/e connection opened successfully
32 |
33 | conn.close();
34 | assertTrue(conn.isClosed());
35 |
36 | // MonetDB/e connection closed successfully
37 |
38 | } catch (SQLException e) {
39 |
40 | fail(e.toString());
41 |
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_02_CloseConnectionTwice.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertFalse;
4 | import static org.junit.Assert.assertNotNull;
5 | import static org.junit.Assert.assertTrue;
6 | import static org.junit.Assert.fail;
7 |
8 | import java.sql.Connection;
9 | import java.sql.DriverManager;
10 | import java.sql.SQLException;
11 | import java.util.stream.Stream;
12 |
13 | import org.junit.Test;
14 |
15 | public class Test_02_CloseConnectionTwice {
16 |
17 | @Test
18 | public void closeConnectionTwice() {
19 | Stream.of(AllTests.CONNECTIONS).forEach(this::closeConnectionTwice);
20 | }
21 |
22 | private void closeConnectionTwice(String connectionUrl) {
23 | try {
24 |
25 | @SuppressWarnings("resource")
26 | Connection conn = DriverManager.getConnection(connectionUrl, null);
27 |
28 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
29 | assertFalse(conn.isClosed());
30 |
31 | // MonetDB/e connection opened successfully
32 |
33 | conn.close();
34 | assertTrue(conn.isClosed());
35 |
36 | // MonetDB/e connection closed successfully
37 |
38 | conn.close();
39 | assertTrue(conn.isClosed());
40 |
41 | } catch (SQLException e) {
42 |
43 | fail(e.toString());
44 |
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_03_AutoCommit.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertFalse;
5 | import static org.junit.Assert.assertNotNull;
6 | import static org.junit.Assert.assertTrue;
7 | import static org.junit.Assert.fail;
8 |
9 | import java.sql.Connection;
10 | import java.sql.DriverManager;
11 | import java.sql.SQLException;
12 | import java.util.stream.Stream;
13 |
14 | import org.junit.Test;
15 |
16 | public class Test_03_AutoCommit {
17 |
18 | @Test
19 | public void autoCommit() {
20 | Stream.of(AllTests.CONNECTIONS).forEach(x -> {
21 | autoCommit(x, true);
22 | autoCommit(x + AllTests.AUTOCOMMIT_FALSE_PARM, false);
23 | });
24 | }
25 |
26 | private void autoCommit(String connectionUrl, boolean autoCommit) {
27 | try {
28 |
29 | @SuppressWarnings("resource")
30 | Connection conn = DriverManager.getConnection(connectionUrl, null);
31 |
32 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
33 | assertFalse(conn.isClosed());
34 |
35 | // MonetDB/e connection opened successfully
36 |
37 | assertEquals(autoCommit, conn.getAutoCommit());
38 |
39 | conn.close();
40 | assertTrue(conn.isClosed());
41 |
42 | // MonetDB/e connection closed successfully
43 |
44 | } catch (SQLException e) {
45 |
46 | fail(e.toString());
47 |
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_04_SimpleInsertAndQueryStatements.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertFalse;
5 | import static org.junit.Assert.assertNotNull;
6 | import static org.junit.Assert.assertNull;
7 | import static org.junit.Assert.assertTrue;
8 | import static org.junit.Assert.fail;
9 |
10 | import java.sql.Connection;
11 | import java.sql.DriverManager;
12 | import java.sql.ResultSet;
13 | import java.sql.SQLException;
14 | import java.sql.Statement;
15 | import java.util.stream.Stream;
16 |
17 | import org.junit.Test;
18 | import org.monetdb.monetdbe.MonetResultSet;
19 |
20 | public class Test_04_SimpleInsertAndQueryStatements {
21 |
22 | @Test
23 | public void simpleInsertAndQueryStatements() {
24 | Stream.of(AllTests.CONNECTIONS).forEach(this::simpleInsertAndQueryStatements);
25 | }
26 |
27 | private void simpleInsertAndQueryStatements(String connectionUrl) {
28 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
29 |
30 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
31 | assertFalse(conn.isClosed());
32 | assertTrue(conn.getAutoCommit());
33 |
34 | // Create table and insert values
35 | try (Statement statement = conn.createStatement()) {
36 | statement.executeUpdate("CREATE TABLE test04 (b BOOLEAN, i INTEGER, s STRING);");
37 | statement.executeUpdate(
38 | "INSERT INTO test04 VALUES (false, 3, 'hello'), (true, 500, 'world'), (false, -1, NULL);");
39 |
40 | // Query table
41 | try (ResultSet rs = statement.executeQuery("SELECT * FROM test04;")) {
42 | assertEquals(3, ((MonetResultSet) rs).getRowsNumber());
43 | assertEquals(3, ((MonetResultSet) rs).getColumnsNumber());
44 |
45 | rs.next();
46 | assertEquals(1, rs.getRow());
47 | assertEquals(false, rs.getBoolean(1));
48 | assertEquals(3, rs.getInt(2));
49 | assertEquals("hello", rs.getString(3));
50 |
51 | rs.next();
52 | assertEquals(2, rs.getRow());
53 | assertEquals(true, rs.getBoolean(1));
54 | assertEquals(500, rs.getInt(2));
55 | assertEquals("world", rs.getString(3));
56 |
57 | rs.next();
58 | assertEquals(3, rs.getRow());
59 | assertEquals(false, rs.getBoolean(1));
60 | assertEquals(-1, rs.getInt(2));
61 | assertNull(rs.getString(3));
62 |
63 | assertFalse(rs.next());
64 | }
65 |
66 | // Clean up
67 | int result = statement.executeUpdate("DROP TABLE test04;");
68 | assertEquals(3, result); // 3: because we've dropped a table with 3 records
69 | assertEquals(-1, statement.getUpdateCount());
70 | }
71 |
72 | } catch (SQLException e) {
73 |
74 | fail(e.toString());
75 |
76 | }
77 | }
78 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_05_BasicInsertAndQueryStatements.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertFalse;
5 | import static org.junit.Assert.assertNotNull;
6 | import static org.junit.Assert.assertTrue;
7 | import static org.junit.Assert.fail;
8 |
9 | import java.sql.Connection;
10 | import java.sql.DriverManager;
11 | import java.sql.ResultSet;
12 | import java.sql.SQLException;
13 | import java.sql.Statement;
14 | import java.util.stream.Stream;
15 |
16 | import org.junit.Test;
17 | import org.monetdb.monetdbe.MonetResultSet;
18 |
19 | public class Test_05_BasicInsertAndQueryStatements {
20 |
21 | @Test
22 | public void basicInsertAndQueryStatements() {
23 | Stream.of(AllTests.CONNECTIONS).forEach(this::basicInsertAndQueryStatements);
24 | }
25 |
26 | private void basicInsertAndQueryStatements(String connectionUrl) {
27 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
28 |
29 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
30 | assertFalse(conn.isClosed());
31 | assertTrue(conn.getAutoCommit());
32 |
33 | // Create table and insert values
34 | try (Statement statement = conn.createStatement()) {
35 | statement.executeUpdate(
36 | "CREATE TABLE test05 (b BOOLEAN, s SMALLINT, i INT, l BIGINT, r REAL, f FLOAT);");
37 | statement.executeUpdate(
38 | "INSERT INTO test05 VALUES " + "(true, 2, 3, 5, 1.0, 1.66), (true, 4, 6, 10, 2.5, 3.643), "
39 | + "(false, 8, 12, 20, 25.25, 372.325), (false, 16, 24, 40, 255.255, 2434.432), "
40 | + "(false, null, 1, 1, 1, null);");
41 |
42 | // Query table
43 | try (ResultSet rs = statement.executeQuery("SELECT * FROM test05;")) {
44 | assertEquals(5, ((MonetResultSet) rs).getRowsNumber());
45 | assertEquals(6, ((MonetResultSet) rs).getColumnsNumber());
46 |
47 | rs.next();
48 | assertEquals(1, rs.getRow());
49 | assertEquals(true, rs.getBoolean(1));
50 | assertEquals(2, rs.getShort(2));
51 | assertEquals(3, rs.getInt(3));
52 | assertEquals(5, rs.getLong(4));
53 | assertEquals(1.0f, rs.getFloat(5), .01d);
54 | assertEquals(1.66d, rs.getDouble(6), .01d);
55 |
56 | rs.next();
57 | assertEquals(2, rs.getRow());
58 | assertEquals(true, rs.getBoolean(1));
59 | assertEquals(4, rs.getShort(2));
60 | assertEquals(6, rs.getInt(3));
61 | assertEquals(10, rs.getLong(4));
62 | assertEquals(2.5f, rs.getFloat(5), .01d);
63 | assertEquals(3.643d, rs.getDouble(6), .01d);
64 |
65 | rs.next();
66 | assertEquals(3, rs.getRow());
67 | assertEquals(false, rs.getBoolean(1));
68 | assertEquals(8, rs.getShort(2));
69 | assertEquals(12, rs.getInt(3));
70 | assertEquals(20, rs.getLong(4));
71 | assertEquals(25.25f, rs.getFloat(5), .01d);
72 | assertEquals(372.325d, rs.getDouble(6), .01d);
73 |
74 | rs.next();
75 | assertEquals(4, rs.getRow());
76 | assertEquals(false, rs.getBoolean(1));
77 | assertEquals(16, rs.getShort(2));
78 | assertEquals(24, rs.getInt(3));
79 | assertEquals(40, rs.getLong(4));
80 | assertEquals(255.255f, rs.getFloat(5), .01d);
81 | assertEquals(2434.432d, rs.getDouble(6), .01d);
82 |
83 | rs.next();
84 | assertEquals(5, rs.getRow());
85 | assertEquals(false, rs.getBoolean(1));
86 | assertEquals(0, rs.getShort(2));
87 | assertEquals(1, rs.getInt(3));
88 | assertEquals(1, rs.getLong(4));
89 | assertEquals(1.0f, rs.getFloat(5), .01d);
90 | assertEquals(0d, rs.getDouble(6), .01d);
91 |
92 | assertFalse(rs.next());
93 | }
94 |
95 | // Clean up
96 | int result = statement.executeUpdate("DROP TABLE test05;");
97 | assertEquals(5, result); // 5: because we've dropped a table with 5 records
98 |
99 | assertEquals(-1, statement.getUpdateCount());
100 | }
101 |
102 | } catch (SQLException e) {
103 |
104 | fail(e.toString());
105 |
106 | }
107 | }
108 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_06_ComplexInsertAndQueryStatements.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertArrayEquals;
4 | import static org.junit.Assert.assertEquals;
5 | import static org.junit.Assert.assertFalse;
6 | import static org.junit.Assert.assertNotNull;
7 | import static org.junit.Assert.assertNull;
8 | import static org.junit.Assert.assertTrue;
9 | import static org.junit.Assert.fail;
10 |
11 | import java.math.BigDecimal;
12 | import java.sql.Connection;
13 | import java.sql.Date;
14 | import java.sql.DriverManager;
15 | import java.sql.ResultSet;
16 | import java.sql.SQLException;
17 | import java.sql.Statement;
18 | import java.sql.Time;
19 | import java.sql.Timestamp;
20 | import java.util.Calendar;
21 | import java.util.stream.Stream;
22 |
23 | import org.junit.Test;
24 | import org.monetdb.monetdbe.MonetResultSet;
25 |
26 | public class Test_06_ComplexInsertAndQueryStatements {
27 |
28 | @Test
29 | public void complexInsertAndQueryStatements() {
30 | Stream.of(AllTests.CONNECTIONS).forEach(this::complexInsertAndQueryStatements);
31 | }
32 |
33 | private void complexInsertAndQueryStatements(String connectionUrl) {
34 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
35 |
36 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
37 | assertFalse(conn.isClosed());
38 | assertTrue(conn.getAutoCommit());
39 |
40 | // Create table and insert values
41 | try (Statement statement = conn.createStatement()) {
42 | statement.executeUpdate(
43 | "CREATE TABLE test06 (bd NUMERIC, s STRING, b BLOB, d DATE, t TIME, ts TIMESTAMP);");
44 | assertEquals(-1, statement.getUpdateCount());
45 | assertEquals(4, statement.executeUpdate("INSERT INTO test06 VALUES "
46 | + "(34589.54, 'hello', '12ff803F', current_date, current_time, current_timestamp), "
47 | + "(34012933.888, 'world', '0000803F', str_to_date('23-09-1987', '%d-%m-%Y'), str_to_time('11:40:30', '%H:%M:%S'), str_to_timestamp('23-09-1987 11:40', '%d-%m-%Y %H:%M')), "
48 | + "(666.666, 'bye', 'ffffffff', str_to_date('23-09-1990', '%d-%m-%Y'), str_to_time('11:40:35', '%H:%M:%S'), str_to_timestamp('23-09-1990 11:40', '%d-%m-%Y %H:%M')), "
49 | + "(NULL, NULL, NULL, NULL, NULL, NULL);"));
50 | long time = Calendar.getInstance().getTimeInMillis();
51 |
52 | // Query table
53 | try (ResultSet rs = statement.executeQuery("SELECT * FROM test06;")) {
54 | assertEquals(4, ((MonetResultSet) rs).getRowsNumber());
55 | assertEquals(6, ((MonetResultSet) rs).getColumnsNumber());
56 |
57 | rs.next();
58 | assertEquals(1, rs.getRow());
59 | assertEquals(new BigDecimal("34589.540").toString(), rs.getBigDecimal(1).toString());
60 | assertEquals("hello", rs.getString(2));
61 | assertArrayEquals(new byte[] { 0x12, (byte) 0xFF, (byte) 0x80, 0x3F },
62 | rs.getBlob(3).getBytes(1, (int) rs.getBlob(3).length()));
63 | assertEquals(new Date(time).toString(),
64 | rs.getDate(4).toString());
65 | //assertEquals(new Time(time).toString(), rs.getTime(5).toString());
66 | //Timestamp ts = new Timestamp(time);
67 | //ts.setNanos(0);
68 | //Timestamp ts_db = rs.getTimestamp(6);
69 | //ts_db.setNanos(0);
70 | //assertEquals(ts, ts_db);
71 |
72 | rs.next();
73 | assertEquals(2, rs.getRow());
74 | assertEquals(new BigDecimal("34012933.888").toString(), rs.getBigDecimal(1).toString());
75 | assertEquals("world", rs.getString(2));
76 | assertArrayEquals(new byte[] { 0x0, 0x0, (byte) 0x80, 0x3F },
77 | rs.getBlob(3).getBytes(1, (int) rs.getBlob(3).length()));
78 | assertEquals(Date.valueOf("1987-09-23"), rs.getDate(4));
79 | assertEquals(Time.valueOf("11:40:30"), rs.getTime(5));
80 | assertEquals(Timestamp.valueOf("1987-09-23 11:40:00"), rs.getTimestamp(6));
81 |
82 | rs.next();
83 | assertEquals(3, rs.getRow());
84 | assertEquals(new BigDecimal("666.666").toString(), rs.getBigDecimal(1).toString());
85 | assertEquals("bye", rs.getString(2));
86 | assertArrayEquals(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF },
87 | rs.getBlob(3).getBytes(1, (int) rs.getBlob(3).length()));
88 | assertEquals(Date.valueOf("1990-09-23"), rs.getDate(4));
89 | assertEquals(Time.valueOf("11:40:35"), rs.getTime(5));
90 | assertEquals(Timestamp.valueOf("1990-09-23 11:40:00"), rs.getTimestamp(6));
91 |
92 | rs.next();
93 | assertEquals(4, rs.getRow());
94 | assertNull(rs.getBigDecimal(1));
95 | assertNull(rs.getString(2));
96 | assertNull(rs.getBlob(3));
97 | assertNull(rs.getDate(4));
98 | assertNull(rs.getTime(5));
99 | assertNull(rs.getTimestamp(6));
100 |
101 | assertFalse(rs.next());
102 | }
103 |
104 | // Clean up
105 | int result = statement.executeUpdate("DROP TABLE test06;");
106 | assertEquals(4, result); // 4: because we've dropped a table with 4 records
107 |
108 | assertEquals(-1, statement.getUpdateCount());
109 | }
110 |
111 | } catch (SQLException e) {
112 |
113 | fail(e.toString());
114 |
115 | }
116 | }
117 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_07_SimplePreparedStatements.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static junit.framework.TestCase.assertNull;
4 | import static org.junit.Assert.assertEquals;
5 | import static org.junit.Assert.assertFalse;
6 | import static org.junit.Assert.assertNotNull;
7 | import static org.junit.Assert.assertTrue;
8 | import static org.junit.Assert.fail;
9 | import java.sql.Connection;
10 | import java.sql.DriverManager;
11 | import java.sql.PreparedStatement;
12 | import java.sql.ResultSet;
13 | import java.sql.SQLException;
14 | import java.sql.Statement;
15 | import java.sql.Types;
16 | import java.util.stream.Stream;
17 | import org.apache.commons.lang3.StringUtils;
18 | import org.junit.Test;
19 | import org.monetdb.monetdbe.MonetResultSet;
20 |
21 | public class Test_07_SimplePreparedStatements {
22 |
23 | @Test
24 | public void simplePreparedStatements() {
25 | Stream.of(AllTests.CONNECTIONS).forEach(this::simplePreparedStatements);
26 | }
27 |
28 | private void simplePreparedStatements(String connectionUrl) {
29 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
30 |
31 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
32 | assertFalse(conn.isClosed());
33 | assertTrue(conn.getAutoCommit());
34 |
35 | // Create table and insert values
36 | try (Statement statement = conn.createStatement()) {
37 | statement.executeUpdate("CREATE TABLE test07 (b BOOLEAN, i INTEGER, s STRING);");
38 |
39 | try (PreparedStatement p = conn.prepareStatement("INSERT INTO test07 VALUES (?, ?, ?);")) {
40 | p.setBoolean(1, true);
41 | p.setInt(2, 10);
42 | p.setString(3, "Hello world");
43 | assertEquals(1, p.executeUpdate());
44 | }
45 |
46 | try (PreparedStatement p = conn.prepareStatement("INSERT INTO test07 VALUES (?, ?, ?);")) {
47 | p.setNull(1, Types.BOOLEAN);
48 | p.setNull(2, Types.INTEGER);
49 | p.setNull(3, Types.VARCHAR);
50 | assertEquals(1, p.executeUpdate());
51 | }
52 |
53 | // Query table
54 | try (ResultSet rs = statement.executeQuery("SELECT * FROM test07;")) {
55 | assertEquals(2, ((MonetResultSet) rs).getRowsNumber());
56 | assertEquals(3, ((MonetResultSet) rs).getColumnsNumber());
57 |
58 | rs.next();
59 | assertEquals(1, rs.getRow());
60 | assertEquals(true, rs.getBoolean(1));
61 | assertEquals(10, rs.getInt(2));
62 | assertEquals("Hello world", rs.getString(3));
63 |
64 | rs.next();
65 | assertEquals(2, rs.getRow());
66 | assertEquals(false, rs.getBoolean(1));
67 | assertEquals(0, rs.getInt(2));
68 | assertNull(rs.getString(3));
69 |
70 | assertFalse(rs.next());
71 | }
72 |
73 | // Clean up
74 | int result = statement.executeUpdate("DROP TABLE test07;");
75 | assertEquals(1, result);
76 |
77 | assertEquals(-1, statement.getUpdateCount());
78 | }
79 |
80 | } catch (SQLException e) {
81 |
82 | fail(e.toString());
83 |
84 | }
85 | }
86 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_08_ComplexPreparedStatements.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertArrayEquals;
4 | import static org.junit.Assert.assertEquals;
5 | import static org.junit.Assert.assertFalse;
6 | import static org.junit.Assert.assertNotNull;
7 | import static org.junit.Assert.assertNull;
8 | import static org.junit.Assert.assertTrue;
9 | import static org.junit.Assert.fail;
10 | import java.io.ByteArrayInputStream;
11 | import java.sql.Connection;
12 | import java.sql.Date;
13 | import java.sql.DriverManager;
14 | import java.sql.PreparedStatement;
15 | import java.sql.ResultSet;
16 | import java.sql.SQLException;
17 | import java.sql.Statement;
18 | import java.sql.Time;
19 | import java.sql.Timestamp;
20 | import java.sql.Types;
21 | import java.util.stream.Stream;
22 | import org.apache.commons.lang3.StringUtils;
23 | import org.junit.Test;
24 | import org.monetdb.monetdbe.MonetBlob;
25 | import org.monetdb.monetdbe.MonetResultSet;
26 |
27 | public class Test_08_ComplexPreparedStatements {
28 |
29 | @Test
30 | public void complexPreparedStatements() {
31 | Stream.of(AllTests.CONNECTIONS).forEach(this::complexPreparedStatements);
32 | }
33 |
34 | private void complexPreparedStatements(String connectionUrl) {
35 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
36 |
37 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
38 | assertFalse(conn.isClosed());
39 | assertTrue(conn.getAutoCommit());
40 |
41 | // Create first table and insert values
42 | try (Statement statement = conn.createStatement()) {
43 | statement.executeUpdate(
44 | "CREATE TABLE test08a (bd NUMERIC, s STRING, b BLOB, d DATE, t TIME, ts TIMESTAMP);");
45 |
46 | try (PreparedStatement p = conn.prepareStatement("INSERT INTO test08a VALUES (?, ?, ?, ?, ?, ?);")) {
47 | // TODO: Implement setBigDecimal
48 | // p.setBigDecimal(1, BigDecimal.TEN);
49 | p.setInt(1, 10);
50 | p.setString(2, "Hello world");
51 | p.setBlob(3, new ByteArrayInputStream("Hello world".getBytes()));
52 | p.setDate(4, Date.valueOf("1975-10-25"));
53 | p.setTime(5, Time.valueOf("12:24:36"));
54 | p.setTimestamp(6, Timestamp.valueOf("1975-10-25 12:24:36"));
55 | assertEquals(1, p.executeUpdate());
56 | }
57 |
58 | try (PreparedStatement p = conn.prepareStatement("INSERT INTO test08a VALUES (NULL, ?, ?, ?, ?, ?);")) {
59 | p.setString(1, "Hello world 2");
60 | p.setBlob(2, new ByteArrayInputStream("Hello world 2".getBytes()));
61 | p.setDate(3, Date.valueOf("1975-10-26"));
62 | p.setTime(4, Time.valueOf("12:24:37"));
63 | p.setTimestamp(5, Timestamp.valueOf("1975-10-25 12:24:37"));
64 | assertEquals(1, p.executeUpdate());
65 | }
66 |
67 | try (PreparedStatement p = conn.prepareStatement("INSERT INTO test08a VALUES (?, ?, ?, ?, ?, ?);")) {
68 | p.setNull(1, Types.NUMERIC);
69 | p.setNull(2, Types.VARCHAR);
70 | p.setNull(3, Types.BLOB);
71 | p.setNull(4, Types.DATE);
72 | p.setNull(5, Types.TIME);
73 | p.setNull(6, Types.TIMESTAMP);
74 | assertEquals(1, p.executeUpdate());
75 | }
76 |
77 | // Query table
78 | try (ResultSet rs = statement.executeQuery("SELECT * FROM test08a;")) {
79 | assertEquals(3, ((MonetResultSet) rs).getRowsNumber());
80 | assertEquals(6, ((MonetResultSet) rs).getColumnsNumber());
81 |
82 | rs.next();
83 | // assertEquals(BigDecimal.TEN, rs.getBigDecimal(1));
84 | assertEquals(1, rs.getRow());
85 | assertEquals(10, rs.getInt(1));
86 | assertEquals("Hello world", rs.getString(2));
87 | MonetBlob b = (MonetBlob) rs.getBlob(3);
88 | assertArrayEquals("Hello world".getBytes(),b.getBytes(1,(int) b.length()));
89 | assertEquals(Date.valueOf("1975-10-25"), rs.getDate(4));
90 | assertEquals(Time.valueOf("12:24:36"), rs.getTime(5));
91 | assertEquals(Timestamp.valueOf("1975-10-25 12:24:36"), rs.getTimestamp(6));
92 |
93 | rs.next();
94 | assertEquals(2, rs.getRow());
95 | assertNull(rs.getBigDecimal(1));
96 | assertEquals("Hello world 2", rs.getString(2));
97 | MonetBlob blob = (MonetBlob) rs.getBlob(3);
98 | assertArrayEquals("Hello world 2".getBytes(), blob.getBytes(1L, (int)blob.length()));
99 | assertEquals(Date.valueOf("1975-10-26"), rs.getDate(4));
100 | assertEquals(Time.valueOf("12:24:37"), rs.getTime(5));
101 | assertEquals(Timestamp.valueOf("1975-10-25 12:24:37"), rs.getTimestamp(6));
102 |
103 | rs.next();
104 | assertEquals(3, rs.getRow());
105 | assertNull(rs.getBigDecimal(1));
106 | assertNull(rs.getString(2));
107 | assertNull(rs.getBlob(3));
108 | assertNull(rs.getDate(4));
109 | assertNull(rs.getTime(5));
110 | assertNull(rs.getTimestamp(6));
111 |
112 | assertFalse(rs.next());
113 | }
114 |
115 | // Clean up
116 | int result = statement.executeUpdate("DROP TABLE test08a;");
117 | assertEquals(1, result);
118 |
119 | assertEquals(-1, statement.getUpdateCount());
120 | }
121 |
122 | // Create second table and insert values
123 | try (Statement statement = conn.createStatement()) {
124 | statement.executeUpdate(
125 | "CREATE TABLE test08b (i INTEGER, l BIGINT, f REAL, df FLOAT, s STRING, d DATE, t TIME, ts TIMESTAMP);");
126 |
127 | try (PreparedStatement p = conn.prepareStatement("INSERT INTO test08b VALUES (?,?,?,?,?,'2020-10-31','15:16:59','2007-12-24 14:11:40');")) {
128 | p.setInt(1, 1000);
129 | p.setLong(2, 1000000);
130 | p.setFloat(3, 3.5f);
131 | p.setDouble(4, 3.5d);
132 | p.setString(5, "bye world");
133 | assertEquals(1, p.executeUpdate());
134 | }
135 |
136 | try (PreparedStatement p = conn.prepareStatement("INSERT INTO test08b VALUES (?,?,?,?,?,NULL,NULL,NULL);")) {
137 | p.setNull(1, Types.INTEGER);
138 | p.setNull(2, Types.BIGINT);
139 | p.setNull(3, Types.REAL);
140 | p.setNull(4, Types.DOUBLE);
141 | p.setNull(5, Types.VARCHAR);
142 | assertEquals(1, p.executeUpdate());
143 | }
144 |
145 | // Query table
146 | try (ResultSet rs = statement.executeQuery("SELECT * FROM test08b;")) {
147 | assertEquals(2, ((MonetResultSet) rs).getRowsNumber());
148 | assertEquals(8, ((MonetResultSet) rs).getColumnsNumber());
149 |
150 | rs.next();
151 | assertEquals(1, rs.getRow());
152 | assertEquals(1000, rs.getInt(1));
153 | assertEquals(1000000, rs.getInt(2));
154 | assertEquals(3.5f, rs.getFloat(3), .01f);
155 | assertEquals(3.5d, rs.getDouble(4), 0.1d);
156 | assertEquals("bye world", rs.getString(5));
157 | assertEquals(Date.valueOf("2020-10-31"), rs.getDate(6));
158 | assertEquals(Time.valueOf("15:16:59"), rs.getTime(7));
159 | assertEquals(Timestamp.valueOf("2007-12-24 14:11:40"), rs.getTimestamp(8));
160 |
161 | rs.next();
162 | assertEquals(2, rs.getRow());
163 | assertEquals(0, rs.getInt(1));
164 | assertEquals(0, rs.getInt(2));
165 | assertEquals(0.0f, rs.getFloat(3), .01f);
166 | assertEquals(0.0d, rs.getDouble(4), 0.1d);
167 | assertNull(rs.getString(5));
168 | assertNull(rs.getDate(6));
169 | assertNull(rs.getTime(7));
170 | assertNull(rs.getTimestamp(8));
171 |
172 | assertFalse(rs.next());
173 | }
174 |
175 | // Clean up
176 | int result = statement.executeUpdate("DROP TABLE test08b;");
177 | assertEquals(1, result);
178 |
179 | assertEquals(-1, statement.getUpdateCount());
180 | }
181 |
182 | } catch (SQLException e) {
183 |
184 | fail(e.toString());
185 |
186 | }
187 | }
188 | }
189 |
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_10_MetaData.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertFalse;
5 | import static org.junit.Assert.assertNotNull;
6 | import static org.junit.Assert.assertTrue;
7 | import static org.junit.Assert.fail;
8 |
9 | import java.sql.Connection;
10 | import java.sql.DatabaseMetaData;
11 | import java.sql.DriverManager;
12 | import java.sql.ResultSet;
13 | import java.sql.ResultSetMetaData;
14 | import java.sql.SQLException;
15 | import java.sql.Statement;
16 | import java.sql.Types;
17 | import java.util.stream.Stream;
18 |
19 | import org.apache.commons.lang3.StringUtils;
20 | import org.junit.Test;
21 | import org.monetdb.monetdbe.MonetResultSet;
22 |
23 | public class Test_10_MetaData {
24 |
25 | @Test
26 | public void metaData() {
27 | Stream.of(AllTests.CONNECTIONS).forEach(this::metaData);
28 | }
29 |
30 | private void metaData(String connectionUrl) {
31 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
32 |
33 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
34 | assertFalse(conn.isClosed());
35 | assertTrue(conn.getAutoCommit());
36 |
37 | try (Statement statement = conn.createStatement();
38 | ResultSet rs = statement.executeQuery("SELECT 1, 'hey', 200000000000, 912387.3232;")) {
39 |
40 | assertEquals(1, ((MonetResultSet) rs).getRowsNumber());
41 | assertEquals(4, ((MonetResultSet) rs).getColumnsNumber());
42 |
43 | ResultSetMetaData rsMeta = rs.getMetaData();
44 |
45 | rs.next();
46 | assertEquals((short) 1, rs.getObject(1));
47 | assertEquals("%2", rsMeta.getColumnName(1));
48 | assertEquals(Types.TINYINT, rsMeta.getColumnType(1));
49 | assertEquals("monetdbe_int8_t", rsMeta.getColumnTypeName(1));
50 | assertEquals(Short.class.getName(), rsMeta.getColumnClassName(1));
51 | assertEquals(0, rsMeta.getColumnDisplaySize(1));
52 | }
53 |
54 | DatabaseMetaData dbMeta = conn.getMetaData();
55 |
56 | assertTrue(StringUtils.isNotBlank(dbMeta.getSQLKeywords()));
57 | assertTrue(StringUtils.isNotBlank(dbMeta.getNumericFunctions()));
58 | assertTrue(StringUtils.isNotBlank(dbMeta.getStringFunctions()));
59 | assertTrue(StringUtils.isNotBlank(dbMeta.getSystemFunctions()));
60 | assertTrue(StringUtils.isNotBlank(dbMeta.getTimeDateFunctions()));
61 |
62 | try (ResultSet rs = dbMeta.getTableTypes()) {
63 | assertTrue(((MonetResultSet) rs).getRowsNumber() >= 8);
64 | }
65 | try (ResultSet rs = dbMeta.getProcedures(null, null, null)) {
66 | assertTrue(((MonetResultSet) rs).getRowsNumber() > 70);
67 | assertEquals(9, ((MonetResultSet) rs).getColumnsNumber());
68 | }
69 | try (ResultSet rs = dbMeta.getProcedureColumns(null, null, null, null)) {
70 | assertTrue(((MonetResultSet) rs).getRowsNumber() >= 10);
71 | assertEquals(20, ((MonetResultSet) rs).getColumnsNumber());
72 | }
73 | try (ResultSet rs = dbMeta.getTables(null, null, null, null)) {
74 | assertTrue(((MonetResultSet) rs).getRowsNumber() >= 10);
75 | assertEquals(10, ((MonetResultSet) rs).getColumnsNumber());
76 | }
77 | try (ResultSet rs = dbMeta.getSchemas(null, null)) {
78 | assertEquals(7, ((MonetResultSet) rs).getRowsNumber());
79 | assertEquals(2, ((MonetResultSet) rs).getColumnsNumber());
80 | }
81 | try (ResultSet rs = dbMeta.getColumns(null, null, null, null)) {
82 | assertTrue(((MonetResultSet) rs).getRowsNumber() >= 10);
83 | assertEquals(24, ((MonetResultSet) rs).getColumnsNumber());
84 | }
85 | try (ResultSet rs = dbMeta.getColumnPrivileges(null, null, null, null)) {
86 | assertTrue(((MonetResultSet) rs).getRowsNumber() >= 10);
87 | assertEquals(8, ((MonetResultSet) rs).getColumnsNumber());
88 | }
89 | try (ResultSet rs = dbMeta.getTablePrivileges(null, null, null)) {
90 | assertTrue(((MonetResultSet) rs).getRowsNumber() >= 10);
91 | assertEquals(7, ((MonetResultSet) rs).getColumnsNumber());
92 | }
93 | try (ResultSet rs = dbMeta.getPrimaryKeys(null, null, null)) {
94 | assertTrue(((MonetResultSet) rs).getRowsNumber() >= 9);
95 | assertEquals(6, ((MonetResultSet) rs).getColumnsNumber());
96 | }
97 | try (ResultSet rs = dbMeta.getImportedKeys(null, null, null)) {
98 | assertEquals(0, ((MonetResultSet) rs).getRowsNumber());
99 | assertEquals(14, ((MonetResultSet) rs).getColumnsNumber());
100 | }
101 | try (ResultSet rs = dbMeta.getTypeInfo()) {
102 | assertTrue(((MonetResultSet) rs).getRowsNumber() >= 10);
103 | assertEquals(18, ((MonetResultSet) rs).getColumnsNumber());
104 | }
105 | try (ResultSet rs = dbMeta.getIndexInfo(null, null, null, false, false)) {
106 | assertTrue(((MonetResultSet) rs).getRowsNumber() >= 10);
107 | assertEquals(13, ((MonetResultSet) rs).getColumnsNumber());
108 | }
109 | try (ResultSet rs = dbMeta.getFunctions(null, null, null)) {
110 | assertTrue(((MonetResultSet) rs).getRowsNumber() >= 10);
111 | assertEquals(6, ((MonetResultSet) rs).getColumnsNumber());
112 | }
113 | try (ResultSet rs = dbMeta.getFunctionColumns(null, null, null, null)) {
114 | assertTrue(((MonetResultSet) rs).getRowsNumber() >= 10);
115 | assertEquals(17, ((MonetResultSet) rs).getColumnsNumber());
116 | }
117 | try (ResultSet rs = dbMeta.getClientInfoProperties()) {
118 | assertEquals(7, ((MonetResultSet) rs).getRowsNumber());
119 | assertEquals(4, ((MonetResultSet) rs).getColumnsNumber());
120 | }
121 |
122 | } catch (SQLException e) {
123 |
124 | fail(e.toString());
125 |
126 | }
127 | }
128 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_11_ConcurrentConnections.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertFalse;
5 | import static org.junit.Assert.assertNotNull;
6 | import static org.junit.Assert.assertTrue;
7 | import static org.junit.Assert.fail;
8 |
9 | import java.sql.Connection;
10 | import java.sql.DriverManager;
11 | import java.sql.ResultSet;
12 | import java.sql.SQLException;
13 | import java.sql.Statement;
14 |
15 | import org.junit.Test;
16 |
17 | // TODO: Remove comments from concurrent connections when more than one active database are supported (future feature)
18 | // TODO: Currently this only tests concurrent connections to one database
19 | public class Test_11_ConcurrentConnections {
20 |
21 | @Test
22 | public void concurrentConnections() {
23 |
24 | Connection conn2 = null;
25 | Connection conn3 = null;
26 |
27 | try (Connection conn1 = DriverManager.getConnection(AllTests.LOCAL_CONNECTION, null)) {
28 |
29 | assertNotNull("Could not connect to database with connection string: " + AllTests.LOCAL_CONNECTION,
30 | conn1);
31 | assertFalse(conn1.isClosed());
32 |
33 | try (Statement s = conn1.createStatement()) {
34 | s.executeUpdate("CREATE TABLE test11 (i INTEGER);");
35 | s.executeUpdate("INSERT INTO test11 VALUES (1), (2);");
36 |
37 | try (ResultSet rs = s.executeQuery("SELECT * FROM test11;")) {
38 | assertTrue(rs.next());
39 | assertEquals(1, rs.getInt(1));
40 | assertTrue(rs.next());
41 | assertEquals(2, rs.getInt(1));
42 | }
43 | }
44 |
45 | // Connection to same database
46 | conn2 = DriverManager.getConnection(AllTests.LOCAL_CONNECTION, null);
47 |
48 | assertNotNull("Could not connect to database with connection string: " + AllTests.LOCAL_CONNECTION,
49 | conn2);
50 | assertFalse(conn1.isClosed());
51 | assertFalse(conn2.isClosed());
52 |
53 | try (Statement s = conn2.createStatement(); ResultSet rs = s.executeQuery("SELECT * FROM test11;")) {
54 | assertTrue(rs.next());
55 | assertEquals(1, rs.getInt(1));
56 | assertTrue(rs.next());
57 | assertEquals(2, rs.getInt(1));
58 | }
59 |
60 | // Connection 1 can still be used
61 | try (Statement s = conn1.createStatement(); ResultSet rs = s.executeQuery("SELECT sum(i) FROM test11;")) {
62 | assertTrue(rs.next());
63 | assertEquals(3, rs.getInt(1));
64 | }
65 |
66 | // Connecting to another database
67 | // TODO: Allow multiple concurrent connections
68 | // TODO: This is a plan for future versions, not allowed right now
69 | /*conn3 = DriverManager.getConnection(AllTests.MEMORY_CONNECTION, null);
70 |
71 | assertNotNull("Could not connect to database with connection string: " + AllTests.MEMORY_CONNECTION,
72 | conn3);*/
73 | assertFalse(conn1.isClosed());
74 | assertFalse(conn2.isClosed());
75 | /*assertFalse(conn3.isClosed());
76 |
77 | try (Statement s = conn3.createStatement()) {
78 | s.executeUpdate("CREATE TABLE test11 (i INTEGER);");
79 | s.executeUpdate("INSERT INTO test11 VALUES (30), (40);");
80 |
81 | try (ResultSet rs = s.executeQuery("SELECT * FROM test11;")) {
82 | assertTrue(rs.next());
83 | assertEquals(30, rs.getInt(1));
84 | assertTrue(rs.next());
85 | assertEquals(40, rs.getInt(1));
86 | }
87 | }*/
88 |
89 | // Connection 1 can still be used
90 | try (Statement s = conn1.createStatement(); ResultSet rs = s.executeQuery("SELECT sum(i) FROM test11;")) {
91 | assertTrue(rs.next());
92 | assertEquals(3, rs.getInt(1));
93 | }
94 |
95 | } catch (SQLException e) {
96 |
97 | fail(e.toString());
98 |
99 | } finally {
100 | try {
101 | if (conn2 != null) {
102 | try (Statement s = conn2.createStatement()) {
103 | s.execute("DROP TABLE test11;");
104 | }
105 | conn2.close();
106 | assertTrue(conn2.isClosed());
107 | }
108 | if (conn3 != null) {
109 | try (Statement s = conn3.createStatement()) {
110 | s.execute("DROP TABLE test11;");
111 | }
112 | conn3.close();
113 | assertTrue(conn3.isClosed());
114 | }
115 | } catch (SQLException e) {
116 | fail(e.toString());
117 | }
118 | }
119 | }
120 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_12_BatchesAndJoinsMovies.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import java.sql.Connection;
4 | import java.sql.DriverManager;
5 | import java.sql.PreparedStatement;
6 | import java.sql.ResultSet;
7 | import java.sql.SQLException;
8 | import java.sql.Statement;
9 | import java.util.stream.Stream;
10 |
11 | import org.junit.Test;
12 | import org.monetdb.monetdbe.MonetResultSet;
13 |
14 | import static org.junit.Assert.*;
15 |
16 | public class Test_12_BatchesAndJoinsMovies {
17 |
18 | private final String[] TITLES = {"Iron Man", "The Incredible Hulk", "Iron Man 2", "Thor", "Captain America: The First Avenger", "The Avengers", "Iron Man 3", "Captain America: The Winter Soldier", "Avengers: Age of Ultron", "Captain America: Civil War", "Doctor Strange", "Black Panther", "Avengers: Infinity War"};
19 | private final int[] YEARS = {2008, 2008, 2010, 2011, 2011, 2012, 2013, 2014, 2015, 2016, 2016, 2018, 2018};
20 | private final String[] FIRSTNAME = {"Robert","Chris","Scarlett","Samuel L.","Benedict","Brie","Chadwick"};
21 | private final String[] LASTNAME = {"Downey Jr.", "Evans", "Johansson", "Jackson", "Cumberbatch", "Larson", "Boseman"};
22 | private final String[] HERO = {"Iron Man", "Captain America", "Black Widow", "Nick Fury", "Dr. Strange", "Captain Marvel", "Black Panther"};
23 | private final int[] AGE = {53, 37, 33, 69, 42, 29, 40};
24 | private final int[] ACTORS = {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 7, 7, 7};
25 | private final int[] MOVIES = {1, 2, 3, 6, 7, 9, 10, 13, 5, 6, 8, 9, 10, 13, 3, 6, 8, 9, 10, 13, 1, 3, 4, 5, 6, 8, 9, 13, 11, 13, 10, 12, 13};
26 |
27 | @Test
28 | public void batchesAndJoinsMovies() {
29 | Stream.of(AllTests.CONNECTIONS).forEach(this::batchesAndJoinsMovies);
30 | }
31 |
32 | private void batchesAndJoinsMovies(String connectionUrl) {
33 | try {
34 |
35 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
36 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
37 | assertFalse(conn.isClosed());
38 | assertTrue(conn.getAutoCommit());
39 |
40 | // Here we create a primary key, and use "NOT NULL" to prevent inserting invalid data
41 | try (Statement statement = conn.createStatement()) {
42 | statement.addBatch("CREATE TABLE Movies (id SERIAL, title STRING NOT NULL, \"year\" INTEGER NOT NULL);");
43 | statement.addBatch("CREATE TABLE Actors (id SERIAL, first_name TEXT NOT NULL, last_name TEXT NOT NULL, \"character\" TEXT NOT NULL, age REAL NOT NULL);");
44 | statement.addBatch("CREATE TABLE MovieActors (id SERIAL, movie_id INTEGER NOT NULL, actor_id INTEGER NOT NULL);");
45 | long[] updateCounts = statement.executeLargeBatch();
46 | long[] expectedCounts = {0,0,0};
47 | assertEquals(3,updateCounts.length);
48 | assertArrayEquals(expectedCounts,updateCounts);
49 | }
50 |
51 | // Using a Prepared Statement, we can reuse a query for multiple parameters
52 | // Using addBatch, we can store multiple input parameters, which can then be executed at once
53 | try (PreparedStatement ps = conn.prepareStatement("INSERT INTO Movies (title, \"year\") VALUES (?, ?);")) {
54 | for (int i = 0; i < TITLES.length; i++) {
55 | ps.setString(1, TITLES[i]);
56 | ps.setInt(2, YEARS[i]);
57 | ps.addBatch();
58 | }
59 | ps.executeBatch();
60 | }
61 | try (PreparedStatement ps = conn.prepareStatement("INSERT INTO Actors (first_name, last_name, \"character\", age) VALUES (?, ?, ?, ?);")) {
62 | for (int i = 0; i < AGE.length; i++) {
63 | ps.setString(1, FIRSTNAME[i]);
64 | ps.setString(2, LASTNAME[i]);
65 | ps.setString(3, HERO[i]);
66 | ps.setInt(4, AGE[i]);
67 | ps.addBatch();
68 | }
69 | ps.executeBatch();
70 | }
71 | try (PreparedStatement ps = conn.prepareStatement("INSERT INTO MovieActors (movie_id, actor_id) VALUES (?, ?);")) {
72 | for (int i = 0; i < ACTORS.length; i++) {
73 | ps.setInt(1, MOVIES[i]);
74 | ps.setInt(2, ACTORS[i]);
75 | ps.addBatch();
76 | }
77 | ps.executeBatch();
78 | }
79 |
80 | // Check some of the data
81 | try (Statement statement = conn.createStatement();
82 | ResultSet rs = statement.executeQuery("SELECT * FROM Movies;")) {
83 | assertEquals(TITLES.length, ((MonetResultSet) rs).getRowsNumber());
84 | assertEquals(3, ((MonetResultSet) rs).getColumnsNumber());
85 | }
86 | try (Statement statement = conn.createStatement();
87 | ResultSet rs = statement.executeQuery("SELECT * FROM Movies ORDER BY \"year\" DESC;")) {
88 | assertEquals(TITLES.length, ((MonetResultSet) rs).getRowsNumber());
89 | assertEquals(3, ((MonetResultSet) rs).getColumnsNumber());
90 | }
91 |
92 | try (Statement statement = conn.createStatement();
93 | ResultSet rs = statement.executeQuery("SELECT Movies.title, Movies.\"year\", Actors.first_name, Actors.\"character\" FROM MovieActors JOIN Movies ON MovieActors.movie_id = Movies.id JOIN Actors ON MovieActors.actor_id = Actors.id;")) {
94 | assertEquals(33, ((MonetResultSet) rs).getRowsNumber());
95 | assertEquals(4, ((MonetResultSet) rs).getColumnsNumber());
96 | }
97 |
98 | // Clean up
99 | try (Statement statement = conn.createStatement()) {
100 | statement.executeUpdate("DROP TABLE MovieActors;");
101 | statement.executeUpdate("DROP TABLE Actors;");
102 | statement.executeUpdate("DROP TABLE Movies;");
103 | }
104 | }
105 |
106 | } catch (SQLException e) {
107 |
108 | fail(e.toString());
109 |
110 | }
111 | }
112 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_13_Schema.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertFalse;
5 | import static org.junit.Assert.assertNotNull;
6 | import static org.junit.Assert.assertTrue;
7 | import static org.junit.Assert.fail;
8 |
9 | import java.sql.Connection;
10 | import java.sql.DriverManager;
11 | import java.sql.SQLException;
12 | import java.sql.Statement;
13 | import java.util.stream.Stream;
14 |
15 | import org.junit.Test;
16 | import org.monetdb.monetdbe.MonetConnection;
17 |
18 | public class Test_13_Schema {
19 |
20 | @Test
21 | public void schema() {
22 | Stream.of(AllTests.CONNECTIONS).forEach(this::schema);
23 | }
24 |
25 | private void schema(String connectionUrl) {
26 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
27 |
28 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
29 | assertFalse(conn.isClosed());
30 | assertTrue(conn.getAutoCommit());
31 |
32 | assertEquals("sys", conn.getSchema());
33 | assertEquals("monetdb", ((MonetConnection) conn).getUserName());
34 |
35 | // Create table and insert values
36 | try (Statement statement = conn.createStatement()) {
37 | statement.execute("CREATE SCHEMA test13_voc;");
38 |
39 | conn.setSchema("test13_voc");
40 | assertEquals("test13_voc", conn.getSchema());
41 | assertEquals("monetdb", ((MonetConnection) conn).getUserName());
42 |
43 | conn.setSchema("sys");
44 | assertEquals("sys", conn.getSchema());
45 | assertEquals("monetdb", ((MonetConnection) conn).getUserName());
46 | }
47 |
48 | try (Statement statement = conn.createStatement()) {
49 | // Clean up
50 | statement.execute("DROP SCHEMA test13_voc;");
51 |
52 | assertEquals(0, statement.getUpdateCount()); // 0: drop succeeded
53 | }
54 |
55 | } catch (SQLException e) {
56 |
57 | fail(e.toString());
58 |
59 | }
60 | }
61 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_14_MultipleResultSet.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertFalse;
5 | import static org.junit.Assert.assertNotNull;
6 | import static org.junit.Assert.assertTrue;
7 | import static org.junit.Assert.fail;
8 |
9 | import java.sql.Connection;
10 | import java.sql.DriverManager;
11 | import java.sql.ResultSet;
12 | import java.sql.SQLException;
13 | import java.sql.Statement;
14 | import java.util.stream.Stream;
15 |
16 | import org.junit.Test;
17 |
18 | // TODO: Multiple ResultSets are not supported with the current monetdbe API, future feature
19 | // TODO: Test is disabled in AllTests.java, enable when this feature is implemented
20 | public class Test_14_MultipleResultSet {
21 |
22 | @Test
23 | public void multipleResultSet() {
24 | Stream.of(AllTests.CONNECTIONS).forEach(this::multipleResultSet);
25 | }
26 |
27 | private void multipleResultSet(String connectionUrl) {
28 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
29 |
30 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
31 | assertFalse(conn.isClosed());
32 | assertTrue(conn.getAutoCommit());
33 |
34 | try (Statement statement = conn.createStatement()) {
35 | // TODO: support multiple resultsets with statement.getMoreResults()
36 | assertTrue(statement.execute("SELECT 1; SELECT 2; SELECT 3;"));
37 | try (ResultSet rs = statement.getResultSet()) {
38 | rs.next();
39 | assertEquals((short)1, rs.getObject(1));
40 | assertTrue(statement.getMoreResults());
41 | rs.next();
42 | assertEquals((short)2, rs.getObject(1));
43 | assertTrue(statement.getMoreResults());
44 | rs.next();
45 | assertEquals((short)3, rs.getObject(1));
46 | assertFalse(statement.getMoreResults());
47 | }
48 | }
49 |
50 | } catch (SQLException e) {
51 |
52 | fail(e.toString());
53 |
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_15_Transactions.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertFalse;
5 | import static org.junit.Assert.assertNotNull;
6 | import static org.junit.Assert.assertTrue;
7 | import static org.junit.Assert.fail;
8 |
9 | import java.sql.Connection;
10 | import java.sql.DriverManager;
11 | import java.sql.ResultSet;
12 | import java.sql.SQLException;
13 | import java.sql.Statement;
14 | import java.util.stream.Stream;
15 |
16 | import org.junit.Test;
17 |
18 | public class Test_15_Transactions {
19 |
20 | @Test
21 | public void transactions() {
22 | Stream.of(AllTests.CONNECTIONS).forEach(this::transactions);
23 | }
24 |
25 | private void transactions(String connectionUrl) {
26 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
27 |
28 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
29 | assertFalse(conn.isClosed());
30 | assertTrue(conn.getAutoCommit());
31 |
32 | try (Statement statement = conn.createStatement()) {
33 | statement.executeUpdate("CREATE TABLE test15 (i int);");
34 |
35 | // Begin transaction
36 | conn.setAutoCommit(false);
37 | assertFalse(conn.getAutoCommit());
38 |
39 | statement.executeUpdate("INSERT INTO test15 VALUES (12345);");
40 | conn.rollback();
41 |
42 | try (ResultSet rs = statement.executeQuery("SELECT * FROM test15;")) {
43 | assertFalse(rs.next());
44 | }
45 |
46 | statement.executeUpdate("INSERT INTO test15 VALUES (23456);");
47 | conn.commit();
48 |
49 | try (ResultSet rs = statement.executeQuery("SELECT * FROM test15;")) {
50 | assertTrue(rs.next());
51 | assertEquals(23456, rs.getInt(1));
52 | }
53 |
54 | // Finish transaction
55 | conn.setAutoCommit(true);
56 | assertTrue(conn.getAutoCommit());
57 |
58 | // Clean up
59 | int result = statement.executeUpdate("DROP TABLE test15;");
60 | assertEquals(1, result); // 1: because we've dropped a table with 1 record
61 |
62 | assertEquals(-1, statement.getUpdateCount());
63 | }
64 |
65 | } catch (SQLException e) {
66 |
67 | fail(e.toString());
68 |
69 | }
70 | }
71 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_16_MixedOrderStatements.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertFalse;
5 | import static org.junit.Assert.assertNotNull;
6 | import static org.junit.Assert.assertTrue;
7 | import static org.junit.Assert.fail;
8 |
9 | import java.sql.Connection;
10 | import java.sql.DriverManager;
11 | import java.sql.ResultSet;
12 | import java.sql.SQLException;
13 | import java.sql.Statement;
14 | import java.util.stream.Stream;
15 |
16 | import org.junit.Test;
17 |
18 | public class Test_16_MixedOrderStatements {
19 |
20 | @Test
21 | public void mixedOrderStatements() {
22 | Stream.of(AllTests.CONNECTIONS).forEach(this::mixedOrderStatements);
23 | }
24 |
25 | private void mixedOrderStatements(String connectionUrl) {
26 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
27 |
28 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
29 | assertFalse(conn.isClosed());
30 | assertTrue(conn.getAutoCommit());
31 |
32 | try (Statement statement1 = conn.createStatement();
33 | Statement statement2 = conn.createStatement();
34 | Statement statement3 = conn.createStatement()) {
35 | statement1.executeUpdate("CREATE TABLE test16 (ID INTEGER GENERATED ALWAYS AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY,NAME VARCHAR(256) NOT NULL);");
36 |
37 | statement3.executeUpdate("INSERT INTO test16 (NAME) VALUES ('A');");
38 |
39 | try (ResultSet rs = statement2.executeQuery("SELECT ID, NAME FROM test16;")) {
40 | assertTrue(rs.next());
41 | }
42 |
43 | statement2.executeUpdate("INSERT INTO test16 (NAME) VALUES ('B');");
44 |
45 | try (ResultSet rs = statement1.executeQuery("SELECT ID, NAME FROM test16;")) {
46 | assertTrue(rs.next());
47 | assertEquals(0, rs.getInt(1));
48 | assertEquals("A", rs.getString(2));
49 | assertTrue(rs.next());
50 | assertEquals(1, rs.getInt(1));
51 | assertEquals("B", rs.getString(2));
52 | }
53 |
54 | // Clean up
55 | int result = statement2.executeUpdate("DROP TABLE test16;");
56 | assertEquals(1, result); // 1: because we've dropped a table with 1 record
57 |
58 | assertEquals(-1, statement2.getUpdateCount());
59 | }
60 |
61 | } catch (SQLException e) {
62 |
63 | fail(e.toString());
64 |
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_17_QueryInThread.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import static org.junit.Assert.assertFalse;
5 | import static org.junit.Assert.assertNotNull;
6 | import static org.junit.Assert.assertTrue;
7 | import static org.junit.Assert.fail;
8 |
9 | import java.sql.Connection;
10 | import java.sql.DriverManager;
11 | import java.sql.ResultSet;
12 | import java.sql.SQLException;
13 | import java.sql.Statement;
14 | import java.util.stream.Stream;
15 |
16 | import org.junit.Test;
17 |
18 | public class Test_17_QueryInThread {
19 |
20 | private class QueryThread extends Thread {
21 |
22 | private String connString_;
23 |
24 | public QueryThread(String connString) {
25 | connString_ = connString;
26 | }
27 |
28 | @Override
29 | public void run() {
30 | Test_17_QueryInThread.queryInThread(connString_);
31 | }
32 | }
33 |
34 | @Test
35 | public void queryInThread() {
36 | Stream.of(AllTests.CONNECTIONS).forEach(x -> queryInThread(x));
37 |
38 | // Now perform the same queries in a separate thread
39 | // TODO: support query in separate thread and prevent hard JRE crash
40 | Stream.of(AllTests.CONNECTIONS).forEach(x -> {
41 | try {
42 | Thread t = new QueryThread(x);
43 | t.start();
44 | t.join(3000);
45 | } catch (InterruptedException e) {
46 | fail(e.toString());
47 | Thread.currentThread().interrupt();
48 | }
49 | });
50 | }
51 |
52 | private static void queryInThread(String connectionUrl) {
53 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
54 |
55 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
56 | assertFalse(conn.isClosed());
57 | assertTrue(conn.getAutoCommit());
58 |
59 | try (Statement statement = conn.createStatement()) {
60 |
61 | // Set up some data
62 | statement.executeUpdate("CREATE TABLE test17 (ID INTEGER, NAME VARCHAR(256));");
63 | statement.executeUpdate("INSERT INTO test17 VALUES (1, 'A');");
64 | statement.executeUpdate("INSERT INTO test17 VALUES (2, 'B');");
65 |
66 | // Simple query
67 | try (ResultSet rs = statement.executeQuery("SELECT ID, NAME FROM test17;")) {
68 | assertTrue(rs.next());
69 | assertEquals(1, rs.getRow());
70 | assertEquals(1, rs.getInt(1));
71 | assertEquals("A", rs.getString(2));
72 | assertTrue(rs.next());
73 | assertEquals(2, rs.getRow());
74 | assertEquals(2, rs.getInt(1));
75 | assertEquals("B", rs.getString(2));
76 | }
77 |
78 | // Clean up
79 | int result = statement.executeUpdate("DROP TABLE test17;");
80 | assertEquals(1, result); // 1: because we've dropped a table with 1 record
81 |
82 | assertEquals(-1, statement.getUpdateCount());
83 | }
84 |
85 | } catch (SQLException e) {
86 |
87 | fail(e.toString());
88 |
89 | }
90 | }
91 | }
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_18_Multithreaded_Connection.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import org.junit.Test;
4 | import org.monetdb.monetdbe.MonetResultSet;
5 |
6 | import java.math.BigDecimal;
7 | import java.sql.*;
8 | import java.util.Calendar;
9 | import java.util.concurrent.ExecutorService;
10 | import java.util.concurrent.Executors;
11 | import java.util.concurrent.TimeUnit;
12 | import java.util.stream.Stream;
13 |
14 | import static org.junit.Assert.*;
15 | import static org.junit.Assert.assertEquals;
16 | import static org.junit.Assert.fail;
17 |
18 |
19 | class MultiThreadRun implements Runnable {
20 | String tableName;
21 | int threadNum;
22 | Connection c;
23 |
24 | public MultiThreadRun(Connection c, int threadNum) {
25 | this.threadNum = threadNum;
26 | this.tableName = "a_" + threadNum;
27 | this.c = c;
28 | }
29 |
30 | @Override
31 | public void run() {
32 | try {
33 | Statement stat = c.createStatement();
34 | ResultSet rs = null;
35 | stat.execute("CREATE TABLE " + tableName + " (a INT)");
36 | assertEquals(1,stat.executeUpdate("INSERT INTO " + tableName + " VALUES (" + threadNum + ")"));
37 | rs = stat.executeQuery("SELECT * FROM " + tableName);
38 | assertEquals(1,((MonetResultSet) rs).getRowsNumber());
39 | while (rs.next())
40 | assertEquals(threadNum,rs.getObject(1));
41 | rs = stat.executeQuery("SELECT * FROM a_0");
42 | assertEquals(1,((MonetResultSet) rs).getRowsNumber());
43 | while(rs.next())
44 | assertEquals(0,rs.getObject(1));
45 | assertFalse(rs.next());
46 | c.close();
47 | } catch (SQLException e) {
48 | fail(e.toString());
49 | }
50 |
51 | }
52 | }
53 |
54 | public class Test_18_Multithreaded_Connection {
55 | @Test
56 | public void multithreadedConnection() {
57 | Stream.of(AllTests.CONNECTIONS).forEach(this::multithreadedConnection);
58 | }
59 |
60 | private void multithreadedConnection(String connectionUrl) {
61 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
62 | int n = 5;
63 | ExecutorService executor = Executors.newFixedThreadPool(n);
64 | for (int i = 0; i < n; i++) {
65 | Runnable t = null;
66 | t = new MultiThreadRun(conn, i);
67 | executor.execute(t);
68 | }
69 | executor.shutdown();
70 | try {
71 | executor.awaitTermination(10,TimeUnit.SECONDS);
72 | } catch (InterruptedException e) {
73 | e.printStackTrace();
74 | }
75 | Statement dropStat = conn.createStatement();
76 | for (int i = 0; i < n; i++) {
77 | //Cleanup
78 | int result = dropStat.executeUpdate("DROP TABLE a_" + i + ";");
79 | assertEquals(result,0);
80 | }
81 | try {
82 | conn.close();
83 | assertTrue(conn.isClosed());
84 | } catch (SQLException e) {
85 | e.printStackTrace();
86 | }
87 | } catch (SQLException e) {
88 | fail(e.toString());
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_19_ParameterMetadata.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import org.junit.Test;
4 | import org.monetdb.monetdbe.MonetResultSet;
5 |
6 | import java.math.BigDecimal;
7 | import java.sql.*;
8 | import java.util.Calendar;
9 | import java.util.stream.Stream;
10 |
11 | import static org.junit.Assert.*;
12 | import static org.junit.Assert.assertEquals;
13 | import static org.junit.Assert.fail;
14 |
15 | public class Test_19_ParameterMetadata {
16 | @Test
17 | public void parameterMetadata() {
18 | Stream.of(AllTests.CONNECTIONS).forEach(this::parameterMetadata);
19 | }
20 |
21 | private void parameterMetadata(String connectionUrl) {
22 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
23 |
24 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
25 | assertFalse(conn.isClosed());
26 | Statement s = conn.createStatement();
27 | s.execute("CREATE TABLE test19 (i int, l bigint, f real, d double, bd NUMERIC(36,18), s STRING, b BLOB, da DATE);");
28 |
29 | try (PreparedStatement ps = conn.prepareStatement("INSERT INTO test19 VALUES (?,?,?,?,?,?,?,?)")) {
30 | ParameterMetaData meta = ps.getParameterMetaData();
31 | assertEquals(8,meta.getParameterCount());
32 |
33 | if (meta.getPrecision(1) != -1) {
34 | //Check Precision and Scale
35 | assertEquals(32,meta.getPrecision(1));
36 | assertEquals(0,meta.getScale(1));
37 | assertEquals(64,meta.getPrecision(2));
38 | assertEquals(0,meta.getScale(2));
39 |
40 | //TODO Why 24 and 53 instead of 32 and 64?
41 | assertEquals(24,meta.getPrecision(3));
42 | assertEquals(0,meta.getScale(3));
43 | assertEquals(53,meta.getPrecision(4));
44 | assertEquals(0,meta.getScale(4));
45 |
46 | assertEquals(36,meta.getPrecision(5));
47 | assertEquals(18,meta.getScale(5));
48 | assertEquals(0,meta.getPrecision(6));
49 | assertEquals(0,meta.getScale(6));
50 | assertEquals(0,meta.getPrecision(7));
51 | assertEquals(0,meta.getScale(7));
52 | assertEquals(0,meta.getPrecision(8));
53 | assertEquals(0,meta.getScale(8));
54 | }
55 | //TODO Find better strategy to do different tests for older versions
56 | //In Jul2021, there is no precision info on Parameter Metadata
57 | else {
58 | for (int i = 0; i < meta.getParameterCount(); i++) {
59 | assertEquals(-1,meta.getPrecision(i+1));
60 | assertEquals(-1,meta.getScale(i+1));
61 | }
62 |
63 | }
64 |
65 | //Check types (sql, monetdbe, java)
66 | assertEquals(Types.INTEGER,meta.getParameterType(1));
67 | assertEquals("monetdbe_int32_t",meta.getParameterTypeName(1));
68 | assertEquals(Integer.class.getName(),meta.getParameterClassName(1));
69 | assertEquals(Types.BIGINT,meta.getParameterType(2));
70 | assertEquals("monetdbe_int64_t",meta.getParameterTypeName(2));
71 | assertEquals(Long.class.getName(),meta.getParameterClassName(2));
72 | assertEquals(Types.REAL,meta.getParameterType(3));
73 | assertEquals("monetdbe_float",meta.getParameterTypeName(3));
74 | assertEquals(Float.class.getName(),meta.getParameterClassName(3));
75 | assertEquals(Types.DOUBLE,meta.getParameterType(4));
76 | assertEquals("monetdbe_double",meta.getParameterTypeName(4));
77 | assertEquals(Double.class.getName(),meta.getParameterClassName(4));
78 | assertEquals(Types.NUMERIC,meta.getParameterType(5));
79 | //TODO MonetDBe type should return monetdbe_int64 (NUMERIC is not necessarily a int128)
80 | assertEquals("monetdbe_int128_t",meta.getParameterTypeName(5));
81 | assertEquals(BigDecimal.class.getName(),meta.getParameterClassName(5));
82 | assertEquals(Types.VARCHAR,meta.getParameterType(6));
83 | assertEquals("monetdbe_str",meta.getParameterTypeName(6));
84 | assertEquals(String.class.getName(),meta.getParameterClassName(6));
85 | assertEquals(Types.BLOB,meta.getParameterType(7));
86 | assertEquals("monetdbe_blob",meta.getParameterTypeName(7));
87 | assertEquals(Blob.class.getName(),meta.getParameterClassName(7));
88 | assertEquals(Types.DATE,meta.getParameterType(8));
89 | assertEquals("monetdbe_date",meta.getParameterTypeName(8));
90 | assertEquals(Date.class.getName(),meta.getParameterClassName(8));
91 |
92 | }
93 | s.execute("DROP TABLE test19");
94 |
95 | } catch (SQLException e) {
96 | fail(e.toString());
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_20_PreparedResultMetadata.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import org.junit.Test;
4 | import org.monetdb.monetdbe.MonetResultSet;
5 |
6 | import java.math.BigDecimal;
7 | import java.sql.*;
8 | import java.util.stream.Stream;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | public class Test_20_PreparedResultMetadata {
13 |
14 | @Test
15 | public void preparedResultMetadata() {
16 | Stream.of(AllTests.CONNECTIONS).forEach(this::preparedResultMetadata);
17 | }
18 |
19 | private void preparedResultMetadata(String connectionUrl) {
20 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
21 | assertNotNull("Could not connect to database with connection string: " + connectionUrl, conn);
22 | assertFalse(conn.isClosed());
23 |
24 | Statement s = conn.createStatement();
25 | s.execute("CREATE TABLE test20 (i int, l bigint, f real, d double, bd NUMERIC(36,18), s STRING, b BLOB, da DATE);");
26 | s.execute("INSERT INTO test20 VALUES (20,60000,20.4321,20934.43029,4398574389.5983798,'string','12ff803F',current_date);");
27 |
28 | try (PreparedStatement ps = conn.prepareStatement("SELECT * FROM test20 WHERE i = ?")) {
29 | //Jul2021 doesn't support PreparedStatement output ResultMetadata
30 | //TODO Find better strategy to do different tests for older versions
31 | if (ps.getMetaData() == null) {
32 | s.execute("DROP TABLE test20");
33 | return;
34 | }
35 | ResultSetMetaData meta = ps.getMetaData();
36 | assertEquals(8,meta.getColumnCount());
37 |
38 | //Check Precision and Scale
39 | assertEquals(32,meta.getPrecision(1));
40 | assertEquals(0,meta.getScale(1));
41 | assertEquals(64,meta.getPrecision(2));
42 | assertEquals(0,meta.getScale(2));
43 |
44 | //TODO Why 24 and 53 instead of 32 and 64?
45 | assertEquals(24,meta.getPrecision(3));
46 | assertEquals(0,meta.getScale(3));
47 | assertEquals(53,meta.getPrecision(4));
48 | assertEquals(0,meta.getScale(4));
49 |
50 | assertEquals(36,meta.getPrecision(5));
51 | assertEquals(18,meta.getScale(5));
52 | assertEquals(0,meta.getPrecision(6));
53 | assertEquals(0,meta.getScale(6));
54 | assertEquals(0,meta.getPrecision(7));
55 | assertEquals(0,meta.getScale(7));
56 | assertEquals(0,meta.getPrecision(8));
57 | assertEquals(0,meta.getScale(8));
58 |
59 | //Check types (sql, monetdbe, java)
60 | assertEquals(Types.INTEGER,meta.getColumnType(1));
61 | assertEquals("monetdbe_int32_t",meta.getColumnTypeName(1));
62 | assertEquals(Integer.class.getName(),meta.getColumnClassName(1));
63 | assertEquals(Types.BIGINT,meta.getColumnType(2));
64 | assertEquals("monetdbe_int64_t",meta.getColumnTypeName(2));
65 | assertEquals(Long.class.getName(),meta.getColumnClassName(2));
66 | assertEquals(Types.REAL,meta.getColumnType(3));
67 | assertEquals("monetdbe_float",meta.getColumnTypeName(3));
68 | assertEquals(Float.class.getName(),meta.getColumnClassName(3));
69 | assertEquals(Types.DOUBLE,meta.getColumnType(4));
70 | assertEquals("monetdbe_double",meta.getColumnTypeName(4));
71 | assertEquals(Double.class.getName(),meta.getColumnClassName(4));
72 | assertEquals(Types.NUMERIC,meta.getColumnType(5));
73 | //TODO MonetDBe type should return monetdbe_int64 (NUMERIC is not necessarily a int128)
74 | assertEquals("monetdbe_int128_t",meta.getColumnTypeName(5));
75 | assertEquals(BigDecimal.class.getName(),meta.getColumnClassName(5));
76 | assertEquals(Types.VARCHAR,meta.getColumnType(6));
77 | assertEquals("monetdbe_str",meta.getColumnTypeName(6));
78 | assertEquals(String.class.getName(),meta.getColumnClassName(6));
79 | assertEquals(Types.BLOB,meta.getColumnType(7));
80 | assertEquals("monetdbe_blob",meta.getColumnTypeName(7));
81 | assertEquals(Blob.class.getName(),meta.getColumnClassName(7));
82 | assertEquals(Types.DATE,meta.getColumnType(8));
83 | assertEquals("monetdbe_date",meta.getColumnTypeName(8));
84 | assertEquals(Date.class.getName(),meta.getColumnClassName(8));
85 |
86 | //Names
87 | assertEquals("i",meta.getColumnName(1));
88 | assertEquals("l",meta.getColumnName(2));
89 | assertEquals("f",meta.getColumnName(3));
90 | assertEquals("d",meta.getColumnName(4));
91 | assertEquals("bd",meta.getColumnName(5));
92 | assertEquals("s",meta.getColumnName(6));
93 | assertEquals("b",meta.getColumnName(7));
94 | assertEquals("da",meta.getColumnName(8));
95 | }
96 | s.execute("DROP TABLE test20;");
97 |
98 | } catch (SQLException e) {
99 | fail(e.toString());
100 | }
101 | }
102 | public static void main (String[] args) {
103 | Test_20_PreparedResultMetadata t = new Test_20_PreparedResultMetadata();
104 | Stream.of(AllTests.CONNECTIONS).forEach(t::preparedResultMetadata);
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_21_ConnectionOptions.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import org.junit.Test;
4 |
5 | import java.sql.*;
6 | import java.util.Properties;
7 | import java.util.stream.Stream;
8 |
9 | import static org.junit.Assert.*;
10 |
11 | public class Test_21_ConnectionOptions {
12 | @Test
13 | public void connectionOptions() {
14 | Stream.of(AllTests.CONNECTIONS).forEach(this::connectionOptions);
15 | }
16 |
17 | private void sessionTimeout (String connectionUrl, Integer shortTimeout, Integer longTimeout) {
18 | Properties props = new Properties();
19 | props.setProperty("session_timeout",shortTimeout.toString());
20 | long start = System.currentTimeMillis();
21 | long duration;
22 | //Session timeout: timeout reached case
23 | try (Connection conn = DriverManager.getConnection(connectionUrl, props)) {
24 | Statement st = conn.createStatement();
25 | Thread.sleep(shortTimeout);
26 | st.executeQuery("select 1;");
27 | fail("Timeout not reached");
28 | } catch (SQLException e) {
29 | duration = System.currentTimeMillis() - start;
30 | assertEquals(e.toString(),"java.sql.SQLException: MALException:mal.interpreter:HYT00!Query aborted due to session timeout");
31 | assertTrue(duration > shortTimeout);
32 | } catch (InterruptedException e) {
33 | fail(e.toString());
34 | }
35 | //Session timeout: timeout not reached case
36 | duration = 0;
37 | props = new Properties();
38 | props.setProperty("session_timeout",longTimeout.toString());
39 | start = System.currentTimeMillis();
40 | try (Connection conn = DriverManager.getConnection(connectionUrl, props)) {
41 | Statement st = conn.createStatement();
42 | ResultSet rs = st.executeQuery("select 1;");
43 | conn.close();
44 | duration = System.currentTimeMillis() - start;
45 | assertNotNull(rs);
46 | assertTrue(duration < longTimeout);
47 | } catch (SQLException e) {
48 | if (duration == 0)
49 | duration = System.currentTimeMillis() - start;
50 | fail(e.toString() + "\nTimeout: " + longTimeout + " \tExecution time: " + duration);
51 | }
52 | }
53 |
54 | private void queryTimeout (String connectionUrl, Integer shortTimeout, Integer longTimeout) {
55 | Properties props = new Properties();
56 | props.setProperty("query_timeout",shortTimeout.toString());
57 | long start = 0;
58 | long duration = 0;
59 | //Query timeout: timeout reached case
60 | try (Connection conn = DriverManager.getConnection(connectionUrl, props)) {
61 | Statement st = conn.createStatement();
62 | //Wait longer than the short timeout, so we know that query timeout is acting different from session timeout
63 | Thread.sleep(1000);
64 | start = System.currentTimeMillis();
65 | st.executeQuery("select 1;");
66 | fail("Timeout not reached");
67 | } catch (SQLException e) {
68 | duration = System.currentTimeMillis() - start;
69 | assertEquals(e.toString(),"java.sql.SQLException: MALException:mal.interpreter:HYT00!Query aborted due to timeout");
70 | assertTrue(duration > shortTimeout);
71 | } catch (InterruptedException e) {
72 | fail(e.toString());
73 | }
74 | //Query timeout: timeout not reached case
75 | duration = 0;
76 | props = new Properties();
77 | props.setProperty("query_timeout",longTimeout.toString());
78 | try (Connection conn = DriverManager.getConnection(connectionUrl, props)) {
79 | Statement st = conn.createStatement();
80 | //Wait longer than the long timeout, so we know that query timeout is acting different from session timeout
81 | Thread.sleep(1000);
82 | start = System.currentTimeMillis();
83 | ResultSet rs = st.executeQuery("select 1;");
84 | duration = System.currentTimeMillis() - start;
85 | assertNotNull(rs);
86 | assertTrue(duration < longTimeout);
87 | } catch (SQLException e) {
88 | fail(e.toString() + "\nTimeout: " + longTimeout + " \tExecution time: " + duration);
89 | } catch (InterruptedException e) {
90 | fail(e.toString());
91 | }
92 | //Query timeout: Test if session timeout fails faster than query timeout
93 | props = new Properties();
94 | props.setProperty("query_timeout",longTimeout.toString());
95 | props.setProperty("session_timeout",longTimeout.toString());
96 | try (Connection conn = DriverManager.getConnection(connectionUrl, props)) {
97 | Statement st = conn.createStatement();
98 | st.executeQuery("select 1;");
99 | fail("Timeout not reached");
100 | } catch (SQLException e) {
101 | assertEquals(e.toString(),"java.sql.SQLException: MALException:mal.interpreter:HYT00!Query aborted due to session timeout");
102 | }
103 | }
104 |
105 | private void checkSessionValues (String connectionUrl, Integer memoryLimit, Integer threadsLimit, Integer timeout) {
106 | Properties props = new Properties();
107 | props.setProperty("memory_limit",memoryLimit.toString());
108 | props.setProperty("nr_threads",threadsLimit.toString());
109 | props.setProperty("session_timeout",timeout.toString());
110 | props.setProperty("query_timeout",timeout.toString());
111 | try (Connection conn = DriverManager.getConnection(connectionUrl, props)) {
112 | Statement st = conn.createStatement();
113 | ResultSet rs = st.executeQuery("select name, value FROM sys.session() where name in ('sessiontimeout','querytimeout','workerlimit','memorylimit');");
114 | while(rs.next()) {
115 | String name = rs.getString(1);
116 | int value = rs.getInt(2);
117 | if (name.equals("sessiontimeout") || name.equals("querytimeout"))
118 | assertEquals(value,(int) timeout);
119 | else if (name.equals("workerlimit"))
120 | assertEquals(value,(int) threadsLimit);
121 | else if (name.equals("memorylimit"))
122 | assertEquals(value,(int) memoryLimit);
123 | else
124 | fail("Unknown variable");
125 | }
126 | } catch (SQLException e) {
127 | fail(e.toString());
128 | }
129 | }
130 |
131 | private void connectionOptions(String connectionUrl) {
132 | sessionTimeout(connectionUrl, 100, 2000);
133 | queryTimeout(connectionUrl, 1, 100);
134 | //checkSessionValues(connectionUrl,1024,2,10000);
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_22_GetObject.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | import org.junit.Test;
4 | import org.monetdb.monetdbe.MonetBlob;
5 |
6 | import java.math.BigDecimal;
7 | import java.math.BigInteger;
8 | import java.sql.*;
9 | import java.util.stream.Stream;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | public class Test_22_GetObject {
14 | @Test
15 | public void getObject() {
16 | Stream.of(AllTests.CONNECTIONS).forEach(this::getObject);
17 | }
18 |
19 | public void getObject(String connectionUrl) {
20 | try (Connection conn = DriverManager.getConnection(connectionUrl, null)) {
21 | Statement s = conn.createStatement();
22 | s.executeUpdate("CREATE TABLE test22 (b BOOLEAN, ti TINYINT, si SMALLINT, i INTEGER, l BIGINT, r REAL, f FLOAT,de DECIMAL(32,20), h HUGEINT, s STRING, bl BLOB, d DATE, t TIME, ts TIMESTAMP);");
23 | PreparedStatement ps = conn.prepareStatement("INSERT INTO test22 VALUES (?,?,?,?,?,?,?,1237831.123879879,9223372036854776800,?,?,?,?,?);");
24 | long instant = System.currentTimeMillis();
25 | Date d = new Date(instant);
26 | Time t = new Time(instant);
27 | Timestamp ts = new Timestamp(instant);
28 | BigInteger bigint = BigInteger.valueOf(9223372036854775800L);
29 | bigint = bigint.add(BigInteger.valueOf(1000));
30 | BigDecimal bigdec = BigDecimal.valueOf(1237831.123879879);
31 | long lng = 3000000L;
32 | float fl = 3287.3289f;
33 | double db = 328732.328129;
34 |
35 | ps.setObject(1,false);
36 | ps.setObject(2,1);
37 | ps.setObject(3,20);
38 | ps.setObject(4,50000);
39 | ps.setObject(5,lng);
40 | ps.setObject(6,fl);
41 | ps.setObject(7,db);
42 | //TODO Set BigDec and BigInt are not yet supported (Jan2022)
43 | //ps.setObject(8,bigdec);
44 | //ps.setObject(9,bigint);
45 | ps.setObject(8,"string");
46 | ps.setObject(9,new MonetBlob("12ff803F"));
47 | ps.setObject(10,d);
48 | ps.setObject(11,t);
49 | ps.setTimestamp(12,ts);
50 |
51 | assertEquals(1,ps.executeUpdate());
52 |
53 | ResultSet rs = s.executeQuery("SELECT * FROM test22;");
54 | assertTrue(rs.next());
55 |
56 | assertEquals(false,rs.getObject(1));
57 | assertEquals((short)1,rs.getObject(2));
58 | assertEquals((short) 20,rs.getObject(3));
59 | assertEquals((int) 50000,rs.getObject(4));
60 | assertEquals(lng,rs.getObject(5));
61 | assertEquals(fl,rs.getObject(6));
62 | assertEquals(db,rs.getObject(7));
63 | //TODO Change
64 | assertEquals(bigdec,rs.getBigDecimal(8).stripTrailingZeros());
65 | assertEquals(bigint,rs.getObject(9));
66 | assertEquals("string",rs.getObject(10));
67 | assertEquals(MonetBlob.class,rs.getObject(11).getClass());
68 | assertEquals(d.toString(),rs.getObject(12).toString());
69 | assertEquals(t.toString(),rs.getObject(13).toString());
70 | assertEquals(ts,rs.getObject(14));
71 | assertFalse(rs.next());
72 |
73 | s.execute("DROP TABLE test22;");
74 | } catch (SQLException e) {
75 | fail(e.getLocalizedMessage());
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/java/src/test/java/test/Test_23_LogFile.java:
--------------------------------------------------------------------------------
1 | package test;
2 |
3 | public class Test_23_LogFile {
4 | }
5 |
--------------------------------------------------------------------------------
/run_dev.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -x
3 |
4 | if [ $# -eq 0 ]; then
5 | echo "No example to run was provided"
6 | exit 1
7 | fi
8 |
9 | javac -cp java/target/monetdbe-java-1.11-SNAPSHOT.jar example/$1.java
10 | java -cp java/target/monetdbe-java-1.11-SNAPSHOT.jar:example/ $1
11 |
--------------------------------------------------------------------------------