diff --git a/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
new file mode 100644
index 0000000..68cbdf9
--- /dev/null
+++ b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
new file mode 100644
index 0000000..68cbdf9
--- /dev/null
+++ b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__junit_junit_4_11.xml b/.idea/libraries/Gradle__junit_junit_4_11.xml
index dc26b34..720213c 100644
--- a/.idea/libraries/Gradle__junit_junit_4_11.xml
+++ b/.idea/libraries/Gradle__junit_junit_4_11.xml
@@ -1,11 +1,9 @@
-
+
-
-
-
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
new file mode 100644
index 0000000..68cbdf9
--- /dev/null
+++ b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__junit_junit_4_11.xml b/.idea/libraries/Gradle__junit_junit_4_11.xml
index dc26b34..720213c 100644
--- a/.idea/libraries/Gradle__junit_junit_4_11.xml
+++ b/.idea/libraries/Gradle__junit_junit_4_11.xml
@@ -1,11 +1,9 @@
-
+
-
-
-
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml b/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml
new file mode 100644
index 0000000..9a00155
--- /dev/null
+++ b/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
new file mode 100644
index 0000000..68cbdf9
--- /dev/null
+++ b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__junit_junit_4_11.xml b/.idea/libraries/Gradle__junit_junit_4_11.xml
index dc26b34..720213c 100644
--- a/.idea/libraries/Gradle__junit_junit_4_11.xml
+++ b/.idea/libraries/Gradle__junit_junit_4_11.xml
@@ -1,11 +1,9 @@
-
+
-
-
-
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml b/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml
new file mode 100644
index 0000000..9a00155
--- /dev/null
+++ b/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
index 8262f72..b9f5b31 100644
--- a/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
+++ b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
@@ -1,11 +1,9 @@
-
+
-
-
-
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
new file mode 100644
index 0000000..68cbdf9
--- /dev/null
+++ b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__junit_junit_4_11.xml b/.idea/libraries/Gradle__junit_junit_4_11.xml
index dc26b34..720213c 100644
--- a/.idea/libraries/Gradle__junit_junit_4_11.xml
+++ b/.idea/libraries/Gradle__junit_junit_4_11.xml
@@ -1,11 +1,9 @@
-
+
-
-
-
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml b/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml
new file mode 100644
index 0000000..9a00155
--- /dev/null
+++ b/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
index 8262f72..b9f5b31 100644
--- a/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
+++ b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
@@ -1,11 +1,9 @@
-
+
-
-
-
+
\ No newline at end of file
diff --git a/.idea/modules/simple-database-kotlin_test.iml b/.idea/modules/simple-database-kotlin_test.iml
index b1cd811..5cef15d 100644
--- a/.idea/modules/simple-database-kotlin_test.iml
+++ b/.idea/modules/simple-database-kotlin_test.iml
@@ -17,6 +17,7 @@
+
diff --git a/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
new file mode 100644
index 0000000..68cbdf9
--- /dev/null
+++ b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__junit_junit_4_11.xml b/.idea/libraries/Gradle__junit_junit_4_11.xml
index dc26b34..720213c 100644
--- a/.idea/libraries/Gradle__junit_junit_4_11.xml
+++ b/.idea/libraries/Gradle__junit_junit_4_11.xml
@@ -1,11 +1,9 @@
-
+
-
-
-
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml b/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml
new file mode 100644
index 0000000..9a00155
--- /dev/null
+++ b/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
index 8262f72..b9f5b31 100644
--- a/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
+++ b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
@@ -1,11 +1,9 @@
-
+
-
-
-
+
\ No newline at end of file
diff --git a/.idea/modules/simple-database-kotlin_test.iml b/.idea/modules/simple-database-kotlin_test.iml
index b1cd811..5cef15d 100644
--- a/.idea/modules/simple-database-kotlin_test.iml
+++ b/.idea/modules/simple-database-kotlin_test.iml
@@ -17,6 +17,7 @@
+
diff --git a/build.gradle b/build.gradle
index 2c1de53..e411bce 100644
--- a/build.gradle
+++ b/build.gradle
@@ -33,6 +33,8 @@
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
+ testCompile "com.h2database:h2:1.4.+"
+
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "nl.astraeus:simple-database:2.0.0-SNAPSHOT"
}
diff --git a/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
new file mode 100644
index 0000000..68cbdf9
--- /dev/null
+++ b/.idea/libraries/Gradle__com_h2database_h2_1_4_193.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__junit_junit_4_11.xml b/.idea/libraries/Gradle__junit_junit_4_11.xml
index dc26b34..720213c 100644
--- a/.idea/libraries/Gradle__junit_junit_4_11.xml
+++ b/.idea/libraries/Gradle__junit_junit_4_11.xml
@@ -1,11 +1,9 @@
-
+
-
-
-
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml b/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml
new file mode 100644
index 0000000..9a00155
--- /dev/null
+++ b/.idea/libraries/Gradle__nl_astraeus_template_very_simple_templates_1_3.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
index 8262f72..b9f5b31 100644
--- a/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
+++ b/.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3.xml
@@ -1,11 +1,9 @@
-
+
-
-
-
+
\ No newline at end of file
diff --git a/.idea/modules/simple-database-kotlin_test.iml b/.idea/modules/simple-database-kotlin_test.iml
index b1cd811..5cef15d 100644
--- a/.idea/modules/simple-database-kotlin_test.iml
+++ b/.idea/modules/simple-database-kotlin_test.iml
@@ -17,6 +17,7 @@
+
diff --git a/build.gradle b/build.gradle
index 2c1de53..e411bce 100644
--- a/build.gradle
+++ b/build.gradle
@@ -33,6 +33,8 @@
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
+ testCompile "com.h2database:h2:1.4.+"
+
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "nl.astraeus:simple-database:2.0.0-SNAPSHOT"
}
diff --git a/test/nl/astraeus/database/TestQueries.kt b/test/nl/astraeus/database/TestQueries.kt
index f01f09a..930f0c1 100644
--- a/test/nl/astraeus/database/TestQueries.kt
+++ b/test/nl/astraeus/database/TestQueries.kt
@@ -3,6 +3,8 @@
import nl.astraeus.database.annotations.Column
import nl.astraeus.database.annotations.Id
import nl.astraeus.database.annotations.Table
+import nl.astraeus.database.jdbc.ConnectionPool
+import nl.astraeus.database.jdbc.ConnectionProvider
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
@@ -48,15 +50,15 @@
protected constructor(): this(Company(""), User(Company(""), "", ""))
}
-class CompanyDao(): Dao(Company::class.java)
+class CompanyDao(): SimpleDao(Company::class.java)
-class UserDao(): Dao(User::class.java)
+class UserDao(): SimpleDao(User::class.java)
-class MTMDao(): Dao(ManyToMany::class.java) {
+class MTMDao(): SimpleDao(ManyToMany::class.java) {
fun users(comp: Company): List {
return transaction> {
- var dao = UserDao()
+ val dao = UserDao()
dao.from("join manytomany where manytomany.user = usr.id and manytomany.company = ?", comp.id)
}
@@ -64,7 +66,7 @@
fun companies(user: User): List {
return transaction> {
- var dao = CompanyDao()
+ val dao = CompanyDao()
dao.from("join manytomany where manytomany.company = company.id and manytomany.user = ?", user.id)
}
@@ -81,38 +83,37 @@
return connection
}
+class MyConnectionProvider : ConnectionProvider() {
+
+ override fun getConnection() = createConnection()
+
+ override fun getDefinition(): DdlMapping.DatabaseDefinition {
+ return DdlMapping.DatabaseDefinition.H2
+ }
+}
+
class TestQueries {
@Before fun setUp() {
- DdlMapping.get().setExecuteDDLUpdates(true)
+ val db = SimpleDatabase.define(ConnectionPool(MyConnectionProvider()))
- setConnectionProvider(::createConnection)
-
- setConnectionProvider {
- Class.forName("org.h2.Driver")
-
- val connection = DriverManager.getConnection("jdbc:h2:mem:TestQueries", "sa", "")
- connection.autoCommit = false
-
- // result
- connection
- }
+ db.setExecuteDDLUpdates(true);
}
@Test fun testWhere() {
- var companyDao = CompanyDao()
- var userDao = UserDao()
- var mtmDao = MTMDao()
+ val companyDao = CompanyDao()
+ val userDao = UserDao()
+ val mtmDao = MTMDao()
transaction {
- var company = Company("company")
+ val company = Company("company")
- var rien = User(company, "Rien", "info@somewhere.com")
- var piet = User(company, "Piet", "piet@somewhere.com")
+ val rien = User(company, "Info", "info@somewhere.com")
+ val piet = User(company, "Piet", "piet@somewhere.com")
userDao.insert(rien)
userDao.upsert(piet)
- rien.name = "Rrrrien"
+ rien.name = "Iiiinfo"
userDao.update(rien)
piet.email = "pietje@somewhere.com"
@@ -124,14 +125,14 @@
}
transaction {
- var user = userDao.find("name = ?", "Rrrrien")
+ val user = userDao.find("name = ?", "Iiiinfo")
if (user != null) {
user.company.name = "Better Company!"
companyDao.update(user.company)
- var companies = mtmDao.companies(user)
+ val companies = mtmDao.companies(user)
for (company in companies) {
println("Company from ${user.name} -> ${company.name}")
@@ -140,7 +141,7 @@
}
transaction {
- var found = userDao.where("name = ?", "Rrrrien")
+ val found = userDao.where("name = ?", "Iiiinfo")
assertTrue(found.size == 1)
@@ -160,7 +161,7 @@
println("Found: #${user.id} - ${user.name} - ${user.email} - ${user.company.name}")
}
- var rs = query("SELECT * FROM company")
+ var rs = query(query = "SELECT * FROM company")
while(rs.next()) {
print("Company: ")
@@ -169,7 +170,7 @@
println(rs.getString(2))
}
- rs = query("SELECT * FROM usr")
+ rs = query(query = "SELECT * FROM usr")
while(rs.next()) {
print("User: ")
@@ -182,7 +183,7 @@
println(rs.getString(4))
}
- rs = query("SELECT * FROM manytomany")
+ rs = query(query = "SELECT * FROM manytomany")
while(rs.next()) {
print("MTM: ")