try {
if (f.exists()) {
ConnectionProperties cp = new ConnectionProperties(
new ExtendedProperties(f.getAbsolutePath()));
if (((adapter != null && !adapter.startsWith("$"))
|| (usr != null && !usr.startsWith("$"))
|| (pass != null && !pass.startsWith("$"))
|| (url != null && !url.startsWith("$")) || (driver != null && !driver
.startsWith("$")))
&& (System.getProperty("cayenneTestConnection") != null && !System
.getProperty("cayenneTestConnection")
.equals("null"))) {
DataSourceInfo dsiOld = null;
if (connectionInfos.get(System.getProperty("cayenneTestConnection")) != null) {
dsiOld = connectionInfos.get(System
.getProperty("cayenneTestConnection"));
connectionInfos.remove(System
.getProperty("cayenneTestConnection"));
}
if (adapter != null && !adapter.startsWith("$")) {
dsi.setAdapterClassName(adapter);
}
else if (dsiOld != null) {
dsi.setAdapterClassName(dsiOld.getAdapterClassName());
}
if (usr != null && !usr.startsWith("$")) {
dsi.setUserName(usr);
}
else if (dsiOld != null) {
dsi.setUserName(dsiOld.getUserName());
}
if (pass != null && !pass.startsWith("$")) {
dsi.setPassword(pass);
}
else if (dsiOld != null) {
dsi.setPassword(dsiOld.getPassword());
}
if (url != null && !url.startsWith("$")) {
dsi.setDataSourceUrl(url);
}
else if (dsiOld != null) {
dsi.setDataSourceUrl(dsiOld.getDataSourceUrl());
}
if (driver != null && !driver.startsWith("$")) {
dsi.setJdbcDriver(driver);
}
else if (dsiOld != null) {
dsi.setJdbcDriver(dsiOld.getJdbcDriver());
}
connectionInfos.put(System.getProperty("cayenneTestConnection"), dsi);
}
else {
return cp;
}
}
else {
if (((adapter != null && !adapter.startsWith("$"))
|| (usr != null && !usr.startsWith("$"))
|| (pass != null && !pass.startsWith("$"))
|| (url != null && !url.startsWith("$")) || (driver != null && !driver
.startsWith("$")))
&& (System.getProperty("cayenneTestConnection") != null && !System
.getProperty("cayenneTestConnection")
.equals("null"))) {
if (adapter != null && !adapter.startsWith("$")) {
dsi.setAdapterClassName(adapter);
}
if (usr != null && !usr.startsWith("$")) {
dsi.setUserName(usr);
}
if (pass != null && !pass.startsWith("$")) {
dsi.setPassword(pass);
}
if (url != null && !url.startsWith("$")) {
dsi.setDataSourceUrl(url);
}
if (driver != null && !driver.startsWith("$")) {
dsi.setJdbcDriver(driver);
}
connectionInfos.put(System.getProperty("cayenneTestConnection"), dsi);
}
// lets touch this file so that users would get a clue of what it is
createSamplePropertiesFile(f);
}
}
catch (IOException e) {
// ignoring
}
return new ConnectionProperties(new ExtendedProperties());
}