Sean Summers  committed 36c9556

object decoding in base library

  • Participants
  • Parent commits a99f0fb

Comments (0)

Files changed (1)

File db4o/

 import com.db4o.Db4oEmbedded.newConfiguration
 import com.db4o.Db4oEmbedded.openFile
 import com.db4o.internal.StoredClassImpl
+import com.db4o.reflect.generic.GenericObject
 def readonlyConfiguration():
     ''' create a read only DB4O configuration object (to feed db()) '''
     ''' return a count of objects in this container, for a specified class (or all) '''
     return len(objIDs(db, o) if o else objAll(db).IDs)
+def fieldValue(field, obj):
+    ''' given a field and object, return a tuple of values, recursing if necessary '''
+    value = field.get(obj)
+    if isinstance(value, com.db4o.reflect.generic.GenericObject):
+        value = tuple(fieldValue(f, value) for f in value.genericClass.declaredFields)
+    return (, value)
+def objTuple(db, o):
+    ''' return a tuple for an object, suitable for dict() '''
+    if not isinstance(o, (com.db4o.internal.StoredClassImpl, com.db4o.reflect.generic.GenericObject)):
+        o = objByID(db, o)
+    return [fieldValue(f, o) for f in objFields(db, o)]