espeed / bulbs

A Python persistence framework for graph databases like Neo4j, OrientDB and Titan.

Home Page:http://bulbflow.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DRY in groovy scripts

kefirbandi opened this issue · 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.

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
notifications@github.comwrote:

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//issues/107
.