bulbs icon indicating copy to clipboard operation
bulbs copied to clipboard

DRY in groovy scripts

Open kefirbandi opened this issue 10 years ago • 1 comments

Bulbs allows you to write a groovy script on the client side and send it for execution to the server, but unfortunately it is not possible to store a procedure for later use by an other procedure. This may lead to multiple definitions of the same helper function if it is used by multiple functions.

See for example the multiple definition of transaction in https://github.com/espeed/bulbs/blob/master/bulbs/rexster/gremlin.groovy

I wrote a work-around for this which may be best explained by this example:

This is how your groovy source file looks like:

def do_something(){
    do()
}

def do_something_twice(){
    ::do_something::
    do_something()
    do_something()
}

I modified the python code, so if in python you issue g.scripts.update('my_gremlin.groovy') the ::do_something:: part will textually be replaced and the final result would be equivalent to

def do_something(){
    do()
}

def do_something_twice(){
    def do_something(){
        do()
    }
    do_something()
    do_something()
}

If you think this is a useful feature, I am happy to send a pull request.

kefirbandi avatar Aug 22 '13 12:08 kefirbandi

Since the Bulbs 0.3 release, Rexster and Titan Server have added the capability to load stored procedures:

See https://github.com/tinkerpop/rexster/wiki/Gremlin-Extension#load-parameter

Bulbs 0.4 will provide a way to switch between the two -- client side for ease of development/testing, and server side for performance.

Neo4j Server does not offer this explicitly, but it can be finagled to load server-side scripts.

  • James

On Thu, Aug 22, 2013 at 7:32 AM, Andras Gefferth [email protected]:

Bulbs allows you to write a groovy script on the client side and send it for execution to the server, but unfortunately it is not possible to store a procedure for later use by an other procedure. This may lead to multiple definitions of the same helper function if it is used by multiple functions.

See for example the multiple definition of transaction in https://github.com/espeed/bulbs/blob/master/bulbs/rexster/gremlin.groovy

I wrote a work-around for this which may be best explained by this example:

This is how your groovy source file looks like:

def do_something(){ do()} def do_something_twice(){ ::do_something:: do_something() do_something()}

I modified the python code, so if in python you issue g.scripts.update('my_gremlin.groovy') the ::do_something:: part will textually be replaced and the final result would be equivalent to

def do_something(){ do()} def do_something_twice(){ def do_something(){ do() } do_something() do_something()}

If you think this is a useful feature, I am happy to send a pull request.

— Reply to this email directly or view it on GitHubhttps://github.com/espeed/bulbs/issues/107 .

espeed avatar Aug 22 '13 14:08 espeed