ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Invoke a Java Compute Node's Method from other java class

Post new topic  Reply to topic
 Invoke a Java Compute Node's Method from other java class « View previous topic :: View next topic » 
Author Message
er_pankajgupta84
PostPosted: Wed Mar 25, 2009 11:33 pm    Post subject: Invoke a Java Compute Node's Method from other java class Reply with quote

Master

Joined: 14 Nov 2008
Posts: 203
Location: charlotte,NC, USA

Hi..

Can we invoke a method defined in a Java compute Node's java class from the other java classes.

I have the following requirement..

I have written one method DbOperation() which will accept 4 parameters
- DataSource Name
- Query string
- Input Assembly
- New Assembly

This method will then create a SQLStatement and then execute it and store the result set in new assembly..

My problem is I have to use this method at different places (JCN)...so I have to replicate this method at all those java compute node's java file..

Is there any way i can store this method at some common location and invoke it at rest of the places.

As this method has createSQLStatement function so it has to be in some JCN java class.

Here is the method defination:

private void selectDatabase(MbMessageAssembly contact admin,String p_dataSrcName, String P_QueryString,MbMessageAssembly p_newAssembly) throws MbException {

MbSQLStatement l_sqlStatement = null;

try {
String l_statement = "SET OutputRoot.XMLNS.Records[] = PASSTHRU('"+P_QueryString+"')";

int l_ITrnstionType = MbSQLStatement.SQL_TRANSACTION_COMMIT;


l_sqlStatement = createSQLStatement(p_dataSrcName, l_statement,
l_ITrnstionType);

l_sqlStatement.setThrowExceptionOnDatabaseError(false);

l_sqlStatement.select(contact admin, p_newAssembly);
}}
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
rekarm01
PostPosted: Sun Mar 29, 2009 3:44 pm    Post subject: Re: Invoke a Java Compute Node's Method from other java clas Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 1415

er_pankajgupta84 wrote:
Can we invoke a method defined in a Java compute Node's java class from the other java classes?

Here is the method definition:
Code:
private void selectDatabase(...) throws MbException {
    ...
        l_sqlStatement = createSQLStatement(...);
    ...
}

Java does not allow invoking private methods from other classes; such methods must have either public, protected, or default access.

er_pankajgupta84 wrote:
Is there any way i can store this method at some common location and invoke it at rest of the places?

As this method has createSQLStatement function so it has to be in some JCN java class.

The method does not have to be in some JCN java class. It can be defined as a method in an unrelated class, by adding an argument of type MbJavaComputeNode. For example:
Code:
public class UnrelatedClass {
    public static void selectDatabase(MbJavaComputeNode jcn, ...) throws MbException {
        ...
            l_sqlStatement = jcn.createSQLStatement(...);
        ...
    }
}
Code:
public class MyJCN extends MbJavaComputeNode {
    public void evaluate(MbMessageAssembly assembly) throws MbException {
        ...
            UnrelatedClass.selectDatabase(this, ...);
        ...
    }
}

Alternatively, the method can be defined in an abstract JCN class, and inherited by JCN subclasses. For example:
Code:
public abstract class AbstractJCN extends MbJavaComputeNode {
    public abstract void evaluate(MbMessageAssembly assembly) throws MbException;
    protected void selectDatabase(...) throws MbException {
        ...
            l_sqlStatement = createSQLStatement(...);
        ...
    }
}
Code:
public class MyJCN extends AbstractJCN {
    public void evaluate(MbMessageAssembly assembly) throws MbException {
        ...
            selectDatabase(...);
        ...
    }
}
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sun Mar 29, 2009 8:53 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

I think more revealing is following in his Java call:
Quote:
try {
String l_statement = "SET OutputRoot.XMLNS.Records[] = PASSTHRU('"+P_QueryString+"')";


I would urge him to check if this syntax is acceptable in Java for the statement... I would have expected something like this:
Code:
String i_statement = "PASSTHRU(" + P_QueryString + ")";
mymbelement = i_statement.execute();

or something similar... Anyways OutputRoot.XMLNS.Records should be passed as Reference and looked at in MbElement format ??

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
er_pankajgupta84
PostPosted: Sun Mar 29, 2009 9:51 pm    Post subject: Reply with quote

Master

Joined: 14 Nov 2008
Posts: 203
Location: charlotte,NC, USA

Thanks for your replies....

It's really a great information...

Regarding public & private method...it was pretty obvious stuff...
Regarding execution of query..again its the obvious stuff...

My point of discussion was how to invoke jcn's method from other jcn...

I have one last question... i.e. declaring an abstract JCN java class is legal and accepted as best practice....or not....same goes for passing this the this pointer as argument...

Have you guys used this thing in your code at anytime...

Thanks again for the valuable information ...
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
fjb_saper
PostPosted: Tue Mar 31, 2009 2:14 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

er_pankajgupta84 wrote:
Thanks for your replies....

It's really a great information...

Regarding public & private method...it was pretty obvious stuff...
Regarding execution of query..again its the obvious stuff...

My point of discussion was how to invoke jcn's method from other jcn...

I have one last question... i.e. declaring an abstract JCN java class is legal and accepted as best practice....or not....same goes for passing this the this pointer as argument...

Have you guys used this thing in your code at anytime...

Thanks again for the valuable information ...

Abstract Class used in Java development ... pretty obvious stuff...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Invoke a Java Compute Node's Method from other java class
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.