Skip to content

Commit

Permalink
oracle support
Browse files Browse the repository at this point in the history
  • Loading branch information
deusaquilus committed Feb 19, 2019
1 parent f12f1cd commit c5adb22
Show file tree
Hide file tree
Showing 39 changed files with 1,247 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ jobs:
include:
stage: release
if: type != pull_request
script:
script:
- travis_retry ./build/release.sh
75 changes: 51 additions & 24 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enablePlugins(TutPlugin)

lazy val modules = Seq[sbt.ClasspathDep[sbt.ProjectReference]](
`quill-core-jvm`, `quill-core-js`, `quill-monix`, `quill-sql-jvm`, `quill-sql-js`,
`quill-jdbc`, `quill-jdbc-monix`, `quill-finagle-mysql`, `quill-finagle-postgres`,
`quill-jdbc`, `quill-jdbc-monix`, `quill-finagle-mysql`, `quill-finagle-postgres`,
`quill-async`, `quill-async-mysql`, `quill-async-postgres`, `quill-cassandra`,
`quill-cassandra-lagom`, `quill-cassandra-monix`, `quill-orientdb`, `quill-spark`
)
Expand Down Expand Up @@ -67,21 +67,17 @@ lazy val `quill-sql` =
lazy val `quill-sql-jvm` = `quill-sql`.jvm
lazy val `quill-sql-js` = `quill-sql`.js

val includeOracle =
sys.props.getOrElse("oracle", "false").toBoolean

def includeIfOracle[T](t:T):Seq[T] =
if (includeOracle) Seq(t) else Seq()

lazy val `quill-jdbc` =
(project in file("quill-jdbc"))
.settings(commonSettings: _*)
.settings(mimaSettings: _*)
.settings(
fork in Test := true,
libraryDependencies ++= Seq(
"com.zaxxer" % "HikariCP" % "3.3.1",
"mysql" % "mysql-connector-java" % "8.0.15" % Test,
"com.h2database" % "h2" % "1.4.197" % Test,
"org.postgresql" % "postgresql" % "42.2.5" % Test,
"org.xerial" % "sqlite-jdbc" % "3.25.2" % Test,
"com.microsoft.sqlserver" % "mssql-jdbc" % "7.1.1.jre8-preview" % Test
)
)
.settings(jdbcTestingSettings: _*)
.dependsOn(`quill-sql-jvm` % "compile->compile;test->test")

lazy val `quill-monix` =
Expand All @@ -101,19 +97,8 @@ lazy val `quill-jdbc-monix` =
(project in file("quill-jdbc-monix"))
.settings(commonSettings: _*)
.settings(mimaSettings: _*)
.settings(jdbcTestingSettings: _*)
.settings(
fork in Test := true,
libraryDependencies ++= Seq(
"io.monix" %% "monix-eval" % "3.0.0-RC2",
"io.monix" %% "monix-reactive" % "3.0.0-RC2",
"com.zaxxer" % "HikariCP" % "3.3.1",
"mysql" % "mysql-connector-java" % "8.0.15" % Test,
"com.h2database" % "h2" % "1.4.197" % Test,
"org.postgresql" % "postgresql" % "42.2.5" % Test,
"org.xerial" % "sqlite-jdbc" % "3.25.2" % Test,
"com.microsoft.sqlserver" % "mssql-jdbc" % "7.1.1.jre8-preview" % Test,
"org.mockito" %% "mockito-scala" % "1.1.4" % Test
),
testGrouping in Test := {
(definedTests in Test).value map { test =>
if (test.name endsWith "IntegrationSpec")
Expand Down Expand Up @@ -328,6 +313,48 @@ def updateWebsiteTag =
st
})

lazy val jdbcTestingSettings = Seq(
fork in Test := true,
resolvers ++= includeIfOracle( // read ojdbc7 jar in case it is deployed
Resolver.mavenLocal
),
libraryDependencies ++= {
val deps =
Seq(
"com.zaxxer" % "HikariCP" % "3.3.1",
"mysql" % "mysql-connector-java" % "8.0.15" % Test,
"com.h2database" % "h2" % "1.4.197" % Test,
"org.postgresql" % "postgresql" % "42.2.5" % Test,
"org.xerial" % "sqlite-jdbc" % "3.25.2" % Test,
"com.microsoft.sqlserver" % "mssql-jdbc" % "7.1.1.jre8-preview" % Test,
"org.mockito" %% "mockito-scala" % "1.1.4" % Test
)

deps ++ includeIfOracle(
"com.oracle.jdbc" % "ojdbc7" % "12.1.0.2" % Test
)
},
excludeFilter in unmanagedSources := {
val oracleSourceDirs =
(unmanagedSourceDirectories in Test).value.map { dir =>
(dir / "io" / "getquill" / "context" / "jdbc" / "oracle").getCanonicalPath
} ++
(unmanagedSourceDirectories in Test).value.map { dir =>
(dir / "io" / "getquill" / "context" / "monix" / "oracle").getCanonicalPath
}
val excludeThisPath =
(path: String) =>
oracleSourceDirs.exists { srcDir =>
!includeOracle && (path contains srcDir)
}
new SimpleFileFilter(file => {
if (excludeThisPath(file.getCanonicalPath))
println(s"Excluding: ${file.getCanonicalPath}")
excludeThisPath(file.getCanonicalPath)
})
}
)

lazy val commonSettings = ReleasePlugin.extraReleaseCommands ++ Seq(
organization := "io.getquill",
scalaVersion := "2.11.12",
Expand Down
8 changes: 6 additions & 2 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ export MYSQL_PORT=3306
export SQL_SERVER_HOST=127.0.0.1
export SQL_SERVER_PORT=11433

export ORACLE_HOST=127.0.0.1
export ORACLE_PORT=11521

export CASSANDRA_HOST=127.0.0.1
export CASSANDRA_PORT=19042

export ORIENTDB_HOST=127.0.0.1
export ORIENTDB_PORT=12424

export SBT_ARGS="-Dquill.macro.log=false -Xms512m -Xmx1536m -Xss2m -XX:ReservedCodeCacheSize=256m -XX:+TieredCompilation -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC ++$TRAVIS_SCALA_VERSION"
export SBT_ARGS="-Doracle=true -Dquill.macro.log=false -Xms512m -Xmx1536m -Xss2m -XX:ReservedCodeCacheSize=256m -XX:+TieredCompilation -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC ++$TRAVIS_SCALA_VERSION"

if [[ $TRAVIS_SCALA_VERSION == 2.11* ]]; then
export SBT_ARGS="$SBT_ARGS coverage"
Expand Down Expand Up @@ -53,11 +56,12 @@ if [[ "$?" != "0" ]]; then
fi
show_mem

echo "Running tests"
time sbt $SBT_ARGS checkUnformattedFiles test tut doc

show_mem

echo "Tests completed. Shutting down"

time docker-compose down
# for 2.11 publish coverage
if [[ $TRAVIS_SCALA_VERSION == 2.11* ]]; then
Expand Down
3 changes: 3 additions & 0 deletions build/oracle_setup/create_quill_test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
alter session set "_ORACLE_SCRIPT"=true;
CREATE USER quill_test IDENTIFIED BY "QuillRocks!" QUOTA 50M ON system;
GRANT DBA TO quill_test;
14 changes: 14 additions & 0 deletions build/oracle_setup/external_check_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

source /root/.bashrc

echo "Setting up Oracle"

until source /root/.bashrc; sqlplus quill_test/QuillRocks! < /oracle_setup/external_match_script.sql; do
echo "Trying Again"
sleep 5;
done

echo "Oracle Setup Complete"
1 change: 1 addition & 0 deletions build/oracle_setup/external_match_script.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select 'match_this_test_to_pass' from DUAL;
29 changes: 29 additions & 0 deletions build/oracle_setup/external_setup_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

echo "Running Global Oracle Init"

# Start the oracle database
nohup /entrypoint.sh &

# Save the pid which we need to wait for (otherwise container will exit)
pid=$!

echo "Waiting for Oracle Setup to Complete"

until source /root/.bashrc; sqlplus system/oracle@//localhost:1521/xe < /oracle_setup/external_match_script.sql | grep "match_this_test_to_pass"; do
echo "Trying Again"
sleep 5;
done

source /root/.bashrc

echo "Setting Up Test Database"
sqlplus system/oracle@//localhost:1521/xe < /oracle_setup/create_quill_test.sql

echo "Setting Up Test Database Schema"
sqlplus quill_test/QuillRocks! < /quill_setup/oracle-schema.sql

echo "Oracle Setup Complete"

# Wait until oracle DB externally closed
wait $pid
13 changes: 13 additions & 0 deletions build/oracle_setup/load_jdbc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Copy the jdbc jar from the container to local
docker cp "$(docker-compose ps -q oracle)":/u01/app/oracle-product/12.1.0/xe/jdbc/lib/ojdbc7.jar ./

mvn install:install-file \
-Dfile=ojdbc7.jar \
-DgroupId='com.oracle.jdbc' \
-DartifactId=ojdbc7 \
-Dversion=12.1.0.2 \
-Dpackaging=jar

rm ojdbc7.jar
20 changes: 19 additions & 1 deletion build/setup_db_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export SQLITE_SCRIPT=quill-jdbc/src/test/resources/sql/sqlite-schema.sql
export MYSQL_SCRIPT=quill-sql/src/test/sql/mysql-schema.sql
export POSTGRES_SCRIPT=quill-sql/src/test/sql/postgres-schema.sql
export SQL_SERVER_SCRIPT=quill-sql/src/test/sql/sqlserver-schema.sql
export ORACLE_SCRIPT=quill-sql/src/test/sql/oracle-schema.sql
export CASSANDRA_SCRIPT=quill-cassandra/src/test/cql/cassandra-schema.cql


Expand Down Expand Up @@ -88,8 +89,25 @@ function setup_sqlserver() {
/opt/mssql-tools/bin/sqlcmd -S $2 -U SA -P "QuillRocks!" -d quill_test -i $1
}

# Do a simple necat poll to make sure the oracle database is ready.
# All internal database creation and schema setup scripts are handled
# by the container and docker-compose steps.

function setup_oracle() {

while ! nc -z $2 1521; do
echo "Waiting for Oracle"
sleep 5;
done;
sleep 5;

echo "Connected to Oracle"
sleep 5
}

export -f setup_sqlite
export -f setup_mysql
export -f setup_postgres
export -f setup_cassandra
export -f setup_sqlserver
export -f setup_sqlserver
export -f setup_oracle
1 change: 1 addition & 0 deletions build/setup_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ time setup_mysql $MYSQL_SCRIPT mysql
time setup_postgres $POSTGRES_SCRIPT postgres
time setup_cassandra $CASSANDRA_SCRIPT cassandra
time setup_sqlserver $SQL_SERVER_SCRIPT sqlserver
time setup_oracle $ORACLE_SCRIPT oracle

echo "Databases are ready!"
15 changes: 13 additions & 2 deletions build/setup_travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

set -e

time docker-compose up -d cassandra sqlserver orientdb
time docker-compose up -d cassandra sqlserver oracle orientdb

# import setup functions
. build/setup_db_scripts.sh

# load sbt deps to local repo
. build/oracle_setup/load_jdbc.sh

# run setup scripts for local databases
time setup_sqlite $SQLITE_SCRIPT 127.0.0.1
time setup_mysql $MYSQL_SCRIPT 127.0.0.1
time setup_postgres $POSTGRES_SCRIPT 127.0.0.1


function send_script() {
echo "Send Script Args: 1: $1 - 2 $2 - 3: $3"
docker cp $2 "$(docker-compose ps -q $1)":/$3
}

Expand All @@ -22,6 +25,14 @@ send_script sqlserver $SQL_SERVER_SCRIPT sqlserver-schema.sql
send_script sqlserver ./build/setup_db_scripts.sh setup_db_scripts.sh
time docker-compose exec -T sqlserver bash -c ". setup_db_scripts.sh && setup_sqlserver sqlserver-schema.sql 127.0.0.1"

until docker-compose exec -T oracle "/oracle_setup_local/external_check_script.sh" | grep "match_this_test_to_pass"; do
docker-compose exec -T oracle "/oracle_setup_local/external_check_script.sh"
echo "Waiting for Oracle"
sleep 5;
done
sleep 5;
echo "Oracle Setup Complete"

# setup cassandra in docker
send_script cassandra $CASSANDRA_SCRIPT cassandra-schema.cql
send_script cassandra ./build/setup_db_scripts.sh setup_db_scripts.sh
Expand Down
16 changes: 15 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,34 @@ services:
- ACCEPT_EULA=Y
- SA_PASSWORD=QuillRocks!

# These 2 are only kept for local development
oracle:
image: medgetablelevvel/oracle-12c-base
ports:
- "11521:1521"
volumes:
- ./build/oracle_setup:/oracle_setup
- ./quill-sql/src/test/sql/:/quill_setup
command: bash -c "mkdir /oracle_setup_local; cp /oracle_setup/* /oracle_setup_local && cd /oracle_setup_local && ./external_setup_script.sh"

setup:
build:
context: .
dockerfile: ./build/Dockerfile-setup
depends_on:
- oracle
links:
- postgres:postgres
- mysql:mysql
- cassandra:cassandra
- orientdb:orientdb
- sqlserver:sqlserver
- oracle:oracle
volumes:
- ./:/app
command:
- ./build/setup_local.sh


sbt:
build:
context: .
Expand All @@ -69,6 +80,7 @@ services:
- cassandra:cassandra
- orientdb:orientdb
- sqlserver:sqlserver
- oracle:oracle
volumes:
- ./:/app
- ~/.ivy2:/root/.ivy2
Expand All @@ -82,6 +94,8 @@ services:
- MYSQL_PORT=3306
- SQL_SERVER_HOST=sqlserver
- SQL_SERVER_PORT=1433
- ORACLE_HOST=oracle
- ORACLE_PORT=1521
- CASSANDRA_HOST=cassandra
- CASSANDRA_PORT=9042
- ORIENTDB_HOST=orientdb
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.getquill

import java.io.Closeable

import com.typesafe.config.Config
import io.getquill.context.jdbc.OracleJdbcContextBase
import io.getquill.context.monix.{ MonixJdbcContext, Runner }
import io.getquill.util.LoadConfig
import javax.sql.DataSource

class OracleMonixJdbcContext[N <: NamingStrategy](
val naming: N,
dataSource: DataSource with Closeable,
runner: Runner
) extends MonixJdbcContext[OracleDialect, N](dataSource, runner)
with OracleJdbcContextBase[N] {

def this(naming: N, config: JdbcContextConfig, runner: Runner) = this(naming, config.dataSource, runner)
def this(naming: N, config: Config, runner: Runner) = this(naming, JdbcContextConfig(config), runner)
def this(naming: N, configPrefix: String, runner: Runner) = this(naming, LoadConfig(configPrefix), runner)
def this(naming: N, configPrefix: String) = this(naming, LoadConfig(configPrefix), Runner.default)
}
8 changes: 8 additions & 0 deletions quill-jdbc-monix/src/test/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@ testSqlServerDB.dataSource.password="QuillRocks!"
testSqlServerDB.dataSource.databaseName=quill_test
testSqlServerDB.dataSource.portNumber=${?SQL_SERVER_PORT}
testSqlServerDB.dataSource.serverName=${?SQL_SERVER_HOST}

testOracleDB.dataSourceClassName=oracle.jdbc.xa.client.OracleXADataSource
testOracleDB.dataSource.databaseName=xe
testOracleDB.dataSource.user=quill_test
testOracleDB.dataSource.password="QuillRocks!"
testOracleDB.dataSource.driverType=thin
testOracleDB.dataSource.portNumber=${?ORACLE_PORT}
testOracleDB.dataSource.serverName=${?ORACLE_HOST}
Loading

0 comments on commit c5adb22

Please sign in to comment.