Skip to content

Commit

Permalink
Merge pull request #98 from JetBrains/adopt-orientdb-drop-boolean-opt…
Browse files Browse the repository at this point in the history
…imization

Adopt orientdb drop boolean optimization
  • Loading branch information
leostryuk authored Sep 4, 2024
2 parents 2ef3811 + c7c01a3 commit 89454d0
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext.kotlin_version = '1.8.10'
ext.exodus_version = '9.9.89'
ext.exodus_version = '9.9.91'
ext.dokka_version = '1.7.20'
ext.log4j_version = '2.17.1'
ext.google_truth_version = '1.4.2'
Expand Down
9 changes: 3 additions & 6 deletions dnq/src/main/kotlin/kotlinx/dnq/simple/XdProperty.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,14 @@ class XdProperty<in R : XdEntity, T : Comparable<T>>(
override fun getValue(thisRef: R, property: KProperty<*>): T {
val result: T? = thisRef.reattachAndGetPrimitiveValue(property.dbName)
if (isBoolean) {
return (result != null) as T
@Suppress("UNCHECKED_CAST", "KotlinConstantConditions")
return (result == true) as T
}
return result ?: default(thisRef, property)
}

override fun setValue(thisRef: R, property: KProperty<*>, value: T) {
if (isBoolean && value == false) {
thisRef.reattachAndSetPrimitiveValue(property.dbName, null, clazz)
} else {
thisRef.reattachAndSetPrimitiveValue(property.dbName, value, clazz)
}
thisRef.reattachAndSetPrimitiveValue(property.dbName, value, clazz)
}

override fun isDefined(thisRef: R, property: KProperty<*>): Boolean {
Expand Down
3 changes: 1 addition & 2 deletions dnq/src/test/kotlin/kotlinx/dnq/HasChangesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package kotlinx.dnq
import com.google.common.truth.Truth.assertThat
import jetbrains.exodus.entitystore.Entity
import kotlinx.dnq.util.hasChanges
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
Expand Down Expand Up @@ -72,7 +71,7 @@ class HasChangesTest(
thread {
store.transactional {
// set flag to false and save to database
assertThat(e.flagOfSchepotiev).isNull()
assertThat(e.flagOfSchepotiev).isFalse()
e.flagOfSchepotiev = true
}
}.join()
Expand Down
108 changes: 108 additions & 0 deletions dnq/src/test/kotlin/kotlinx/dnq/query/EnumTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* Copyright 2006 - 2024 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package kotlinx.dnq.query

import jetbrains.exodus.entitystore.Entity
import kotlinx.dnq.*
import org.junit.Assert
import org.junit.Before
import org.junit.Test

class EnumTest : DBTest() {


abstract class Vehicle(entity: Entity) : XdEntity(entity) {
companion object : XdNaturalEntityType<Vehicle>()
var engine by xdLink0_1(Engine)
var body by xdLink0_1(Body)
}

class Car(entity: Entity) : Vehicle(entity) {
companion object : XdNaturalEntityType<Car>()

var name by xdRequiredStringProp()

}

class Engine(entity: Entity) : XdEnumEntity(entity) {

companion object : XdEnumEntityType<Engine>() {
val DIESEL by Engine.enumField {}
val GASOLINE by Engine.enumField {}
val MICROWAVE by Engine.enumField {}
}
}

class Body(entity: Entity) : XdEnumEntity(entity) {
companion object : XdEnumEntityType<Body>() {
val COUPE by Body.enumField {}
val SALOON by Body.enumField {}
val PICKUP by Body.enumField {}
}
}

override fun registerEntityTypes() {
XdModel.registerNodes(Car, Engine, Body, Vehicle)
}


@Before
fun init() {
transactional {
Car.new {
name = "pick1"
engine = Engine.DIESEL
body = Body.PICKUP
}
Car.new {
name = "pick2"
engine = Engine.GASOLINE
body = Body.PICKUP
}
Car.new {
name = "coupe1"
engine = Engine.DIESEL
body = Body.COUPE
}
Car.new {
name = "coupe2"
engine = Engine.GASOLINE
body = Body.COUPE
}
Car.new {
name = "grill"
engine = Engine.MICROWAVE
body = Body.SALOON
}
}
}


@Test
fun andQueryWith2Enums() {
val diesel = transactional {
Car.filter {
((it.body eq Body.COUPE) and (it.engine eq Engine.DIESEL))
}.toList().firstOrNull()
}
transactional {
Assert.assertNotNull(diesel)
Assert.assertEquals("coupe1", diesel?.name)
}
}


}

0 comments on commit 89454d0

Please sign in to comment.