Search in sources :

Example 16 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.

the class DatabaseLogExceptionFactory method extractDatabase.

private static DatabaseInterfaceExtended extractDatabase(LogTableCoreInterface table) {
    DatabaseInterfaceExtended result = null;
    if (table != null && table.getDatabaseMeta() != null) {
        DatabaseInterface databaseInterface = table.getDatabaseMeta().getDatabaseInterface();
        result = databaseInterface instanceof DatabaseInterfaceExtended ? (DatabaseInterfaceExtended) databaseInterface : null;
    }
    return result;
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) DatabaseInterfaceExtended(org.pentaho.di.core.database.DatabaseInterfaceExtended)

Example 17 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-metaverse by pentaho.

the class TableInputExternalResourceConsumerTest method setUp.

@Before
public void setUp() throws Exception {
    consumer = spy(new TableInputExternalResourceConsumer());
    DatabaseInterface dbi = mock(DatabaseInterface.class);
    when(dbMeta.getDatabaseInterface()).thenReturn(dbi);
    when(dbi.getPluginId()).thenReturn("JNDI");
    when(dbMeta.getAccessTypeDesc()).thenReturn("JNDI");
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) Before(org.junit.Before)

Example 18 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-metaverse by pentaho.

the class TableOutputExternalResourceConsumerTest method testGetResourcesFromMeta_static.

@Test
public void testGetResourcesFromMeta_static() throws Exception {
    TableOutputMeta meta = mock(TableOutputMeta.class);
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    DatabaseInterface dbi = mock(DatabaseInterface.class);
    when(meta.getDatabaseMeta()).thenReturn(dbMeta);
    when(meta.getTableName()).thenReturn("tableName");
    when(meta.getSchemaName()).thenReturn("schemaName");
    when(meta.getParentStepMeta()).thenReturn(parentStepMeta);
    when(parentStepMeta.getParentTransMeta()).thenReturn(parentTransMeta);
    when(parentTransMeta.environmentSubstitute("tableName")).thenReturn("tableName");
    when(parentTransMeta.environmentSubstitute("schemaName")).thenReturn("schemaName");
    when(dbMeta.getAccessTypeDesc()).thenReturn("JNDI");
    when(dbMeta.getName()).thenReturn("TestConnection");
    when(dbMeta.getDescription()).thenReturn("my conn description");
    when(dbMeta.getDatabaseInterface()).thenReturn(dbi);
    when(dbi.getPluginId()).thenReturn("POSTGRESQL");
    Collection<IExternalResourceInfo> resources = consumer.getResourcesFromMeta(meta, new AnalysisContext(DictionaryConst.CONTEXT_STATIC));
    assertEquals(1, resources.size());
    IExternalResourceInfo res = resources.iterator().next();
    assertEquals("TestConnection", res.getName());
    assertEquals("tableName", res.getAttributes().get(DictionaryConst.PROPERTY_TABLE));
    assertEquals("schemaName", res.getAttributes().get(DictionaryConst.PROPERTY_SCHEMA));
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) AnalysisContext(org.pentaho.metaverse.api.AnalysisContext) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 19 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-metaverse by pentaho.

the class DatabaseConnectionAnalyzer method analyze.

/**
 * Analyzes a database connection for metadata.
 *
 * @param dbMeta the object
 * @see IAnalyzer#analyze(IComponentDescriptor, java.lang.Object)
 */
@Override
public IMetaverseNode analyze(IComponentDescriptor descriptor, DatabaseMeta dbMeta) throws MetaverseAnalyzerException {
    if (dbMeta == null) {
        throw new MetaverseAnalyzerException(Messages.getString("ERROR.DatabaseMeta.IsNull"));
    }
    if (metaverseObjectFactory == null) {
        throw new MetaverseAnalyzerException(Messages.getString("ERROR.MetaverseObjectFactory.IsNull"));
    }
    if (metaverseBuilder == null) {
        throw new MetaverseAnalyzerException(Messages.getString("ERROR.MetaverseBuilder.IsNull"));
    }
    IMetaverseNode node = createNodeFromDescriptor(descriptor);
    node.setType(DictionaryConst.NODE_TYPE_DATASOURCE);
    int accessType = dbMeta.getAccessType();
    node.setProperty("accessType", accessType);
    String accessTypeDesc = dbMeta.getAccessTypeDesc();
    node.setProperty("accessTypeDesc", accessTypeDesc);
    String databaseName = dbMeta.getDatabaseName();
    node.setProperty("databaseName", databaseName);
    node.setProperty("name", dbMeta.getName());
    DatabaseInterface dbInterface = dbMeta.getDatabaseInterface();
    node.setProperty("databaseType", dbInterface != null ? Const.NVL(dbInterface.getPluginName(), "Unknown") : "Unknown");
    String port = dbMeta.getDatabasePortNumberString();
    node.setProperty(DictionaryConst.PROPERTY_PORT, port);
    String host = dbMeta.getHostname();
    node.setProperty(DictionaryConst.PROPERTY_HOST_NAME, host);
    String user = dbMeta.getUsername();
    node.setProperty(DictionaryConst.PROPERTY_USER_NAME, user);
    boolean shared = dbMeta.isShared();
    node.setProperty("shared", shared);
    if (accessTypeDesc != null && accessTypeDesc.equals("JNDI")) {
        node.setLogicalIdGenerator(DictionaryConst.LOGICAL_ID_GENERATOR_DB_JNDI);
    } else {
        node.setLogicalIdGenerator(getLogicalIdGenerator());
    }
    metaverseBuilder.addNode(node);
    return node;
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode)

Example 20 with DatabaseInterface

use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-platform by pentaho.

the class SqlMetadataQueryExec method getDatabaseInterface.

protected DatabaseInterface getDatabaseInterface(final SQLConnection conn) {
    String prod = null;
    try {
        prod = conn.getNativeConnection().getMetaData().getDatabaseProductName();
        DatabaseInterface di = DatabaseMetaUtil.getDatabaseInterface(prod);
        if (prod != null && di == null) {
            logger.warn(Messages.getInstance().getString("MQLRelationalDataComponent.WARN_0001_NO_DIALECT_DETECTED", // $NON-NLS-1$
            prod));
        }
        return di;
    } catch (SQLException e) {
        logger.warn(Messages.getInstance().getString("MQLRelationalDataComponent.WARN_0002_DIALECT_EXCEPTION", prod), // $NON-NLS-1$
        e);
    }
    return null;
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) SQLException(java.sql.SQLException)

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