Search in sources :

Example 1 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)

Example 2 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 3 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 4 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 org.pentaho.metaverse.api.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.environmentSubstitute(dbMeta.getAccessTypeDesc());
    node.setProperty("accessTypeDesc", accessTypeDesc);
    String databaseName = dbMeta.environmentSubstitute(dbMeta.getDatabaseName());
    node.setProperty("databaseName", databaseName);
    String connectionName = dbMeta.environmentSubstitute(dbMeta.getName());
    node.setProperty("name", connectionName);
    DatabaseInterface dbInterface = dbMeta.getDatabaseInterface();
    node.setProperty("databaseType", dbInterface != null ? Const.NVL(dbInterface.getPluginName(), "Unknown") : "Unknown");
    String port = dbMeta.environmentSubstitute(dbMeta.getDatabasePortNumberString());
    node.setProperty(DictionaryConst.PROPERTY_PORT, port);
    String host = dbMeta.environmentSubstitute(dbMeta.getHostname());
    node.setProperty(DictionaryConst.PROPERTY_HOST_NAME, host);
    String user = dbMeta.environmentSubstitute(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());
    }
    return node;
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) MetaverseAnalyzerException(org.pentaho.metaverse.api.MetaverseAnalyzerException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode)

Example 5 with DatabaseInterface

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

the class ValueMetaBaseTest method testGetValueFromSqlTypeNetezza.

/**
 * PDI-10877 Table input step returns no data when pulling a timestamp column from IBM Netezza
 *
 * @throws Exception
 */
@Test
public void testGetValueFromSqlTypeNetezza() throws Exception {
    ValueMetaBase obj = new ValueMetaBase();
    DatabaseInterface databaseInterface = new NetezzaDatabaseMeta();
    ResultSetMetaData metaData = mock(ResultSetMetaData.class);
    when(resultSet.getMetaData()).thenReturn(metaData);
    when(metaData.getColumnType(1)).thenReturn(Types.DATE);
    when(metaData.getColumnType(2)).thenReturn(Types.TIME);
    obj.type = ValueMetaInterface.TYPE_DATE;
    // call to testing method
    obj.getValueFromResultSet(databaseInterface, resultSet, 0);
    // for jdbc Date type getDate method called
    verify(resultSet, times(1)).getDate(anyInt());
    obj.getValueFromResultSet(databaseInterface, resultSet, 1);
    // for jdbc Time type getTime method called
    verify(resultSet, times(1)).getTime(anyInt());
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) NetezzaDatabaseMeta(org.pentaho.di.core.database.NetezzaDatabaseMeta) Test(org.junit.Test)

Aggregations

DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)42 Test (org.junit.Test)28 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)22 MySQLDatabaseMeta (org.pentaho.di.core.database.MySQLDatabaseMeta)10 MariaDBDatabaseMeta (org.pentaho.di.core.database.MariaDBDatabaseMeta)7 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)7 ResultSetMetaData (java.sql.ResultSetMetaData)5 PacketTooBigException (com.mysql.jdbc.PacketTooBigException)4 BaseDatabaseMeta (org.pentaho.di.core.database.BaseDatabaseMeta)4 NetezzaDatabaseMeta (org.pentaho.di.core.database.NetezzaDatabaseMeta)4 OracleDatabaseMeta (org.pentaho.di.core.database.OracleDatabaseMeta)4 Vertica5DatabaseMeta (org.pentaho.di.core.database.Vertica5DatabaseMeta)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 GenericDatabaseMeta (org.pentaho.di.core.database.GenericDatabaseMeta)3 GreenplumDatabaseMeta (org.pentaho.di.core.database.GreenplumDatabaseMeta)3 PostgreSQLDatabaseMeta (org.pentaho.di.core.database.PostgreSQLDatabaseMeta)3 SQLiteDatabaseMeta (org.pentaho.di.core.database.SQLiteDatabaseMeta)3 TeradataDatabaseMeta (org.pentaho.di.core.database.TeradataDatabaseMeta)3 MysqlDataTruncation (com.mysql.jdbc.MysqlDataTruncation)2 KettleException (org.pentaho.di.core.exception.KettleException)2