|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Thread
net.craftforge.commons.database.memory.InMemoryDb
public class InMemoryDb
An in-memory db is a wrapper for holding derby in-memory database instances. An in-memory db will be destroyed after a certain timeout has been reached, so it acts as temporary database which is only used for a certain time. The timeout is reset to its initial value with entity manager factory call. So an in-memory database keeps alive as long as it is frequently used.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.lang.Thread |
|---|
Thread.State, Thread.UncaughtExceptionHandler |
| Field Summary | |
|---|---|
static long |
DEFAULT_INITIAL_TIMEOUT
Default maximum idle time before a database is dropped: 1 hour. |
static long |
DEFAULT_TIMEOUT_CHECK_INTERVAL
Default update interval to check if the database should be dropped: 10 seconds. |
| Fields inherited from class java.lang.Thread |
|---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
|---|---|
protected |
InMemoryDb(InMemoryDbManager manager,
String databaseName,
long timeout,
long timeoutCheckInterval)
Create a new in memory-db with the given database name. |
| Method Summary | |
|---|---|
protected javax.persistence.EntityManagerFactory |
buildEntityManagerFactory()
Builds an entity manager factory associated to this in-memory database using the EJB configuration of the in-memory database manager. |
protected org.hibernate.SessionFactory |
buildSessionFactory()
Builds a hibernate session factory associated to this in-memory database for the database setup. |
protected void |
destroyDatabase()
Destroys an associated Derby in-memory database instance. |
protected void |
executeStatements(org.hibernate.Session session,
String[] statements)
Executes all given SQL statements using the given hibernate session. |
javax.persistence.EntityManagerFactory |
getEntityManagerFactory()
Gets the entity-manager factory creating entity-managers for entities persisted in this database. |
void |
run()
Sets up the database and then waits until the timeout is reached |
protected void |
setupDatabase()
Sets up an associated Derby in-memory database instance and executes the SQL setup script of the in-memory database manager. |
protected boolean |
waitForCreationCompleted()
The first process calling this method will trigger the creation of a Derby in-memory database. |
protected void |
waitForTimeout()
Waits for the timeout to be reaches by frequently checking if the timeout has already been reached an decreasing the remaining time. |
| Methods inherited from class java.lang.Thread |
|---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final long DEFAULT_INITIAL_TIMEOUT
public static final long DEFAULT_TIMEOUT_CHECK_INTERVAL
| Constructor Detail |
|---|
protected InMemoryDb(InMemoryDbManager manager,
String databaseName,
long timeout,
long timeoutCheckInterval)
manager - The in-memory database manager for this databasedatabaseName - The database nametimeout - The timeout in millisecondstimeoutCheckInterval - The interval to check for timeout in milliseconds| Method Detail |
|---|
public void run()
run in interface Runnablerun in class Threadpublic javax.persistence.EntityManagerFactory getEntityManagerFactory()
protected boolean waitForCreationCompleted()
protected void setupDatabase()
protected void waitForTimeout()
protected void destroyDatabase()
protected javax.persistence.EntityManagerFactory buildEntityManagerFactory()
protected org.hibernate.SessionFactory buildSessionFactory()
protected void executeStatements(org.hibernate.Session session,
String[] statements)
session - The hibernate sessionstatements - The SQL statements
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||