Hi Gurus…
I am curious on better coding practice for Java services. I would like to throw some ideas to you, to start and would love to hear your comments.
I have created java service using two different styles. Below is my test service examples for both.
Style 1. Create code using Tools=> Generate Code
Code created using this style is as below.
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String testin = IDataUtil.getString( pipelineCursor, "testin" );
pipelineCursor.destroy();
// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
IDataUtil.put( pipelineCursor_1, "testout", testin );
pipelineCursor_1.destroy();
Advantages :
1. Ease of code creation.
2. Cursor is immediately destroyed (pipelineCursor.destroy()
after getting data of the pipeline to local variables. This can be significant for complex and heavy java service.
need more from you guys…
Style 2. Hand craft you java service.
IDataCursor c = null;
try
{
c = pipeline.getCursor();
String testout = null;
if(c.first("testin"))
testout = (String)c.getValue();
c.insertAfter("testout", testout);
}
catch(Exception e)
{
throw new ServiceException(e.toString());
}
finally
{
if(c != null)
c.destroy();
}
Advantages :
1. Only one instance of cursor to for whole service. (not sure if this is good or not…)
2. Not using IDataUtil at all…(again not sure if this is good or not…!!)
Question I have are
- Which one is efficient from performance point of view.
String testin = IDataUtil.getString( pipelineCursor, "testin" );
Or
if(c.first("testin"))
testout = (String)c.getValue();
- If I throw service exception in catch block as throw new ServiceException(e.toString()); will it still go to finally block and destroy the cursor???
- Most of built in WM Java services uses Style 2. Does that mean its better practice or they are using different IDE to create java service…???
Please throw your idea and though on this and also let me know if there is any other Style or Practice is there for Java Services???
Cheers,
Ajit
#Integration-Server-and-ESB#webMethods#Flow-and-Java-services