|
PersistentObject
class.PersistentObject
, a databean has the
following characteristics:init
methods
(see the advanced topics regarding the few implications)get
an set
methods that take the property name as argument
and perform actual data storage access.public class Employee extends PersistentObject {
public String getName() { return
(String)get("name"); }
public void setName(String s) { set("name",s); }
public Department getDepartment() { return
(Department)get("department"); }
public void setDepartment(Department d) {
set("department",d); }
public String getLocation() { return
(String)get("location"); }
public void setLocation(String s) {
set("location",s); }
public double getSalary() { return
((Double)get("salary")).doubleValue(); }
public void setSalary(double d) { set("salary",new
Double(d)); }
public Employee getManager() { return
(Employee)get("manager"); }
public void setManager(Employee e) {
set("manager",e); }
public String getJob() { return (String)get("job"); }
public void setJob(String s) { set("job",s); }
}
Department
is
another persistent type of our example.)Serializable
java
class.new
call, but
instead by calling one of the create
methods of the Connection
object (obtaining a connection and using its transaction facilities
is covered
in the suitable chapter): PersistentObject create(String name);
PersistentObject create(Class clazz);
PersistentObject create(Class clazz, Class types[],
Object args[]);
PersistentArray create(Class componentType, int
length);
PersistentArray create(Object component[]);
init
method, if presentPersistentObject
's
subclass NotifiedObject
. Client
objects register themselves as PropertyChangeListener
s or
VetoableChangeListener
s, and receive PropertyChangeEvent
s
accordingly. This mechanism emulates the trigger concept of relational
databases.init
method in
the advanced topics, as NotifiedObject
is concerned.
alloc()
call and
freed using free()
. There are two memory models available
: 32 and 64 bits. The default is 64 bits, with a total addressed space
of 2^64 bytes. A single object image is limited to 2^32 bytes in both
memory models.gc()
call (or also when the databeans server is restarted)Connections.getConnection("//[host]/store");
Connection
object are
very similar to those of a java.sql.Connection
: int getTransactionIsolation();
void setTransactionIsolation(int level);
boolean isReadOnly();
void setReadOnly(boolean readOnly);
boolean isAutoCommit();
void setAutoCommit(boolean autoCommit);
void commit();
void rollback();
void close();
boolean isClosed();
XAResource getXAResource();
Object root();
void setRoot(Object obj);
new
Date()
for instance or anything from it to domain models of
arbitrary complexity.
java -classpath databeans.jar bsh.Interpreter bsh/import.bsh [file.xml]
Connections.getAdminConnection("//[host]/store");
PersistentSystem system();
void changePassword(String username, String
password);
void changePassword(String username, String
oldPassword, String newPassword);
void addUser(String username, String password);
void deleteUser(String username);
void inport(String name);
void export(String name);
void shutdown();
void gc();
long allocatedSpace();
long maxSpace();
init
methods. The re-creation is achieved by
the implicit no-arg constructor. The following rules must be obeyed:
public
, as per java rules ; it does
nothinginit
method can be omitted, in which
case one with no arguments will be inherited from PersistentObject
init
methods can take any number of
arguments of
any types.
init
method, to
call the superclass' no-arg init
if no other is
specified, and in first place, to emulate the implicit call to super()
that takes place in regular constructors. See for instance the case of NotifiedObject
,
whose init
has initializations to perform (namely
create a PropertyChangeSupport
and a VetoableChangeSupport
).
PersistentException
will be
thrown when the access attempt is made (either for reading or writing)ClassCastException
will be thrown when a read access attempt is made (the write access
will still work, except for primitive types)modified on Sat Mar 1 2008