Source

jython-db4o / db4o / db4o.py

Diff from to

File db4o/db4o.py

 import com.db4o.Db4oEmbedded.newConfiguration
 import com.db4o.Db4oEmbedded.openFile
 import com.db4o.internal.StoredClassImpl
-import collections
 
 def readonlyConfiguration():
     ''' create a read only DB4O configuration object (to feed db()) '''
         pass
     return config
 
-def db4o(db4ofilename, db4oConfig = None):
+def db(db4ofilename, db4oConfig = None):
     ''' return db4o container for a file, optionally with a configuration (readonly, if not provided) '''
     if not db4oConfig: db4oConfig = readonlyConfiguration()
     return com.db4o.Db4oEmbedded.openFile(db4oConfig, db4ofilename)
 
-def db4oClasses(db, blacklist = BLACKLIST):
-    ''' generate StoredClass list for a given db4o container '''
-    classes = (c for c in db.storedClasses())
-    return (c for c in classes if not c.name.startswith(blacklist) if blacklist else classes)
+def dbClasses(db, blacklist = BLACKLIST):
+    ''' generate StoredClass list for a given db4o container, filtering out blacklist '''
+    return (c for c in db.storedClasses() if not c.name.startswith(blacklist))
 
-def db4oClass(db, o):
+def objClass(db, o):
     ''' return StoredClass for a given class name '''
     return o if isinstance(o, com.db4o.internal.StoredClassImpl) else db.storedClass(o)
 
-def db4oClasspath(db, o):
+def objClassFields(db, o):
+    ''' return instance fields for a given StoredClass '''
+    return objClass(db, o).storedFields
+
+def objClasspath(db, o):
     ''' generate full class lineage for a given StoredClass '''
-    c = db4oClass(db, o)
+    c = objClass(db, o)
     while c:
         yield c
         c = c.parentStoredClass
 
-def db4oClassFields(db, o):
-    ''' return instance fields for a given StoredClass '''
-    return dbClass(db, o).storedFields
-
-def db4oObjFields(db, o):
+def objFields(db, o):
     ''' return all fields for a given StoredClass (including parent fields [heritage order]) '''
-    fields = collections.deque()
-    for dbo in db4oClasspath(db, o):
-        f = dbo.storedFields
-        f.reverse()
-        fields.extendleft(f)
+    fields = []
+    [fields.extend(cls.storedFields) for cls in reversed(tuple(objClasspath(db, o)))]
     return tuple(fields)
 
-def db4oAll(db):
+def objByID(db, oid, depth = 2):
+    ''' return an activated object by ID '''
+    obj = db.getByID(oid)
+    db.activate(obj, depth)
+    return obj
+
+def objAll(db):
     ''' return all objects stored in this container '''
     return db.queryByExample(None)
 
-def db4oIDs(db, o = None):
+def objIDs(db, o = None):
     ''' return a list of all object IDs in this container, for a specified class (or all) '''
-    return db4oClass(db, o).IDs
+    return objClass(db, o).IDs
     
 def objCount(db, o = None):
     ''' return a count of objects in this container, for a specified class (or all) '''
-    return len(db4oIDs(db, o) if o else db4oAll(db).IDs)
+    return len(objIDs(db, o) if o else objAll(db).IDs)
 
-def objByID(db, oid):
-    ''' return an object by ID '''
-    obj = db.getByID(oid)
-    db.activate(obj, 2)
-    return obj
-