How to customize own ConnectionProvider in PlayFramework 2.0

61 views
Skip to first unread message

Haffner Wong

unread,
Sep 14, 2012, 6:32:09 AM9/14/12
to circumfl...@googlegroups.com
Hi, I'm doing a demo project for my team , using circumflex-orm in playframework, the others goes really fine, 
 but when i try to customize my own ConnectionProvider I get a instance exception.

play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[Instan
tiationException: models.CrawlerConnectionProvider]]
        at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [
play_2.9.1.jar:2.0.2]
        at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [
play_2.9.1.jar:2.0.2]
        at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
        at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.
2]
        at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.
2]
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.j
ar:2.0.2]
Caused by: java.lang.InstantiationException: models.CrawlerConnectionProvider
        at java.lang.Class.newInstance0(Unknown Source) ~[na:1.6.0_32]
        at java.lang.Class.newInstance(Unknown Source) ~[na:1.6.0_32]
        at ru.circumflex.core.UntypedContainer$class.instantiateObject(circumfle
x.scala:119) ~[circumflex-core-2.1.jar:na]
        at ru.circumflex.core.Circumflex$.instantiateObject(circumflex.scala:29)
 ~[circumflex-core-2.1.jar:na]
        at ru.circumflex.core.UntypedContainer$class.instantiate(circumflex.scal
a:108) ~[circumflex-core-2.1.jar:na]
        at ru.circumflex.core.Circumflex$.instantiate(circumflex.scala:29) ~[cir
cumflex-core-2.1.jar:na]

my cx.properties 

orm.connectionProvider=models.CrawlerConnectionProvider

CrawlerConnectionProvider  is under the path 
${project}/app/models/

Sorry for this , maybe it looks like easy for you guys , but this is the first time i use scala and playframework and circumflex.

Thanks in advance!

Boris Okunskiy

unread,
Sep 14, 2012, 7:05:34 AM9/14/12
to circumfl...@googlegroups.com
Warm greetings Haffner,

Can you please post the cause of InstantiationException (e.g. invoke `e.getCause` with debugger)?

Also, if it is your first time of making Circumflex ORM work in conjunction with Play Framework, you should find a way to demarcate your transactions properly. Please refer to https://groups.google.com/forum/?fromgroups=#!topic/circumflex-scala/GcT65gin0G4 and https://groups.google.com/forum/#!topic/circumflex-scala/ma2uCVgPx1Q.

Best regards,
Boris Okunskiy
Chief Software Architect
EduArea LLC / SAVANT.PRO

王刚

unread,
Sep 14, 2012, 7:47:45 AM9/14/12
to circumfl...@googlegroups.com
Thanks for your fast reply.

I paste all the informations i saw in the console. Now i'm off work. I will try to debug it and post the detail on next Monday .

Thanks again! 

Boris Okunskiy

unread,
Sep 14, 2012, 10:06:43 AM9/14/12
to circumfl...@googlegroups.com
Of course. I'm looking forward to help resolving your issues.

Best regards,
Boris Okunskiy
Chief Software Architect
EduArea LLC / SAVANT.PRO

Haffner Wong

unread,
Sep 16, 2012, 10:36:31 PM9/16/12
to circumfl...@googlegroups.com
Hi, 

  Morning. I tried your said just now  , wrap the code with Context.executeInNew. But the getCause returns null ,  and the debug logs are useless , cause i found there is no diff to the stackTrace i wrote in the #1. Anyway , i gonna paste it below.

[info] play - Application started (Dev)
cause==>null
java.lang.InstantiationException: models.CrawlerConnectionProvider
        at java.lang.Class.newInstance0(Unknown Source)
        at java.lang.Class.newInstance(Unknown Source)
        at ru.circumflex.core.UntypedContainer$class.instantiateObject(circumfle
x.scala:119)
        at ru.circumflex.core.Circumflex$.instantiateObject(circumflex.scala:29)

        at ru.circumflex.core.UntypedContainer$class.instantiate(circumflex.scal
a:108)
        at ru.circumflex.core.Circumflex$.instantiate(circumflex.scala:29)
        at ru.circumflex.orm.ORMConfiguration$class.connectionProvider(config.sc
ala:88)
        at ru.circumflex.orm.SimpleORMConfiguration.connectionProvider(config.sc
ala:92)
        at ru.circumflex.orm.Transaction.getConnection(config.scala:247)
        at ru.circumflex.orm.Transaction.execute(config.scala:264)
        at ru.circumflex.orm.Transaction.execute(config.scala:275)
        at ru.circumflex.orm.SQLQuery$$anonfun$2.apply(query.scala:98)
        at ru.circumflex.core.package$.time(package.scala:28)
        at ru.circumflex.orm.SQLQuery.resultSet(query.scala:97)
        at ru.circumflex.orm.Criteria.unique(criteria.scala:217)
        at ru.circumflex.orm.Relation$$anonfun$get$1$$anonfun$apply$1.apply(rela
tion.scala:100)
        at ru.circumflex.orm.Relation$$anonfun$get$1$$anonfun$apply$1.apply(rela
tion.scala:100)
        at ru.circumflex.orm.RelationNode.map(node.scala:33)
        at ru.circumflex.orm.Relation$$anonfun$get$1.apply(relation.scala:100)
        at ru.circumflex.orm.Relation$$anonfun$get$1.apply(relation.scala:100)
        at ru.circumflex.orm.DefaultCacheService$$anonfun$cacheRecord$2.apply(ca
che.scala:120)
        at ru.circumflex.orm.DefaultCacheService$$anonfun$cacheRecord$2.apply(ca
che.scala:118)
        at scala.Option.orElse(Option.scala:218)
        at ru.circumflex.orm.DefaultCacheService.cacheRecord(cache.scala:118)
        at ru.circumflex.orm.Relation$class.get(relation.scala:99)
        at models.Role$.get(Role.scala:20)
        at controllers.Application$$anonfun$index$1$$anonfun$apply$1.apply(Appli
cation.scala:18)
        at controllers.Application$$anonfun$index$1$$anonfun$apply$1.apply(Appli
cation.scala:16)
        at ru.circumflex.core.Context$.executeInNew(context.scala:90)
        at controllers.Application$$anonfun$index$1.apply(Application.scala:16)
        at controllers.Application$$anonfun$index$1.apply(Application.scala:12)
        at play.api.mvc.Action$$anonfun$apply$4.apply(Action.scala:204)
        at play.api.mvc.Action$$anonfun$apply$4.apply(Action.scala:204)
        at play.api.mvc.Action$$anon$1.apply(Action.scala:170)
        at play.core.ActionInvoker$$anonfun$receive$1$$anonfun$6.apply(Invoker.s
cala:126)
        at play.core.ActionInvoker$$anonfun$receive$1$$anonfun$6.apply(Invoker.s
cala:126)
        at play.utils.Threads$.withContextClassLoader(Threads.scala:17)
        at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:125)
        at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115)
        at akka.actor.Actor$class.apply(Actor.scala:318)
        at play.core.ActionInvoker.apply(Invoker.scala:113)
        at akka.actor.ActorCell.invoke(ActorCell.scala:626)
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197)
        at akka.dispatch.Mailbox.run(Mailbox.scala:179)
        at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(
AbstractDispatcher.scala:516)
        at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259)
        at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975)
        at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479)
        at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)

Boris Okunskiy

unread,
Sep 17, 2012, 2:26:39 AM9/17/12
to circumfl...@googlegroups.com
Hi,

Can you then please paste the code which produces the following exception along with the CrawlerConnectionProvider?

Best regards,
Boris Okunskiy
Chief Software Architect
EduArea LLC / SAVANT.PRO

Haffner Wong

unread,
Sep 17, 2012, 2:43:39 AM9/17/12
to circumfl...@googlegroups.com
Of course, it's pretty simple.  

  def index = Action {
    try {
      Context.executeInNew {
        ctx =>
          Role.get(1)
      }
    } catch {
      case ex => println("cause==>" + ex.getCause)
      ex.printStackTrace()
    }
    Ok(views.html.index("Your new application is ready."))
  }

 In this case , i just wanna prove this framework  can support customize connection provider.
So ,My models.CrawlerConnectionProvider is copy your SimpleConnectionProvider.


And config in cx.properties

orm.connection.driver=com.mysql.jdbc.Driver
orm.connection.url=jdbc:mysql://Haffner-PC/play_db
orm.connection.username=root
orm.connection.password=123
orm.connectionProvider=models.CrawlerConnectionProvider
orm.ehcache.config=ormCache

Boris Okunskiy

unread,
Sep 17, 2012, 2:55:25 AM9/17/12
to circumfl...@googlegroups.com
Well, nothing seems obviously wrong with your snippet.

According to JavaDocs of InstantiationException (http://docs.oracle.com/javase/6/docs/api/java/lang/InstantiationException.html) the instantiation can fail due to the problems with the class modifiers (abstract, trait, etc.) or due to absence of proper constructor.

Does it work when you switch off the CrawlerConnectionProvider (just comment out the orm.connectionProvider line in cx.properties)?

Best regards,
Boris Okunskiy
Chief Software Architect
EduArea LLC / SAVANT.PRO

Haffner Wong

unread,
Sep 17, 2012, 3:15:24 AM9/17/12
to circumfl...@googlegroups.com
It runs fine if i comment the line  
#orm.connectionProvider=models.CrawlerConnectionProvider

That's really weird and frustrating, i never meet this kind of problem before.(I have 4+ yrs exp in java, 5 yrs in C) 


Do you have any project or demo using customize connection provider and can run without problem?


Boris Okunskiy

unread,
Sep 17, 2012, 7:04:48 AM9/17/12
to circumfl...@googlegroups.com
Nope, we don't have one. What exactly are you trying to achieve with custom connection provider? Maybe it would make more sense implementing the `ConnectionProvider` trait then?

Best regards,
Boris Okunskiy
Chief Software Architect
EduArea LLC / SAVANT.PRO

王刚

unread,
Sep 18, 2012, 3:59:52 AM9/18/12
to circumfl...@googlegroups.com
My problem resolved this morning, i really really wanna kill myself ,
for such a stupid mistake .

In my code ,CrawlerConnectionProvider have some constructor parameters
, but i never mentioned it before , because in your source code the
SimpleConnectionProvider still have some constructor parameters.

This morning , i decompile your jar (circumflex-core-2.1jar sorry for
that -_-!) , found that your code need a default constructor for
instance object . So, i rewrite my constructor without parameters.


You are a great man Boris , pleasure to have help from you.

Boris Okunskiy

unread,
Sep 18, 2012, 3:38:03 PM9/18/12
to circumfl...@googlegroups.com
Aw, it's great to hear the good news!

And the pleasure is all mine. Best wishes for you and your projects :)
If there's anything else we can do, please feel free to contact us.

Best regards,
Boris Okunskiy
Chief Software Architect
EduArea LLC / SAVANT.PRO

“Soit le meilleur dans ce que tu feras.”
Reply all
Reply to author
Forward
0 new messages