payintech / play-ebean

Play Ebean module
31 stars 3 forks source link

Any chance of integrating QueryBeans support? #2

Open corrspt opened 7 years ago

corrspt commented 7 years ago

This was never integrated in play-ebean as such I don't think there's currently a way to use QueryBeans in a Play Framework project? Would be really nice to be able to use them.

Thanks for the project in any case, really helpful to keep with the latest Ebean versions (started using this week)

thibaultmeyer commented 7 years ago

Hi,

QueryBeans is a really nice evolution but to be honest we have try (many times) to test QueryBeans in a simple Maven project... we only get NullPointerException :-(

Since, @rbygrave have done a lot of modifications like merging Ebean Agent and Ebean QueryBeans Agent into a single agent, maybe, in a near futur, he will achieve modifications to get QueryBeans as simple as "standard" query system.

Of course, you are welcome to propose a pull request if you succeed to implement QueryBeans.

Sincerely.

corrspt commented 7 years ago

I would absolutely propose a PR if I had been able to do it, but I haven't been able as well. 👎 Thanks for the reply, should I close the issue?

rbygrave commented 7 years ago

> test QueryBeans in a simple Maven project... we only get NullPointerException :-(

Are you are unable to git pull and run the example application? ... https://github.com/ebean-orm-examples/example-java8

On 5 April 2017 at 21:52, Pedro Rio notifications@github.com wrote:

I would absolutely propose a PR if I had been able to do it, but I haven't been able as well. 👎 Thanks for the reply, should I close the issue?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/payintech/play-ebean/issues/2#issuecomment-291812209, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMwTTaLzFoJ98fOh2XYVTJuf_GPq-Neks5rs2R2gaJpZM4MzJXg .

thibaultmeyer commented 7 years ago

Hi @rbygrave,

the Java 8 example run very well (mvn test). But I dont find the ebean-agent ? All the "magic" seems done by a Maven plugin.

Currently, this project (play-ebean) is using ebean 10.2.1 and ebean-agent 10.1.7. The enhancement is performed with the class "OfflineFileTransform" provided by Ebean. Here the Scala code:

// Ebean enhancement
def enhanceEbeanClasses(classpath: Classpath, analysis: Analysis, classDirectory: File, pkg: String): Analysis = {
  // Ebean (really hacky sorry)
  val cp = classpath.map(_.data.toURI.toURL).toArray :+ classDirectory.toURI.toURL
  val cl = new java.net.URLClassLoader(cp)
  val t = cl.loadClass("io.ebean.enhance.Transformer").getConstructor(classOf[ClassLoader], classOf[String]).newInstance(cl, "debug=0").asInstanceOf[AnyRef]
  val ft = cl.loadClass("io.ebean.enhance.ant.OfflineFileTransform").getConstructor(
    t.getClass, classOf[ClassLoader], classOf[String]
  ).newInstance(t, ClassLoader.getSystemClassLoader, classDirectory.getAbsolutePath).asInstanceOf[AnyRef]
  ft.getClass.getDeclaredMethod("process", classOf[String]).invoke(ft, pkg)
  analysis
}

Do you have any advice how to enhance this project to get working with QueryBeans ?

I suspect it only missing the Qxxxxxx (eg: QAccount) class generation...

Sincerely.

corrspt commented 7 years ago

Sorry for pinging you @rbygrave , you probably haven't responded because you're busy, but if by chance you missed @0xbaadf00d reply, it's just to bring it to your attention again as It would make us Play Framework users very happy to have query beans working.

Thanks for the support and great work on Ebean.

rbygrave commented 7 years ago

No problem. Yes I did see it, yes I'm really busy at the moment.

There are 2 query bean generators

On 18 April 2017 at 22:34, Pedro Rio notifications@github.com wrote:

Sorry for pinging you @rbygrave https://github.com/rbygrave , you probably haven't responded because you're busy, but if by chance you missed @0xbaadf00d https://github.com/0xbaadf00d reply, it's just to bring it to your attention again as It would make us Play Framework users very happy to have query beans working.

Thanks for the support and great work on Ebean.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/payintech/play-ebean/issues/2#issuecomment-294772919, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMwTfND--1ngM2yiuONmXsQgDiu3aITks5rxJHAgaJpZM4MzJXg .

thibaultmeyer commented 7 years ago

Hi Rob,

Thank for your time. I will take a look at these two generators.

thibaultmeyer commented 7 years ago

@rbygrave , it seems that import Generator and GeneratorConfig are no longer provided by querybean-generator ("io.ebean" % "querybean-generator" % "10.1.3")

image

image

corrspt commented 6 years ago

Pinging @rbygrave in hopes you by any chance have the free time to contribute again :)

coreycaplan3 commented 6 years ago

What is the state of this PR as of now? I've been running a "modified approach" of using the static alias instance of the Query-Bean class and calling toString on the properties to still get some type safety. I would love to migrate this: Ebean.createQuery(InvitedUser.class).where().eq(QInvitedUser.alias().email.toString(), email).findOne()

To some real type safety goodness, and still be able to use Play!

The only reason why this works, is because enhancement initializes the fields in the alias static instance but not any of the other (non-private) constructors. Interesting dilemma. I would like to fix it myself if time permitted.

Note: without this workaround, I get NullPointerExceptions, like everyone else. This also does not support nesting unfortunately, since I can't call "toString" to get the name of the property in the owning model.