US and Worldwide: +1 (866) 660-7555
Results 1 to 5 of 5

Thread: Connection with Database at UDJC

  1. #1
    Join Date
    Jun 2012
    Posts
    9

    Default Connection with Database at UDJC

    Hi guys. I would like to know if the way I'm connecting to database is right. I'm using the step "User Defined Java Class" and init() and dispose() methods. The following code shows how I'm doing:

    Code:
    public boolean init(StepMetaInterface smi, StepDataInterface sdi)
    {
        if (parent.initImpl(smi, sdi)){
            try{
                db = new Database(this.parent, getTransMeta().findDatabase("SISPE"));
                db.shareVariablesWith(this.parent);
                db.connect();
                return true;
            }
            catch(KettleDatabaseException e){
                logError("Erro ao conectar no banco SISPE: " + e.getMessage());
                setErrors(1);
                stopAll();
            }
        }
     
        return false;
    }
    //------------------------- Inicialização dos objetos para conexão com a base de dados -----------//
    
    
    //------------------------- Fechando conexão com banco de dados ----------------------------------//
    public void dispose(StepMetaInterface smi, StepDataInterface sdi)
    {
        if (db != null) {
            db.disconnect();
        }
     
        parent.disposeImpl(smi, sdi);
    Att. Fabricio Vallim

  2. #2
    Join Date
    Nov 1999
    Posts
    9,533

    Default

    That looks fine to me.
    Matt Casters, Chief Data Integration
    Pentaho, Open Source Business Intelligence
    http://www.pentaho.org -- mcasters@pentaho.org

    Author of the book Pentaho Kettle Solutions by Wiley. Also available as e-Book and on the Kindle reading applications (iPhone, iPad, Android, Kindle devices, ...)

    Join us on IRC server Freenode.net, channel ##pentaho

  3. #3
    Join Date
    Jun 2012
    Posts
    9

    Default

    Hi Matt Casters. Thanks for attention. I would like to take other doubt about connection manipulation at Pentaho. In my transformations I'm enabling the "Make transformation database transactional" option for that I can rolling back if occurs an error during the execution of the transformation. My main doubt is about how Pentaho creates and manages your connections. For each "UDJC (User Defined Java Class)" step the Pentaho creates a connection or it creates just one connection for entire transformation?

    Quote Originally Posted by MattCasters View Post
    That looks fine to me.

  4. #4
    Join Date
    Nov 1999
    Posts
    9,533

    Default

    Looking at the source code of the other steps I would say something like this is needed to make the transformation transactional:

    if (getTransMeta().isUsingUniqueConnections())
    {
    synchronized (getTrans()) { db.connect(getTrans().getThreadName(), getPartitionID()); }
    }
    else
    {
    db.connect(getPartitionID());
    }
    Matt Casters, Chief Data Integration
    Pentaho, Open Source Business Intelligence
    http://www.pentaho.org -- mcasters@pentaho.org

    Author of the book Pentaho Kettle Solutions by Wiley. Also available as e-Book and on the Kindle reading applications (iPhone, iPad, Android, Kindle devices, ...)

    Join us on IRC server Freenode.net, channel ##pentaho

  5. #5
    Join Date
    Jun 2012
    Posts
    9

    Default

    Thanks. The problem was resolved.

    Att.
    Fabricio Vallim
    Last edited by vallim; 07-25-2012 at 04:18 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •