def get_nodes(self, type, keys): try: rows = self.multiget(type, keys) except NotFoundException: raise NodeNotFoundException() return [ prim.Node(self, type, key, values) for key, values in rows ]
def get_nodes_by_attr(self, type, attrs = {}, expressions=None, start_key='', row_count = 2147483647, **kwargs): if expressions is None: expressions = [] for attr, value in self.serialize_columns(attrs).items(): expressions.append(index.create_index_expression(attr, value)) clause = index.create_index_clause(expressions, start_key=start_key, count=row_count) try: column_family = self.delegate.get_cf(type) rows = column_family.get_indexed_slices(clause, **kwargs) except NotFoundException: raise NodeNotFoundException() return [ prim.Node(self, type, key, self.deserialize_value(values)) for key, values in rows ]
def get_relationship(self, rel_type, rel_key): try: values = self.get(RELATIONSHIP_CF, ENDPOINT_NAME_TEMPLATE % (rel_type, rel_key)) except NotFoundException: raise NodeNotFoundException() source_node_key = None source_node_type = None source_attributes = {} for column in values.keys(): value = values[column] if column == 'source__type': source_node_type = value elif column == 'source__key': source_node_key = value elif column.startswith('source__'): source_attributes[column[8:]] = value source = prim.Node(self, source_node_type, source_node_key, source_attributes) rel_key = RELATIONSHIP_KEY_PATTERN % (rel_type, rel_key) return self.get_outgoing_relationship(rel_type, source, (rel_key, values))
def create_node(self, type, key, args=None, reference=False): if args is None: args = {} try: node = self.get_node(type, key) node.attributes.update(args) self.save_node(node) self.delegate.on_modify(node) return node except NodeNotFoundException: #since node won't get created without args, we will include __id by default args["__id"] = key serialized = self.serialize_columns(args) self.insert(type, key, serialized) node = prim.Node(self, type, key, args) if not reference: #this adds the created node to the reference node for this type of object #that reference node functions as an index to easily access all nodes of a specific type reference_node = self.get_reference_node(type) reference_node.instance(node, key=key) self.delegate.on_create(node) return node
def get_incoming_relationship(self, rel_type, target_node, super_column): """ Process the contents of a SuperColumn to extract an incoming relationship and the associated from_node and return a constructed relationship """ rel_key = super_column[0] source_node_key = None source_node_type = None source_attributes = {} rel_attributes = {} for column in super_column[1].keys(): value = super_column[1][column] if column == 'source__type': source_node_type = value elif column == 'source__key': source_node_key = value elif column.startswith('source__'): source_attributes[column[8:]] = value else: rel_attributes[column] = value return prim.Relationship(rel_key, prim.Node(self, source_node_type, source_node_key, source_attributes), target_node, self, rel_type, rel_attributes)
def get_outgoing_relationship(self, rel_type, source_node, super_column): """ Process the contents of a SuperColumn to extract the relationship and to_node properties and return a constructed relationship """ rel_key = super_column[0] target_node_key = None target_node_type = None target_attributes = {} rel_attributes = {} for column in super_column[1].keys(): value = super_column[1][column] if column == 'target__type': target_node_type = value elif column == 'target__key': target_node_key = value elif column.startswith('target__'): target_attributes[column[8:]] = value else: rel_attributes[column] = value return prim.Relationship(rel_key, source_node, prim.Node(self, target_node_type, target_node_key, target_attributes), self , rel_type, rel_attributes)
def get_node(self, type, key): try: values = self.get(type, key) except NotFoundException: raise NodeNotFoundException() return prim.Node(self, type, key, values)