Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ sql/oracle/init/.cache
pom.xml.releaseBackup
pom.xml.versionsBackup
release.properties

14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sudo: required
language: java
jdk: openjdk8
services:
- docker
- postgresql
- mysql
before_install:
- ./build/setup_postgres.sh
- ./build/setup_mysql.sh
- ./build/setup_oracle.sh
cache:
directories:
- $HOME/.m2
4 changes: 4 additions & 0 deletions build/setup_mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

mysql < sql/mysql/create-test-user.sql
mysql -u test --password=test test < sql/mysql/schema-mysql-1.sql
40 changes: 40 additions & 0 deletions build/setup_oracle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

CONTAINER_NAME="oracle18"

# pull from private repo
echo "$DOCKER_PASSWORD" | docker login --username "$DOCKER_USERNAME" --password-stdin
docker pull morejdbc/morejdbc-oracle-18:latest

# run
echo "Running $CONTAINER_NAME container"
docker run -d --name "$CONTAINER_NAME" -p 1521:1521 --expose=1521 morejdbc/morejdbc-oracle-18:latest

# wait database to be ready
DB_IS_READY="0"
while test "$DB_IS_READY" = "0";
do
sleep 5;

if docker logs "$CONTAINER_NAME" | grep -q 'DATABASE IS READY TO USE';
then
DB_IS_READY="1"
fi

if docker logs "$CONTAINER_NAME" | grep -q 'DATABASE SETUP WAS NOT SUCCESSFUL';
then
exit 1
fi
echo "It's Oracle. Please wait..."
done;
###

docker exec -i "$CONTAINER_NAME" sqlplus / as sysdba << EOF
$(cat sql/oracle/create-test-user.sql)
exit;
EOF

docker exec -i "$CONTAINER_NAME" sqlplus test/test << EOF
$(cat sql/oracle/schema-oracle-1.sql)
exit;
EOF
4 changes: 4 additions & 0 deletions build/setup_postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

psql -U postgres -f sql/postgres/create-test-user.sql
psql -U test -f sql/postgres/schema-postgres-1.sql
32 changes: 24 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,21 @@

<!--test-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
<version>3.4.4</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -95,7 +101,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
<version>8.0.11</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -107,8 +113,8 @@

<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
<artifactId>ojdbc8</artifactId>
<version>19.7.0.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -149,8 +155,13 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.2</version>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -165,6 +176,11 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
Expand Down
11 changes: 4 additions & 7 deletions readme-oracle-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ https://download.liquibase.org/download/
Set environment variable LIQUIBASE_HOME
Copy driver to $LIQUIBASE_HOME/lib

#### Run docker with Oracle XE 11 release 2
#### Run docker with Oracle XE 18c (you need to build it first)
```
cd sql/oracle
rm -f init/.cache
docker run --rm -it -p 1521:1521 -v $PWD/init:/docker-entrypoint-initdb.d --name morejdbc-oracle wnameless/oracle-xe-11g-r2
docker run --name morejdbc-oracle -d -p 1521:1521 oracle/database:18.4.0-xe
```
You can pass the tablespace volume with extra parameter `-v $HOME/oracle_data:/u01/app/oracle`

#### Create Oracle schema as test user
```

# Workaround only for XE and Russian locale (ORA-12705: Cannot access NLS data files or invalid environment specified)
# export JAVA_OPTS="-Duser.country=en -Duser.language=en"
$LIQUIBASE_HOME/liquibase --url=jdbc:oracle:thin:@127.0.0.1:1521:XE --username=test --password=test --changeLogFile=changelog.xml --logLevel=info update
$LIQUIBASE_HOME/liquibase --url=jdbc:oracle:thin:@127.0.0.1:1521:XEPDB1 --username=test --password=test --changeLogFile=changelog.xml --logLevel=info update
```

#### Run tests
Expand All @@ -31,5 +29,4 @@ docker stop morejdbc-oracle
```

For more information:
https://github.com/wnameless/docker-oracle-xe-11g
https://hub.docker.com/r/wnameless/oracle-xe-11g-r2
https://blogs.oracle.com/oraclemagazine/deliver-oracle-database-18c-express-edition-in-containers
72 changes: 39 additions & 33 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[![license](https://img.shields.io/badge/License-Apache%202.0-green)](https://www.apache.org/licenses/LICENSE-2.0)
[![build](https://travis-ci.com/dmvolodin/morejdbc.svg?branch=master)](https://travis-ci.com/github/dmvolodin/morejdbc)



This project contains helper classes to call stored procedures and functions. The base framework is spring (spring-jdbc).
It is fair-typesafe (no unsafe casts inside). Most compatible database is Oracle.
It is fair-typesafe (no unsafe casts inside). The most compatible database is Oracle.

To add the library in Maven:
```xml
Expand All @@ -18,26 +23,27 @@ For Oracle procedure/function calls you can use NamedJdbcCall. The parameters ar
* support default value
* support overloading

Consider you have a procedure and a function:
Consider you have a procedure and a function in a package:

```sql
CREATE PROCEDURE test_math(
val1 IN number,
val2 number,
out_sum OUT number,
out_mlt OUT number
) IS
BEGIN
out_sum := val1 + val2;
out_mlt := val1 * val2;
END;

CREATE FUNCTION get_concat(s1 varchar2, s2 varchar2)
RETURN VARCHAR2
IS
BEGIN
RETURN s1 || s2;
END;
create or replace package body test_more_jdbc_pkg
as
procedure calc_sum_and_multiply_of_two_numbers(p_number1 number,
p_number2 number,
po_sum out number,
po_mlt out number)
is
begin
po_sum := p_number1 + p_number2;
po_mlt := p_number1 * p_number2;
end;

function get_concat_of_two_strings(p_string1 varchar2, p_string2 varchar2)
return varchar2 is
begin
return p_string1 || p_string2;
end;
end;
```

You can call it:
Expand All @@ -52,11 +58,11 @@ private JdbcTemplate jdbcTemplate;
...
Out<Integer> sum = Out.of(INTEGER);
Out<Long> mlt = Out.of(BIGINT);
jdbcTemplate.execute(call("test_math")
.in("val1", 1)
.in("val2", 2L)
.out("out_sum", sum)
.out("out_mlt", mlt)
jdbcTemplate.execute(call("test_more_jdbc_pkg.calc_sum_and_multiply_of_two_numbers")
.in("p_number1", 1)
.in("p_number2", 2L)
.out("po_sum", sum)
.out("po_mlt", mlt)
);
// sum.get() is 3 (Integer)
// mlt.get() is 2L (Long)
Expand All @@ -68,11 +74,11 @@ or in value-consumer style with lambdas
```java
AtomicReference<Integer> sum = new AtomicReference<>();
AtomicReference<Long> mlt = new AtomicReference<>();
jdbcTemplate.execute(call("test_math")
.in("val1", 1)
.in("val2", 2L)
.out("out_sum", INTEGER, sum::set)
.out("out_mlt", BIGINT, mlt::set)
jdbcTemplate.execute(call("test_more_jdbc_pkg.calc_sum_and_multiply_of_two_numbers")
.in("p_number1", 1)
.in("p_number2", 2L)
.out("po_sum", INTEGER, sum::set)
.out("po_mlt", BIGINT, mlt::set)
);
// sum.get() is 3 (Integer)
// mlt.get() is 2L (Long)
Expand All @@ -81,10 +87,10 @@ jdbcTemplate.execute(call("test_math")
For functions:

```java
String result = jdbcTemplate.execute(call("get_concat", VARCHAR)
.in("s2", "def")
.in("s1", "abc") // note: reordered s1, s2
String result = jdbcTemplate.execute(call("test_more_jdbc_pkg.get_concat_of_two_strings", VARCHAR)
.in("p_string2", "def")
.in("p_string1", "abc") // note: reordered p_string1, p_string2
);
// result is "abcdef" (s1 || s2)
// result is "abcdef" (p_string1 + p_string2)
```

4 changes: 4 additions & 0 deletions sql/mysql/create-test-user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
create database test;
create user 'test'@'%' identified by 'test';
grant all privileges on *.* to 'test'@'%';
flush privileges;
9 changes: 0 additions & 9 deletions sql/mysql/init/create-test-user.sql

This file was deleted.

19 changes: 7 additions & 12 deletions sql/mysql/schema-mysql-1.sql
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
-- liquibase formatted sql

-- changeset seregamorph:FEA-1-create-schema-1 splitStatements:false
CREATE PROCEDURE test_math(
IN val1 int,
IN val2 int,
OUT out_sum int,
OUT out_mlt int
)
BEGIN
delimiter //
create procedure test_math(IN val1 int, IN val2 int, OUT out_sum int, OUT out_mlt int)
begin
set out_sum = val1 + val2;
set out_mlt = val1 * val2;
END;
end;
//

-- changeset seregamorph:FEA-1-create-schema-2 splitStatements:false
CREATE FUNCTION get_concat(s1 varchar(50), s2 varchar(50))
RETURNS VARCHAR(100) DETERMINISTIC
RETURN concat(s1, s2);

create function get_concat(s1 varchar(50), s2 varchar(50)) returns varchar(100)
return concat(s1, s2);
2 changes: 2 additions & 0 deletions sql/oracle/create-test-user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
create user test identified by test default tablespace users quota 100m on users;
grant connect, resource to test;
16 changes: 0 additions & 16 deletions sql/oracle/init/create-test-user.sql

This file was deleted.

Loading