Skip to content

Commit e9d4df2

Browse files
authored
Merge pull request #120 from JetBrains/adopt-orientdb-with-new-init
Adopt orientdb with new init
2 parents cf4f9c6 + cf6f384 commit e9d4df2

File tree

5 files changed

+29
-83
lines changed

5 files changed

+29
-83
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
buildscript {
22
ext.kotlin_version = '1.8.10'
3-
ext.exodus_version = '9.9.127'
3+
ext.exodus_version = '9.9.129'
44
ext.dokka_version = '1.7.20'
55
ext.log4j_version = '2.17.1'
66
ext.google_truth_version = '1.4.2'

dnq/src/main/kotlin/kotlinx/dnq/store/container/StaticStoreContainer.kt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@
1616
package kotlinx.dnq.store.container
1717

1818
import com.jetbrains.teamsys.dnq.database.TransientEntityStoreImpl
19-
import com.orientechnologies.orient.core.config.OGlobalConfiguration
2019
import com.orientechnologies.orient.core.db.ODatabaseType
2120
import com.orientechnologies.orient.core.db.OrientDB
22-
import com.orientechnologies.orient.core.db.OrientDBConfig
21+
import com.orientechnologies.orient.core.db.OrientDBConfigBuilder
2322
import jetbrains.exodus.database.TransientEntityStore
23+
import jetbrains.exodus.entitystore.orientdb.ODatabaseConfig
2424
import jetbrains.exodus.entitystore.orientdb.ODatabaseProvider
2525
import jetbrains.exodus.entitystore.orientdb.ODatabaseProviderImpl
26-
import jetbrains.exodus.env.EnvironmentConfig
26+
import jetbrains.exodus.entitystore.orientdb.initOrientDbServer
2727
import java.io.File
2828

2929
object StaticStoreContainer : StoreContainer {
3030
private var _store: TransientEntityStore? = null
31+
var dbProvider: ODatabaseProvider? = null
32+
var db: OrientDB? = null
33+
3134

3235
override var store: TransientEntityStore
3336
get() {
@@ -37,25 +40,22 @@ object StaticStoreContainer : StoreContainer {
3740
this._store = value
3841
}
3942

40-
fun init(dbFolder: File, entityStoreName: String, primary: Boolean = true, configure: EnvironmentConfig.() -> Unit = {}): TransientEntityStoreImpl {
43+
fun init(dbFolder: File, entityStoreName: String, configure: OrientDBConfigBuilder.() -> Unit = {}): TransientEntityStoreImpl {
44+
val config = ODatabaseConfig.builder()
45+
.withUserName("admin")
46+
.withPassword("admin")
47+
.withDatabaseType(ODatabaseType.MEMORY)
48+
.withDatabaseName("memory")
49+
.withDatabaseRoot(dbFolder.absolutePath)
50+
.tweakConfig(configure)
51+
.build()
4152
//TODO use dbFolder
42-
val builder = OrientDBConfig.builder()
43-
builder.addConfig(OGlobalConfiguration.NON_TX_READS_WARNING_MODE, "SILENT")
53+
db = initOrientDbServer(config)
4454

45-
val db = OrientDB("memory", builder.build())
46-
val databaseType = ODatabaseType.MEMORY
47-
db.createIfNotExists(entityStoreName, databaseType,"admin", "password", "admin")
48-
dbProvider = ODatabaseProviderImpl(
49-
db,
50-
entityStoreName,
51-
"admin",
52-
"password",
53-
databaseType,
54-
)
55+
dbProvider = ODatabaseProviderImpl(config, db!!)
5556
val store = createTransientEntityStore(dbProvider!!, entityStoreName)
5657
this.store = store
5758
return store
5859
}
5960

60-
var dbProvider: ODatabaseProvider? = null
6161
}

dnq/src/test/kotlin/kotlinx/dnq/DBTest.kt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import jetbrains.exodus.entitystore.TransientChangesMultiplexer
2828
import jetbrains.exodus.entitystore.Where
2929
import jetbrains.exodus.entitystore.Where.SYNC_AFTER_FLUSH
3030
import jetbrains.exodus.entitystore.Where.SYNC_BEFORE_FLUSH_BEFORE_CONSTRAINTS
31-
import jetbrains.exodus.entitystore.orientdb.OPersistentEntityStore
3231
import jetbrains.exodus.util.IOUtil
3332
import kotlinx.dnq.link.OnDeletePolicy.CLEAR
3433
import kotlinx.dnq.listener.XdEntityListener
@@ -41,6 +40,7 @@ import kotlinx.dnq.simple.email
4140
import kotlinx.dnq.simple.min
4241
import kotlinx.dnq.store.container.StaticStoreContainer
4342
import kotlinx.dnq.util.initMetaData
43+
import mu.KLogging
4444
import org.junit.After
4545
import org.junit.Before
4646
import java.io.File
@@ -49,8 +49,9 @@ import java.nio.file.*
4949
import java.nio.file.attribute.BasicFileAttributes
5050

5151
abstract class DBTest {
52-
lateinit var store: TransientEntityStoreImpl
52+
companion object : KLogging()
5353
lateinit var databaseHome: File
54+
lateinit var store: TransientEntityStoreImpl
5455
val typeListeners = mutableListOf<Pair<XdEntityType<*>, XdEntityListener<*>>>()
5556
val instanceListeners = mutableListOf<Pair<XdEntity, XdEntityListener<*>>>()
5657

@@ -148,8 +149,11 @@ abstract class DBTest {
148149
} catch (e: IOException) {
149150
throw RuntimeException(e)
150151
}
151-
152-
openStore()
152+
try {
153+
openStore()
154+
} catch (e: Throwable){
155+
logger.error("Failed to open the store", e)
156+
}
153157
}
154158

155159
open fun registerEntityTypes() {
@@ -163,15 +167,8 @@ abstract class DBTest {
163167
}
164168

165169
fun openStore() {
166-
store = StaticStoreContainer.init(databaseHome, "testDB") {
167-
envCloseForcedly = true
168-
}
169-
170-
171-
170+
store = StaticStoreContainer.init(databaseHome, "testDB")
172171
initMetaData(XdModel.hierarchy, store)
173-
174-
175172
val changesMultiplexer = TransientChangesMultiplexer()
176173
store.changesMultiplexer = changesMultiplexer
177174
}
@@ -186,8 +183,9 @@ abstract class DBTest {
186183
eventsMultiplexer.removeListener(it.first.entity, it.second.asEntityListener())
187184
}
188185
}
189-
StaticStoreContainer.dbProvider?.close()
190186
store.close()
187+
StaticStoreContainer.db?.drop("OSystem")
188+
StaticStoreContainer.dbProvider?.close()
191189
}
192190

193191
protected fun createAsyncProcessor(): JobProcessor {

dnq/src/test/kotlin/kotlinx/dnq/NamedOrientDBStoreCreator.kt

Lines changed: 0 additions & 50 deletions
This file was deleted.

dnq/src/test/kotlin/kotlinx/dnq/blob/BlobTest.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class BlobTest : DBTest() {
7575

7676
@Test
7777
fun textReplay() {
78-
store.persistentStore.config.maxInPlaceBlobSize = 0
7978

8079
val user = transactional {
8180
transactional(isNew = true) { User.new() }
@@ -101,7 +100,6 @@ class BlobTest : DBTest() {
101100

102101
@Test
103102
fun blobReplay() {
104-
store.persistentStore.config.maxInPlaceBlobSize = 0
105103

106104
val user = transactional {
107105
transactional(isNew = true) { User.new() }

0 commit comments

Comments
 (0)