Search in sources :

Example 1 with EngineInstantiationException

use of org.jaffa.persistence.exceptions.EngineInstantiationException in project jaffa-framework by jaffa-projects.

the class PersistenceEngineFactory method createPersistenceEngine.

/**
 * Creates a new PersistenceEngine object.
 * Reads the 'framework.persistence.Persistence_Engine' property from the framework.properties file.
 * Instantiates the class returned by the property.
 *
 * @return an instance of IPersistenceEngine.
 * @throws EngineInstantiationException when the property is not defined, the class cannot be found,
 * or the class cannot be instantiated.
 */
private static IPersistenceEngine createPersistenceEngine() throws EngineInstantiationException {
    String engineName = null;
    try {
        IPersistenceEngine engine;
        if (persistenceEngineFactory != null) {
            engine = persistenceEngineFactory.newPersistenceEngine();
        } else {
            engineName = (String) Config.getProperty(ENGINE_KEY);
            if (log.isDebugEnabled())
                log.debug("Creating an instance of the Persistence Engine: " + engineName);
            Class engineClass = Class.forName(engineName);
            engine = (IPersistenceEngine) engineClass.newInstance();
        }
        return engine;
    } catch (Exception e) {
        log.error(String.format(FAILED_ENGINE_INSTANTIATION, engineName), e);
        throw new EngineInstantiationException(null, e);
    }
}
Also used : EngineInstantiationException(org.jaffa.persistence.exceptions.EngineInstantiationException) IPersistenceEngine(org.jaffa.persistence.engines.IPersistenceEngine) EngineInstantiationException(org.jaffa.persistence.exceptions.EngineInstantiationException)

Aggregations

IPersistenceEngine (org.jaffa.persistence.engines.IPersistenceEngine)1 EngineInstantiationException (org.jaffa.persistence.exceptions.EngineInstantiationException)1