Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixes to remove attributes for rdf

  • Loading branch information...
commit defaee167ae33f44fa3f5acefd8b16e959853123 1 parent 7ae46ae
@turtlebender turtlebender authored
View
18 agamemnon/factory.py
@@ -266,6 +266,13 @@ def save_node(self, node):
"""
This needs to update the entry in the type table as well as all of the relationships
"""
+ self.insert(node.type, node.key, self.serialize_columns(node.attributes))
+ columns_to_remove = []
+ for key in node.old_values:
+ if not key in node.new_values:
+ columns_to_remove.append(key)
+ if len(columns_to_remove) > 0:
+ self.remove(self.get_cf(node.type), node.key, columns=columns_to_remove)
source_key = ENDPOINT_NAME_TEMPLATE % (node.type, node.key)
target_key = ENDPOINT_NAME_TEMPLATE % (node.type, node.key)
@@ -288,6 +295,10 @@ def save_node(self, node):
serialized = self.serialize_columns(target)
self.insert(OUTBOUND_RELATIONSHIP_CF, source_key, serialized, key)
self.insert(INBOUND_RELATIONSHIP_CF, target_key, serialized, key)
+ self.delete(OUTBOUND_RELATIONSHIP_CF, source_key, super_key=key,
+ columns=['source__%s' % column for column in columns_to_remove])
+ self.delete(INBOUND_RELATIONSHIP_CF, target_key, super_key=key,
+ columns=['source__%s' % column for column in columns_to_remove])
inbound_columns = {'target__type': node.type.encode('utf-8'), 'target__key': node.key.encode('utf-8')}
for attribute_key in node.attributes.keys():
inbound_columns['target__%s' % attribute_key] = node_attributes[attribute_key]
@@ -299,7 +310,12 @@ def save_node(self, node):
serialized = self.serialize_columns(source)
self.insert(OUTBOUND_RELATIONSHIP_CF, source_key, serialized, key)
self.insert(INBOUND_RELATIONSHIP_CF, target_key, serialized, key)
- self.insert(node.type, node.key, self.serialize_columns(node.attributes))
+ self.delete(OUTBOUND_RELATIONSHIP_CF, source_key, super_key=key,
+ columns=['target__%s' % column for column in columns_to_remove])
+ self.delete(INBOUND_RELATIONSHIP_CF, target_key, super_key=key,
+ columns=['target__%s' % column for column in columns_to_remove])
+
+
def get_node(self, type, key):
try:
View
25 agamemnon/primitives.py
@@ -241,6 +241,7 @@ def __init__(self, data_store, type, key, args=None):
self._type = type
self.old_values = args
self.new_values = {}
+ self.new_values.update(self.old_values)
self.relationship_factories = {}
self.dirty = False
self._delete = False
@@ -289,11 +290,12 @@ def __getattr__(self, item):
self.relationship_factories[item] = relationship_factory
return relationship_factory
+ def __contains__(self, item):
+ return item in self.attributes
+
def __getitem__(self, item):
if item in self.new_values:
return self.new_values[item]
- else:
- return self.old_values[item]
def __setitem__(self, key, value):
self.new_values[key] = value
@@ -302,27 +304,24 @@ def __setitem__(self, key, value):
def __delitem__(self, key):
if key in self.new_values.keys():
del(self.new_values[key])
- if key in self.old_values.keys():
- del(self.old_values[key])
- self.dirty = True
+ self.dirty = True
@property
def attributes(self):
- attr = {}
- if self.old_values is not None:
- attr.update(self.old_values)
- if self.new_values is not None:
- attr.update(self.new_values)
- return attr
+ return self.new_values
def delete(self):
self._data_store.delete_node(self)
self.node = None
def commit(self):
- for key in self.new_values:
- self.old_values[key] = self.new_values[key]
self._data_store.save_node(self)
+ self.old_values = {}
+ self.old_values.update(self.new_values)
+
+ def clear(self):
+ self.new_values = {}
+ self.new_values.update(self.old_values)
def __str__(self):
return 'Node: %s => %s' % (self.type, self.key)
View
9 agamemnon/tests/unit_tests.py
@@ -68,14 +68,11 @@ def get_set_attributes(self, node, attributes):
self.failUnlessEqual('new sample attr', node['new_attribute'])
self.failIfEqual(attributes, node.attributes)
with updating_node(node):
- del(node['new sample attr'])
+ del(node['new_attribute'])
node = self.ds.get_node(node.type, node.key)
- try:
- attr = node['new sample attr']
- print "We should not have found 'new sample attr' = %s" % attr
+ if 'new_attribute' in node:
+ print "We should not have found 'new_attribute' = %s" % node['new_attribute']
self.fail()
- except KeyError:
- pass
def create_random_relationship(self, node, target_type, node_list):
View
8 docs/conf.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# Agamemnon documentation build configuration file, created by
-# sphinx-quickstart on Wed May 25 12:04:27 2011.
+# sphinx-quickstart on Sun Aug 7 19:21:48 2011.
#
# This file is execfile()d with the current directory set to its containing dir.
#
@@ -25,7 +25,7 @@
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = []
+extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
@@ -48,9 +48,9 @@
# built documents.
#
# The short X.Y version.
-version = '0.2.2.3'
+version = '0.2.2.0'
# The full version, including alpha/beta/rc tags.
-release = '0.2.2.3'
+release = '0.2.2.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
View
2  docs/index.rst
@@ -14,6 +14,8 @@ Contents:
arch
usage
+.. include:: ../README.rst
+
Indices and tables
==================
View
4 docs/usage.rst
@@ -35,12 +35,12 @@ confirm that the node and it's attributes were created correctly.
Nodes can have different types as well. Here we create a node of type simpson, with name Homer. This node has
different attributes than the previous nodes.
->>> homer = graph_db.create_node('simpson', 'Homer', {'sound':'Doh', 'job':'Safety Technician'})
+>>> homer = graph_db.create_node('simpson', 'Homer', {'sound':'Doh', 'job':'Safety Inspector'})
>>> homer = graph_db.get_node('simpson', 'Homer')
>>> homer['sound']
'Doh'
>>> homer['job']
-'Safety Technician'
+'Safety Inspector'
Nodes by themselves are not very useful. Let's create a relationship between spiderpig and Harry Plopper.
Please sign in to comment.
Something went wrong with that request. Please try again.