diff --git a/build.gradle b/build.gradle index 7d28635490..57cb768b50 100755 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ buildscript { } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "com.avast.gradle:gradle-docker-compose-plugin:0.5.2" + classpath "com.avast.gradle:gradle-docker-compose-plugin:0.7.1" } } @@ -51,14 +51,37 @@ exposedDialectTestWithDocker.doFirst { dockerCompose.isRequiredBy(exposedDialectTestWithDocker) +task mysql56Test(type: Test) { + apply from: 'src/test-conf/mysql56.gradle' +// composeUp.execute() +// exposedDialectTestWithDocker.execute() + println "MYSQL" +// environment 'DB_VERSION' "5.6" +} + dockerCompose { - useComposeFiles = ['docker-compose-' + dialect + '.yml'] +// def dialectProp = System.getProperty("dialect", "") +// println dialectProp +// println ext.dialect + mysql { + environment.put 'DB_VERSION', '5.6' + + useComposeFiles = ['src/test-conf/compose/docker-compose-mysql.yml'] + isRequiredBy(project.tasks.mysql56Test) + } +// } captureContainersOutput = true removeVolumes = true environment.put 'COMPOSE_CONVERT_WINDOWS_PATHS', 'true' waitForHealthyStateTimeout = Duration.ofMinutes(60) } +//gradle.taskGraph.whenReady {taskGraph -> +// if (taskGraph.hasTask(mysql56Test)) { +//// System.setProperty("dialect", "oracle") +// } +//} + artifacts { archives sourcesJar } @@ -88,6 +111,10 @@ dependencies { testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.2.1.jre7' } + + +//mysql56Test.dependsOn(mysql) + test { jvmArgs "-XX:MaxPermSize=256m" testLogging { diff --git a/gradle.properties b/gradle.properties index fec6710227..b8457fe622 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ group=org.jetbrains.exposed version=0.10.2-SNAPSHOT kotlin_version=1.2.30 spring_version=4.3.7.RELEASE -dialect= \ No newline at end of file +dialect=custom \ No newline at end of file diff --git a/src/main/kotlin/org/jetbrains/exposed/sql/Database.kt b/src/main/kotlin/org/jetbrains/exposed/sql/Database.kt index 4445e660d3..3c032ed6e5 100644 --- a/src/main/kotlin/org/jetbrains/exposed/sql/Database.kt +++ b/src/main/kotlin/org/jetbrains/exposed/sql/Database.kt @@ -25,7 +25,7 @@ class Database private constructor(val connector: () -> Connection) { val url: String by lazy { metadata.url } - internal val dialect by lazy { + var dialect : DatabaseDialect = run { val name = url.removePrefix("jdbc:").substringBefore(':') dialects[name.toLowerCase()]?.invoke() ?: error("No dialect registered for $name. URL=$url") } @@ -61,7 +61,7 @@ class Database private constructor(val connector: () -> Connection) { private fun Char.isIdentifierStart(): Boolean = this in 'a'..'z' || this in 'A'..'Z' || this == '_' || this in extraNameCharacters companion object { - private val dialects = ConcurrentHashMapDatabaseDialect>() + private val dialects = ConcurrentHashMapDatabaseDialect>() init { registerDialect(H2Dialect.dialectName) { H2Dialect() } @@ -76,6 +76,8 @@ class Database private constructor(val connector: () -> Connection) { dialects[prefix] = dialect } + fun getDialect(dialectName: String) = dialects[dialectName] + private fun doConnect(getNewConnection: () -> Connection, setupConnection: (Connection) -> Unit = {}, manager: (Database) -> TransactionManager = { ThreadLocalTransactionManager(it, DEFAULT_ISOLATION_LEVEL) } ): Database { diff --git a/src/test-conf/compose/docker-compose-mysql.yml b/src/test-conf/compose/docker-compose-mysql.yml new file mode 100644 index 0000000000..591e80a02e --- /dev/null +++ b/src/test-conf/compose/docker-compose-mysql.yml @@ -0,0 +1,8 @@ +version: '3.5' + +services: + mysql: + image: "mysql:${DB_VERSION:-latest}" + restart: always + environment: + MYSQL_ROOT_PASSWORD: password \ No newline at end of file diff --git a/docker-compose-oracle.yml b/src/test-conf/compose/docker-compose-oracle.yml similarity index 100% rename from docker-compose-oracle.yml rename to src/test-conf/compose/docker-compose-oracle.yml diff --git a/docker-compose-sqlserver.yml b/src/test-conf/compose/docker-compose-sqlserver.yml similarity index 100% rename from docker-compose-sqlserver.yml rename to src/test-conf/compose/docker-compose-sqlserver.yml diff --git a/src/test-conf/mysql56.gradle b/src/test-conf/mysql56.gradle new file mode 100644 index 0000000000..e4d8e4c03a --- /dev/null +++ b/src/test-conf/mysql56.gradle @@ -0,0 +1,3 @@ +dependencies { + "mysql:mysql-connector-java:5.1.44" +} \ No newline at end of file diff --git a/src/test/kotlin/org/jetbrains/exposed/sql/tests/DatabaseTestsBase.kt b/src/test/kotlin/org/jetbrains/exposed/sql/tests/DatabaseTestsBase.kt index 4aa6702638..7f67297ba0 100644 --- a/src/test/kotlin/org/jetbrains/exposed/sql/tests/DatabaseTestsBase.kt +++ b/src/test/kotlin/org/jetbrains/exposed/sql/tests/DatabaseTestsBase.kt @@ -55,9 +55,21 @@ enum class TestDB(val connection: String, val driver: String, val user: String = }), SQLSERVER("jdbc:sqlserver://${System.getProperty("exposed.test.sqlserver.host", "192.168.99.100")}" + ":${System.getProperty("exposed.test.sqlserver.port", "32781")}", - "com.microsoft.sqlserver.jdbc.SQLServerDriver", "SA", "yourStrong(!)Password"); + "com.microsoft.sqlserver.jdbc.SQLServerDriver", "SA", "yourStrong(!)Password"), - fun connect() = Database.connect(connection, user = user, password = pass, driver = driver) + CUSTOM(System.getProperty("exposed.test.custom.url", ""), + System.getProperty("exposed.test.custom.driver", ""), + System.getProperty("exposed.test.custom.user", ""), + System.getProperty("exposed.test.custom.pass", "") + ); + + fun connect() = Database.connect(connection, user = user, password = pass, driver = driver).also { db -> + if (this == CUSTOM) { + System.getProperty("exposed.test.custom.dialect")?.let { dialect -> + db.dialect = Database.getDialect(dialect)!!() + } + } + } companion object { fun enabledInTests(): List {