@Test public void testCreateCommandLine() throws Exception { StepMockHelper<OraBulkLoaderMeta, OraBulkLoaderData> stepMockHelper = new StepMockHelper<OraBulkLoaderMeta, OraBulkLoaderData>( "TEST_CREATE_COMMANDLINE", OraBulkLoaderMeta.class, OraBulkLoaderData.class ); when( stepMockHelper.logChannelInterfaceFactory.create( any(), any( LoggingObjectInterface.class ) ) ).thenReturn( stepMockHelper.logChannelInterface ); when( stepMockHelper.trans.isRunning() ).thenReturn( true ); OraBulkLoader oraBulkLoader = new OraBulkLoader( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); File tmp = File.createTempFile( "testCreateCOmmandLine", "tmp" ); tmp.deleteOnExit(); OraBulkLoaderMeta meta = new OraBulkLoaderMeta(); meta.setSqlldr( tmp.getAbsolutePath() ); meta.setControlFile( tmp.getAbsolutePath() ); DatabaseMeta dm = mock( DatabaseMeta.class ); when( dm.getUsername() ).thenReturn( "user" ); when( dm.getPassword() ).thenReturn( "Encrypted 2be98afc86aa7f2e4cb298b5eeab387f5" ); meta.setDatabaseMeta( dm ); String cmd = oraBulkLoader.createCommandLine( meta, true ); String expected = tmp.getAbsolutePath() + " control='" + tmp.getAbsolutePath() + "' userid=user/PENTAHO@"; assertEquals( "Comandline for oracle bulkloader is not as expected", expected, cmd ); }
public String createCommandLine( OraBulkLoaderMeta meta, boolean password ) throws KettleException { StringBuilder sb = new StringBuilder( 300 ); if ( meta.getSqlldr() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getSqlldr() ), getTransMeta() ); String sqlldr = KettleVFS.getFilename( fileObject ); sb.append( sqlldr ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving sqlldr string", ex ); } } else { throw new KettleException( "No sqlldr application specified" ); } if ( meta.getControlFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getControlFile() ), getTransMeta() ); sb.append( " control=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving controlfile string", ex ); } } else { throw new KettleException( "No control file specified" ); } if ( OraBulkLoaderMeta.METHOD_AUTO_CONCURRENT.equals( meta.getLoadMethod() ) ) { sb.append( " data=\'-\'" ); } if ( meta.getLogFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getLogFile() ), getTransMeta() ); sb.append( " log=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving logfile string", ex ); } } if ( meta.getBadFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getBadFile() ), getTransMeta() ); sb.append( " bad=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving badfile string", ex ); } } if ( meta.getDiscardFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getDiscardFile() ), getTransMeta() ); sb.append( " discard=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving discardfile string", ex ); } } DatabaseMeta dm = meta.getDatabaseMeta(); if ( dm != null ) { String user = Const.NVL( dm.getUsername(), "" ); String pass = Const.NVL( Encr.decryptPasswordOptionallyEncrypted( environmentSubstitute( dm.getPassword() ) ), "" ); if ( !password ) { pass = "******"; } String dns = Const.NVL( dm.getDatabaseName(), "" ); sb.append( " userid=" ).append( environmentSubstitute( user ) ).append( "/" ).append( environmentSubstitute( pass ) ).append( "@" ); String overrideName = meta.getDbNameOverride(); if ( Utils.isEmpty( Const.rtrim( overrideName ) ) ) { sb.append( environmentSubstitute( dns ) ); } else { sb.append( environmentSubstitute( overrideName ) ); } } else { throw new KettleException( "No connection specified" ); } if ( meta.isDirectPath() ) { sb.append( " DIRECT=TRUE" ); if ( getStepMeta().getCopies() > 1 || meta.isParallel() ) { sb.append( " PARALLEL=TRUE" ); } } return sb.toString(); }
OraBulkLoader extends BaseStep implements StepInterface { public String createCommandLine( OraBulkLoaderMeta meta, boolean password ) throws KettleException { StringBuilder sb = new StringBuilder( 300 ); if ( meta.getSqlldr() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getSqlldr() ), getTransMeta() ); String sqlldr = KettleVFS.getFilename( fileObject ); sb.append( sqlldr ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving sqlldr string", ex ); } } else { throw new KettleException( "No sqlldr application specified" ); } if ( meta.getControlFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getControlFile() ), getTransMeta() ); sb.append( " control=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving controlfile string", ex ); } } else { throw new KettleException( "No control file specified" ); } if ( OraBulkLoaderMeta.METHOD_AUTO_CONCURRENT.equals( meta.getLoadMethod() ) ) { sb.append( " data=\'-\'" ); } if ( meta.getLogFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getLogFile() ), getTransMeta() ); sb.append( " log=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving logfile string", ex ); } } if ( meta.getBadFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getBadFile() ), getTransMeta() ); sb.append( " bad=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving badfile string", ex ); } } if ( meta.getDiscardFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getDiscardFile() ), getTransMeta() ); sb.append( " discard=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving discardfile string", ex ); } } DatabaseMeta dm = meta.getDatabaseMeta(); if ( dm != null ) { String user = Const.NVL( dm.getUsername(), "" ); String pass = Const.NVL( Encr.decryptPasswordOptionallyEncrypted( environmentSubstitute( dm.getPassword() ) ), "" ); if ( !password ) { pass = "******"; } String dns = Const.NVL( dm.getDatabaseName(), "" ); sb.append( " userid=" ).append( environmentSubstitute( user ) ).append( "/" ).append( environmentSubstitute( pass ) ).append( "@" ); String overrideName = meta.getDbNameOverride(); if ( Utils.isEmpty( Const.rtrim( overrideName ) ) ) { sb.append( environmentSubstitute( dns ) ); } else { sb.append( environmentSubstitute( overrideName ) ); } } else { throw new KettleException( "No connection specified" ); } if ( meta.isDirectPath() ) { sb.append( " DIRECT=TRUE" ); if ( getStepMeta().getCopies() > 1 || meta.isParallel() ) { sb.append( " PARALLEL=TRUE" ); } } return sb.toString(); } }
OraBulkLoader extends BaseStep implements StepInterface { public String createCommandLine( OraBulkLoaderMeta meta, boolean password ) throws KettleException { StringBuilder sb = new StringBuilder( 300 ); if ( meta.getSqlldr() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getSqlldr() ), getTransMeta() ); String sqlldr = KettleVFS.getFilename( fileObject ); sb.append( sqlldr ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving sqlldr string", ex ); } } else { throw new KettleException( "No sqlldr application specified" ); } if ( meta.getControlFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getControlFile() ), getTransMeta() ); sb.append( " control=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving controlfile string", ex ); } } else { throw new KettleException( "No control file specified" ); } if ( OraBulkLoaderMeta.METHOD_AUTO_CONCURRENT.equals( meta.getLoadMethod() ) ) { sb.append( " data=\'-\'" ); } if ( meta.getLogFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getLogFile() ), getTransMeta() ); sb.append( " log=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving logfile string", ex ); } } if ( meta.getBadFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getBadFile() ), getTransMeta() ); sb.append( " bad=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving badfile string", ex ); } } if ( meta.getDiscardFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getDiscardFile() ), getTransMeta() ); sb.append( " discard=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving discardfile string", ex ); } } DatabaseMeta dm = meta.getDatabaseMeta(); if ( dm != null ) { String user = Const.NVL( dm.getUsername(), "" ); String pass = Const.NVL( Encr.decryptPasswordOptionallyEncrypted( environmentSubstitute( dm.getPassword() ) ), "" ); if ( !password ) { pass = "******"; } String dns = Const.NVL( dm.getDatabaseName(), "" ); sb.append( " userid=" ).append( environmentSubstitute( user ) ).append( "/" ).append( environmentSubstitute( pass ) ).append( "@" ); String overrideName = meta.getDbNameOverride(); if ( Utils.isEmpty( Const.rtrim( overrideName ) ) ) { sb.append( environmentSubstitute( dns ) ); } else { sb.append( environmentSubstitute( overrideName ) ); } } else { throw new KettleException( "No connection specified" ); } if ( meta.isDirectPath() ) { sb.append( " DIRECT=TRUE" ); if ( getStepMeta().getCopies() > 1 || meta.isParallel() ) { sb.append( " PARALLEL=TRUE" ); } } return sb.toString(); } OraBulkLoader( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
    Trans trans ); }
OraBulkLoader extends BaseStep implements StepInterface { public String createCommandLine( OraBulkLoaderMeta meta, boolean password ) throws KettleException { StringBuilder sb = new StringBuilder( 300 ); if ( meta.getSqlldr() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getSqlldr() ), getTransMeta() ); String sqlldr = KettleVFS.getFilename( fileObject ); sb.append( sqlldr ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving sqlldr string", ex ); } } else { throw new KettleException( "No sqlldr application specified" ); } if ( meta.getControlFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getControlFile() ), getTransMeta() ); sb.append( " control=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving controlfile string", ex ); } } else { throw new KettleException( "No control file specified" ); } if ( OraBulkLoaderMeta.METHOD_AUTO_CONCURRENT.equals( meta.getLoadMethod() ) ) { sb.append( " data=\'-\'" ); } if ( meta.getLogFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getLogFile() ), getTransMeta() ); sb.append( " log=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving logfile string", ex ); } } if ( meta.getBadFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getBadFile() ), getTransMeta() ); sb.append( " bad=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving badfile string", ex ); } } if ( meta.getDiscardFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getDiscardFile() ), getTransMeta() ); sb.append( " discard=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving discardfile string", ex ); } } DatabaseMeta dm = meta.getDatabaseMeta(); if ( dm != null ) { String user = Const.NVL( dm.getUsername(), "" ); String pass = Const.NVL( Encr.decryptPasswordOptionallyEncrypted( environmentSubstitute( dm.getPassword() ) ), "" ); if ( !password ) { pass = "******"; } String dns = Const.NVL( dm.getDatabaseName(), "" ); sb.append( " userid=" ).append( environmentSubstitute( user ) ).append( "/" ).append( environmentSubstitute( pass ) ).append( "@" ); String overrideName = meta.getDbNameOverride(); if ( Utils.isEmpty( Const.rtrim( overrideName ) ) ) { sb.append( environmentSubstitute( dns ) ); } else { sb.append( environmentSubstitute( overrideName ) ); } } else { throw new KettleException( "No connection specified" ); } if ( meta.isDirectPath() ) { sb.append( " DIRECT=TRUE" ); if ( getStepMeta().getCopies() > 1 || meta.isParallel() ) { sb.append( " PARALLEL=TRUE" ); } } return sb.toString(); } OraBulkLoader( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
    Trans trans ); String getControlFileContents( OraBulkLoaderMeta meta, RowMetaInterface rm, Object[] r ); void createControlFile( String filename, Object[] row, OraBulkLoaderMeta meta ); String createCommandLine( OraBulkLoaderMeta meta, boolean password ); void checkExitVal( int exitVal ); boolean execute( OraBulkLoaderMeta meta, boolean wait ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }
OraBulkLoader extends BaseStep implements StepInterface { public String createCommandLine( OraBulkLoaderMeta meta, boolean password ) throws KettleException { StringBuilder sb = new StringBuilder( 300 ); if ( meta.getSqlldr() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getSqlldr() ), getTransMeta() ); String sqlldr = KettleVFS.getFilename( fileObject ); sb.append( sqlldr ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving sqlldr string", ex ); } } else { throw new KettleException( "No sqlldr application specified" ); } if ( meta.getControlFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getControlFile() ), getTransMeta() ); sb.append( " control=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving controlfile string", ex ); } } else { throw new KettleException( "No control file specified" ); } if ( OraBulkLoaderMeta.METHOD_AUTO_CONCURRENT.equals( meta.getLoadMethod() ) ) { sb.append( " data=\'-\'" ); } if ( meta.getLogFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getLogFile() ), getTransMeta() ); sb.append( " log=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving logfile string", ex ); } } if ( meta.getBadFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getBadFile() ), getTransMeta() ); sb.append( " bad=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving badfile string", ex ); } } if ( meta.getDiscardFile() != null ) { try { FileObject fileObject = KettleVFS.getFileObject( environmentSubstitute( meta.getDiscardFile() ), getTransMeta() ); sb.append( " discard=\'" ); sb.append( KettleVFS.getFilename( fileObject ) ); sb.append( "\'" ); } catch ( KettleFileException ex ) { throw new KettleException( "Error retrieving discardfile string", ex ); } } DatabaseMeta dm = meta.getDatabaseMeta(); if ( dm != null ) { String user = Const.NVL( dm.getUsername(), "" ); String pass = Const.NVL( Encr.decryptPasswordOptionallyEncrypted( environmentSubstitute( dm.getPassword() ) ), "" ); if ( !password ) { pass = "******"; } String dns = Const.NVL( dm.getDatabaseName(), "" ); sb.append( " userid=" ).append( environmentSubstitute( user ) ).append( "/" ).append( environmentSubstitute( pass ) ).append( "@" ); String overrideName = meta.getDbNameOverride(); if ( Utils.isEmpty( Const.rtrim( overrideName ) ) ) { sb.append( environmentSubstitute( dns ) ); } else { sb.append( environmentSubstitute( overrideName ) ); } } else { throw new KettleException( "No connection specified" ); } if ( meta.isDirectPath() ) { sb.append( " DIRECT=TRUE" ); if ( getStepMeta().getCopies() > 1 || meta.isParallel() ) { sb.append( " PARALLEL=TRUE" ); } } return sb.toString(); } OraBulkLoader( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
    Trans trans ); String getControlFileContents( OraBulkLoaderMeta meta, RowMetaInterface rm, Object[] r ); void createControlFile( String filename, Object[] row, OraBulkLoaderMeta meta ); String createCommandLine( OraBulkLoaderMeta meta, boolean password ); void checkExitVal( int exitVal ); boolean execute( OraBulkLoaderMeta meta, boolean wait ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); static final int EX_SUCC; static final int EX_WARN; }