|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.marringtons.object.Database
The DAO system uses this class for database wide control for procedures such as DAO association, opening, closing and backing up.It can also be used to manipulate a single open database. It also has a method for DAO access so that the DAO object can be pure data transfer.
Database db; db = Database.resetDefaultDatabase(); // go back to primary database for new objects as default db = Database.defaultDatabase(); // retrieve the current default database Database db2 = Database.get( Database.defaultDatabase().dataFile.file.file.getAbsolutePath()); assertTrue( db == db2); db = associateDatabase( "myStaticDB", true); // set a default to a new known database file - used by associate(); db.associate( myReferenceData.class); // to the above read-only database, index size 1 million or from ini file db.associate( myReferenceData.class, 10000); // same as above, but assuming a small number of records String[] dbs = Database.listDatabases(); assertTrue( dbs[0].endsWith( "primary.database"); if (atMidnight) Database.flushDatabases(); // write all to disk (closes all to reopen when needed) db.backup(); // backs up the default database Database.backupAll(); // backs up all open databases ZipOutputStream zip = new ZipOutputStream( Output.makeUnique( "testBackup", "zip"), false); db.backup( zip); // backs up the default database to an archive db.restore( "mydb.xml"); db.restore( myFileReader); Access access = Dabatase.access( myDAO); access.commit(); Database.closeDatabases(); // always call before program exits.
| Field Summary | |
String |
fileName
Name of the file that contains this database. |
| Method Summary | |
com.marringtons.object.Database.Association |
associate(Class dataClass)
Associate a DAO with a known database database. |
com.marringtons.object.Database.Association |
associate(Class dataClass,
int indexSizeEstimate)
Associate a DAO with a known database database. |
String |
backup()
Back up the complete default database |
String |
backup(ZipOutputStream zip)
Back up the complete default database to a unique file as XML. |
void |
clear()
Empty database of contents. |
static void |
closeDatabases()
Called before program exits to make sure all systems are flushed. |
static void |
flushDatabases()
Make sure changes on all open databases are committed to disk for perpetuity. |
static Database |
get(String name)
retrieve the database for a known file from the cache. |
static Database |
get(String name,
boolean readOnly)
Let the DAO system know of databases that will be used by the program. |
boolean |
isOpen()
Check to see if the database supplied exists and is open. |
static String[] |
listDatabases()
Retrieve an array of open databases. |
static Database |
resetDefaultDatabase()
All new DAOs after this point will be placed back in the default database. |
void |
restore(FileReader fileReader)
Restore a database from an XML backup file. |
void |
restore(String name)
Restore a database from an XML backup file. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public String fileName
| Method Detail |
public static Database resetDefaultDatabase()
throws IOException
IOExceptionpublic boolean isOpen()
public static Database get(String name)
throws IOException
name - File name for the database.
IOException
public static Database get(String name,
boolean readOnly)
throws IOException
name - path name of database.readOnly - true if database for reading only (dictionary).
IOExceptionpublic static String[] listDatabases()
public static void closeDatabases()
public static void flushDatabases()
public com.marringtons.object.Database.Association associate(Class dataClass)
dataClass - class of the object to be persisted in the database
public com.marringtons.object.Database.Association associate(Class dataClass,
int indexSizeEstimate)
dataClass - class of the object to be persisted in the databaseindexSizeEstimate - a guess on number of records that require indexing.
public String backup()
throws IllegalArgumentException,
IOException,
IllegalAccessException,
InstantiationException
IOException
InstantiationException
IllegalAccessException
IllegalArgumentException
public String backup(ZipOutputStream zip)
throws IllegalArgumentException,
IOException,
IllegalAccessException,
InstantiationException
zip - stream to write XML to backup to using the database name
IOException
InstantiationException
IllegalAccessException
IllegalArgumentException
public void restore(FileReader fileReader)
throws XMLexception,
IOException
fileReader - stream containing XML backup
IOException
XMLexception
public void clear()
throws IOException
IOException
public void restore(String name)
throws XMLexception,
IOException
name - of XML backup file
IOException
XMLexception
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||