#!/usr/local/bin/xotclsh

package require xotcl::store::persistence
package require xotcl::mixinStrategy

PersistenceMgr jufpMgr
PersistenceMgr tclpMgr -dbPackage TclGdbmStorage
Class PersistenceTest -parameter {{countVar 0} {appendVar ""} pm}
PersistenceTest instproc init args {
  [self] mixinStrategy Persistent=Eager
  [self] persistenceMgr [[self] set pm]
  [self] persistent {countVar appendVar}
  next
}

PersistenceTest instproc incrCount {} {
  puts "in [self] countVar now is [[self] countVar]" 
  [self] incr countVar
}
PersistenceTest instproc append {x} {
  ::append [self]::appendVar $x
  puts "append is: [[self] appendVar]"
} 

PersistenceTest instproc test {} {
  # first we increment a counter:
  [self] incrCount
  # now we 5x append something to appendVar
  for {set i 0} {$i<5} {incr i} {
    [self] append a 
  }
  # now we list all keys in the database 
  puts "Variables stored in [[self] persistenceMgr].db: [[[self] persistenceMgr] list]"
  # now we delete append var
  puts "Deleting append:[[[self] persistenceMgr] delete [self]::appendVar]"
  # now we list the keys again 
  puts "Variables stored in [[self] persistenceMgr].db: [[[self] persistenceMgr] list]"
}

PersistenceTest persistenceJufTest -pm jufpMgr -init -test 
PersistenceTest persistenceTclTest -pm tclpMgr -init -test 

#PersistenceTest instproc count 