diff --git a/build.gradle b/build.gradle index c6e130b..b918b06 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,8 @@ apply plugin: 'kotlin' apply plugin: 'idea' +apply plugin: 'maven' +apply plugin: 'findbugs' sourceSets { main.java.srcDirs += 'src' @@ -34,3 +36,24 @@ compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "nl.astraeus.database:simple-database:1.1-SNAPSHOT" } + +uploadArchives { + repositories { + mavenDeployer { + repository(url: "http://nexus.astraeus.nl/nexus/content/repositories/releases") { + authentication(userName: nexusUsername, password: nexusPassword) + } + snapshotRepository(url: "http://nexus.astraeus.nl/nexus/content/repositories/snapshots") { + authentication(userName: nexusUsername, password: nexusPassword) + } + } + } +} + +findbugs { + ignoreFailures = true +} + +javadoc { + failOnError = false +} diff --git a/build.gradle b/build.gradle index c6e130b..b918b06 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,8 @@ apply plugin: 'kotlin' apply plugin: 'idea' +apply plugin: 'maven' +apply plugin: 'findbugs' sourceSets { main.java.srcDirs += 'src' @@ -34,3 +36,24 @@ compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "nl.astraeus.database:simple-database:1.1-SNAPSHOT" } + +uploadArchives { + repositories { + mavenDeployer { + repository(url: "http://nexus.astraeus.nl/nexus/content/repositories/releases") { + authentication(userName: nexusUsername, password: nexusPassword) + } + snapshotRepository(url: "http://nexus.astraeus.nl/nexus/content/repositories/snapshots") { + authentication(userName: nexusUsername, password: nexusPassword) + } + } + } +} + +findbugs { + ignoreFailures = true +} + +javadoc { + failOnError = false +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2ddb90c..f6b5590 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Oct 18 15:40:15 CEST 2015 +#Sun Oct 18 19:05:23 CEST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip diff --git a/build.gradle b/build.gradle index c6e130b..b918b06 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,8 @@ apply plugin: 'kotlin' apply plugin: 'idea' +apply plugin: 'maven' +apply plugin: 'findbugs' sourceSets { main.java.srcDirs += 'src' @@ -34,3 +36,24 @@ compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "nl.astraeus.database:simple-database:1.1-SNAPSHOT" } + +uploadArchives { + repositories { + mavenDeployer { + repository(url: "http://nexus.astraeus.nl/nexus/content/repositories/releases") { + authentication(userName: nexusUsername, password: nexusPassword) + } + snapshotRepository(url: "http://nexus.astraeus.nl/nexus/content/repositories/snapshots") { + authentication(userName: nexusUsername, password: nexusPassword) + } + } + } +} + +findbugs { + ignoreFailures = true +} + +javadoc { + failOnError = false +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2ddb90c..f6b5590 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Oct 18 15:40:15 CEST 2015 +#Sun Oct 18 19:05:23 CEST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip diff --git a/simple-database-kotlin.iml b/simple-database-kotlin.iml index b202aa0..a418139 100644 --- a/simple-database-kotlin.iml +++ b/simple-database-kotlin.iml @@ -18,8 +18,6 @@ - - @@ -27,5 +25,7 @@ + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index c6e130b..b918b06 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,8 @@ apply plugin: 'kotlin' apply plugin: 'idea' +apply plugin: 'maven' +apply plugin: 'findbugs' sourceSets { main.java.srcDirs += 'src' @@ -34,3 +36,24 @@ compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "nl.astraeus.database:simple-database:1.1-SNAPSHOT" } + +uploadArchives { + repositories { + mavenDeployer { + repository(url: "http://nexus.astraeus.nl/nexus/content/repositories/releases") { + authentication(userName: nexusUsername, password: nexusPassword) + } + snapshotRepository(url: "http://nexus.astraeus.nl/nexus/content/repositories/snapshots") { + authentication(userName: nexusUsername, password: nexusPassword) + } + } + } +} + +findbugs { + ignoreFailures = true +} + +javadoc { + failOnError = false +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2ddb90c..f6b5590 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Oct 18 15:40:15 CEST 2015 +#Sun Oct 18 19:05:23 CEST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip diff --git a/simple-database-kotlin.iml b/simple-database-kotlin.iml index b202aa0..a418139 100644 --- a/simple-database-kotlin.iml +++ b/simple-database-kotlin.iml @@ -18,8 +18,6 @@ - - @@ -27,5 +25,7 @@ + + \ No newline at end of file diff --git a/simple-database-kotlin.ipr b/simple-database-kotlin.ipr index 84f6d94..c043c5c 100644 --- a/simple-database-kotlin.ipr +++ b/simple-database-kotlin.ipr @@ -20,6 +20,7 @@ + diff --git a/build.gradle b/build.gradle index c6e130b..b918b06 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,8 @@ apply plugin: 'kotlin' apply plugin: 'idea' +apply plugin: 'maven' +apply plugin: 'findbugs' sourceSets { main.java.srcDirs += 'src' @@ -34,3 +36,24 @@ compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "nl.astraeus.database:simple-database:1.1-SNAPSHOT" } + +uploadArchives { + repositories { + mavenDeployer { + repository(url: "http://nexus.astraeus.nl/nexus/content/repositories/releases") { + authentication(userName: nexusUsername, password: nexusPassword) + } + snapshotRepository(url: "http://nexus.astraeus.nl/nexus/content/repositories/snapshots") { + authentication(userName: nexusUsername, password: nexusPassword) + } + } + } +} + +findbugs { + ignoreFailures = true +} + +javadoc { + failOnError = false +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2ddb90c..f6b5590 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Oct 18 15:40:15 CEST 2015 +#Sun Oct 18 19:05:23 CEST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip diff --git a/simple-database-kotlin.iml b/simple-database-kotlin.iml index b202aa0..a418139 100644 --- a/simple-database-kotlin.iml +++ b/simple-database-kotlin.iml @@ -18,8 +18,6 @@ - - @@ -27,5 +25,7 @@ + + \ No newline at end of file diff --git a/simple-database-kotlin.ipr b/simple-database-kotlin.ipr index 84f6d94..c043c5c 100644 --- a/simple-database-kotlin.ipr +++ b/simple-database-kotlin.ipr @@ -20,6 +20,7 @@ + diff --git a/src/nl/astraeus/database/Database.kt b/src/nl/astraeus/database/Database.kt index 91d16a7..c9b56d9 100644 --- a/src/nl/astraeus/database/Database.kt +++ b/src/nl/astraeus/database/Database.kt @@ -1,5 +1,9 @@ package nl.astraeus.database +import nl.astraeus.database.jdbc.ConnectionPool +import nl.astraeus.database.jdbc.ConnectionProvider +import java.sql.Connection + /** * User: rnentjes * Date: 18-10-15 @@ -47,3 +51,9 @@ } } } + +fun setConnectionProvider(conn: () -> Connection ) { + ConnectionPool.get().setConnectionProvider(object : ConnectionProvider { + override fun getConnection(): Connection = conn() + }) +} diff --git a/build.gradle b/build.gradle index c6e130b..b918b06 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,8 @@ apply plugin: 'kotlin' apply plugin: 'idea' +apply plugin: 'maven' +apply plugin: 'findbugs' sourceSets { main.java.srcDirs += 'src' @@ -34,3 +36,24 @@ compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "nl.astraeus.database:simple-database:1.1-SNAPSHOT" } + +uploadArchives { + repositories { + mavenDeployer { + repository(url: "http://nexus.astraeus.nl/nexus/content/repositories/releases") { + authentication(userName: nexusUsername, password: nexusPassword) + } + snapshotRepository(url: "http://nexus.astraeus.nl/nexus/content/repositories/snapshots") { + authentication(userName: nexusUsername, password: nexusPassword) + } + } + } +} + +findbugs { + ignoreFailures = true +} + +javadoc { + failOnError = false +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2ddb90c..f6b5590 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Oct 18 15:40:15 CEST 2015 +#Sun Oct 18 19:05:23 CEST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip diff --git a/simple-database-kotlin.iml b/simple-database-kotlin.iml index b202aa0..a418139 100644 --- a/simple-database-kotlin.iml +++ b/simple-database-kotlin.iml @@ -18,8 +18,6 @@ - - @@ -27,5 +25,7 @@ + + \ No newline at end of file diff --git a/simple-database-kotlin.ipr b/simple-database-kotlin.ipr index 84f6d94..c043c5c 100644 --- a/simple-database-kotlin.ipr +++ b/simple-database-kotlin.ipr @@ -20,6 +20,7 @@ + diff --git a/src/nl/astraeus/database/Database.kt b/src/nl/astraeus/database/Database.kt index 91d16a7..c9b56d9 100644 --- a/src/nl/astraeus/database/Database.kt +++ b/src/nl/astraeus/database/Database.kt @@ -1,5 +1,9 @@ package nl.astraeus.database +import nl.astraeus.database.jdbc.ConnectionPool +import nl.astraeus.database.jdbc.ConnectionProvider +import java.sql.Connection + /** * User: rnentjes * Date: 18-10-15 @@ -47,3 +51,9 @@ } } } + +fun setConnectionProvider(conn: () -> Connection ) { + ConnectionPool.get().setConnectionProvider(object : ConnectionProvider { + override fun getConnection(): Connection = conn() + }) +} diff --git a/src/nl/astraeus/database/Queries.kt b/src/nl/astraeus/database/Queries.kt index 36c1d0e..175ea48 100644 --- a/src/nl/astraeus/database/Queries.kt +++ b/src/nl/astraeus/database/Queries.kt @@ -10,35 +10,29 @@ abstract class Dao(val cls: Class) { - open fun find(id: Long): T { - return Persister.find(cls, id) + init { + Persister.init(cls) } - open fun insert(obj: T) { - Persister.insert(obj) - } + open fun find(id: Long): T = Persister.find(cls, id) - open fun update(obj: T) { - Persister.update(obj); - } - open fun delete(obj: T) { - Persister.delete(obj) - } + open fun insert(obj: T) = Persister.insert(obj) + open fun update(obj: T) = Persister.update(obj) + open fun delete(obj: T) = Persister.delete(obj) + open fun upsert(obj: T) = Persister.store(obj) - open fun execute(query: String, args: Array) { - Persister.execute(query, args); - } + open fun execute(query: String, vararg args: String) = Persister.execute(query, *args); - open fun query(query: String, args: Array): ResultSet { - return Persister.executeQuery(query, args); - } + open fun query(query: String, vararg args: String): ResultSet = Persister.executeQuery(query, *args) - open fun update(query: String, args: Array): Int { - return Persister.executeUpdate(query, args); - } + open fun update(query: String, vararg args: String): Int = Persister.executeUpdate(query, *args) - open fun where(query: String, vararg args: String): List { - return Persister.selectWhere(cls, query, *args) - } + open fun where(query: String, vararg args: String): List = Persister.selectWhere(cls, query, *args) -} \ No newline at end of file + open fun from(query: String, vararg args: String): List = Persister.selectFrom(cls, query, *args) + + open fun count(query: String, vararg args: String): Int = Persister.selectCount(cls, query, *args) + + open fun all(): List = Persister.selectAll(cls) + +} diff --git a/build.gradle b/build.gradle index c6e130b..b918b06 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,8 @@ apply plugin: 'kotlin' apply plugin: 'idea' +apply plugin: 'maven' +apply plugin: 'findbugs' sourceSets { main.java.srcDirs += 'src' @@ -34,3 +36,24 @@ compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "nl.astraeus.database:simple-database:1.1-SNAPSHOT" } + +uploadArchives { + repositories { + mavenDeployer { + repository(url: "http://nexus.astraeus.nl/nexus/content/repositories/releases") { + authentication(userName: nexusUsername, password: nexusPassword) + } + snapshotRepository(url: "http://nexus.astraeus.nl/nexus/content/repositories/snapshots") { + authentication(userName: nexusUsername, password: nexusPassword) + } + } + } +} + +findbugs { + ignoreFailures = true +} + +javadoc { + failOnError = false +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2ddb90c..f6b5590 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Oct 18 15:40:15 CEST 2015 +#Sun Oct 18 19:05:23 CEST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-all.zip diff --git a/simple-database-kotlin.iml b/simple-database-kotlin.iml index b202aa0..a418139 100644 --- a/simple-database-kotlin.iml +++ b/simple-database-kotlin.iml @@ -18,8 +18,6 @@ - - @@ -27,5 +25,7 @@ + + \ No newline at end of file diff --git a/simple-database-kotlin.ipr b/simple-database-kotlin.ipr index 84f6d94..c043c5c 100644 --- a/simple-database-kotlin.ipr +++ b/simple-database-kotlin.ipr @@ -20,6 +20,7 @@ + diff --git a/src/nl/astraeus/database/Database.kt b/src/nl/astraeus/database/Database.kt index 91d16a7..c9b56d9 100644 --- a/src/nl/astraeus/database/Database.kt +++ b/src/nl/astraeus/database/Database.kt @@ -1,5 +1,9 @@ package nl.astraeus.database +import nl.astraeus.database.jdbc.ConnectionPool +import nl.astraeus.database.jdbc.ConnectionProvider +import java.sql.Connection + /** * User: rnentjes * Date: 18-10-15 @@ -47,3 +51,9 @@ } } } + +fun setConnectionProvider(conn: () -> Connection ) { + ConnectionPool.get().setConnectionProvider(object : ConnectionProvider { + override fun getConnection(): Connection = conn() + }) +} diff --git a/src/nl/astraeus/database/Queries.kt b/src/nl/astraeus/database/Queries.kt index 36c1d0e..175ea48 100644 --- a/src/nl/astraeus/database/Queries.kt +++ b/src/nl/astraeus/database/Queries.kt @@ -10,35 +10,29 @@ abstract class Dao(val cls: Class) { - open fun find(id: Long): T { - return Persister.find(cls, id) + init { + Persister.init(cls) } - open fun insert(obj: T) { - Persister.insert(obj) - } + open fun find(id: Long): T = Persister.find(cls, id) - open fun update(obj: T) { - Persister.update(obj); - } - open fun delete(obj: T) { - Persister.delete(obj) - } + open fun insert(obj: T) = Persister.insert(obj) + open fun update(obj: T) = Persister.update(obj) + open fun delete(obj: T) = Persister.delete(obj) + open fun upsert(obj: T) = Persister.store(obj) - open fun execute(query: String, args: Array) { - Persister.execute(query, args); - } + open fun execute(query: String, vararg args: String) = Persister.execute(query, *args); - open fun query(query: String, args: Array): ResultSet { - return Persister.executeQuery(query, args); - } + open fun query(query: String, vararg args: String): ResultSet = Persister.executeQuery(query, *args) - open fun update(query: String, args: Array): Int { - return Persister.executeUpdate(query, args); - } + open fun update(query: String, vararg args: String): Int = Persister.executeUpdate(query, *args) - open fun where(query: String, vararg args: String): List { - return Persister.selectWhere(cls, query, *args) - } + open fun where(query: String, vararg args: String): List = Persister.selectWhere(cls, query, *args) -} \ No newline at end of file + open fun from(query: String, vararg args: String): List = Persister.selectFrom(cls, query, *args) + + open fun count(query: String, vararg args: String): Int = Persister.selectCount(cls, query, *args) + + open fun all(): List = Persister.selectAll(cls) + +} diff --git a/test/nl/astraeus/database/TestQueries.kt b/test/nl/astraeus/database/TestQueries.kt index 8c0a1b4..14ab635 100644 --- a/test/nl/astraeus/database/TestQueries.kt +++ b/test/nl/astraeus/database/TestQueries.kt @@ -1,14 +1,10 @@ package nl.astraeus.database import nl.astraeus.database.annotations.Id -import nl.astraeus.database.jdbc.ConnectionPool -import nl.astraeus.database.jdbc.ConnectionProvider import org.junit.After import org.junit.Before import org.junit.Test -import java.sql.Connection import java.sql.DriverManager -import java.sql.SQLException import kotlin.test.assertTrue /** @@ -29,22 +25,14 @@ @Before fun setUp() { DdlMapping.get().setExecuteDDLUpdates(true) - ConnectionPool.get().setConnectionProvider(object : ConnectionProvider { - override fun getConnection(): Connection { - try { - Class.forName("org.h2.Driver") + setConnectionProvider { + Class.forName("org.h2.Driver") - val connection = DriverManager.getConnection("jdbc:h2:mem:TestQueries", "sa", "") - connection.autoCommit = false + val connection = DriverManager.getConnection("jdbc:h2:mem:TestQueries", "sa", "") + connection.autoCommit = false - return connection - } catch (e: ClassNotFoundException) { - throw IllegalStateException(e) - } catch (e: SQLException) { - throw IllegalStateException(e) - } - } - }) + connection + } } @After fun tearDown() { @@ -55,17 +43,34 @@ var dao = UserDao() transaction { - dao.insert(User("Rien", "info@nentjes.com")) - dao.insert(User("Piet", "piet@nentjes.com")) + var rien = User("Rien", "info@somewhere.com") + var piet = User("Piet", "piet@somewhere.com") - var found = dao.where("name = ?", "Rien") + dao.insert(rien) + dao.upsert(piet) + + rien.name = "Rrrrien" + dao.update(rien) + + piet.email = "pietje@somewhere.com" + dao.upsert(piet) + + var found = dao.where("name = ?", "Rrrrien") assertTrue { found.size() == 1 } - for(user in found) { - println("Found: ${user.name}") + assertTrue { + dao.all().size() == 2 + } + + assertTrue { + dao.count("name = ?", "Piet") == 1 + } + + for(user in dao.all()) { + println("Found: #${user.id} - ${user.name} - ${user.email}") } } }