gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: Prefer varchar for "id" columns.


From: gnunet
Subject: [libeufin] branch master updated: Prefer varchar for "id" columns.
Date: Tue, 28 Jan 2020 20:13:39 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 849bca9  Prefer varchar for "id" columns.
849bca9 is described below

commit 849bca95be1cd6f772457ab5f974c58c62ecf6bf
Author: Marcello Stanisci <address@hidden>
AuthorDate: Tue Jan 28 20:13:18 2020 +0100

    Prefer varchar for "id" columns.
---
 nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt    | 12 ++++---
 .../src/main/kotlin/tech/libeufin/nexus/Helpers.kt |  9 ++---
 nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt  |  2 +-
 nexus/src/test/kotlin/DbTest.kt                    | 39 ++++++++++++++++++++++
 sandbox/src/test/kotlin/DbTest.kt                  |  1 -
 5 files changed, 49 insertions(+), 14 deletions(-)

diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
index f337b95..f399ee7 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/DB.kt
@@ -6,8 +6,11 @@ import 
org.jetbrains.exposed.sql.transactions.TransactionManager
 import org.jetbrains.exposed.sql.transactions.transaction
 import java.sql.Connection
 
+const val ID_MAX_LENGTH = 50
 
-object EbicsSubscribersTable : IntIdTable() {
+object EbicsSubscribersTable : IdTable<String>() {
+
+    override val id = varchar("id", ID_MAX_LENGTH).entityId().primaryKey()
     val ebicsURL = text("ebicsURL")
     val hostID = text("hostID")
     val partnerID = text("partnerID")
@@ -20,10 +23,9 @@ object EbicsSubscribersTable : IntIdTable() {
     val bankAuthenticationPublicKey = 
blob("bankAuthenticationPublicKey").nullable()
 }
 
-class EbicsSubscriberEntity(id: EntityID<Int>) : IntEntity(id) {
-    companion object : IntEntityClass<EbicsSubscriberEntity>(
-        EbicsSubscribersTable
-    )
+class EbicsSubscriberEntity(id: EntityID<String>) : Entity<String>(id) {
+
+    companion object : EntityClass<String, 
EbicsSubscriberEntity>(EbicsSubscribersTable)
 
     var ebicsURL by EbicsSubscribersTable.ebicsURL
     var hostID by EbicsSubscribersTable.hostID
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
index 79c0cbb..4e6e5c3 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/Helpers.kt
@@ -170,13 +170,8 @@ fun chunkString(input: String): String {
 
 }
 
-fun expectId(param: String?): Int {
-
-    try {
-        return param!!.toInt()
-    } catch (e: Exception) {
-        throw NotAnIdError(HttpStatusCode.BadRequest)
-    }
+fun expectId(param: String?): String {
+    return param ?: throw NotAnIdError(HttpStatusCode.BadRequest)
 }
 
 fun signOrder(
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt 
b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
index 202548e..9bbcb89 100644
--- a/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
+++ b/nexus/src/main/kotlin/tech/libeufin/nexus/JSON.kt
@@ -43,7 +43,7 @@ data class EbicsSubscriberInfoRequest(
  * Contain the ID that identifies the new user in the Nexus system.
  */
 data class EbicsSubscriberInfoResponse(
-    val accountID: Int,
+    val accountID: String,
     val ebicsURL: String,
     val hostID: String,
     val partnerID: String,
diff --git a/nexus/src/test/kotlin/DbTest.kt b/nexus/src/test/kotlin/DbTest.kt
new file mode 100644
index 0000000..2a4b4af
--- /dev/null
+++ b/nexus/src/test/kotlin/DbTest.kt
@@ -0,0 +1,39 @@
+package tech.libeufin.nexus
+
+import org.jetbrains.exposed.dao.EntityID
+import org.junit.Before
+import org.junit.Test
+
+import org.jetbrains.exposed.sql.Database
+import org.jetbrains.exposed.sql.transactions.transaction
+import org.jetbrains.exposed.sql.SchemaUtils
+import javax.sql.rowset.serial.SerialBlob
+
+
+class DbTest {
+
+    @Before
+    fun connectAndMakeTables() {
+        Database.connect("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", driver = 
"org.h2.Driver")
+        transaction {
+            SchemaUtils.create(EbicsSubscribersTable)
+        }
+    }
+
+    @Test
+    fun makeCustomer() {
+        transaction {
+            EbicsSubscriberEntity.new(id = "123asdf") {
+                ebicsURL = "ebics url"
+                hostID = "host"
+                partnerID = "partner"
+                userID = "user"
+                systemID = "system"
+                signaturePrivateKey = 
SerialBlob("signturePrivateKey".toByteArray())
+                authenticationPrivateKey = 
SerialBlob("authenticationPrivateKey".toByteArray())
+                encryptionPrivateKey = 
SerialBlob("encryptionPrivateKey".toByteArray())
+            }
+            assert(EbicsSubscriberEntity.findById("123asdf") != null)
+        }
+    }
+}
\ No newline at end of file
diff --git a/sandbox/src/test/kotlin/DbTest.kt 
b/sandbox/src/test/kotlin/DbTest.kt
index 6f15ea0..797ab98 100644
--- a/sandbox/src/test/kotlin/DbTest.kt
+++ b/sandbox/src/test/kotlin/DbTest.kt
@@ -33,7 +33,6 @@ class DbTest {
             SchemaUtils.create(BankTransactionsTable)
             SchemaUtils.create(BankCustomersTable)
         }
-
     }
 
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]