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
}
}
}
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;
}
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);
}
}
}
Aggregations