use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.
the class DataHandlerTest method testLoadAccessDataWithSelectedItem.
@Test
public void testLoadAccessDataWithSelectedItem() throws Exception {
when(accessBox.getSelectedItem()).thenReturn("ODBC");
DatabaseInterface dbInterface = mock(DatabaseInterface.class);
DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
when(dbInterface.getAccessTypeList()).thenReturn(new int[] { DatabaseMeta.TYPE_ACCESS_NATIVE, DatabaseMeta.TYPE_ACCESS_ODBC });
when(dbInterface.getDefaultDatabasePort()).thenReturn(5309);
when(connectionBox.getSelectedItem()).thenReturn("myDb");
DataHandler.connectionMap.put("myDb", dbInterface);
dataHandler.cache = databaseMeta;
dataHandler.getData();
dataHandler.loadAccessData();
}
use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.
the class DataHandlerTest method testLoadConnectionDataWithSelectedItem.
@Test
public void testLoadConnectionDataWithSelectedItem() throws Exception {
DatabaseInterface dbInterface = mock(DatabaseInterface.class);
when(dbInterface.getDefaultDatabasePort()).thenReturn(5309);
when(connectionBox.getSelectedItem()).thenReturn("myDb");
dataHandler.loadConnectionData();
}
use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.
the class FragmentHandlerTest method testGetFragment.
@Test
public void testGetFragment() throws Exception {
DatabaseInterface dbInterface = mock(DatabaseInterface.class);
assertEquals("org/pentaho/ui/database/", fragmentHandler.getFragment(dbInterface, null, null, null));
when(dbInterface.getXulOverlayFile()).thenReturn("overlay.xul");
// In real life the xul file should be available in the classpath as a resource, but during testing it won't be.
// So instead of expecting FragmentHandler.packagePath + overlay.xul, it's just the package path
assertEquals("org/pentaho/ui/database/", fragmentHandler.getFragment(dbInterface, null, null, null));
}
use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.
the class StringSearcher method stringSearchInObject.
private static void stringSearchInObject(Object obj, int level, List<StringSearchResult> stringList, Object parentObject, Object grandParentObject, Field field) {
String fieldName = field.getName();
if (obj instanceof String) {
// OK, let's add the String
stringList.add(new StringSearchResult((String) obj, parentObject, grandParentObject, fieldName));
} else if (obj instanceof String[]) {
String[] array = (String[]) obj;
for (int x = 0; x < array.length; x++) {
if (array[x] != null) {
stringList.add(new StringSearchResult(array[x], parentObject, grandParentObject, fieldName + " #" + (x + 1)));
}
}
} else if (obj instanceof Boolean) {
// OK, let's add the String
stringList.add(new StringSearchResult(((Boolean) obj).toString(), parentObject, grandParentObject, fieldName + " (Boolean)"));
} else if (obj instanceof Condition) {
stringList.add(new StringSearchResult(((Condition) obj).toString(), parentObject, grandParentObject, fieldName + " (Condition)"));
} else if (obj instanceof DatabaseInterface) {
// Make sure we read the attributes. This is not picked up by default. (getDeclaredFields doesn't pick up
// inherited fields)
//
DatabaseInterface databaseInterface = (DatabaseInterface) obj;
findMapMetaData(databaseInterface.getAttributes(), level + 1, stringList, parentObject, grandParentObject, field);
findMetaData(obj, level + 1, stringList, parentObject, grandParentObject);
} else if (obj instanceof Map) {
findMapMetaData((Map<?, ?>) obj, level, stringList, parentObject, grandParentObject, field);
} else if (obj instanceof Object[]) {
for (int j = 0; j < ((Object[]) obj).length; j++) {
findMetaData(((Object[]) obj)[j], level + 1, stringList, parentObject, grandParentObject);
}
} else {
findMetaData(obj, level + 1, stringList, parentObject, grandParentObject);
}
}
use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.
the class DatabaseMetaStoreUtil method loadDatabaseMetaFromDatabaseElement.
public static DatabaseMeta loadDatabaseMetaFromDatabaseElement(IMetaStore metaStore, IMetaStoreElement element) throws KettlePluginException {
DatabaseMeta databaseMeta = new DatabaseMeta();
PluginRegistry pluginRegistry = PluginRegistry.getInstance();
// Load the appropriate database plugin (database interface)
//
String pluginId = getChildString(element, MetaStoreConst.DB_ATTR_ID_PLUGIN_ID);
String driverClassName = getChildString(element, MetaStoreConst.DB_ATTR_DRIVER_CLASS);
if (Utils.isEmpty(pluginId) && Utils.isEmpty(driverClassName)) {
throw new KettlePluginException("The attributes 'plugin_id' and 'driver_class' can't be both empty");
}
if (Utils.isEmpty(pluginId)) {
// Determine pluginId using the plugin registry.
//
List<PluginInterface> plugins = pluginRegistry.getPlugins(DatabasePluginType.class);
for (PluginInterface plugin : plugins) {
DatabaseInterface databaseInterface = (DatabaseInterface) pluginRegistry.loadClass(plugin);
if (driverClassName.equalsIgnoreCase(databaseInterface.getDriverClass())) {
pluginId = plugin.getIds()[0];
}
}
}
if (Utils.isEmpty(pluginId)) {
throw new KettlePluginException("The 'plugin_id' attribute could not be determined using 'driver_class' value '" + driverClassName + "'");
}
// Look for the plugin
//
PluginInterface plugin = PluginRegistry.getInstance().getPlugin(DatabasePluginType.class, pluginId);
DatabaseInterface databaseInterface = (DatabaseInterface) PluginRegistry.getInstance().loadClass(plugin);
databaseInterface.setPluginId(pluginId);
databaseMeta.setDatabaseInterface(databaseInterface);
databaseMeta.setObjectId(new StringObjectId(element.getId()));
databaseMeta.setName(element.getName());
databaseMeta.setDescription(getChildString(element, MetaStoreConst.DB_ATTR_ID_DESCRIPTION));
String accessTypeString = getChildString(element, MetaStoreConst.DB_ATTR_ID_ACCESS_TYPE);
if (Utils.isEmpty(accessTypeString)) {
accessTypeString = DatabaseMeta.getAccessTypeDesc(DatabaseMeta.TYPE_ACCESS_NATIVE);
}
databaseMeta.setAccessType(DatabaseMeta.getAccessType(accessTypeString));
databaseMeta.setHostname(getChildString(element, MetaStoreConst.DB_ATTR_ID_HOSTNAME));
databaseMeta.setDBPort(getChildString(element, MetaStoreConst.DB_ATTR_ID_PORT));
databaseMeta.setDBName(getChildString(element, MetaStoreConst.DB_ATTR_ID_DATABASE_NAME));
databaseMeta.setUsername(getChildString(element, MetaStoreConst.DB_ATTR_ID_USERNAME));
databaseMeta.setPassword(metaStore.getTwoWayPasswordEncoder().decode(getChildString(element, MetaStoreConst.DB_ATTR_ID_PASSWORD)));
databaseMeta.setServername(getChildString(element, MetaStoreConst.DB_ATTR_ID_SERVERNAME));
databaseMeta.setDataTablespace(getChildString(element, MetaStoreConst.DB_ATTR_ID_DATA_TABLESPACE));
databaseMeta.setIndexTablespace(getChildString(element, MetaStoreConst.DB_ATTR_ID_INDEX_TABLESPACE));
IMetaStoreAttribute attributesChild = element.getChild(MetaStoreConst.DB_ATTR_ID_ATTRIBUTES);
if (attributesChild != null) {
// Now add a list of all the attributes set on the database connection...
//
Properties attributes = databaseMeta.getAttributes();
for (IMetaStoreAttribute attr : attributesChild.getChildren()) {
String code = attr.getId();
String value = getAttributeString(attr);
attributes.put(code, Const.NVL(value, ""));
}
}
return databaseMeta;
}
Aggregations