Search in sources :

Example 1 with Param

use of org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Param in project jaffa-framework by jaffa-projects.

the class ConnectionHelper method getDatabaseInfo.

private static Map getDatabaseInfo() throws Exception {
    URL initUrl = URLHelper.newExtendedURL((String) Config.getProperty(Config.PROP_JDBC_ENGINE_INIT));
    InputStream stream = null;
    try {
        stream = initUrl.openStream();
        // create a JAXBContext capable of handling classes generated into the package
        JAXBContext jc = JAXBContext.newInstance("org.jaffa.persistence.engines.jdbcengine.configservice.initdomain");
        // create an Unmarshaller
        Unmarshaller u = jc.createUnmarshaller();
        // enable validation
        u.setSchema(JAXBHelper.createSchema(SCHEMA));
        // unmarshal a document into a tree of Java content objects composed of classes from the package.
        Init init = (Init) u.unmarshal(XmlHelper.stripDoctypeDeclaration(stream));
        Database database = null;
        for (Iterator i = init.getDatabase().iterator(); i.hasNext(); ) {
            database = (Database) i.next();
            if (database.getName().equals("default")) {
                break;
            }
        }
        if (database == null) {
            throw new Exception("The 'default' database has not been defined in init.xml ");
        }
        Map info = new HashMap();
        info.put(ENGINE, database.getEngine());
        for (Iterator i = database.getConnectionFactory().getParam().iterator(); i.hasNext(); ) {
            Param param = (Param) i.next();
            if (URL.equals(param.getName())) {
                info.put(URL, param.getValue());
            } else if (DRIVER_CLASS.equals(param.getName())) {
                info.put(DRIVER_CLASS, param.getValue());
            } else if (USER.equals(param.getName())) {
                info.put(USER, param.getValue());
            } else if (PASSWORD.equals(param.getName())) {
                info.put(PASSWORD, param.getValue());
            } else if (MAXIMUM_CONNECTIONS.equals(param.getName())) {
                info.put(MAXIMUM_CONNECTIONS, param.getValue());
            }
        }
        return info;
    } finally {
        try {
            if (stream != null) {
                stream.close();
            }
        } catch (IOException e) {
        // do nothing
        }
    }
}
Also used : Init(org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Init) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Database(org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Database) Iterator(java.util.Iterator) Param(org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Param) JAXBContext(javax.xml.bind.JAXBContext) IOException(java.io.IOException) Unmarshaller(javax.xml.bind.Unmarshaller) HashMap(java.util.HashMap) Map(java.util.Map) URL(java.net.URL) IOException(java.io.IOException) SQLException(java.sql.SQLException)

Example 2 with Param

use of org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Param in project jaffa-framework by jaffa-projects.

the class AbstractDataWrapper method getDatabaseInfo.

static Map getDatabaseInfo() throws Exception {
    URL initUrl = URLHelper.newExtendedURL((String) Config.getProperty(Config.PROP_JDBC_ENGINE_INIT));
    // create a JAXBContext capable of handling classes generated into the package
    JAXBContext jc = JAXBContext.newInstance("org.jaffa.persistence.engines.jdbcengine.configservice.initdomain");
    // create an Unmarshaller
    Unmarshaller u = jc.createUnmarshaller();
    // enable validation
    u.setValidating(true);
    // unmarshal a document into a tree of Java content objects composed of classes from the package.
    Init init = (Init) u.unmarshal(XmlHelper.stripDoctypeDeclaration(initUrl));
    Database database = null;
    for (Iterator i = init.getDatabase().iterator(); i.hasNext(); ) {
        database = (Database) i.next();
        if (database.getName().equals("default"))
            break;
    }
    if (database == null)
        throw new Exception("The 'default' database has not been defined in init.xml ");
    Map info = new HashMap();
    info.put(ENGINE, database.getEngine());
    for (Iterator i = database.getConnectionFactory().getParam().iterator(); i.hasNext(); ) {
        Param param = (Param) i.next();
        if (URL.equals(param.getName()))
            info.put(URL, param.getValue());
        else if (DRIVER_CLASS.equals(param.getName()))
            info.put(DRIVER_CLASS, param.getValue());
        else if (USER.equals(param.getName()))
            info.put(USER, param.getValue());
        else if (PASSWORD.equals(param.getName()))
            info.put(PASSWORD, param.getValue());
        else if (MAXIMUM_CONNECTIONS.equals(param.getName()))
            info.put(MAXIMUM_CONNECTIONS, param.getValue());
    }
    return info;
}
Also used : Init(org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Init) Database(org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Database) Param(org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Param) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) URL(java.net.URL) SQLException(java.sql.SQLException)

Example 3 with Param

use of org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Param in project jaffa-framework by jaffa-projects.

the class DataSourceFactory method initialize.

private static synchronized void initialize(Database database) throws DataSourceCreationException {
    if (c_connectionFactory == null) {
        try {
            // create an instance of the JDBC Security Plugin, while instantiating the ConnectionFactory
            if (database.getJdbcSecurityPlugin() != null && database.getJdbcSecurityPlugin().getValue() != null && database.getJdbcSecurityPlugin().getValue().length() > 0)
                c_jdbcSecurityPlugin = (IJdbcSecurityPlugin) Class.forName(database.getJdbcSecurityPlugin().getValue()).newInstance();
        } catch (Exception e) {
            String str = "Error in creating an instance of the JDBC Security Plugin for the class: " + database.getJdbcSecurityPlugin();
            log.error(str, e);
            throw new DataSourceCreationException(DataSourceCreationException.JDBC_PLUGIN_CREATION_FAILED, new Object[] { database.getJdbcSecurityPlugin() }, e);
        }
        try {
            // now instantiate the ConnectionFactory and set its properties
            IConnectionFactory connectionFactory = (IConnectionFactory) Class.forName(database.getConnectionFactory().getClassName()).newInstance();
            if (database.getConnectionFactory().getParam() != null) {
                for (Iterator<?> i = database.getConnectionFactory().getParam().iterator(); i.hasNext(); ) {
                    Param param = (Param) i.next();
                    BeanHelper.setField(connectionFactory, param.getName(), param.getValue());
                }
            }
            c_connectionFactory = connectionFactory;
        } catch (Exception e) {
            String str = "Error in creating an instance of the ConnectionFactory for the class: " + database.getConnectionFactory().getClassName();
            log.error(str, e);
            throw new DataSourceCreationException(DataSourceCreationException.CONNECTION_FACTORY_CREATION_FAILED, new Object[] { database.getConnectionFactory().getClassName() }, e);
        }
    }
}
Also used : Param(org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Param) DataSourceCreationException(org.jaffa.persistence.engines.jdbcengine.datasource.exceptions.DataSourceCreationException) IJdbcSecurityPlugin(org.jaffa.persistence.engines.jdbcengine.security.IJdbcSecurityPlugin) DataSourceCreationException(org.jaffa.persistence.engines.jdbcengine.datasource.exceptions.DataSourceCreationException) SQLException(java.sql.SQLException)

Aggregations

SQLException (java.sql.SQLException)3 Param (org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Param)3 URL (java.net.URL)2 JAXBContext (javax.xml.bind.JAXBContext)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 Database (org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Database)2 Init (org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Init)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 DataSourceCreationException (org.jaffa.persistence.engines.jdbcengine.datasource.exceptions.DataSourceCreationException)1 IJdbcSecurityPlugin (org.jaffa.persistence.engines.jdbcengine.security.IJdbcSecurityPlugin)1