Skip to content
This repository has been archived by the owner on Nov 1, 2018. It is now read-only.

Commit

Permalink
fixes to remove attributes for rdf
Browse files Browse the repository at this point in the history
  • Loading branch information
turtlebender committed Aug 8, 2011
1 parent 7ae46ae commit defaee1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 26 deletions.
18 changes: 17 additions & 1 deletion agamemnon/factory.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 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) source_key = ENDPOINT_NAME_TEMPLATE % (node.type, node.key)
target_key = ENDPOINT_NAME_TEMPLATE % (node.type, node.key) target_key = ENDPOINT_NAME_TEMPLATE % (node.type, node.key)


Expand All @@ -288,6 +295,10 @@ def save_node(self, node):
serialized = self.serialize_columns(target) serialized = self.serialize_columns(target)
self.insert(OUTBOUND_RELATIONSHIP_CF, source_key, serialized, key) self.insert(OUTBOUND_RELATIONSHIP_CF, source_key, serialized, key)
self.insert(INBOUND_RELATIONSHIP_CF, target_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')} inbound_columns = {'target__type': node.type.encode('utf-8'), 'target__key': node.key.encode('utf-8')}
for attribute_key in node.attributes.keys(): for attribute_key in node.attributes.keys():
inbound_columns['target__%s' % attribute_key] = node_attributes[attribute_key] inbound_columns['target__%s' % attribute_key] = node_attributes[attribute_key]
Expand All @@ -299,7 +310,12 @@ def save_node(self, node):
serialized = self.serialize_columns(source) serialized = self.serialize_columns(source)
self.insert(OUTBOUND_RELATIONSHIP_CF, source_key, serialized, key) self.insert(OUTBOUND_RELATIONSHIP_CF, source_key, serialized, key)
self.insert(INBOUND_RELATIONSHIP_CF, target_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): def get_node(self, type, key):
try: try:
Expand Down
25 changes: 12 additions & 13 deletions agamemnon/primitives.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def __init__(self, data_store, type, key, args=None):
self._type = type self._type = type
self.old_values = args self.old_values = args
self.new_values = {} self.new_values = {}
self.new_values.update(self.old_values)
self.relationship_factories = {} self.relationship_factories = {}
self.dirty = False self.dirty = False
self._delete = False self._delete = False
Expand Down Expand Up @@ -289,11 +290,12 @@ def __getattr__(self, item):
self.relationship_factories[item] = relationship_factory self.relationship_factories[item] = relationship_factory
return relationship_factory return relationship_factory


def __contains__(self, item):
return item in self.attributes

def __getitem__(self, item): def __getitem__(self, item):
if item in self.new_values: if item in self.new_values:
return self.new_values[item] return self.new_values[item]
else:
return self.old_values[item]


def __setitem__(self, key, value): def __setitem__(self, key, value):
self.new_values[key] = value self.new_values[key] = value
Expand All @@ -302,27 +304,24 @@ def __setitem__(self, key, value):
def __delitem__(self, key): def __delitem__(self, key):
if key in self.new_values.keys(): if key in self.new_values.keys():
del(self.new_values[key]) del(self.new_values[key])
if key in self.old_values.keys(): self.dirty = True
del(self.old_values[key])
self.dirty = True


@property @property
def attributes(self): def attributes(self):
attr = {} return self.new_values
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


def delete(self): def delete(self):
self._data_store.delete_node(self) self._data_store.delete_node(self)
self.node = None self.node = None


def commit(self): def commit(self):
for key in self.new_values:
self.old_values[key] = self.new_values[key]
self._data_store.save_node(self) 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): def __str__(self):
return 'Node: %s => %s' % (self.type, self.key) return 'Node: %s => %s' % (self.type, self.key)
Expand Down
9 changes: 3 additions & 6 deletions agamemnon/tests/unit_tests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -68,14 +68,11 @@ def get_set_attributes(self, node, attributes):
self.failUnlessEqual('new sample attr', node['new_attribute']) self.failUnlessEqual('new sample attr', node['new_attribute'])
self.failIfEqual(attributes, node.attributes) self.failIfEqual(attributes, node.attributes)
with updating_node(node): with updating_node(node):
del(node['new sample attr']) del(node['new_attribute'])
node = self.ds.get_node(node.type, node.key) node = self.ds.get_node(node.type, node.key)
try: if 'new_attribute' in node:
attr = node['new sample attr'] print "We should not have found 'new_attribute' = %s" % node['new_attribute']
print "We should not have found 'new sample attr' = %s" % attr
self.fail() self.fail()
except KeyError:
pass




def create_random_relationship(self, node, target_type, node_list): def create_random_relationship(self, node, target_type, node_list):
Expand Down
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# #
# Agamemnon documentation build configuration file, created by # 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. # This file is execfile()d with the current directory set to its containing dir.
# #
Expand All @@ -25,7 +25,7 @@


# Add any Sphinx extension module names here, as strings. They can be extensions # Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. # 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. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ['_templates']
Expand All @@ -48,9 +48,9 @@
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = '0.2.2.3' version = '0.2.2.0'
# The full version, including alpha/beta/rc tags. # 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 # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Contents:
arch arch
usage usage


.. include:: ../README.rst

Indices and tables Indices and tables
================== ==================


Expand Down
4 changes: 2 additions & 2 deletions docs/usage.rst
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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 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. 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 = graph_db.get_node('simpson', 'Homer')
>>> homer['sound'] >>> homer['sound']
'Doh' 'Doh'
>>> homer['job'] >>> homer['job']
'Safety Technician' 'Safety Inspector'


Nodes by themselves are not very useful. Let's create a relationship between spiderpig and Harry Plopper. Nodes by themselves are not very useful. Let's create a relationship between spiderpig and Harry Plopper.


Expand Down

0 comments on commit defaee1

Please sign in to comment.