public class CoreFactory extends Object
The CoreFactory will be responsible for setting up the real connection to the database and the intialization of the EntityManager. It will also be the central reference for the NullDriver and NullConnection since they will add every query they receive to the list maintained by the CoreFactory.
Bear in mind that the CoreFactory is not intended to be thread-safe.
Constructor and Description |
---|
CoreFactory() |
Modifier and Type | Method and Description |
---|---|
static javax.persistence.EntityManager |
getEntityManager()
Returns a reference to the JPA EntityManager.
|
static CoreProperties |
getProperties()
Returns the properties containing all the settings for this application.
|
static List<String> |
getQueries() |
static Connection |
getRealConnection() |
static Driver |
getRealDriver() |
static void |
shutdown()
Closes the entity manager and databse connection.
|
public static final CoreProperties getProperties()
public static javax.persistence.EntityManager getEntityManager() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException
At first call, the EntityManager will be initialized. In order to correctly initialize, the CoreProperties must contains at least the following information:
EntityFinder
)
Please bare in mind that the EntityManager will make a connection using the NullDriver, it will never be able to execute statements on the database. It does require a database connection to gather information about your database's capabilities, this connection will be set read-only. The databse itself may be emtpy.
It is important to close the database connection afterwards using the shutdown()
method.
ClassNotFoundException
- if the databse driver is not found on the classpathInstantiationException
- if failed to initliaze the database driverIllegalAccessException
- if failed to initliaze the database driverSQLException
- if failed to connect to the database or failed to set the connection to read-only mode.public static void shutdown() throws SQLException
SQLException
- if failed to close the connection.public static Connection getRealConnection()
public static Driver getRealDriver()
Copyright © 2012-2013. All Rights Reserved.