Skip to content

Commit

Permalink
Fix dependencies and ERS bindings (#268)
Browse files Browse the repository at this point in the history
[jacodb-core] Add DoubleBinging

DoubleBinging is another BuiltInBinding allowing to set Entities'
properties & blobs of type Double.

[jacodb-core] Make foreign dependencies for implementations of PluggableKeyValueStorage optional

Set Libs.xodusEnvironment, Libs.lmdb_java & Libs.rocks_db dependencies as compileOnly.
  • Loading branch information
Saloed authored Sep 18, 2024
1 parent c37de8f commit 94784e0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
11 changes: 7 additions & 4 deletions jacodb-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,20 @@ dependencies {
implementation(Libs.jdot)
implementation(Libs.guava)
implementation(Libs.sqlite)
implementation(Libs.xodusUtils)
implementation(Libs.xodusEnvironment)
implementation(Libs.hikaricp)
implementation(Libs.lmdb_java)
implementation(Libs.rocks_db)
implementation(Libs.xodusUtils)
compileOnly(Libs.xodusEnvironment)
compileOnly(Libs.lmdb_java)
compileOnly(Libs.rocks_db)

testImplementation(Libs.javax_activation)
testImplementation(Libs.javax_mail)
testImplementation(Libs.joda_time)
testImplementation(Libs.slf4j_simple)
testImplementation(Libs.hikaricp)
testImplementation(Libs.xodusEnvironment)
testImplementation(Libs.lmdb_java)
testImplementation(Libs.rocks_db)

testFixturesImplementation(project(":jacodb-api-jvm"))
testFixturesImplementation(kotlin("reflect"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ private val builtInBindings: Array<BuiltInBinding<*>> = arrayOf(
StringBinding, // UTF-8 strings
IntegerBinding, // 4-byte signed integers
LongBinding, // 8-byte signed integers (longs)
DoubleBinging, // 8-byte floating point numbers (doubles)
BooleanBinding // boolean values
)

Expand Down Expand Up @@ -240,6 +241,17 @@ private object LongBinding : BuiltInBinding<Long>() {
}
}

private object DoubleBinging : BuiltInBinding<Double>() {

override val classes: Set<Class<*>> get() = setOf(Double::class.java, java.lang.Double::class.java)

override fun getBytes(obj: Double): ByteArray = LongBinding.getBytes(java.lang.Double.doubleToLongBits(obj))

override fun getObject(bytes: ByteArray, offset: Int): Double =
java.lang.Double.longBitsToDouble(LongBinding.getObject(bytes, offset))

}

private object BooleanBinding : BuiltInBinding<Boolean>() {

override val classes = setOf(Boolean::class.java, java.lang.Boolean::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ class BindingsTest {
assertEquals(Long.MAX_VALUE shr 17, serializeDeserializeCompressed(Long.MAX_VALUE shr 17))
}

@Test
fun booleanBinding() {
assertEquals(false, serializeDeserialize(false))
assertEquals(true, serializeDeserialize(true))
}

@Test
fun doubleBinding() {
assertEquals(.0, serializeDeserialize(.0))
assertEquals(1.0, serializeDeserialize(1.0))
assertEquals(2.71281828, serializeDeserialize(2.71281828))
assertEquals(3.14159265259, serializeDeserialize(3.14159265259))
assertEquals(Double.NEGATIVE_INFINITY, serializeDeserialize(Double.NEGATIVE_INFINITY))
assertEquals(Double.POSITIVE_INFINITY, serializeDeserialize(Double.POSITIVE_INFINITY))
assertEquals(Double.MIN_VALUE, serializeDeserialize(Double.MIN_VALUE))
assertEquals(Double.MAX_VALUE, serializeDeserialize(Double.MAX_VALUE))
assertEquals(java.lang.Double.MIN_NORMAL, serializeDeserialize(java.lang.Double.MIN_NORMAL))
assertEquals(Double.NaN, serializeDeserialize(Double.NaN))
}

private companion object {
val hash = byteArrayOf(
-17, -65, -67, 68, 85, 96, -17, -65, -67, 28, 4, 76, 28,
Expand Down

0 comments on commit 94784e0

Please sign in to comment.