GithubHelp home page GithubHelp logo

dimparf / soriento Goto Github PK

View Code? Open in Web Editor NEW
23.0 23.0 9.0 771 KB

Scala OrientDb object mapping library

Home Page: http://dimparf.github.io/Soriento/

License: Apache License 2.0

Scala 97.83% Java 2.17%

soriento's People

Contributors

b0c1 avatar baddlan avatar dimparf avatar gitter-badger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

soriento's Issues

Support for polymorphic types in query result?

I'm trying to model access to a list of items, where the items can be of varying types

class TraceElement(val date: Long)  // or better, trait

case class LoginEventElement( override val date: Long, val userID: Int) extends TraceElement(date)
case class ViewEventElement(  override val date: Long, val userID: Int, val itemID: Int) extends TraceElement(date)

  // Login and view events in a single list
  val result[TraceElement] = db.queryBySql[TraceElement](...)

I think soriento is close to letting this work. However, queryBySql requires a case class as a the parameter (which cannot be subclassed).

In principle I should queryBySql should be able to instantiate the LoginEventElement or ViewEventElement objects by the type information in the ODocument right?

Do you see any issues with this? (if not I'll try implementing it).

Example in Readme

What's going on here?
When you define the class Blog, it contains two attributes and none of them is content.

//...
val blog = Blog("Dim", content = Message("Hi"))
//...

should read

//...
val blog = Blog("Dim", message = Message("Hi"))
//...

Or if you want to leverage some semantics, maybe the case class has to be defined

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

Unexpectedly closed transaction

Hi,

I'm trying to use Soriento for a new project -- it looks exactly like what I need (thanks for releasing it).

However, I'm running into some unexpected behavior.

In the following, the ODatabaseDocumentTx becomes closed and fails at the 3rd save (see **).
Any ideas why?

If I move the db.create() to before the createOClass, the db fails at the first save.

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

  import com.emotioncity.soriento.ODocumentReader._
  import com.emotioncity.soriento.RichODatabaseDocumentImpl._


  test("serializeTest5") {

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

    createOClass[Blog]
    createOClass[Record]

    db.create()


    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()
  }
}

Package scan for classes

If you have very many classes to be marshalled into ODB it would be useful to automatically detect them with a package scanner and to automate calling OCreate and typereaderregistry.

Should mark classes to be imported as @entity, or @table in order to identify which should be imported?

I have a local implementation that uses the Reflection package scanner to find classes: http://reflections.googlecode.com/svn/trunk/reflections/javadoc/apidocs/index.html?org/reflections/Reflections.html

Release a version to maven central or some maven repository.

Hello

Any plan of releasing a version of Soriento in maven central repository or any other maven repo?
We would like to integrate this library in our code using maven (and in general we would like to go to production with released versions of all jar libraries). Right now we are using last version but it feels a bit risky because some pull request could change behavior when people download a new version, therefore our code could not work the same for everyone.

Select simple type value from db

db.asyncQueryBySql[String]("select name from User") is not working.
scala.ScalaReflectionException: constructor String encapsulates multiple overloaded alternatives and cannot be treated as a method. Consider invoking <offending symbol>.asTerm.alternatives and manually picking the required method
at scala.reflect.api.Symbols$SymbolApi$class.asMethod(Symbols.scala:228)
at scala.reflect.internal.Symbols$SymbolContextApiImpl.asMethod(Symbols.scala:84)
at com.emotioncity.soriento.ReflectionUtils$.constructor(ReflectionUtils.scala:28)
at com.emotioncity.soriento.loadbyname.DocumentFromConstructor.(ClassNameReadersRegistry.scala:36)

Recursive LinkSet/LinkList error

If I create OClasses with recursive dependencies I have error:
Example User(@linkset subscriptions: Set[Place]) and Place(@linkset subscribers: Set[User])
java.lang.StackOverflowError
at java.lang.StringCoding$StringDecoder.decode(StringCoding.java:153)
at java.lang.StringCoding.decode(StringCoding.java:193)
at java.lang.String.(String.java:426)
at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.stringFromBytes(ORecordSerializerBinaryV0.java:815)
at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.readString(ORecordSerializerBinaryV0.java:772)
at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.readSingleValue(ORecordSerializerBinaryV0.java:304)
at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.deserializePartial(ORecordSerializerBinaryV0.java:143)
at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinary.fromStream(ORecordSerializerBinary.java:72)
at com.orientechnologies.orient.core.record.impl.ODocument.deserializeFields(ODocument.java:1817)
at com.orientechnologies.orient.core.record.impl.ODocument.checkForFields(ODocument.java:2413)
at com.orientechnologies.orient.core.record.impl.ODocument.rawField(ODocument.java:767)
at com.orientechnologies.orient.core.record.impl.ODocument.field(ODocument.java:792)
at com.emotioncity.soriento.loadbyname.ClassNameReadersRegistry$$anonfun$com$emotioncity$soriento$loadbyname$ClassNameReadersRegistry$$toFieldReader$3.apply(ClassNameReadersRegistry.scala:190)
at com.emotioncity.soriento.loadbyname.ClassNameReadersRegistry$$anonfun$com$emotioncity$soriento$loadbyname$ClassNameReadersRegistry$$toFieldReader$3.apply(ClassNameReadersRegistry.scala:190)
at com.emotioncity.soriento.loadbyname.DocumentFromConstructor$$anonfun$1.apply(ClassNameReadersRegistry.scala:43)
at com.emotioncity.soriento.loadbyname.DocumentFromConstructor$$anonfun$1.apply(ClassNameReadersRegistry.scala:43)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
at scala.collection.mutable.ArrayOps$ofRef.map(ArrayOps.scala:186)
at com.emotioncity.soriento.loadbyname.DocumentFromConstructor.apply(ClassNameReadersRegistry.scala:43)
at com.emotioncity.soriento.loadbyname.DocumentFromConstructor.apply(ClassNameReadersRegistry.scala:33)
at com.emotioncity.soriento.loadbyname.ClassNameReadersRegistry.createClassByDocumentClassName(ClassNameReadersRegistry.scala:141)
at com.emotioncity.soriento.loadbyname.ClassNameReadersRegistry$$anonfun$getValueMapperForRead$4.apply(ClassNameReadersRegistry.scala:264)
at com.emotioncity.soriento.loadbyname.ClassNameReadersRegistry$$anonfun$com$emotioncity$soriento$loadbyname$ClassNameReadersRegistry$$toFieldReader$3.apply(ClassNameReadersRegistry.scala:190)
at com.emotioncity.soriento.loadbyname.ClassNameReadersRegistry$$anonfun$com$emotioncity$soriento$loadbyname$ClassNameReadersRegistry$$toFieldReader$3.apply(ClassNameReadersRegistry.scala:190)
at com.emotioncity.soriento.loadbyname.DocumentFromConstructor$$anonfun$1.apply(ClassNameReadersRegistry.scala:43)
at com.emotioncity.soriento.loadbyname.DocumentFromConstructor$$anonfun$1.apply(ClassNameReadersRegistry.scala:43)

@Embedded<Container> - container needs a type check

In the documentation on the main page:

  case class BlogWithEmbeddedMessages(author: String, @EmbeddedSet messages: List[Message])
  val blogWithEmbeddedMessages = BlogWithEmbeddedMessages("John", List(...)

@EmbeddedSet need to be consistent with the messages type (which is a List).

override modifier in case class parameters causes mayhem

def productToDocument(cc:Product)
    ...
    val values = cc.productIterator
    val fieldList = cc.getClass.getDeclaredFields.toList
    ...
    val purifiedFromId = values.zip(fieldList.iterator).toList.filter { case (v, f) => !isId(f.getName, cc.getClass) }

values and fieldList are not guaranteed to be the same length. Some values may be saved with incorrect field names.

For example:

  class TraceElement3( val date: Int )
  case class LoginEvent3(val userID: Int)
  case class TraceElementLoginEvent3( override val date: Int, val xx:String, val data: LoginEvent3 ) extends TraceElement3(date)

... the overridden value is hidden from the field list (two fields, three values).

Since loading matches fields to the document by case constructor's parameters, one solution to this is to look at the constructor's parameter list fieldList (and their annotations). This would also ensure reading and writing use the same policy to identify fields).

Am working on a fix for this.

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.