OpFlex Framework  1.7.0
opflex::modb::Mutator Class Reference

A mutator represents a set of changes to apply to the data store. More...

#include <opflex/modb/Mutator.h>

Public Member Functions

 Mutator (const std::string &owner)
 Create a mutator that will work with the default framework instance and owner. More...
 
 Mutator (ofcore::OFFramework &framework, const std::string &owner)
 Create a mutator that will work with the provided framework instance and owner. More...
 
 ~Mutator ()
 Destroy the Mutator. More...
 
void commit ()
 Commit the changes stored in the mutator to the object store. More...
 
OF_SHARED_PTR< mointernal::ObjectInstance > & modify (class_id_t class_id, const URI &uri)
 Create a new mutable object with the given URI which is a copy of any existing object with the specified URI. More...
 
void remove (class_id_t class_id, const URI &uri)
 Delete the child object specified along with its link to its parents. More...
 
OF_SHARED_PTR< mointernal ::ObjectInstance > & addChild (class_id_t parent_class, const URI &parent_uri, prop_id_t parent_prop, class_id_t child_class, const URI &child_uri)
 Create a new child object with the specified class and URI, and make it a child of the given parent. More...
 

Friends

class MutatorImpl
 

Detailed Description

A mutator represents a set of changes to apply to the data store.

When modifying data through the managed object accessor classes, changes are not actually written into the store, but rather are written into the Mutator registered using the framework in a thread-local variable. These changes will not become visible until the mutator is committed by calling commit()

The changes are applied to the data store all at once but not necessarily guaranteed to be atomic. That is, a read in another thread could see some objects updated but not others. Each individual object update is applied atomically, however, so the fields within that object will either all be modified or none.

This is most similar to a database transaction with an isolation level set to read uncommitted.

Constructor & Destructor Documentation

◆ Mutator() [1/2]

opflex::modb::Mutator::Mutator ( const std::string &  owner)

Create a mutator that will work with the default framework instance and owner.

Parameters
ownerthe owner string that will control which fields can be modified.

◆ Mutator() [2/2]

opflex::modb::Mutator::Mutator ( ofcore::OFFramework framework,
const std::string &  owner 
)

Create a mutator that will work with the provided framework instance and owner.

Parameters
frameworkthe framework instance that will be modified
ownerthe owner string that will control which fields can be modified.

◆ ~Mutator()

opflex::modb::Mutator::~Mutator ( )

Destroy the Mutator.

Any uncommitted changes will be lost.

Member Function Documentation

◆ addChild()

OF_SHARED_PTR<mointernal ::ObjectInstance>& opflex::modb::Mutator::addChild ( class_id_t  parent_class,
const URI parent_uri,
prop_id_t  parent_prop,
class_id_t  child_class,
const URI child_uri 
)

Create a new child object with the specified class and URI, and make it a child of the given parent.

If the object already exists, get a mutable copy of that object.

Parameters
parent_classthe class ID of the parent
parent_urithe URI of the parent object
parent_propthe property ID in the parent object
child_classthe class ID of the child
child_urithe URI of the child

Referenced by opflex::modb::mointernal::MO::addChild().

◆ commit()

void opflex::modb::Mutator::commit ( )

Commit the changes stored in the mutator to the object store.

If this method is not called, these changes will simply be lost. After you call commit(), you can continue to make changes using the same mutator which will be effectively a new "transaction".

◆ modify()

OF_SHARED_PTR<mointernal::ObjectInstance>& opflex::modb::Mutator::modify ( class_id_t  class_id,
const URI uri 
)

Create a new mutable object with the given URI which is a copy of any existing object with the specified URI.

Parameters
class_idthe class ID for the object
uriThe URI for the object

Referenced by opflex::modb::mointernal::MO::createRootElement().

◆ remove()

void opflex::modb::Mutator::remove ( class_id_t  class_id,
const URI uri 
)

Delete the child object specified along with its link to its parents.

If the child object has any children that are not removed, then they will be garbage-collected at some later time.

Parameters
class_idthe class ID for the object
urithe URI to remove

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