oscript.data
Class Database

java.lang.Object
  extended byoscript.data.Value
      extended byoscript.data.OObject
          extended byoscript.data.Database
All Implemented Interfaces:
java.io.Serializable

public class Database
extends OObject

A database provides persistant storage.... for example

    var cache = new Database("cache.db");
    cache.foo.bar = "something";
 

Author:
Rob Clark (rob@ti.com)
See Also:
Serialized Form

Field Summary
static java.lang.String[] MEMBER_NAMES
           
static java.lang.String PARENT_TYPE_NAME
           
static Value TYPE
          The type object for an instance of Object.
static java.lang.String TYPE_NAME
           
 
Fields inherited from class oscript.data.OObject
EMPTY_EXPR_LIST_EVALUATOR
 
Fields inherited from class oscript.data.Value
DEBUG, NULL, UNDEFINED
 
Constructor Summary
Database(AbstractFile file)
          Class Constructor.
Database(AbstractFile file, boolean sideEffects)
          Class Constructor.
Database(AbstractFile file, java.lang.ClassLoader loader)
          Class Constructor.
Database(AbstractFile file, java.lang.ClassLoader loader, boolean sideEffects)
          Class Constructor.
Database(MemberTable args)
          Class Constructor.
 
Method Summary
protected  void finalize()
          Make sure we flush before we're gc'd.
 void flush()
          Flush contents to file.
 Value get(java.lang.String key)
           
 Value get(Value key)
          Get an entry from the database.
 Value getMember(int id, boolean exception)
          Get a member of this object.
protected  Value getTypeImpl()
          Get the type of this object.
 java.util.Iterator keys()
           
protected  void populateMemberSet(java.util.Set s, boolean debugger)
          Derived classes that implement getMember(int, boolean) should also implement this.
 void put(java.lang.String key, Value val)
           
 void put(Value key, Value val)
          Put an entry into the database.
 void remove(java.lang.String key)
           
 void remove(Value key)
           
 
Methods inherited from class oscript.data.OObject
castToString
 
Methods inherited from class oscript.data.Value
_getTypeMember, _populateTypeMemberSet, bopBitwiseAnd, bopBitwiseAndR, bopBitwiseOr, bopBitwiseOrR, bopBitwiseXor, bopBitwiseXorR, bopCast, bopCastR, bopDivide, bopDivideR, bopEquals, bopEqualsR, bopGreaterThan, bopGreaterThanOrEquals, bopGreaterThanOrEqualsR, bopGreaterThanR, bopInstanceOf, bopInstanceOfR, bopLeftShift, bopLeftShiftR, bopLessThan, bopLessThanOrEquals, bopLessThanOrEqualsR, bopLessThanR, bopLogicalAnd, bopLogicalAndR, bopLogicalOr, bopLogicalOrR, bopMinus, bopMinusR, bopMultiply, bopMultiplyR, bopNotEquals, bopNotEqualsR, bopPlus, bopPlusR, bopRemainder, bopRemainderR, bopSignedRightShift, bopSignedRightShiftR, bopUnsignedRightShift, bopUnsignedRightShiftR, callAsConstructor, callAsConstructor, callAsConstructor, callAsExtends, callAsExtends, callAsExtends, callAsFunction, callAsFunction, callAsFunction, castToBoolean, castToExactNumber, castToInexactNumber, castToJavaObject, elementAt, elementsAt, getMember, getMember, getMember, getMember, getMember, getMonitor, getType, getTypeMember, getTypeMember, isA, length, memberSet, noSuchMember, opAssign, populateTypeMemberSet, readExternal, toString, unhand, uopBitwiseNot, uopDecrement, uopIncrement, uopLogicalNot, uopMinus, uopPlus, writeExternal
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE

public static final Value TYPE
The type object for an instance of Object.


PARENT_TYPE_NAME

public static final java.lang.String PARENT_TYPE_NAME
See Also:
Constant Field Values

TYPE_NAME

public static final java.lang.String TYPE_NAME
See Also:
Constant Field Values

MEMBER_NAMES

public static final java.lang.String[] MEMBER_NAMES
Constructor Detail

Database

public Database(AbstractFile file)
Class Constructor.

Parameters:
file - the file to read from and store to

Database

public Database(AbstractFile file,
                boolean sideEffects)
Class Constructor.

Parameters:
file - the file to read from and store to
sideEffects - can be set to false if you do not expect side effects (ie. member of database is not mutable). If true, the database is always flushed at exit, regardless of whether there have been any put() operations.

Database

public Database(AbstractFile file,
                java.lang.ClassLoader loader)
Class Constructor.

Parameters:
file - the file to read from and store to
loader - an optional class loader used to resolve class references when loading the database from disk

Database

public Database(AbstractFile file,
                java.lang.ClassLoader loader,
                boolean sideEffects)
Class Constructor.

Parameters:
file - the file to read from and store to
loader - an optional class loader used to resolve class references when loading the database from disk
sideEffects - can be set to false if you do not expect side effects (ie. member of database is not mutable). If true, the database is always flushed at exit, regardless of whether there have been any put() operations.

Database

public Database(MemberTable args)
Class Constructor. This is the constructor that gets called via an BuiltinType instance.

Parameters:
args - arguments to this constructor
Throws:
PackagedScriptObjectException(Exception) - if wrong number of args
Method Detail

finalize

protected void finalize()
Make sure we flush before we're gc'd.


getTypeImpl

protected Value getTypeImpl()
Get the type of this object. The returned type doesn't have to take into account the possibility of a script type extending a built-in type, since that is handled by Value.getType().

Overrides:
getTypeImpl in class OObject
Returns:
the object's type

flush

public void flush()
Flush contents to file.


get

public Value get(Value key)
Get an entry from the database. The key is a "." seperated path, for example "foo.bar".

Parameters:
key - the key
Returns:
the value, or null if none.

get

public Value get(java.lang.String key)

put

public void put(Value key,
                Value val)
Put an entry into the database. The key is a "." seperated path, for example "foo.bar".

Parameters:
key - the key
val - the new value

put

public void put(java.lang.String key,
                Value val)

keys

public java.util.Iterator keys()

remove

public void remove(Value key)

remove

public void remove(java.lang.String key)

getMember

public Value getMember(int id,
                       boolean exception)
                throws PackagedScriptObjectException
Get a member of this object.

Overrides:
getMember in class OObject
Parameters:
id - the id of the symbol that maps to the member
exception - whether an exception should be thrown if the member object is not resolved
Returns:
a reference to the member
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException(NoSuchMemberException)
PackagedScriptObjectException

populateMemberSet

protected void populateMemberSet(java.util.Set s,
                                 boolean debugger)
Derived classes that implement getMember(int, boolean) should also implement this.

Overrides:
populateMemberSet in class OObject
Parameters:
s - the set to populate
debugger - true if being used by debugger, in which case both public and private/protected field names should be returned
See Also:
getMember(int, boolean)