Get connection metadata from shared.xml in KETTLE_HOME

1,326 views
Skip to first unread message

origin

unread,
Jul 26, 2012, 7:05:13 AM7/26/12
to kettle-d...@googlegroups.com
Hi,

I already posted this in the Pentaho Kettle forum, but was told that it is the place to post for the point-and-click developers. I'm trying to read a shared connection from the shared.xml using the Java API. My question from them Pentaho forum:

Is it possible to get database metadata of a specific shared database connection via the Java API from $KETTLE_HOME/.kettle/shared.xml by providing the connection name? What I'd expect is something like

DatabaseMeta dm = KettleEnvironment.getDatabaseMeta("myconnection");

(... with "myconnection" being a shared connection in the shared.xml.)

Regards,
Origin

Matt Casters

unread,
Jul 26, 2012, 7:14:18 AM7/26/12
to kettle-d...@googlegroups.com
Hey Origin,

Try :

SharedObjects sharedObjects = SharedObjects(); // loads shared.xml

Then you have access to the shared objects map.

In this case you probably need something like the following:

DatabaseMeta dbMeta = (DatabaseMeta) sharedObjects.getObjectsMap().get(new SharedEntry(DatabaseMeta.class.getName(), "myconnection");

That reminds me to put some generics in there... somewhere ;-)

Cheers,
Matt


2012/7/26 origin <stra...@hotmail.com>

--
You received this message because you are subscribed to the Google Groups "kettle-developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/kettle-developers/-/SwZ8PIYPQ9AJ.
To post to this group, send email to kettle-d...@googlegroups.com.
To unsubscribe from this group, send email to kettle-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/kettle-developers?hl=en.



--
Matt Casters <mcas...@pentaho.org>
Chief Data Integration, Kettle founder, Author of Pentaho Kettle Solutions (Wiley)
Fonteinstraat 70 - 9400 OKEGEM - Belgium - Cell : +32 486 97 29 37
Pentaho  -  Powerful Analytics Made Easy

origin

unread,
Jul 27, 2012, 2:35:02 AM7/27/12
to kettle-d...@googlegroups.com, mcas...@pentaho.org
Hi,

thanks for your reply! The problem is that SharedEntry is a private class in SharedObjects, so we can't simply create an instance of it.

But we found a snippet like this somewhere in the kettle code:

        SharedObjects so = new SharedObjects();
        for (SharedObjectInterface soi : so.getObjectsMap().values()) {
            if ((soi instanceof DatabaseMeta)
                    && soi.getName().equals(connectionName)) {
                DatabaseMeta dm = (DatabaseMeta) soi;
                this.driver = dm.getDriverClass();
                this.user = dm.getUsername();
                this.password = dm.getPassword();
                this.jdbcUrl = dm.getURL();
                break;
            }
        }

... which is of course less than very clean (looping over the set of values and doing an instanceof).

(Perhaps it would be better to make the key class of the Map public (?))

Regards,
Origin

Matt Casters

unread,
Aug 10, 2012, 8:36:31 AM8/10/12
to kettle-d...@googlegroups.com
Sorry for the late reply Origin, vacation and a lot of work got in the way.
Did you ever create a JIRA case for your proposed improvement?  I would be happy to pass the change into 5.0 so that future generations of Kettle developers have an easier time ;-)

Thanks in advance!

Matt


2012/7/27 origin <stra...@hotmail.com>


Regards,
Origin

--
You received this message because you are subscribed to the Google Groups "kettle-developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/kettle-developers/-/7hk2utQ2d_8J.

To post to this group, send email to kettle-d...@googlegroups.com.
To unsubscribe from this group, send email to kettle-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/kettle-developers?hl=en.

origin

unread,
Sep 4, 2012, 7:00:36 AM9/4/12
to kettle-d...@googlegroups.com, mcas...@pentaho.org
OK, this is really a very late reply :) Sorry, I didn't expect an answer anymore and I didn't get a mail notification either.

No, I didn't haven't created a JIRA entry yet, but I'm going to do so once I'm registered.

Regards!

Phil

origin

unread,
Sep 4, 2012, 7:19:18 AM9/4/12
to kettle-d...@googlegroups.com, mcas...@pentaho.org

Matt Casters

unread,
Sep 10, 2012, 5:57:09 AM9/10/12
to kettle-d...@googlegroups.com
I put some extra convenience methods in 4.4.0 and trunk (5.0) so hopefully that helps future developers.  Thanks for the feedback.

Matt


2012/9/4 origin <stra...@hotmail.com>
To view this discussion on the web visit https://groups.google.com/d/msg/kettle-developers/-/bjPOWcNfFGQJ.

To post to this group, send email to kettle-d...@googlegroups.com.
To unsubscribe from this group, send email to kettle-develop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/kettle-developers?hl=en.
Reply all
Reply to author
Forward
0 new messages