*/
public DBCreator(InitParams params, ConfigurationManager configurationManager) throws ConfigurationException
{
if (params == null)
{
throw new ConfigurationException("Initializations parameters expected");
}
PropertiesParam prop = params.getPropertiesParam(DB_CONNECTION);
if (prop != null)
{
if (prop.getProperty(DB_DRIVER) == null)
{
throw new ConfigurationException("driverClassName expected in db-connection properties section");
}
serverUrl = prop.getProperty(DB_URL);
if (serverUrl == null)
{
throw new ConfigurationException("url expected in db-connection properties section");
}
if (prop.getProperty(DB_USERNAME) == null)
{
throw new ConfigurationException("username expected in db-connection properties section");
}
if (prop.getProperty(DB_PASSWORD) == null)
{
throw new ConfigurationException("password expected in db-connection properties section");
}
// Store all connection properties into single map
Iterator<Property> pit = prop.getPropertyIterator();
connectionProperties = new HashMap<String, String>();
while (pit.hasNext())
{
Property p = pit.next();
if (!p.getName().equalsIgnoreCase(DB_URL))
{
connectionProperties.put(p.getName(), p.getValue());
}
}
}
else
{
throw new ConfigurationException("db-connection properties expected in initializations parameters");
}
prop = params.getPropertiesParam(DB_CREATION);
if (prop != null)
{
String scriptPath = prop.getProperty(DB_SCRIPT_PATH);
if (scriptPath != null)
{
String dbScript;
try
{
dbScript = readScriptResource(configurationManager.getInputStream(scriptPath));
}
catch (Exception e)
{
try
{
dbScript = readScriptResource(PrivilegedFileHelper.fileInputStream(scriptPath));
}
catch (IOException ioe)
{
throw new ConfigurationException("Can't read script resource " + scriptPath, e);
}
}
this.dbScript = dbScript;
}
else
{
throw new ConfigurationException("scriptPath expected in db-creation properties section");
}
this.dbUserName = prop.getProperty(DB_USERNAME);
if (dbUserName == null)
{
throw new ConfigurationException("username expected in db-creation properties section");
}
this.dbPassword = prop.getProperty(DB_PASSWORD);
if (dbPassword == null)
{
throw new ConfigurationException("password expected in db-creation properties section");
}
}
else
{
throw new ConfigurationException("db-creation properties expected in initializations parameters");
}
}