Search in sources :

Example 6 with DatabaseInterface

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();
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) BaseDatabaseMeta(org.pentaho.di.core.database.BaseDatabaseMeta) Test(org.junit.Test)

Example 7 with DatabaseInterface

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();
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) Test(org.junit.Test)

Example 8 with DatabaseInterface

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));
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) Test(org.junit.Test)

Example 9 with DatabaseInterface

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);
    }
}
Also used : Condition(org.pentaho.di.core.Condition) DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) Map(java.util.Map)

Example 10 with DatabaseInterface

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;
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) Properties(java.util.Properties) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StringObjectId(org.pentaho.di.repository.StringObjectId)

Aggregations

DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)35 Test (org.junit.Test)22 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)16 MySQLDatabaseMeta (org.pentaho.di.core.database.MySQLDatabaseMeta)7 ResultSetMetaData (java.sql.ResultSetMetaData)5 ResultSet (java.sql.ResultSet)4 MariaDBDatabaseMeta (org.pentaho.di.core.database.MariaDBDatabaseMeta)4 NetezzaDatabaseMeta (org.pentaho.di.core.database.NetezzaDatabaseMeta)4 Vertica5DatabaseMeta (org.pentaho.di.core.database.Vertica5DatabaseMeta)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 GenericDatabaseMeta (org.pentaho.di.core.database.GenericDatabaseMeta)3 PacketTooBigException (com.mysql.jdbc.PacketTooBigException)2 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)2 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)2 TableOutputMeta (org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)2 AnalysisContext (org.pentaho.metaverse.api.AnalysisContext)2 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)2 XulTextbox (org.pentaho.ui.xul.components.XulTextbox)2 MysqlDataTruncation (com.mysql.jdbc.MysqlDataTruncation)1