A problem when trying to get DataSourcesConfig of grails datasources plugin.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

A problem when trying to get DataSourcesConfig of grails datasources plugin.

blackdiz
I try to get configures in Datasources.groovy in BootStrap.groovy, and after some search I find a post from datasources plugin author, and he gave these code:

 import org.codehaus.groovy.grails.commons.ApplicationHolder as AH
   import com.burtbeckwith.grails.plugin.datasources.DatasourcesBuilder
   ...
   def script = AH.application.classLoader.loadClass('Datasources').newInstance()
   script.run()
   def builder = new DatasourcesBuilder()
   def datasources = script.datasources
   datasources.delegate = builder
   datasources()
       
   def sources = builder.dataSources

but when runs at datasources(), I get an exception like this:
ava.lang.ArrayIndexOutOfBoundsException: Negative array index [-1] too large for array size 0
at com.burtbeckwith.grails.plugin.datasources.DatasourcesBuilder.createNode(DatasourcesBuilder.groovy:41)
at Datasources$_run_closure1_closure2.doCall(Datasources.groovy:45)
at Datasources$_run_closure1_closure2.doCall(Datasources.groovy)
at Datasources$_run_closure1.doCall(Datasources.groovy:44)
at Datasources$_run_closure1.doCall(Datasources.groovy)

I can't figure out why this happens, and I'll be very appreciate if someone can explain to me or provide a workround.
Thank you
Reply | Threaded
Open this post in threaded view
|

Re: A problem when trying to get DataSourcesConfig of grails datasources plugin.

burtbeckwith
Any chance you can upgrade to Grails 2+? That plugin is old and unsupported,  and Grails now has direct support for multiple DataSources.

Burt

blackdiz wrote
I try to get configures in Datasources.groovy in BootStrap.groovy, and after some search I find a post from datasources plugin author, and he gave these code:

 import org.codehaus.groovy.grails.commons.ApplicationHolder as AH
   import com.burtbeckwith.grails.plugin.datasources.DatasourcesBuilder
   ...
   def script = AH.application.classLoader.loadClass('Datasources').newInstance()
   script.run()
   def builder = new DatasourcesBuilder()
   def datasources = script.datasources
   datasources.delegate = builder
   datasources()
       
   def sources = builder.dataSources

but when runs at datasources(), I get an exception like this:
ava.lang.ArrayIndexOutOfBoundsException: Negative array index [-1] too large for array size 0
at com.burtbeckwith.grails.plugin.datasources.DatasourcesBuilder.createNode(DatasourcesBuilder.groovy:41)
at Datasources$_run_closure1_closure2.doCall(Datasources.groovy:45)
at Datasources$_run_closure1_closure2.doCall(Datasources.groovy)
at Datasources$_run_closure1.doCall(Datasources.groovy:44)
at Datasources$_run_closure1.doCall(Datasources.groovy)

I can't figure out why this happens, and I'll be very appreciate if someone can explain to me or provide a workround.
Thank you
Reply | Threaded
Open this post in threaded view
|

Re: A problem when trying to get DataSourcesConfig of grails datasources plugin.

blackdiz
This post was updated on .
I am very appriciate your reply, but unfortunately I can't upgarde to Grails 2.x.

After reviewing source code I find the exception happened at follow code:

def dataSources = []

+

+ private List<String> _stack = []

+ private DatasourceConfig _currentDs

+ private Closure _hibernateClosure

+

+ /**

+ * {@inheritDoc}

+ * @see groovy.util.BuilderSupport#createNode(java.lang.Object)

+ */

+ @Override

+ protected Object createNode(Object name) {

+ switch (name) {

+ case 'hibernate':

+ case 'cache':

+ _stack.push name

+ return name

+ default:

+ throw new IllegalArgumentException("Cannot create empty node with name '$name'")

+ }

+ }

+

+ /**

+ * {@inheritDoc}

+ * @see groovy.util.BuilderSupport#createNode(java.lang.Object, java.lang.Object)

+ */

+ @Override

+ protected Object createNode(Object name, Object value) {

+

EXCEPTION HAPPENS HERE -> String level = _stack[-1]

+ _stack.push name



Can you suggest about other ways to achieve this goal or some way to resolve this exception?

Thank you