Author: sergiykarpenko
Date: 2011-01-24 08:18:50 -0500 (Mon, 24 Jan 2011)
New Revision: 3833
Modified:
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java
Log:
EXOJCR-1148: DBConnectionInfo uses only properties map
Modified:
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java
===================================================================
---
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java 2011-01-24
10:54:51 UTC (rev 3832)
+++
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBConnectionInfo.java 2011-01-24
13:18:50 UTC (rev 3833)
@@ -28,103 +28,20 @@
*/
public class DBConnectionInfo
{
- /**
- * Driver class name.
- */
- private final String driver;
+ private final Map<String, String> connectionProperties;
/**
- * DB connection url;
- */
- private final String url;
-
- /**
- * DB connection user name;
- */
- private final String username;
-
- /**
- * User's password.
- */
- private final String password;
-
- private final Map<String, String> additionalProperties;
-
- /**
* DBConnectionInfo constructor.
- *
- * @param driver
- * driver class name
- * @param url
- * db connection url
- * @param username
- * db connection user name
- * @param password
- * user's password
+ * @param connectionProperties
+ * connection properties
*/
- public DBConnectionInfo(String driver, String url, String username, String password)
+ public DBConnectionInfo(Map<String, String> connectionProperties)
{
- this(driver, url, username, password, null);
+ this.connectionProperties = connectionProperties;
}
- /**
- * DBConnectionInfo constructor.
- *
- * @param driver
- * driver class name
- * @param url
- * db connection url
- * @param username
- * db connection user name
- * @param password
- * user's password
- * @param additionalProperties
- * additonal connection properties
- */
- public DBConnectionInfo(String driver, String url, String username, String password,
- Map<String, String> additionalProperties)
+ public Map<String, String> getProperties()
{
- this.driver = driver;
- this.url = url;
- this.username = username;
- this.password = password;
- this.additionalProperties = additionalProperties;
+ return connectionProperties;
}
-
- /**
- * @return the driver
- */
- public String getDriver()
- {
- return driver;
- }
-
- /**
- * @return the url
- */
- public String getUrl()
- {
- return url;
- }
-
- /**
- * @return the username
- */
- public String getUsername()
- {
- return username;
- }
-
- /**
- * @return the password
- */
- public String getPassword()
- {
- return password;
- }
-
- public Map<String, String> getAdditionalProperties()
- {
- return additionalProperties;
- }
}
Modified:
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
===================================================================
---
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java 2011-01-24
10:54:51 UTC (rev 3832)
+++
core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java 2011-01-24
13:18:50 UTC (rev 3833)
@@ -36,6 +36,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
/**
* @author <a href="anatoliy.bazko(a)exoplatform.org">Anatoliy
Bazko</a>
@@ -44,6 +45,22 @@
public class DBCreator
{
+ private final static String DB_CONNECTION = "db-connection";
+
+ private final static String DB_DRIVER = "driverClassName";
+
+ private final static String DB_URL = "url";
+
+ private final static String DB_USERNAME = "username";
+
+ private final static String DB_PASSWORD = "password";
+
+ private final static String DB_ORCL_INTERNAL_LOGON = "internal_logon";
+
+ private final static String DB_CREATION = "db-creation";
+
+ private final static String DB_SCRIPT_PATH = "scriptPath";
+
/**
* Database template.
*/
@@ -100,9 +117,9 @@
protected final String dbPassword;
/**
- * Additional connection properties.
+ * Connection properties.
*/
- protected final Map<String, String> additionalProperties;
+ protected final Map<String, String> connectionProperties;
/**
* DBCreator constructor.
@@ -117,63 +134,58 @@
throw new ConfigurationException("Initializations parameters
expected");
}
- PropertiesParam prop = params.getPropertiesParam("db-connection");
+ PropertiesParam prop = params.getPropertiesParam(DB_CONNECTION);
if (prop != null)
{
- this.driver = prop.getProperty("driverClassName");
+ this.driver = prop.getProperty(DB_DRIVER);
if (driver == null)
{
throw new ConfigurationException("driverClassName expected in
db-connection properties section");
}
- this.serverUrl = prop.getProperty("url");
+ this.serverUrl = prop.getProperty(DB_URL);
if (serverUrl == null)
{
throw new ConfigurationException("url expected in db-connection
properties section");
}
- this.adminName = prop.getProperty("username");
+ this.adminName = prop.getProperty(DB_USERNAME);
if (adminName == null)
{
throw new ConfigurationException("username expected in db-connection
properties section");
}
- this.adminPwd = prop.getProperty("password");
+ this.adminPwd = prop.getProperty(DB_PASSWORD);
if (adminPwd == null)
{
throw new ConfigurationException("password expected in db-connection
properties section");
}
- this.internal_logon = prop.getProperty("internal_logon");
+ this.internal_logon = prop.getProperty(DB_ORCL_INTERNAL_LOGON);
- // Store additional properties into map
+ // Store all connection properties into single map
Iterator<Property> pit = prop.getPropertyIterator();
-
- additionalProperties = new HashMap<String, String>();
-
+ Map<String, String> tempMap = new HashMap<String, String>();
while (pit.hasNext())
{
Property p = pit.next();
- String name = p.getName();
- if (name.equalsIgnoreCase("driverClassName") ||
name.equalsIgnoreCase("url")
- || name.equalsIgnoreCase("username") ||
name.equalsIgnoreCase("password")
- || name.equalsIgnoreCase("internal_logon"))
+ if (!p.getName().equalsIgnoreCase(DB_URL))
{
- continue;
+ tempMap.put(p.getName(), p.getValue());
}
- additionalProperties.put(name, p.getValue());
}
+ connectionProperties = tempMap;
}
else
{
throw new ConfigurationException("db-connection properties expected in
initializations parameters");
}
- prop = params.getPropertiesParam("db-creation");
+ prop = params.getPropertiesParam(DB_CREATION);
if (prop != null)
{
- String scriptPath = prop.getProperty("scriptPath");
+ String scriptPath = prop.getProperty(DB_SCRIPT_PATH);
if (scriptPath != null)
{
try
@@ -190,13 +202,13 @@
throw new ConfigurationException("scriptPath expected in db-creation
properties section");
}
- this.dbUserName = prop.getProperty("username");
+ this.dbUserName = prop.getProperty(DB_USERNAME);
if (dbUserName == null)
{
throw new ConfigurationException("username expected in db-creation
properties section");
}
- this.dbPassword = prop.getProperty("password");
+ this.dbPassword = prop.getProperty(DB_PASSWORD);
if (dbPassword == null)
{
throw new ConfigurationException("password expected in db-creation
properties section");
@@ -407,7 +419,17 @@
dbUrl = dbUrl + (dbUrl.endsWith("/") ? "" : "/") +
dbName;
}
- return new DBConnectionInfo(driver, dbUrl, dbUserName, dbPassword,
additionalProperties);
+ // clone connection properties
+ Map<String, String> connProperties = new HashMap<String, String>();
+
+ for (Entry<String, String> entry : this.connectionProperties.entrySet())
+ {
+ connProperties.put(entry.getKey(), entry.getValue());
+ }
+
+ connProperties.put(DB_URL, dbUrl);
+
+ return new DBConnectionInfo(connProperties);
}
/**
Modified:
core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java
===================================================================
---
core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java 2011-01-24
10:54:51 UTC (rev 3832)
+++
core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java 2011-01-24
13:18:50 UTC (rev 3833)
@@ -26,7 +26,6 @@
import org.exoplatform.services.naming.InitialContextInitializer;
import java.sql.Connection;
-import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
@@ -58,17 +57,16 @@
DBConnectionInfo dbInfo = dbCreator.createDatabase("testdb");
DBConnectionInfo dbInfo1 = dbCreator.getDBConnectionInfo("testdb");
- assertEquals(dbInfo.getDriver(), dbInfo1.getDriver());
- assertEquals(dbInfo.getPassword(), dbInfo1.getPassword());
- assertEquals(dbInfo.getUrl(), dbInfo1.getUrl());
- assertEquals(dbInfo.getUsername(), dbInfo1.getUsername());
+ Map<String, String> connProps = dbInfo.getProperties();
+ Map<String, String> connProps1 = dbInfo1.getProperties();
- Map<String, String> refAddr = new HashMap<String, String>();
- refAddr.put("driverClassName", dbInfo.getDriver());
- refAddr.put("url", dbInfo.getUrl());
- refAddr.put("username", dbInfo.getUsername());
- refAddr.put("password", dbInfo.getPassword());
+ assertEquals(connProps.get("driverClassName"),
connProps1.get("driverClassName"));
+ assertEquals(connProps.get("password"),
connProps1.get("password"));
+ assertEquals(connProps.get("url"), connProps1.get("url"));
+ assertEquals(connProps.get("username"),
connProps1.get("username"));
+ Map<String, String> refAddr = dbInfo.getProperties();
+
initContext.bind("testjdbcjcr", "javax.sql.DataSource",
"org.apache.commons.dbcp.BasicDataSourceFactory", null,
refAddr);
@@ -125,11 +123,7 @@
{
DBConnectionInfo dbInfo = dbCreator.createDatabase("testdb_" +
threadNumber);
- Map<String, String> refAddr = new HashMap<String, String>();
- refAddr.put("driverClassName", dbInfo.getDriver());
- refAddr.put("url", dbInfo.getUrl());
- refAddr.put("username", dbInfo.getUsername());
- refAddr.put("password", dbInfo.getPassword());
+ Map<String, String> refAddr = dbInfo.getProperties();
initContext.bind("testjdbcjcr_" + threadNumber,
"javax.sql.DataSource",
"org.apache.commons.dbcp.BasicDataSourceFactory", null,
refAddr);