Comments (4)
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.
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.
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.
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)
- Example in Readme HOT 1
- Create or nothing on createOClass[T]
- Support for polymorphic types in query result? HOT 6
- Possible to release this with an open license? HOT 1
- @Embedded<Container> - container needs a type check
- override modifier in case class parameters causes mayhem HOT 2
- Package scan for classes HOT 3
- Release a version to maven central or some maven repository. HOT 3
- Create schema for case classes with @EmbeddedList/@EmbeddedSet fields
- Recursive LinkSet/LinkList error HOT 3
- Fetch plan support for queries HOT 1
- Async command request HOT 1
- Select simple type value from db HOT 2
- Support asynchronous queries
- Create macros for generate ODocumentReader[T]'s HOT 4
- Create schema with Option[T] link annotated fields HOT 1
- Recursive drop OClass tree
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from soriento.