use of org.jaffa.persistence.engines.jdbcengine.configservice.initdomain.Init 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.Init 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;
}
Aggregations