Job Processor Examples

Contents Hide

  

Example 1. Importing a CSV file into a database table

importClass (Packages.au.com.brightsoft.integrator.bi.Job) ;

importClass (Packages.au.com.brightsoft.integrator.bi.Task) ;

importClass (Packages.au.com.brightsoft.integrator.bi.FilePoint) ;

importClass (Packages.au.com.brightsoft.integrator.bi.FileSet) ;

importClass (Packages.au.com.brightsoft.integrator.bi.DatabasePoint) ;

importClass (Packages.au.com.brightsoft.integrator.bi.DatabaseSet) ;

 

function run()

{

    try

    {

        ScriptSession.logInfo("Creating job...") ;

        

        // Create the job manager instance

        var jobManager = ScriptSession.createJobManagerObject() ;

        

        // Create the job definition

        var job = new Job("Import contacts job") ;

        // Task definition

        var task = new Task("Task for importing contacts") ;

        

        // Create source (CSV file)

        var contactsFile = new FilePoint("fileCONTACTS") ;

        var setFileContacts = new FileSet("CONTACTS", "c:/temp/contacts_sample.csv", "MappingContactsFile") ;

        contactsFile.addSet(setFileContacts) ;

        

        // Create destination (database table)

        var contactsTable = new DatabasePoint("jdbcCONTACTS") ;

        contactsTable.setURL("jdbc:sqlserver://localhost:1433;DatabaseName=test") ;

        contactsTable.setUserName("testuser") ;

        contactsTable.setPassword("testpwd") ;

        contactsTable.setDriverName("com.microsoft.sqlserver.jdbc.SQLServerDriver") ;

        contactsTable.setQueryName("QueryContacts") ;

        var setTableContacts = new DatabaseSet("CONTACTS", "CONTACTS", "MappingContactsTable") ;

        contactsTable.addSet(setTableContacts) ;

        

        // Add source and destination definitons to task definition

        task.setSource(contactsFile) ;

        task.setOldSource(contactsTable) ;

        task.setDestination(contactsTable) ;

        

        // Add the task to the job

        job.addTask(task) ;

        

        // Run the job

        ScriptSession.logInfo("Running job...") ;

        jobManager.run(job) ;

        

        ScriptSession.logInfo("Job has completed successfully") ;

    }

    catch (error)

    {

        ScriptSession.logError("Failed to run job " + error.toString()) ;

    }

}

 

Note: