Ejemplo n.º 1
0
class Atlas(object):
    def __init__(self, graph_name, hostname, username = None, password = None, batchmode = False):
        self.graph_name = graph_name
        self.username = username
        self.password = password
        self.batchmode = batchmode
        self.conn = RexProConnection(hostname, 8184, graph_name)

        #self.conn.execute("g.makeType().name('vid').dataType(String.class).unique(Direction.OUT).unique(Direction.IN).indexed(Vertex.class).indexed(Edge.class).makePropertyKey()")

        if self.batchmode:
            self.execute("bg = new BatchGraph(g, VertexIDType.STRING, 1000) ;")

    def execute(self, query, params = {}):

        try:
            content = self.conn.execute(query, params, isolate = False, transaction = False)
        except:
            logger.info("==========================================================================")
            logger.info(query)
            logger.info(params)
            logger.info("==========================================================================")
            
            logger.info("--------->")
            logger.info(content)
            logger.info("==========================================================================")

        return content
Ejemplo n.º 2
0
class GraphBase(object):

    def __init__(self):
        self.conn = RexProConnection('localhost', 8184, 'graph')


    def execute_query(self, script, params=None):
        self.conn.open()
        r = self.conn.execute(script, params)
        self.conn.close()
        return r
Ejemplo n.º 3
0
class Atlas(object):
    def __init__(self,
                 graph_name,
                 hostname,
                 username=None,
                 password=None,
                 batchmode=False):
        self.graph_name = graph_name
        self.username = username
        self.password = password
        self.batchmode = batchmode
        self.conn = RexProConnection(hostname, 8184, graph_name)

        #self.conn.execute("g.makeType().name('vid').dataType(String.class).unique(Direction.OUT).unique(Direction.IN).indexed(Vertex.class).indexed(Edge.class).makePropertyKey()")

        if self.batchmode:
            self.execute("bg = new BatchGraph(g, VertexIDType.STRING, 1000) ;")

    def execute(self, query, params={}):

        try:
            content = self.conn.execute(query,
                                        params,
                                        isolate=False,
                                        transaction=False)
        except:
            logger.info(
                "=========================================================================="
            )
            logger.info(query)
            logger.info(params)
            logger.info(
                "=========================================================================="
            )

            logger.info("--------->")
            logger.info(content)
            logger.info(
                "=========================================================================="
            )

        return content
Ejemplo n.º 4
0
class Binary(_Request):

    def __init__(self, uri, graph, username=None, password=None, port=8184):
        from rexpro import RexProConnection

        super(Binary, self).__init__(uri, username, password)

        self.connection = RexProConnection(uri, port, graph)

    def send(self, script=None, params=None, update_models=None):
        if params is None:
            params = {}

        if update_models is None:
            update_models = {}

        self.connection.open()
        resp = self.connection.execute(script, params)
        self.connection.close()
        response = _Response(resp, update_models)
        response.script = script
        response.params = params

        return response
Ejemplo n.º 5
0
from rexpro import RexProConnection

conn = RexProConnection('localhost', 8184, 'graph')

# Use the management system to define properties and build indexes
conn.execute("""
from com.tinkerpop.blueprints import Vertex
ms = g.management_system
name = ms.make_property_key('name')
age = ms.make_property_key('age', data_type=Integer)
ms.build_index('by-name', Vertex, keys=[name])
ms.build_index('by-name-and-age', Vertex, keys=[name, age])
ms.commit()
""", language='python')


# the management system can also be used as a context manager with an implied commit when exiting the context
# this might be desirable if you'd like to cut down on some typing or group different blocks of code in transactions
conn.execute("""
from com.tinkerpop.blueprints import Vertex
with g.management_system as ms:
    name = ms.make_property_key('name')
    age = ms.make_property_key('age', data_type=Integer)
    ms.build_index('by-name', Vertex, keys=[name])
    ms.build_index('by-name-and-age', Vertex, keys=[name, age])
""", language='python')

from rexpro import RexProConnection
import os

cwd = os.path.dirname(os.path.realpath(__file__))

script = open(os.path.join(cwd, 'data_load_movies.groovy'), 'r').read()
conn = RexProConnection('localhost', 8184, 'graph')
conn.execute(script, {'path': cwd})

Ejemplo n.º 7
0
from rexpro import RexProConnection

conn = RexProConnection('localhost', 8184, 'graph')

# Use the management system to define properties and build indexes
conn.execute("""
from com.tinkerpop.blueprints import Vertex
ms = g.management_system
name = ms.make_property_key('name')
age = ms.make_property_key('age', data_type=Integer)
ms.build_index('by-name', Vertex, keys=[name])
ms.build_index('by-name-and-age', Vertex, keys=[name, age])
ms.commit()
""",
             language='python')

# the management system can also be used as a context manager with an implied commit when exiting the context
# this might be desirable if you'd like to cut down on some typing or group different blocks of code in transactions
conn.execute("""
from com.tinkerpop.blueprints import Vertex
with g.management_system as ms:
    name = ms.make_property_key('name')
    age = ms.make_property_key('age', data_type=Integer)
    ms.build_index('by-name', Vertex, keys=[name])
    ms.build_index('by-name-and-age', Vertex, keys=[name, age])
""",
             language='python')
Ejemplo n.º 8
0
from rexpro import RexProConnection

conn = RexProConnection('localhost', 8184, 'graph')

conn.execute("""
from com.thinkaurelius.titan.example import GraphOfTheGodsFactory
from com.thinkaurelius.titan.core import SchemaViolationException

try:
    #Try to load up the graph of the gods if it's not already loaded
    GraphOfTheGodsFactory.load(g.graph)
except SchemaViolationException:
    pass
""",
             language='python')

# Run some examples based on https://github.com/thinkaurelius/titan/wiki/Getting-Started
# `as` and `in` have trailing underscores to avoid clashing with python keywords
# whenever possible, naming conventions are the same as other gremlin language implementations
saturn_grandchild = conn.execute("""
g.V.has('name', 'saturn').in_('father').in_('father').name
""",
                                 language='python')

assert saturn_grandchild == ['hercules']

saturn_grandchild = conn.execute("""
g.V.has('name', 'saturn').as_('x').in_('father').loop('x', lambda it: it.loops < 3).name
""",
                                 language='python')
Ejemplo n.º 9
0
mgmt.buildIndex('byMyVertexTestVal', Vertex.class).addKey(myvertex_test_val).buildCompositeIndex()
mgmt.buildIndex('byMyVertexTestDate', Vertex.class).addKey(myvertex_test_date).buildCompositeIndex()

//-MyEdge
mgmt.buildIndex('byMyEdgeName', Edge.class).addKey(myedge_name).buildCompositeIndex()
mgmt.buildIndex('byMyEdgeTestVal', Edge.class).addKey(myedge_test_val).buildCompositeIndex()
mgmt.buildIndex('byMyEdgeTestDate', Edge.class).addKey(myedge_test_date).buildCompositeIndex()

//-Person
mgmt.buildIndex('byPersonName', Vertex.class).addKey(person_name).buildCompositeIndex()
mgmt.buildIndex('byPersonEmail', Vertex.class).addKey(person_email).unique().buildCompositeIndex()

//-Trinket
mgmt.buildIndex('byTrinketName', Vertex.class).addKey(trinket_name).buildCompositeIndex()
mgmt.buildIndex('byTrinketEngraving', Vertex.class).addKey(trinket_engraving).buildCompositeIndex()

//-Owns Edge
mgmt.buildIndex('byOwnsObjectSince', Edge.class).addKey(ownsobject_since).buildCompositeIndex()

//-IsFriendsWith Edge
mgmt.buildIndex('byIsFriendsWithSince', Edge.class).addKey(isfriendswith_since).buildCompositeIndex()


mgmt.commit()

g.commit()
'''

conn = RexProConnection('localhost', 8184, 'sandbox')
conn.execute(script, {})
from rexpro import RexProConnection

conn = RexProConnection('localhost', 8184, 'graph')

conn.execute("""
from com.thinkaurelius.titan.example import GraphOfTheGodsFactory
from com.thinkaurelius.titan.core import SchemaViolationException

try:
    #Try to load up the graph of the gods if it's not already loaded
    GraphOfTheGodsFactory.load(g.graph)
except SchemaViolationException:
    pass
""", language='python')

# Run some examples based on https://github.com/thinkaurelius/titan/wiki/Getting-Started
# `as` and `in` have trailing underscores to avoid clashing with python keywords
# whenever possible, naming conventions are the same as other gremlin language implementations
saturn_grandchild = conn.execute("""
g.V.has('name', 'saturn').in_('father').in_('father').name
""", language='python')

assert saturn_grandchild == ['hercules']

saturn_grandchild = conn.execute("""
g.V.has('name', 'saturn').as_('x').in_('father').loop('x', lambda it: it.loops < 3).name
""", language='python')

assert saturn_grandchild == ['hercules']

hercules_parent_names = conn.execute("""