Wiki
Clone wikipymoult / daccess
#Data access
The module lowlevel.data_access
provides tools for acessing the data in a running application.
ObjectPool
-
ObjectPool
is a singleton holding a weak reference to every object created. It is used for immediate access strategy. -
instance_hook
is a hook to be set when usingObjectPool
. It adds objects to the pool when they are created. Setting this hook requires using our custom version of Pypy. When instantiating theObjectPool
this hook is set up automatically.
HeapWalker
The HeapWalker
class is to be extended to define a walker
specifically adapted to the application to be updated. It walks the
heap of the application to access the data and transform it.
When extending the HeapWalker
class, one has to define a
walk_<type>
method that will be called to walk data of <type>.
traverseHeap(walker,module_names)
walks the heap using walker on
each module whose name are in the list module_names.
DataAccessor
DataAccessor
is a class that can be used to access the data. Its
constructor takes the target class whose instance we want to access
and a string indicating the strategy we want to use (immediate or
progressive).
DataAccessor
is an iterator, meaning that we can use a for
loop to
iterate over every object it accesses. When iterating over a data
accessor using progressive startegy, it will hold each iteration
until a new object has been accessed.
⚠ Warning : The immediate strategy uses the ObjectPool
to access
objects. Remember to create the ObjectPool
before the objects
you want to access are created.
Getter and Setter routers
GetItemRouter
and SetItemRouter
are used by DataAccessor
when
using the progressive access strategy, to overload the __setattr__
and __getattribute__
methods of the target class. When called
(i.e. when accessing an attribute of objects of the target class),
these routers will add a reference to their caller to the data
accessor.
These routers are placed using the add_getter_router
and
add_setter_router
functions.
Eager and Lazy updates
-
setLazyUpdate(class,transformer)
starts a lazy update of objects of class class, applies transformer to them when accessed. This combines progressive access startegy and instant update startegy. -
startEagerUpdate(class,transformer)
start an eager update of ovjects of class class, applies transformer to them when accessed. This combines immediate access strategy and instant update strategy.
Updated