The Assimilation Project  based on Assimilation version 1.1.7.1474836767
cma.store.Store Class Reference
Inheritance diagram for cma.store.Store:
Collaboration diagram for cma.store.Store:

Public Member Functions

def __init__ (self, db, uniqueindexmap=None, classkeymap=None, readonly=False)
 
def __str__ (self)
 
def is_uniqueindex (self, index_name)
 
def dump_clients (self)
 
def fmt_dirty_attrs (self)
 
def save_indexed (self, index_name, key, value, subj)
 
def save_unique (self, index_name, key, value, subj)
 
def save (self, subj, node=None)
 
def delete (self, subj)
 
def refresh (self, subj)
 
def load_indexed (self, index_name, key, value, cls)
 
def load (self, cls, clsargs)
 
def load_or_create (self, cls, clsargs)
 
def relate (self, subj, rel_type, obj, properties=None)
 
def relate_new (self, subj, rel_type, obj, properties=None)
 
def separate (self, subj, rel_type=None, obj=None)
 
def separate_in (self, subj, rel_type=None, obj=None)
 
def load_related (self, subj, rel_type, cls)
 
def load_in_related (self, subj, rel_type, cls)
 
def load_cypher_nodes (self, querystr, cls, params=None, maxcount=None, debug=False)
 
def load_cypher_node (self, query, cls, params=None)
 
def load_cypher_query (self, querystr, clsfact, params=None, maxcount=None)
 
def transaction_pending (self)
 
def constructobj (self, constructor, node)
 
def reset_stats (self)
 
def abort (self)
 
def commit (self)
 
def clean_store (self)
 

Static Public Member Functions

def lucene_escape (query)
 
def id (subj)
 
def has_node (subj)
 
def getstore (subj)
 
def is_abstract (subj)
 
def bound (subj)
 
def callconstructor (constructor, kwargs)
 
def safe_attrs (subj)
 
def mark_dirty (objself, attr)
 
def node (subj)
 

Data Fields

 db
 
 readonly
 
 stats
 
 clients
 
 newrels
 
 deletions
 
 classes
 
 weaknoderefs
 
 uniqueindexmap
 
 batch
 
 batchindex
 
 classkeymap
 
 create_node_count
 
 relate_node_count
 
 index_entry_count
 
 node_update_count
 
 node_deletion_count
 
 node_separate_count
 

Static Public Attributes

 LUCENE_RE = re.compile(r'([\-+&\|!\(\)\{\}[\]^"~\*?:\\])')
 
bool debug = False
 
 log = None
 

Detailed Description

This 'Store' class is a transaction-oriented implementation of Nigel Small's
OGM (Object-Graph-Mapping) API - with a few extensions and a few things not implemented.

Unimplemented APIs
-----------------
The following member functions aren't provided:
    is_saved() - replaced by the transaction_pending property

Some interesting extensions:
----------------------------
    -   You can tell the Store constructor things about your Classes and Indexes
            makes handling indexes simpler and less error prone. This affects the
            save() method and makes it usable far more often.
    -   All updates are happen in a batch job - as a single transaction.
    -   You never need to call save once an object was created.  We
        track changes to the attributes.

New methods:
-----------
    commit          saves all modifications in a single transaction
    load_in_related load objects we're related to by incoming relationships
    load_cypher_nodes generator which yields a vector of sametype nodes from a cypher query
    load_cypher_node return a single object from a cypher query
    load_cypher_query return iterator with objects for fields
    separate_in     separate objects we're related to by incoming relationships
    node            returns the neo4j.Node object associated with an object
    id              returns the id of the neo4j.Node associated with an object
    is_uniqueindex  returns True if the given index name is known to be unique
    __str__         formats information about this Store
    transaction_pending -- Property: True means a transaction is pending
    stats           a data member containing statistics in a dict
    reset_stats     Reset statistics counters and timers

The various save functions do nothing immediately.  Updates are delayed until
the commit member function is called.

Restrictions:
-------------
You can't delete something in the same transaction that you created it.
This could probably be fixed, but would take some effort, and seems unlikely
to be useful.

Objects associated with Nodes must be subclasses of object

Caveats, Warnings and so on...
------------------------------
You can delete the same the same relationship or node multiple times in a transaction.

Attributes beginning with _ are not replicated as Node properties.

There are various times when a constructor is called to create an object from a
node.  Those 'constructors' can be factory functions that construct the right kind
of object for the type of node involved.

Such constructors are called with the arguments which correspond to the Node
properties - but only those which they will legally take (according to python
introspection).  It is assumed that argument names correspond to attribute
(Node property) names.

Any remaining properties not created by the constructor are assigned to the object
as attributes.  This is likely not what Nigel did, but it seems sensible.

Probably should have created some new exception type for a few of our cases.
I'm not compatible with Nigel in terms of exceptions raised. We mostly
raise ValueError()...

In particular, it is possible for data in the database to be incompatible with
object constructors which would be a bad thing worth recognizing -- but I don't
do anything special for this case at the moment.

Definition at line 44 of file store.py.

Constructor & Destructor Documentation

def cma.store.Store.__init__ (   self,
  db,
  uniqueindexmap = None,
  classkeymap = None,
  readonly = False 
)
Constructor for Transactional Write (Batch) Store objects
---------
Parameters:
db             - Database to associate with this object
uniqueindexmap - Dict of indexes, True means its a unique index, False == nonunique
classkeymap    - Map of classes to index attributes - indexed by Class or Class name
         Values are another Dict with these values:
         'index':   name of index
         'key':     constant key value
         'kattr':   object attribute for key
         'value':   constant key 'value'
         'vattr':   object attribute for key 'value'

Definition at line 121 of file store.py.

Member Function Documentation

def cma.store.Store.abort (   self)
def cma.store.Store.bound (   subj)
static

Definition at line 224 of file store.py.

def cma.store.Store.callconstructor (   constructor,
  kwargs 
)
static

Definition at line 575 of file store.py.

References constructor.

Referenced by cma.store.Store.load(), and cma.store.Store.load_or_create().

Here is the caller graph for this function:

def cma.store.Store.clean_store (   self)
Clean out all the objects we used to have in our store - afterwards we
have none associated with this Store

Definition at line 1109 of file store.py.

References cma.store.Store.abort(), and cma.store.Store.weaknoderefs.

Here is the call graph for this function:

def cma.store.Store.constructobj (   self,
  constructor,
  node 
)

Definition at line 608 of file store.py.

References cma.store.Store._get_idx_key_value(), cma.store.Store._localsearch(), cma.store.Store._register(), and cma.store.Store.is_uniqueindex().

Referenced by cma.store.Store.load_cypher_nodes(), and cma.store.Store.load_cypher_query().

Here is the call graph for this function:

Here is the caller graph for this function:

def cma.store.Store.delete (   self,
  subj 
)

Definition at line 314 of file store.py.

References cma.store.Store.readonly, cma.store.Store.separate(), and cma.store.Store.separate_in().

Here is the call graph for this function:

def cma.store.Store.dump_clients (   self)

Definition at line 235 of file store.py.

References cma.store.Store.clients.

def cma.store.Store.fmt_dirty_attrs (   self)

Definition at line 245 of file store.py.

References cma.store.Store.clients.

Referenced by cma.store.Store.__str__().

Here is the caller graph for this function:

def cma.store.Store.getstore (   subj)
static

Definition at line 212 of file store.py.

def cma.store.Store.has_node (   subj)
static

Definition at line 207 of file store.py.

def cma.store.Store.id (   subj)
static

Definition at line 200 of file store.py.

def cma.store.Store.is_abstract (   subj)
static

Definition at line 217 of file store.py.

def cma.store.Store.is_uniqueindex (   self,
  index_name 
)

Definition at line 228 of file store.py.

References cma.store.Store.uniqueindexmap.

Referenced by cma.store.Store.constructobj(), cma.store.Store.load(), and cma.store.Store.save().

Here is the caller graph for this function:

def cma.store.Store.load (   self,
  cls,
  clsargs 
)
Load a pre-existing object from its constructor arguments.

Definition at line 354 of file store.py.

References cma.store.Store._construct_obj_from_node(), cma.store.Store._get_idx_key_value(), cma.store.Store._localsearch(), cma.store.Store.callconstructor(), cma.consts.CMAconsts.classkeymap, cma.store.Store.classkeymap, cma.store.Store.is_uniqueindex(), and cma.store.Store.save().

Referenced by cma.store.Store.load_or_create().

Here is the call graph for this function:

Here is the caller graph for this function:

def cma.store.Store.load_cypher_node (   self,
  query,
  cls,
  params = None 
)

Definition at line 517 of file store.py.

References cma.store.Store.load_cypher_nodes().

Here is the call graph for this function:

def cma.store.Store.load_cypher_nodes (   self,
  querystr,
  cls,
  params = None,
  maxcount = None,
  debug = False 
)
Execute the given query that yields a single column of nodes
all of the same Class (cls) and yield each of those Objects in turn
through an iterator (generator)

Definition at line 484 of file store.py.

References cma.store.Store.constructobj().

Referenced by cma.store.Store.load_cypher_node().

Here is the call graph for this function:

Here is the caller graph for this function:

def cma.store.Store.load_cypher_query (   self,
  querystr,
  clsfact,
  params = None,
  maxcount = None 
)
Iterator returning results from a query translated into classes, and so on
Each iteration returns a namedtuple with node fields as classes, etc.
Note that 'clsfact' must be a class "factory" capable of translating any
type of node encountered into the corresponding objects.
Return result is a generator.

Definition at line 525 of file store.py.

References cma.store.Store._yielded_value(), and cma.store.Store.constructobj().

Here is the call graph for this function:

def cma.store.Store.load_in_related (   self,
  subj,
  rel_type,
  cls 
)

Definition at line 473 of file store.py.

References cma.store.Store._construct_obj_from_node().

Here is the call graph for this function:

def cma.store.Store.load_indexed (   self,
  index_name,
  key,
  value,
  cls 
)
Return the specified set of 'cls' objects from the given index
---------
Parameters:
index_name - name of index to retrieve objects from
key        - key value of nodes to be retrieved
value      - 'value' of nodes to be retrieved
cls        - a class to construct -- or a function to call
     which constructs the desired object

Definition at line 333 of file store.py.

References cma.store.Store._construct_obj_from_node().

Here is the call graph for this function:

def cma.store.Store.load_or_create (   self,
  cls,
  clsargs 
)
Analogous to 'save' - for loading an object or creating it if it
doesn't exist

Definition at line 386 of file store.py.

References cma.store.Store.callconstructor(), cma.store.Store.load(), and cma.store.Store.save().

Here is the call graph for this function:

def cma.store.Store.load_related (   self,
  subj,
  rel_type,
  cls 
)

Definition at line 459 of file store.py.

References cma.store.Store._construct_obj_from_node().

Here is the call graph for this function:

def cma.store.Store.lucene_escape (   query)
static

Definition at line 195 of file store.py.

def cma.store.Store.mark_dirty (   objself,
  attr 
)
static

Definition at line 656 of file store.py.

References cma.store.Store.clients.

def cma.store.Store.refresh (   self,
  subj 
)

Definition at line 327 of file store.py.

References cma.store.Store._construct_obj_from_node().

Here is the call graph for this function:

def cma.store.Store.relate (   self,
  subj,
  rel_type,
  obj,
  properties = None 
)
Define a 'rel_type' relationship subj-[:rel_type]->obj

Definition at line 396 of file store.py.

References cma.store.Store.readonly.

Referenced by cma.store.Store.relate_new().

Here is the caller graph for this function:

def cma.store.Store.relate_new (   self,
  subj,
  rel_type,
  obj,
  properties = None 
)
Define a 'rel_type' relationship subj-[:rel_type]->obj

Definition at line 409 of file store.py.

References cma.store.Store.newrels, and cma.store.Store.relate().

Here is the call graph for this function:

def cma.store.Store.safe_attrs (   subj)
static

Definition at line 636 of file store.py.

References cma.drawwithdot.type.

def cma.store.Store.save (   self,
  subj,
  node = None 
)
Save an object:
    - into a new node
    - into an existing node

    It will be indexed if its class is a known indexed class
not indexed if its class is not a known indexed class

    If the index is known to be a unique index, then it will
    be saved unique - otherwise it won't be unique

Definition at line 279 of file store.py.

References cma.store.Store._get_idx_key_value(), cma.store.Store._register(), cma.consts.CMAconsts.classkeymap, cma.store.Store.classkeymap, cma.store.Store.clients, cma.store.Store.is_uniqueindex(), cma.store.Store.readonly, cma.store.Store.save_indexed(), and cma.store.Store.save_unique().

Referenced by cma.store.Store.load(), and cma.store.Store.load_or_create().

Here is the call graph for this function:

Here is the caller graph for this function:

def cma.store.Store.save_indexed (   self,
  index_name,
  key,
  value,
  subj 
)

Definition at line 263 of file store.py.

References cma.store.Store._register(), and cma.store.Store.readonly.

Referenced by cma.store.Store.save(), and cma.store.Store.save_unique().

Here is the call graph for this function:

Here is the caller graph for this function:

def cma.store.Store.save_unique (   self,
  index_name,
  key,
  value,
  subj 
)

Definition at line 273 of file store.py.

References cma.store.Store.save_indexed().

Referenced by cma.store.Store.save().

Here is the call graph for this function:

Here is the caller graph for this function:

def cma.store.Store.separate (   self,
  subj,
  rel_type = None,
  obj = None 
)

Definition at line 425 of file store.py.

Referenced by cma.store.Store.delete().

Here is the caller graph for this function:

def cma.store.Store.separate_in (   self,
  subj,
  rel_type = None,
  obj = None 
)

Definition at line 444 of file store.py.

Referenced by cma.store.Store.delete().

Here is the caller graph for this function:

def cma.store.Store.transaction_pending (   self)

Field Documentation

cma.store.Store.batch
cma.store.Store.batchindex
cma.store.Store.classes

Definition at line 143 of file store.py.

Referenced by cma.store.Store.__str__(), and cma.store.Store.reset_stats().

cma.store.Store.classkeymap
cma.store.Store.create_node_count

Definition at line 161 of file store.py.

cma.store.Store.db

Definition at line 136 of file store.py.

Referenced by cma.store.Store.__str__(), and cma.store.Store.commit().

cma.store.Store.deletions
cma.store.Store.index_entry_count

Definition at line 163 of file store.py.

Referenced by cma.store.Store.node().

cma.store.Store.log = None
static

Definition at line 119 of file store.py.

cma.store.Store.LUCENE_RE = re.compile(r'([\-+&\|!\(\)\{\}[\]^"~\*?:\\])')
static

Definition at line 115 of file store.py.

cma.store.Store.newrels
cma.store.Store.node_deletion_count

Definition at line 165 of file store.py.

cma.store.Store.node_separate_count

Definition at line 166 of file store.py.

cma.store.Store.node_update_count

Definition at line 164 of file store.py.

Referenced by cma.store.Store.node().

cma.store.Store.readonly
cma.store.Store.relate_node_count

Definition at line 162 of file store.py.

cma.store.Store.uniqueindexmap

Definition at line 151 of file store.py.

Referenced by cma.store.Store.__str__(), and cma.store.Store.is_uniqueindex().


The documentation for this class was generated from the following file: