Giter Club home page Giter Club logo

Comments (15)

rktoomey avatar rktoomey commented on June 27, 2024

Salat does support polymorphic collections. Please update to the latest snapshot, try again and include the text of your compiler error?

from salat.

rktoomey avatar rktoomey commented on June 27, 2024

Oh right. You want to type ChildCollection to an abstract superclass.

We've gone back and forth on allowing that due to its runtime reflection requirement. I'll change the typing and write some specs this weekend, but you should be aware that it will not be as fast as a DAO typed to a concrete class. Will the speed make a difference to your project? Most likely not, but under very heavy usage everything counts, which was our original design intent in not putting it in...

I'll let you know when an updated snapshot is up for you to try.

(Also, Role should have its own _id field, in addition to the "parent id" field - although MongoDB Java driver will insert an ObjectId for you if no _id field exists, it is best practice to add one yourself, and has the side benefit of making child collection "by id" methods work.)

from salat.

mariussoutier avatar mariussoutier commented on June 27, 2024

Cool thanks, looking forward to it.

So your advice would be not to use SalatDAO for polymorphic collections in performance-critical code?

from salat.

rktoomey avatar rktoomey commented on June 27, 2024

Well, for everyday usage it's probably fine. To give you more
background on why Salat was developed, I work at a financial startup
where we do realtime analytics that can require large datasets. In
this case, the time I spend deserializing my data back into my domain
model before I begin doing the calculations is sheer overhead. So I
wouldn't use ProxyGrater under those circumstances.

But we have been moving more toward providing the polymorphism support
people want, because in many use cases the convenience outweighs the
runtime hit - you can see ProxyGrater to get an idea of the added
cost. Grater just serializes and deserializes: done. But ProxyGrater
needs to look up a concrete instance of Grater based on the type of
the incoming/outgoing object, which adds a small continuous cost. If
you're interested, compare the asObject and asDBObject methods in
ProxyGrater and ConcreteGrater:
https://github.com/novus/salat/blob/master/salat-core/src/main/scala/com/novus/salat/ProxyGrater.scala
https://github.com/novus/salat/blob/master/salat-core/src/main/scala/com/novus/salat/Grater.scala

I suggest trying out the child collection typed to Role, and if the
performance is not good enough, consider making Role a case class and
using a sealed abstract class/trait and case object hierarchy to
distinguish different types of role.

I'll have a new snapshot for you tomorrow.

On 21 January 2012 19:22, Marius Soutier
[email protected]
wrote:

Cool thanks, looking forward to it.

So your advice would be not to use SalatDAO for polymorphic collections in performance-critical code?


Reply to this email directly or view it on GitHub:
https://github.com/novus/salat/issues/27#issuecomment-3600149

from salat.

mariussoutier avatar mariussoutier commented on June 27, 2024

Thanks, I'll definitely check it out. I guess for user management I don't need extra performance. But there's also one area in my app where database-object-mapping-performance will matter, so I'll dive into it.

My other big concern so far is the tight coupling between my model classes and the MongoDB classes. But in the end that's just the same problem with relational modeling.

from salat.

mariussoutier avatar mariussoutier commented on June 27, 2024

Also, Role should have its own _id field, in addition to the "parent id" field - although MongoDB Java driver will insert an ObjectId for you if no _id field exists, it is best practice to add one yourself, and has the side benefit of making child collection "by id" methods work

Somehow, this doesn't work. The resulting child collection doesn't have any id at all.
I get something like this:

{ "_id" : { "$oid" : "4f1c63df0364894c96ac18c2" }, "_typeHint" : "models.User", "username" : "[email protected]", "password" : "sdsdf", "email" : "[email protected]", 
  "roles" : [ { "_typeHint" : "models.AdminRole", "someInfo" : "hi" } ], "gender" : 1 }

I added the id directly to the role:

@Salat sealed abstract class Role(profileid: ObjectId = new ObjectId)
case class AdminRole(someInfo: String) extends Role

from salat.

rktoomey avatar rktoomey commented on June 27, 2024

Hi Marius, your snapshot is now available for testing. After running sbt update and your original code should compile without type errors now. Let me know how that works for you.

See novus@9553d12 for details.

The reason why you are not seeing _id in Role above is that it is not actually added until you insert it into the MongoDB collection - this is not done by Salat, nor Casbah, but rather deep in the guts of mongo-java-driver.

from salat.

mariussoutier avatar mariussoutier commented on June 27, 2024

Unfortunately it's not in the snapshot. The date in http://repo.novus.com/snapshots/ is at 29-Nov-2011.

The reason why you are not seeing _id in Role above is that it is not actually added until you insert it into the MongoDB collection

The BSON from above is from the database. I saved it, but the id from the abstract class is missing.

from salat.

rktoomey avatar rktoomey commented on June 27, 2024

I published 2.8.1 and 2.9.1 - which snapshot are you using?
On Jan 24, 2012 7:19 AM, "Marius Soutier" <
[email protected]>
wrote:

Unfortunately it's not in the snapshot. The date in
http://repo.novus.com/snapshots/ is at 29-Nov-2011.

The reason why you are not seeing _id in Role above is that it is not
actually added until you insert it into the MongoDB collection

The BSON from above is from the database. I saved it, but the id from the
abstract class is missing.


Reply to this email directly or view it on GitHub:
https://github.com/novus/salat/issues/27#issuecomment-3631383

from salat.

rktoomey avatar rktoomey commented on June 27, 2024

http://repo.novus.com/snapshots/com/novus/salat-core_2.9.1/0.0.8-SNAPSHOT/ - this shows a timestamp of 23 January for the 2.9.1 snapshot.

from salat.

rktoomey avatar rktoomey commented on June 27, 2024

Ok, it looks like you are using the 2.9.0-1 snapshot. Please use 2.9.1 instead.

from salat.

mariussoutier avatar mariussoutier commented on June 27, 2024

Ok I used the wrong one (2.9.0_1). Everything works now, thank you.

from salat.

rktoomey avatar rktoomey commented on June 27, 2024

Here's a gist that shows what I mean when I say the mongo-java-driver will add an _id field if you don't do it yourself:

https://gist.github.com/1670017

from salat.

rktoomey avatar rktoomey commented on June 27, 2024

Glad to hear everything is working!

from salat.

mariussoutier avatar mariussoutier commented on June 27, 2024

Thanks for the gist. My problem was that Mongo didn't generate any _id for an embedded document (I originally tried to embed the role, because without the user it doesn't make much sense). With the separate collection, the id is generated, and I also added it -as you advised- to the abstract class (had to be a val to be recognized).

Thanks for your quick support, much appreciated!

from salat.

Related Issues (20)

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.