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;
}
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");
}
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));
}
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;
}
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());
}
Aggregations