net.craftforge.commons.database.memory
Class InMemoryDbManager

java.lang.Object
  extended by net.craftforge.commons.database.memory.InMemoryDbManager

public class InMemoryDbManager
extends Object

An in-memory database manager manages several in-memory database instances of the same database setup. This allows test- and demo-databases which can be booted from the scratch with the same scheme and data but are exclusive for users or processes although running at the same time.

The database in-memory manager is unique in respect an SQL setup-script. All databases are setup using this setup-script. An in-memory database itself is unique in respect to its name within an in-memory manager.

It is to the user of this class to find an appropriate way of naming the databases in a way which makes them exclusive in the context of their purpose. Examples: thread id, user id, remote ip address (Base64 encoded).

Since:
02.08.11
Author:
Christian Bick

Method Summary
 boolean existsInMemoryDb(String databaseName)
          Whether an in-memory database with the given database name is already managed by this manager or not.
 org.hibernate.ejb.Ejb3Configuration getConfiguration()
          Gets the EJB3 configuration used by this in-memory manager to create entity-manager factories.
protected  String[] getDbSetupStatements()
          Gets the database setup statements used to set up in-memory databases instances.
 InMemoryDb getInMemoryDb(String databaseName)
          Gets an in-memory database with the given name.
 InMemoryDb getInMemoryDb(String databaseName, long timeout, long timeoutCheckInterval)
          Gets an in-memory database with the given name.
static InMemoryDbManager getInstance(String dbSetupScriptResource, org.hibernate.ejb.Ejb3Configuration configuration)
          Gets or creates and gets The in-memory database manager associated to the given database setup script resource.
protected  void removeInMemoryDb(String databaseName)
          Removes the in-memory database with the given database name from the entity manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static InMemoryDbManager getInstance(String dbSetupScriptResource,
                                            org.hibernate.ejb.Ejb3Configuration configuration)
Gets or creates and gets The in-memory database manager associated to the given database setup script resource.

Parameters:
dbSetupScriptResource - The database setup script resource
configuration - The EJB3 configuration for the entity-manager factory creation
Returns:
The in-memory database manager

getInMemoryDb

public InMemoryDb getInMemoryDb(String databaseName)
Gets an in-memory database with the given name. The database instance will be created if it has not already been existing.

Parameters:
databaseName - The database name
Returns:
The in-memory database

getInMemoryDb

public InMemoryDb getInMemoryDb(String databaseName,
                                long timeout,
                                long timeoutCheckInterval)
Gets an in-memory database with the given name. The database instance will be created if it has not already been existing. The instance will be destroyed after the given timeout and if the timeout has already been reaches is checked in the given interval.

Parameters:
databaseName - The database name
timeout - The timeout (in milliseconds)
timeoutCheckInterval - (in milliseconds)
Returns:
The in-memory database

existsInMemoryDb

public boolean existsInMemoryDb(String databaseName)
Whether an in-memory database with the given database name is already managed by this manager or not.

Parameters:
databaseName - The database name
Returns:
Whether it is already managed or not

getConfiguration

public org.hibernate.ejb.Ejb3Configuration getConfiguration()
Gets the EJB3 configuration used by this in-memory manager to create entity-manager factories.

Returns:
The EJB3 configuration

getDbSetupStatements

protected String[] getDbSetupStatements()
Gets the database setup statements used to set up in-memory databases instances.

Returns:
The SQL statements

removeInMemoryDb

protected void removeInMemoryDb(String databaseName)
Removes the in-memory database with the given database name from the entity manager.

Parameters:
databaseName - The database name


Copyright © 2011. All Rights Reserved.