GithubHelp home page GithubHelp logo

Comments (4)

dimparf avatar dimparf commented on August 16, 2024

Hi,
Current database instance is not active on current thread.
In your case, you use two instances of the database in one thread, one implitsit and one explicit.
Implicit database instance use in createOClass method (db instance defined in test package object soriento).

from soriento.

stuz5000 avatar stuz5000 commented on August 16, 2024

But won't db will used used as the implicit parameter to createOClass?

Its the 3rd save that finds the closed db -- the first two succeed, which make me think that problem is not with the createOClass call.

In fact, if I explicitly pass the same db to the createOClass, the behavior is the same (closed at the 3rd save).

    val db: ODatabaseDocumentTx = new ODatabaseDocumentTx("memory:jsondb")
    db.create()
    createOClass(classTag[Blog], db)
    createOClass(classTag[Record], db)

To be certain I'm not referencing the test DB, I moved everything into a new package separate from the test package, and I gets the same result (see below).

package net.stu

import com.emotioncity.soriento.annotations.Embedded
import com.emotioncity.soriento.{Dsl, ODb}
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx
import org.scalatest.{BeforeAndAfter, FunSuite, Matchers}
import com.emotioncity.soriento.ODocumentReader._
import com.emotioncity.soriento.RichODatabaseDocumentImpl._
import scala.reflect.classTag

case class Record(content: String)
case class Blog(author: String, @Embedded message: Record)

class MyTest extends FunSuite with Matchers with BeforeAndAfter with ODb with Dsl {

  test("serializeTest5") {

    val db: ODatabaseDocumentTx = new ODatabaseDocumentTx("memory:jsondb")

    db.create()

    createOClass(classTag[Blog], db)
    createOClass(classTag[Record], db)

    val blog = Blog(author = "Arnold", message = Record("Agrh!"))
    db.save(blog)
    db.save(blog)

    val blogs: List[Blog] = db.queryBySql[Blog]("select from blog")
    println(blogs)
    println(blogs.size)

    val blog2 = Blog(author = "Arnold2", message = Record("Agrh2!"))
    db.save(blog2) // DB is closed here

    val blogs2: List[Blog] = db.queryBySql[Blog]("select from blog")
    println(blogs2)

    db.drop()
  }
}

from soriento.

stuz5000 avatar stuz5000 commented on August 16, 2024

Tracing the execution I found queryBySql calls ODatabaseDocumentTx].copy()

I think this is where the new instance is coming from (in RichODatabaseDocumentImpl).

    protected def blockingCall[T](payload: ODatabaseDocumentTx => T): T = {
      /*println("Blocking call")
      println(if (isPooled) "Database is pooled" else "Database is unpooled")*/
      val instance = ODatabaseRecordThreadLocal.INSTANCE.get
      //println("ThreadLocal is: " + instance.getClass.getName)
      val internalDb = if (isPooled) instance.asInstanceOf[ODatabaseDocumentTx] else instance.asInstanceOf[ODatabaseDocumentTx].copy()
      payload(internalDb)
    }

Shouldn't this be:

val internalDb = if (! isPooled) ...

from soriento.

stuz5000 avatar stuz5000 commented on August 16, 2024

This change has been merged into the dev branch. I think this fixed this (at least, it fixed my problem and broke no tests.

protected def blockingCall[T](payload: ODatabaseDocumentTx => T)
   val internalDb = if (! isPooled) ...

from soriento.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.