org.pentaho.di.core.database.DatabaseInterface Java Examples
The following examples show how to use
org.pentaho.di.core.database.DatabaseInterface.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatabaseLogExceptionFactoryTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void testExceptionStrategyWithPacketTooBigExceptionPropSetY80driver() { System.setProperty( DatabaseLogExceptionFactory.KETTLE_GLOBAL_PROP_NAME, PROPERTY_VALUE_TRUE ); DatabaseMeta databaseMeta = mock( DatabaseMeta.class ); DatabaseInterface databaseInterface = new MySQLDatabaseMeta(); com.mysql.cj.jdbc.exceptions.PacketTooBigException e = new com.mysql.cj.jdbc.exceptions.PacketTooBigException(); when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta ); when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface ); LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( THROWABLE, strategyName ); }
Example #2
Source File: DatabaseMappingGenerator.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public static void main( String[] args ) { final HashSet knownDrivers = new HashSet(); final DatabaseInterface[] interfaces = DatabaseMeta.getDatabaseInterfaces(); for ( int i = 0; i < interfaces.length; i++ ) { final DatabaseInterface dbi = interfaces[ i ]; final int[] accessTypeList = dbi.getAccessTypeList(); for ( int j = 0; j < accessTypeList.length; j++ ) { final int al = accessTypeList[ j ]; if ( al != DatabaseMeta.TYPE_ACCESS_ODBC ) { dbi.setAccessType( al ); final String driver = dbi.getDriverClass(); if ( knownDrivers.contains( driver ) == false ) { System.out.println( driver + "=" + dbi.getClass().getName() ); knownDrivers.add( driver ); } } } } }
Example #3
Source File: DataHandler.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Override public void pluginAdded( Object serviceObject ) { PluginInterface plugin = (PluginInterface) serviceObject; String pluginName = plugin.getName(); try { DatabaseInterface databaseInterface = (DatabaseInterface) registry.loadClass( plugin ); databaseInterface.setPluginId( plugin.getIds()[ 0 ] ); databaseInterface.setName( pluginName ); databaseTypeAdded( pluginName, databaseInterface ); } catch ( KettleException e ) { Throwable t = e; if ( e.getCause() != null ) { t = e.getCause(); } System.out.println( "Could not create connection entry for " + pluginName + ". " + t.getClass().getName() ); LogChannel.GENERAL.logError( "Could not create connection entry for " + pluginName + ". " + t.getClass().getName() ); } }
Example #4
Source File: ValueMetaInternetAddress.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Override public String getDatabaseColumnTypeDefinition( DatabaseInterface databaseInterface, String tk, String pk, boolean use_autoinc, boolean add_fieldname, boolean add_cr ) { String retval = null; if ( databaseInterface instanceof PostgreSQLDatabaseMeta ) { if ( add_fieldname ) { retval = getName() + " "; } else { retval = ""; } retval += "INET"; if ( add_cr ) { retval += Const.CR; } } return retval; }
Example #5
Source File: FragmentHandler.java From pentaho-kettle with Apache License 2.0 | 6 votes |
protected String getFragment( DatabaseInterface database, String dbName, String extension, String defaultFragment ) { String fragment; String ext = ( extension == null ? "" : extension ); String databaseName = ( dbName == null ? "" : dbName ); String defaultFrag = ( defaultFragment == null ? "" : defaultFragment ); if ( database.getXulOverlayFile() != null ) { fragment = packagePath.concat( database.getXulOverlayFile() ).concat( ext ); } else { fragment = packagePath.concat( databaseName ).concat( ext ); } InputStream in = getClass().getClassLoader().getResourceAsStream( fragment.toLowerCase() ); if ( in == null ) { fragment = packagePath.concat( defaultFrag ); } return fragment; }
Example #6
Source File: TableOutputDialogTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private void isConnectionSupportedTest( boolean supported ) { TableOutputDialog dialog = mock( TableOutputDialog.class ); TransMeta transMeta = mock( TransMeta.class ); DatabaseMeta dbMeta = mock( DatabaseMeta.class ); TextVar text = mock( TextVar.class ); CCombo combo = mock( CCombo.class ); DatabaseInterface dbInterface = mock( DatabaseInterface.class ); setInternalState( dialog, "wTable", text ); setInternalState( dialog, "wConnection", combo ); setInternalState( dialog, "transMeta", transMeta ); when( text.getText() ).thenReturn( "someTable" ); when( combo.getText() ).thenReturn( "someConnection" ); when( transMeta.findDatabase( anyString() ) ).thenReturn( dbMeta ); when( dbMeta.getDatabaseInterface() ).thenReturn( dbInterface ); doNothing().when( dialog ).showUnsupportedConnectionMessageBox( dbInterface ); doCallRealMethod().when( dialog ).isConnectionSupported(); //Check that if the db interface does not support standard output then showUnsupportedConnection is called when( dbInterface.supportsStandardTableOutput() ).thenReturn( supported ); dialog.isConnectionSupported(); verify( dialog, times( !supported ? 1 : 0 ) ).showUnsupportedConnectionMessageBox( dbInterface ); }
Example #7
Source File: ValueMetaBaseTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * 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() ); }
Example #8
Source File: ValueMetaBaseTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void testGetValueFromSQLTypeTypeOverride() throws Exception { final int varbinaryColumnIndex = 2; ValueMetaBase valueMetaBase = new ValueMetaBase(), valueMetaBaseSpy = spy( valueMetaBase ); DatabaseMeta dbMeta = mock( DatabaseMeta.class ); DatabaseInterface databaseInterface = mock( DatabaseInterface.class ); doReturn( databaseInterface ).when( dbMeta ).getDatabaseInterface(); ResultSetMetaData metaData = mock( ResultSetMetaData.class ); valueMetaBaseSpy.getValueFromSQLType( dbMeta, TEST_NAME, metaData, varbinaryColumnIndex, false, false ); verify( databaseInterface, times( 1 ) ).customizeValueFromSQLType( any( ValueMetaInterface.class ), any( ResultSetMetaData.class ), anyInt() ); }
Example #9
Source File: MonetDBBulkLoaderDialog.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public void addDatabases( ComboVar wConnection, Class<? extends DatabaseInterface> databaseType ) { for ( int i = 0; i < transMeta.nrDatabases(); i++ ) { DatabaseMeta ci = transMeta.getDatabase( i ); if ( databaseType == null || ci.getDatabaseInterface().getClass().equals( databaseType ) ) { wConnection.add( ci.getName() ); } } // Add the metaDBConnectionName if we have it // and it is already not added to the list in wConnection. if ( !Utils.isEmpty( input.getDbConnectionName() ) ) { String[] arrayDatabaseList = wConnection.getItems(); if ( arrayDatabaseList == null ) { List<String> databaseNameList = Arrays.asList(); if ( !databaseNameList.contains( input.getDbConnectionName() ) ) { wConnection.add( input.getDbConnectionName() ); } } } }
Example #10
Source File: ValueMetaBaseTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void testVerticaTimeType() throws Exception { // PDI-12244 ResultSetMetaData metaData = mock( ResultSetMetaData.class ); ValueMetaInterface valueMetaInterface = mock( ValueMetaInternetAddress.class ); when( resultSet.getMetaData() ).thenReturn( metaData ); when( metaData.getColumnType( 1 ) ).thenReturn( Types.TIME ); when( resultSet.getTime( 1 ) ).thenReturn( new Time( 0 ) ); when( valueMetaInterface.getOriginalColumnType() ).thenReturn( Types.TIME ); when( valueMetaInterface.getType() ).thenReturn( ValueMetaInterface.TYPE_DATE ); DatabaseInterface databaseInterface = new Vertica5DatabaseMeta(); Object ret = databaseInterface.getValueFromResultSet( resultSet, valueMetaInterface, 0 ); assertEquals( new Time( 0 ), ret ); }
Example #11
Source File: ValueMetaBaseTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void testGetValueFromSQLTypeBinaryMysql() throws Exception { final int binaryColumnIndex = 1; ValueMetaBase valueMetaBase = new ValueMetaBase(); DatabaseMeta dbMeta = spy( new DatabaseMeta() ); DatabaseInterface databaseInterface = new MySQLDatabaseMeta(); dbMeta.setDatabaseInterface( databaseInterface ); ResultSetMetaData metaData = mock( ResultSetMetaData.class ); when( resultSet.getMetaData() ).thenReturn( metaData ); when( metaData.getColumnType( binaryColumnIndex ) ).thenReturn( Types.LONGVARBINARY ); ValueMetaInterface binaryValueMeta = valueMetaBase.getValueFromSQLType( dbMeta, TEST_NAME, metaData, binaryColumnIndex, false, false ); assertEquals( ValueMetaInterface.TYPE_BINARY, binaryValueMeta.getType() ); assertTrue( binaryValueMeta.isBinary() ); }
Example #12
Source File: JobEntryEvalTableContentTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUpBeforeClass() throws Exception { KettleClientEnvironment.init(); dbMap.put( DatabaseInterface.class, DBMockIface.class.getName() ); dbMap.put( InfobrightDatabaseMeta.class, InfobrightDatabaseMeta.class.getName() ); PluginRegistry preg = PluginRegistry.getInstance(); PluginInterface mockDbPlugin = mock( PluginInterface.class ); when( mockDbPlugin.matches( anyString() ) ).thenReturn( true ); when( mockDbPlugin.isNativePlugin() ).thenReturn( true ); when( mockDbPlugin.getMainType() ).thenAnswer( (Answer<Class<?>>) invocation -> DatabaseInterface.class ); when( mockDbPlugin.getPluginType() ).thenAnswer( (Answer<Class<? extends PluginTypeInterface>>) invocation -> DatabasePluginType.class ); when( mockDbPlugin.getIds() ).thenReturn( new String[] { "Oracle", "mock-db-id" } ); when( mockDbPlugin.getName() ).thenReturn( "mock-db-name" ); when( mockDbPlugin.getClassMap() ).thenReturn( dbMap ); preg.registerPlugin( DatabasePluginType.class, mockDbPlugin ); }
Example #13
Source File: DatabaseLogExceptionFactoryTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * Property value has priority */ @Test public void testExceptionStrategyWithPacketTooBigExceptionPropSetY() { System.setProperty( DatabaseLogExceptionFactory.KETTLE_GLOBAL_PROP_NAME, PROPERTY_VALUE_TRUE ); DatabaseMeta databaseMeta = mock( DatabaseMeta.class ); DatabaseInterface databaseInterface = new MySQLDatabaseMeta(); PacketTooBigException e = new PacketTooBigException(); when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta ); when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface ); LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( THROWABLE, strategyName ); }
Example #14
Source File: DatabaseMapping.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public static DatabaseInterface getMappingForDriver(final String driverClass) { if (driverClass == null || driverClass.length() == 0) { return getGenericInterface(); } final Configuration configuration = ClassicEngineBoot.getInstance().getGlobalConfig(); final String mappedInstance = configuration.getConfigProperty ("org.pentaho.reporting.ui.datasources.jdbc.driver-mapping." + driverClass); final DatabaseInterface[] interfaces = DatabaseMeta.getDatabaseInterfaces(); for (int i = 0; i < interfaces.length; i++) { final DatabaseInterface databaseInterface = interfaces[i]; if (databaseInterface.getClass().getName().equals(mappedInstance)) { return databaseInterface; } } return mapTypeFromDriver(driverClass); }
Example #15
Source File: DatabaseMapping.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public static DatabaseInterface getGenericInterface() { // as kettle objects are so easy to break, we have to get the references from the public arrays out // of kettle. There is no safe way (since numeric ids are deprecated) to actually reference a database // meta object without hardcoding its ID. final DatabaseInterface[] interfaces = DatabaseMeta.getDatabaseInterfaces(); for (int i = 0; i < interfaces.length; i++) { final DatabaseInterface anInterface = interfaces[i]; if ("GENERIC".equals(anInterface.getPluginId())) { return anInterface; } } return null; }
Example #16
Source File: DatabaseMetaUtil.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 6 votes |
public static DatabaseInterface getDatabaseInterface( String productName, DatabaseMeta databaseMeta ) { if ( productName == null ) { return null; } // special case to separate hive1 and hive2 if ( productName.indexOf( "Apache Hive" ) >= 0 ) { //$NON-NLS-1$ String hivePluginId = databaseMeta.getDatabaseInterface().getPluginId(); switch ( hivePluginId ) { case "HIVE": //$NON-NLS-1$ case "HIVE2": //$NON-NLS-1$ productName = hivePluginId; break; } } return getDatabaseInterface( productName ); }
Example #17
Source File: DatabaseLogExceptionFactoryTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * PDI-5153 * Test that in case of MysqlDataTruncation exception there will be no stack trace in log */ @Test public void testExceptionStrategyWithMysqlDataTruncationException() { DatabaseMeta databaseMeta = mock( DatabaseMeta.class ); DatabaseInterface databaseInterface = new MySQLDatabaseMeta(); MysqlDataTruncation e = new MysqlDataTruncation(); when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta ); when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface ); LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName ); }
Example #18
Source File: DatabaseLogExceptionFactory.java From pentaho-kettle with Apache License 2.0 | 5 votes |
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; }
Example #19
Source File: DatabaseLogExceptionFactoryTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * PDI-5153 * Test that in case of MaxAllowedPacketException exception there will be no stack trace in log (MariaDB) */ @Test public void testExceptionStrategyWithMaxAllowedPacketException() { DatabaseMeta databaseMeta = mock( DatabaseMeta.class ); DatabaseInterface databaseInterface = new MariaDBDatabaseMeta(); MaxAllowedPacketException e = new MaxAllowedPacketException(); when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta ); when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface ); LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName ); }
Example #20
Source File: DatabaseLogExceptionFactoryTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testExceptionStrategyWithPacketTooBigException80driver() { DatabaseMeta databaseMeta = mock( DatabaseMeta.class ); DatabaseInterface databaseInterface = new MySQLDatabaseMeta(); com.mysql.cj.jdbc.exceptions.PacketTooBigException e = new com.mysql.cj.jdbc.exceptions.PacketTooBigException(); when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta ); when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface ); LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName ); }
Example #21
Source File: ValueMetaTimestamp.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public Object getValueFromResultSet( DatabaseInterface databaseInterface, ResultSet resultSet, int index ) throws KettleDatabaseException { try { return resultSet.getTimestamp( index + 1 ); } catch ( Exception e ) { throw new KettleDatabaseException( toStringMeta() + " : Unable to get timestamp from resultset at index " + index, e ); } }
Example #22
Source File: ValueMetaBase.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private Object getNetezzaDateValueWorkaround( DatabaseInterface databaseInterface, ResultSet resultSet, int index ) throws SQLException, KettleDatabaseException { Object data = null; int type = resultSet.getMetaData().getColumnType( index ); switch ( type ) { case Types.TIME: { data = resultSet.getTime( index ); break; } default: { data = resultSet.getDate( index ); } } return data; }
Example #23
Source File: DatabaseLogExceptionFactoryTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testExceptionStrategyWithMysqlDataTruncationException80driver() { DatabaseMeta databaseMeta = mock( DatabaseMeta.class ); DatabaseInterface databaseInterface = new MySQLDatabaseMeta(); com.mysql.cj.jdbc.exceptions.MysqlDataTruncation e = new com.mysql.cj.jdbc.exceptions.MysqlDataTruncation(); when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta ); when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface ); LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName ); }
Example #24
Source File: DatabaseLogExceptionFactoryTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * PDI-5153 * Test that in case of PacketTooBigException exception there will be no stack trace in log */ @Test public void testExceptionStrategyWithPacketTooBigException() { DatabaseMeta databaseMeta = mock( DatabaseMeta.class ); DatabaseInterface databaseInterface = new MySQLDatabaseMeta(); PacketTooBigException e = new PacketTooBigException(); when( logTable.getDatabaseMeta() ).thenReturn( databaseMeta ); when( databaseMeta.getDatabaseInterface() ).thenReturn( databaseInterface ); LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy( logTable, new KettleDatabaseException( e ) ); String strategyName = exceptionStrategy.getClass().getName(); assertEquals( SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName ); }
Example #25
Source File: DataHandlerTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@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(); }
Example #26
Source File: DataHandlerTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testLoadAccessData() throws Exception { when( accessBox.getSelectedItem() ).thenReturn( "Native" ); DatabaseInterface dbInterface = mock( DatabaseInterface.class ); when( dbInterface.getDefaultDatabasePort() ).thenReturn( 5309 ); DataHandler.connectionMap.put( "myDb", dbInterface ); dataHandler.loadAccessData(); // Should immediately return if called again since the connectionBox will have been loaded dataHandler.loadAccessData(); }
Example #27
Source File: FragmentHandlerTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@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 ) ); }
Example #28
Source File: DataHandlerTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testLoadConnectionDataWithSelectedItem() throws Exception { DatabaseInterface dbInterface = mock( DatabaseInterface.class ); when( dbInterface.getDefaultDatabasePort() ).thenReturn( 5309 ); when( connectionBox.getSelectedItem() ).thenReturn( "myDb" ); dataHandler.loadConnectionData(); }
Example #29
Source File: FragmentHandlerTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void testRefreshOptions() throws Exception { XulListbox connectionBox = mock( XulListbox.class ); when( document.getElementById( "connection-type-list" ) ).thenReturn( connectionBox ); when( connectionBox.getSelectedItem() ).thenReturn( "myDb" ); XulListbox accessBox = mock( XulListbox.class ); when( document.getElementById( "access-type-list" ) ).thenReturn( accessBox ); when( accessBox.getSelectedItem() ).thenReturn( "Native" ); DataHandler dataHandler = mock( DataHandler.class ); when( xulDomContainer.getEventHandler( "dataHandler" ) ).thenReturn( dataHandler ); DatabaseInterface dbInterface = mock( DatabaseInterface.class ); when( dbInterface.getDefaultDatabasePort() ).thenReturn( 5309 ); DataHandler.connectionMap.put( "myDb", dbInterface ); XulComponent component = mock( XulComponent.class ); XulComponent parent = mock( XulComponent.class ); when( component.getParent() ).thenReturn( parent ); when( document.getElementById( "database-options-box" ) ).thenReturn( component ); XulDomContainer fragmentContainer = mock( XulDomContainer.class ); Document mockDoc = mock( Document.class ); XulComponent firstChild = mock( XulComponent.class ); when( mockDoc.getFirstChild() ).thenReturn( firstChild ); when( fragmentContainer.getDocumentRoot() ).thenReturn( mockDoc ); when( xulDomContainer.loadFragment( anyString(), any( Object.class ) ) ).thenReturn( fragmentContainer ); XulTextbox portBox = mock( XulTextbox.class ); when( document.getElementById( "port-number-text" ) ).thenReturn( portBox ); fragmentHandler.refreshOptions(); // Iterate through the other database access types when( accessBox.getSelectedItem() ).thenReturn( "JNDI" ); fragmentHandler.refreshOptions(); when( accessBox.getSelectedItem() ).thenReturn( "ODBC" ); fragmentHandler.refreshOptions(); when( accessBox.getSelectedItem() ).thenReturn( "OCI" ); fragmentHandler.refreshOptions(); when( accessBox.getSelectedItem() ).thenReturn( "Plugin" ); fragmentHandler.refreshOptions(); }
Example #30
Source File: SimplePmdDataFactory.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
private DatabaseInterface getDatabaseInterface( final Connection conn, final DatabaseMeta databaseMeta ) { try { final String prod = conn.getMetaData().getDatabaseProductName(); final DatabaseInterface di = DatabaseMetaUtil.getDatabaseInterface( prod, databaseMeta ); if ( prod != null && di == null ) { logger.warn( "dialect not detected" ); //$NON-NLS-1$ } return di; } catch ( final SQLException e ) { logger.warn( "dialect exception", e ); //$NON-NLS-1$ } return null; }