private void setData(final JdbcConnectionDefinition def)
{
if (def instanceof DriverConnectionDefinition)
{
final DriverConnectionDefinition jdbcDef = (DriverConnectionDefinition) def;
this.meta = new DatabaseMeta();
this.meta.setUsername(jdbcDef.getUsername());
this.meta.setPassword(jdbcDef.getPassword());
this.meta.setName(jdbcDef.getName());
if (jdbcDef.getDatabaseType() != null)
{
log.debug("Database type is known: " + jdbcDef.getDatabaseType());
try
{
this.meta.setDatabaseType(jdbcDef.getDatabaseType());
}
catch (RuntimeException re)
{
// sic!
}
this.meta.setDBName(jdbcDef.getDatabaseName());
this.meta.setHostname(jdbcDef.getHostName());
this.meta.setDBPort(jdbcDef.getPort());
this.meta.getAttributes().setProperty(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_URL, jdbcDef.getConnectionString());
this.meta.getAttributes().setProperty(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_DRIVER_CLASS, jdbcDef.getDriverClass());
}
else if (String.valueOf(jdbcDef.getConnectionString()).startsWith(HSQLDB_MEM_PREFIX))
{
this.meta.setDatabaseType(DatabaseMapping.getGenericInterface().getPluginId());
this.meta.getAttributes().put(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_URL, jdbcDef.getConnectionString());
this.meta.getAttributes().put(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_DRIVER_CLASS, jdbcDef.getDriverClass());
}
else if (String.valueOf(jdbcDef.getConnectionString()).startsWith(HSQLDB_LOCAL_PREFIX))
{
this.meta.setDatabaseType(DatabaseMapping.getGenericInterface().getPluginId());
this.meta.getAttributes().put(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_URL, jdbcDef.getConnectionString());
this.meta.getAttributes().put(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_DRIVER_CLASS, jdbcDef.getDriverClass());
}
else
{
final DatabaseInterface databaseInterface = DatabaseMapping.getMappingForDriver(jdbcDef.getDriverClass());
this.meta.setDatabaseType(databaseInterface.getPluginId());
log.debug("Database type is unknown, using " + databaseInterface);
try
{
final String pattern;
if (databaseInterface instanceof HypersonicDatabaseMeta)
{
final String connectionString = jdbcDef.getConnectionString();
if (connectionString.startsWith(HSQLDB_PREFIX))
{
if (connectionString.indexOf(':', HSQLDB_PREFIX.length()) == -1)
{
pattern = HSQLDB_PREFIX + "{0}/{2}";
}
else
{
pattern = HSQLDB_PREFIX + "{0}:{1}/{2}";
}
}
else
{
pattern = databaseInterface.getURL("{0}", "{1}", "{2}");
}
}
else
{
pattern = databaseInterface.getURL("{0}", "{1}", "{2}");
}
// knowing that most databases are written in C, we can be sure that the zero-character
// is not a common value.
if (pattern != null && pattern.length() > 0)
{
final MessageFormat format = new MessageFormat(pattern);
final Object[] objects = format.parse(jdbcDef.getConnectionString());
if (objects[0] != null)
{
this.meta.setHostname(String.valueOf(objects[0]));
}
if (objects[1] != null)
{
this.meta.setDBPort(String.valueOf(objects[1]));
}
if (objects[2] != null)
{
this.meta.setDBName(String.valueOf(objects[2]));
}
}
}
catch (Exception e)
{
designTimeContext.error(new XulException("Unable to parse database-URL, please report " +
"your database driver to Pentaho to include it in our list of databases.", e));
this.meta.setDatabaseType(DatabaseMapping.getGenericInterface().getPluginId());
this.meta.getAttributes().put(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_URL, jdbcDef.getConnectionString());
this.meta.getAttributes().put(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_DRIVER_CLASS, jdbcDef.getDriverClass());
}
}
final Properties properties = jdbcDef.getProperties();
final Iterator entryIterator = properties.entrySet().iterator();
while (entryIterator.hasNext())
{
final Map.Entry entry = (Map.Entry) entryIterator.next();
final String key = (String) entry.getKey();