Class v.c.a.s.Store(Empowered):

Part of vmc.contrib.axiom.store View In Hierarchy

Implements interfaces: vmc.contrib.axiom.iaxiom.IBeneficiary

I am a database that Axiom Items can be stored in.

Store an item in me by setting its 'store' attribute to be me.

I can be created one of two ways:

    Store()                      # Create an in-memory database

    Store("/path/to/file.axiom") # create an on-disk database in the
                                 # directory /path/to/file.axiom

@ivar typeToTableNameCache: a dictionary mapping Item subclass type objects
to the fully-qualified sqlite table name where items of that type are
stored.  This cache is generated from the saved schema metadata when this
store is opened and updated when schema changes from other store objects
(such as in other processes) are detected.
Method __init__ Create a store.
Method attachToParent Undocumented
Method __repr__ Undocumented
Method findOrCreate Usage:
Method newFilePath Undocumented
Method newTemporaryFilePath Undocumented
Method newFile Open a new file somewhere in this Store's file area.
Method newDirectory Undocumented
Method checkTypeSchemaConsistency Called for all known types at database startup: make sure that what we know
Method whenFullyUpgraded Return a Deferred which fires when this Store has been fully upgraded.
Method getOldVersionOf Undocumented
Method findUnique Find an Item in the database which should be unique. If it is found,
Method findFirst Usage:
Method query Return a generator of instances of tableClass,
Method sum Undocumented
Method count Undocumented
Method batchInsert Create multiple items in the store without loading
Method changed Undocumented
Method checkpoint Undocumented
Method transact Undocumented
Method revert Undocumented
Method close Undocumented
Method avgms Undocumented
Method getTableName Retrieve the fully qualified name of the table holding items
Method getShortColumnName Retreive the column name for a particular attribute in this
Method getColumnName Retreive the fully qualified column name for a particular
Method getTypeID Retrieve the typeID associated with a particular table in the
Method getTableQuery Undocumented
Method getItemByID Retrieve an item by its storeID, and return it.
Method querySchemaSQL Undocumented
Method querySQL For use with SELECT (or SELECT-like PRAGMA) statements.
Method createSQL For use with auto-committing statements such as CREATE TABLE or CREATE
Method executeSchemaSQL Undocumented
Method executeSQL For use with UPDATE or INSERT statements.

Inherited from Empowered:

Method powerUp Installs a powerup (e.g. plugin) on an item or store.
Method powerDown Remove a powerup.
Method __conform__ For 'normal' interfaces, returns the first powerup found when doing
Method powerupsFor Returns powerups installed using powerUp, in order of descending
Method interfacesFor Undocumented
def _currentlyValidAsReferentFor(self, store):
necessary because I can be a target of attributes.reference()
def __init__(self, dbdir=None, filesdir=None, debug=False, parent=None, idInParent=None):
Create a store.
ParametersdbdirA name of an existing Axiom directory, or the name of a directory that does not exist yet which will be created as this Store is instantiated. If unspecified, this database will be kept in memory.
filesdirA name of a directory to keep files in for in-memory stores. An exception will be raised if both this attribute and dbdir are specified.
debugset to True if this Store should print out every SQL statement it sends to SQLite.
parent(internal) If this is opened using an axiom.substore.Substore, a reference to its parent.
idInParent(internal) If this is opened using an axiom.substore.Substore, the storeID of the item within its parent which opened it.
RaisesValueError if both dbdir and filesdir are specified
def _attachChild(self, child):
attach a child database, returning an identifier for it
def attachToParent(self):
Undocumented
def _initSchema(self):
Undocumented
def _startup(self):
Called during __init__. Check consistency of schema in database with classes in memory. Load all Python modules for stored items, and load version information for upgrader service to run later.
def _initdb(self, dbfname):
Undocumented
def __repr__(self):
Undocumented
def findOrCreate(self, userItemClass, __ifnew=None, **attrs):
Usage:

    s.findOrCreate(userItemClass [, function] [, x=1, y=2, ...])

Example:

    class YourItemType(Item):
        a = integer()
        b = text()
        c = integer()

    def f(x):
        print x, "-- it's new!"
    s.findOrCreate(YourItemType, f, a=1, b=u'2')

Search for an item with columns in the database that match the passed
set of keyword arguments, returning the first match if one is found,
creating one with the given attributes if not.  Takes an optional
positional argument function to call on the new item if it is new.
def newFilePath(self, *path):
Undocumented
def newTemporaryFilePath(self, *path):
Undocumented
def newFile(self, *path):
Open a new file somewhere in this Store's file area.
Parameterspatha sequence of path segments.
Returnsan AtomicFile.
def newDirectory(self, *path):
Undocumented
def checkTypeSchemaConsistency(self, actualType):
Called for all known types at database startup: make sure that what we know (in memory) about this type is
def _prepareOldVersionOf(self, typeID, typename, version):
Note that this database contains old versions of a particular type. Create the appropriate dummy item subclass.
def _upgradeOneThing(self):
Upgrade one Item; return True if there may be more work to do, False if this store is definitely fully upgraded.
def _upgradeEverything(self):
Undocumented
def whenFullyUpgraded(self):
Return a Deferred which fires when this Store has been fully upgraded.
def getOldVersionOf(self, typename, version):
Undocumented
def findUnique(self, tableClass, comparison=None, default=_noItem):
Find an Item in the database which should be unique. If it is found, return it. If it is not found, return 'default' if it was passed, otherwise raise errors.ItemNotFound. If more than one item is found, raise errors.DuplicateUniqueItem.
Parameterscomparisonimplementor of iaxiom.IComparison.
defaultvalue to use if the item is not found.
def findFirst(self, tableClass, comparison=None, offset=None, sort=None, default=None):
Usage:

    s.findFirst(tableClass [, query arguments except 'limit'])

Example:

    class YourItemType(Item):
        a = integer()
        b = text()
        c = integer()
    ...
    it = s.findFirst(YourItemType,
                     AND(YourItemType.a == 1,
                         YourItemType.b == u'2'),
                         sort=YourItemType.c.descending)

Search for an item with columns in the database that match the passed
comparison, offset and sort, returning the first match if one is found,
or the passed default (None if none is passed) if one is not found.
def query(self, tableClass, comparison=None, limit=None, offset=None, sort=None):

Return a generator of instances of tableClass, or tuples of instances if tableClass is a tuple of classes.

Examples:
   fastCars = s.query(Vehicle,
       axiom.attributes.AND(
           Vehicle.wheels == 4,
           Vehicle.maxKPH > 200),
       limit=100,
       sort=Vehicle.maxKPH.descending)

   quotesByClient = s.query( (Client, Quote),
       axiom.attributes.AND(
           Client.active == True,
           Quote.client == Client.storeID,
           Quote.created >= someDate),
       limit=10,
       sort=(Client.name.ascending,
             Quote.created.descending))
ParameterstableClassa subclass of Item to look for instances of, or a tuple of subclasses.
comparisona provider of IComparison, or None, to match all items available in the store. If tableClass is a tuple, then the comparison must refer to all Item subclasses in that tuple, and specify the relationships between them.
limitan int to limit the total length of the results, or None for all available results.
offsetan int to specify a starting point within the available results, or None to start at 0.
sortan ISort, something that comes from an SQLAttribute's 'ascending' or 'descending' attribute.
Returnsan ItemQuery object, which is an iterable of Items or tuples of Items, according to tableClass.
def sum(self, summableAttribute, *a, **k):
Undocumented
def count(self, *a, **k):
Undocumented
def batchInsert(self, itemType, itemAttributes, dataRows):

Create multiple items in the store without loading corresponding Python objects into memory.

the items' stored callback will not be called.

Example:
   myData = [(37, u"Fred",  u"Wichita"),
             (28, u"Jim",   u"Fresno"),
             (43, u"Betty", u"Dubuque")]
   myStore.batchInsert(FooItem,
                       [FooItem.age, FooItem.name, FooItem.city],
                       myData)
ParametersitemTypean Item subclass to create instances of.
itemAttributesan iterable of attributes on the Item subclass.
dataRowsan iterable of iterables, each the same length as itemAttributes and containing data corresponding to each attribute in it.
ReturnsNone.
def _loadedItem(self, itemClass, storeID, attrs):
Undocumented
def changed(self, item):
Undocumented
def checkpoint(self):
Undocumented
def transact(self, f, *a, **k):
Undocumented
def _begin(self):
Undocumented
def _setupTxnState(self):
Undocumented
def _commit(self):
Undocumented
def _postCommitHook(self):
Undocumented
def _rollback(self):
Undocumented
def revert(self):
Undocumented
def _inMemoryRollback(self):
Undocumented
def _cleanupTxnState(self):
Undocumented
def close(self, _report=True):
Undocumented
def avgms(self, l):
Undocumented
def _indexNameOf(self, tableClass, attrname):
Undocumented
def _tableNameFor(self, typename, version):
Undocumented
def getTableName(self, tableClass):
Retrieve the fully qualified name of the table holding items
of a particular class in this store.  If the table does not
exist in the database, it will be created as a side-effect.

@param tableClass: an Item subclass

@raises L{axiom.errors.ItemClassesOnly}: if an object other than a subclass of Item is passed.

@return: a string
def getShortColumnName(self, attribute):
Retreive the column name for a particular attribute in this store. The attribute must be bound to an Item subclass (its type must be valid). If the underlying table does not exist in the database, it will be created as a side-effect.
ParameterstableClassan Item subclass
Returns

a string

XXX: The current implementation does not really match the description, which is actually more restrictive. But it will be true soon, so I guess it is ok for now. The reason is that this method is used during table creation.
def getColumnName(self, attribute):
Retreive the fully qualified column name for a particular attribute in this store. The attribute must be bound to an Item subclass (its type must be valid). If the underlying table does not exist in the database, it will be created as a side-effect.
ParameterstableClassan Item subclass
Returnsa string
def getTypeID(self, tableClass):
Retrieve the typeID associated with a particular table in the in-database schema for this Store. A typeID is an opaque integer representing the Item subclass, and the associated table in this Store's SQLite database.
ParameterstableClassa subclass of Item
Returnsan integer
def _maybeCreateTable(self, tableClass, key):

A type ID has been requested for an Item subclass whose table was not present when this Store was opened. Attempt to create the table, and if that fails because another Store object (perhaps in another process) has created the table, re-read the schema. When that's done, return the typeID.

This method is internal to the implementation of getTypeID. It must be run in a transaction.
ParameterstableClassan Item subclass
keya 2-tuple of the tableClass's typeName and schemaVersion
Returnsa typeID for the table; a new one if no table exists, or the existing one if the table was created by another Store object referencing this database.
def _createIndexesFor(self, tableClass):
Undocumented
def getTableQuery(self, typename, version):
Undocumented
def getItemByID(self, storeID, default=_noItem, autoUpgrade=True):

Retrieve an item by its storeID, and return it.

Note: most of the failure modes of this method are catastrophic and should not be handled by application code. The only one that application programmers should be concerned with is KeyError. They are listed for educational purposes.
ParametersstoreIDan int which refers to the store.
defaultif passed, return this value rather than raising in the case where no Item is found.
Returnsan Item, or the given default, if it was passed and no row corresponding to the given storeID can be located in the database.
RaisesTypeErrorif storeID is not an integer.
UnknownItemTypeif the storeID refers to an item row in the database, but the corresponding type information is not available to Python.
RuntimeErrorif the found item's class version is higher than the current application is aware of. (In other words, if you have upgraded a database to a new schema and then attempt to open it with a previous version of the code.)
KeyErrorif no item corresponded to the given storeID.
def _normalizeSQL(self, sql):
Undocumented
def querySchemaSQL(self, sql, args=()):
Undocumented
def querySQL(self, sql, args=()):
For use with SELECT (or SELECT-like PRAGMA) statements.
def _queryandfetch(self, sql, args):
Undocumented
def createSQL(self, sql, args=()):
For use with auto-committing statements such as CREATE TABLE or CREATE INDEX.
def _execSQL(self, sql, args):
Undocumented
def executeSchemaSQL(self, sql, args=()):
Undocumented
def executeSQL(self, sql, args=()):
For use with UPDATE or INSERT statements.
API Documentation for vodafone-mobile-connect-card-driver-for-linux, generated by pydoctor at 2008-01-10 13:06:31.