summaryrefslogtreecommitdiff
path: root/src-py
diff options
context:
space:
mode:
Diffstat (limited to 'src-py')
-rw-r--r--src-py/db_controller.py40
-rw-r--r--src-py/neo4j_util.py19
2 files changed, 32 insertions, 27 deletions
diff --git a/src-py/db_controller.py b/src-py/db_controller.py
index dcb70c10..cb52cc09 100644
--- a/src-py/db_controller.py
+++ b/src-py/db_controller.py
@@ -156,13 +156,10 @@ class DBO_add_link_set(DB_op):
self.add_statement(q, q_params)
def on_completion(self, data):
- super(DBO_add_link_set, self).on_completion(data)
-
id_set = []
for s_id, s, r_set in self:
for row in r_set:
- # [!] fragile - parse results
- lid = row
+ lid = row # [!] fragile
id_set.append(lid)
log.debug('link-set added: ids: ' + str(id_set))
@@ -183,7 +180,7 @@ class DBO_load_node_set_by_DB_id(DB_op):
log.debug('loaded node set: ' + str(data))
return self.parse_single_query_response_data(data)
-class DBO_load_node_set(DB_op):
+class DBO_match_node_id_set(DB_op):
def __init__(self, filter_type=None, filter_attr_map=None):
"""
@@ -208,24 +205,26 @@ class DBO_load_node_set(DB_op):
log.debug('loaded id-set: ' + str(data))
return self.parse_single_query_response_data(data)
-class DBO_load_node_set_by_id_attribute(DBO_load_node_id_set):
+class DBO_match_node_set_by_id_attribute(DBO_match_node_id_set):
def __init__(self, id_set):
"""
convenience op: load a set of nodes by their 'id' attribute != DB node id
"""
assert isinstance(id_set, list)
- super(DBO_load_node_set_by_id_attribute, self).__init__(filter_attr_map={'id': id_set})
+ super(DBO_match_node_set_by_id_attribute, self).__init__(filter_attr_map={'id': id_set})
-class DBO_load_link_set_by_src_or_dst_id_attributes(DB_op):
+class DBO_match_link_set_by_src_or_dst_id_attributes(DB_op):
def __init__(self, src_id=None, dst_id=None):
"""
- load an id-set of links by source/target id attributes != DB node id
+ match a set of links by source/target node id attributes
+
+ @return: a set of loaded links
"""
assert None != src_id or None != dst_id
- super(DBO_load_link_set_by_src_or_dst_id_attributes, self).__init__()
+ super(DBO_match_link_set_by_src_or_dst_id_attributes, self).__init__()
if not src_id:
q = "match ()-[r]->({id: {dst_id}}) return r"
@@ -243,7 +242,7 @@ class DBO_load_link_set_by_src_or_dst_id_attributes(DB_op):
log.debug('loaded id-set: ' + str(data))
return self.parse_single_query_response_data(data)
-class DBO_load_link_id_set(DB_op):
+class DBO_match_link_id_set(DB_op):
def __init__(self, filter_type=None, filter_attr_map={}):
"""
load an id-set of links
@@ -253,7 +252,7 @@ class DBO_load_link_id_set(DB_op):
attributes to match link properties against
@return: a set of loaded link ids
"""
- super(DBO_load_link_id_set, self).__init__()
+ super(DBO_match_link_id_set, self).__init__()
q = "match ()-[r{filter_type} {filter_attr}]->() return id(r)"
q = cfmt(q, filter_type="" if not filter_type else ":" + filter_type)
@@ -280,8 +279,8 @@ class DB_Driver_REST(DB_Driver_Base):
#
# [!] neo4j seems picky about receiving an additional empty statement list
#
- data = data = dbu.statement_set_to_REST_form([])
- ret = dbu.post_neo4j(tx_open_url, data)
+ data = data = db_util.statement_set_to_REST_form([])
+ ret = db_util.post_neo4j(tx_open_url, data)
tx_commit_url = ret['commit']
op.parse_tx_id(tx_commit_url)
@@ -291,10 +290,11 @@ class DB_Driver_REST(DB_Driver_Base):
def exex_op_statements(self, op):
tx_url = "{0}/{1}".format(self.tx_base_url, op.tx_id)
- statement_set = dbu.statement_set_to_REST_form(op.statement_set)
+ statement_set = db_util.statement_set_to_REST_form(op.statement_set)
try:
- ret = dbu.post_neo4j(tx_url, statement_set)
+ ret = db_util.post_neo4j(tx_url, statement_set)
+ op._assign_results_errors(ret)
self.log_committed_queries(statement_set)
return ret
except Exception as e:
@@ -307,8 +307,8 @@ class DB_Driver_REST(DB_Driver_Base):
#
# [!] neo4j seems picky about receiving an additional empty statement list
#
- data = dbu.statement_set_to_REST_form([])
- ret = dbu.post(tx_commit_url, data)
+ data = db_util.statement_set_to_REST_form([])
+ ret = db_util.post(tx_commit_url, data)
log.debug('tx-commit: id: {0}, commit-url: {1}'.format(op.tx_id, tx_commit_url))
@@ -379,5 +379,5 @@ class DB_Controller:
@deprecated: use transaction based api
"""
- # call post and not dbu.post_neo4j to avoid response key errors
- dbu.post(self.config.db_base_url + '/db/data/cypher', {"query" : q})
+ # call post and not db_util.post_neo4j to avoid response key errors
+ db_util.post(self.config.db_base_url + '/db/data/cypher', {"query" : q})
diff --git a/src-py/neo4j_util.py b/src-py/neo4j_util.py
index 120a601a..5169af0d 100644
--- a/src-py/neo4j_util.py
+++ b/src-py/neo4j_util.py
@@ -30,9 +30,9 @@ class Cypher_String_Formatter(string.Formatter):
def get_field(self, field_name, args, kwargs):
# ignore key not found, return bracket wrapped key
try:
- val=super(Cypher_String_Formatter, self).get_field(field_name, args, kwargs)
+ val = super(Cypher_String_Formatter, self).get_field(field_name, args, kwargs)
except (KeyError, AttributeError):
- val="{" + field_name + "}", field_name
+ val = "{" + field_name + "}", field_name
return val
def cfmt(fmt_str, *args, **kwargs):
@@ -72,7 +72,11 @@ def statement_to_REST_form(query, parameters={}):
turn cypher query to neo4j json API format
"""
assert isinstance(query, basestring)
- assert isinstance(parameters, dict)
+ if isinstance(parameters, list):
+ for v in parameters:
+ assert isinstance(v, dict)
+ else:
+ assert isinstance(parameters, dict)
return {'statement' : query, 'parameters': parameters}
@@ -96,13 +100,16 @@ def gen_clause_attr_filter_from_filter_attr_map(filter_attr_map, node_label="n")
filter_str = "{{{0}}}".format(', '.join(filter_arr))
return filter_str
+
def gen_clause_where_from_filter_attr_map(filter_attr_map, node_label="n"):
"""
convert a filter attribute map to a parameterized Cypher where clause, eg.
in: { 'att_foo': [ 'a', 'b' ], 'att_goo': [1,2] }
- out: where n.att_foo in {att_foo} and n.att_goo in {att_goo} ...
+ out: {att_foo: {att_foo}, att_goo: {att_goo}, ...}
+
+ this function will essentially ignore all but the first value in the value list
- @param filter_attr_map: may be None or empty
+ @param filter_attr_map: may be None or empty
"""
if not filter_attr_map:
return ""
@@ -194,8 +201,6 @@ def meta_attr_list_to_meta_attr_map(e_set, meta_attr='__type'):
ret[v_type].append(v_no_meta)
return ret
- q = "match (src {id: {src}.id}),(dst {id: {dst}.id}) create (src)-[:%(l_type)s {link_attr}]->(dst)" % {'l_type':l_type}
- return (q, q_params_set)
def __type_check_link(link):
assert link.has_key('__src')