jdaugherty opened a new issue, #261:
URL: https://github.com/apache/grails-intellij-plugin/issues/261

   Groovy/Grail Console provided by IntelliJ IDEA cannot execute database 
scripts. Groovy comes with a default console, which can be used for executing 
groovy scripts. IntelliJ also provides a more advanced Console with code 
completion features. Let's say, I have  a Person domain.
   
   **Code**
   ```
   package com.clinton
   
   class Person {
       String name
   }
   ```
   And Here is my test suite:
   
   **Code**
   ```
   import com.clinton.Person
   
   def p = new Person(name: 'Fred').save()
   println(Person.count)
   ```
   1.First output, is from default groovy console. The Default Console can be 
started by typing grails console. Its ouptu after running the command is shown 
in attachment 1. It works according to the Output.
   
   2. Same code is executed for Console provided by IntelliJ IDEA. It can be 
started by Tools>Groovy Console. And it throws an exception. Output of log 
is below:
   
   import com.clinton.Person
   
   def p = new Person(name: 'Fred').save()
   println(Person.count)
   
   Result: java.lang.IllegalStateException: Either class [com.clinton.Person] 
is not a domain class or GORM has not been initialized correctly or has already 
been shutdown. If you are unit testing your entities using the mocking APIs
   
   <details>
   <summary> **at** 
org.grails.datastore.gorm.GormEnhancer.stateException(GormEnhancer.groovy:161)</summary>
   
   ```
    at 
org.grails.datastore.gorm.GormEnhancer.findInstanceApi(GormEnhancer.groovy:167)
    at 
org.grails.datastore.gorm.GormEnhancer.findInstanceApi(GormEnhancer.groovy)
    at 
org.grails.datastore.gorm.GormEntity$Trait$Helper.currentGormInstanceApi(GormEntity.groovy:1322)
    at 
org.grails.datastore.gorm.GormEntity$Trait$Helper.save(GormEntity.groovy:98)
    at org.grails.datastore.gorm.GormEntity$Trait$Helper$save.call(Unknown 
Source)
    at com.clinton.Person.save(Person.groovy)
    at com.clinton.Person.save(Person.groovy)
    at org.grails.datastore.gorm.GormEntity$save.call(Unknown Source)
    at 
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
    at ideaGroovyConsole.run(ideaGroovyConsole.groovy:4)
    at 
groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
    at groovy.lang.GroovyShell.run(GroovyShell.java:518)
    at groovy.lang.GroovyShell.run(GroovyShell.java:497)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at 
org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:169)
    at 
org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71)
    at 
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
    at console.run(console.txt:25)
    at groovy.ui.GroovyMain.processReader(GroovyMain.java:632)
    at groovy.ui.GroovyMain.processFiles(GroovyMain.java:540)
    at groovy.ui.GroovyMain.run(GroovyMain.java:382)
    at groovy.ui.GroovyMain.process(GroovyMain.java:370)
    at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)
    at groovy.ui.GroovyMain.main(GroovyMain.java:109)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at 
org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)
    at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at 
com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:49)
   ```
   
   </details>
   
   3. However, the IntelliJ Console is able to execute scripts which do not 
involve database interactions. Example:
   ```
   > print "hi"
   
   Result: hi
   ```
   I will love to use the IntelliJ Console, because of the advance features it 
offers over the default Console provided by Groovy. Please check and fix this 
problem.
   Thank you.
   
   ---
   
   *Imported from 
[IDEA-158726](https://youtrack.jetbrains.com/issue/IDEA-158726) · Type: Bug · 
Votes: 3*
   *Comments, attachments, dates and reporter are not part of the export — 
follow the link above for the full history.*
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to