Author Message
SriniKotaru
Joined: Jan 25, 2006
Messages: 0
Offline
Hi,
I am trying to join two oracle tables in DD. Any ideas how I can implement that? Looks like only one table can be chosen for a new DBOP.

SELECT * FROM candidates where candidate_id not in (select candidate_id from votes where member_id=1111);

I tried to use a stored procedure, but looks like Cursor type variables returning multiple rows aren''t supported in DD. On the other hand a SQL server stored procedure returning multiple rows works fine.
NeilGoldsmith
Joined: Nov 6, 2013
Messages: 902
Offline
To do any complex DB operations (joins for instance), you need to write custom Java code.  You can do it using  a servlet node in your flow or you can override the requestBegin method in your data node and put the code in there.

We are working on improvements to the DB wizard and runtime to make it more versatile.
SriniKotaru
Joined: Jan 25, 2006
Messages: 0
Offline
I would consider database joins to be basic operations, but if it could be done with Servlet node that will work. Is there an example for using the Servlet node in the samples? 

Also I thought that making changes to the java code (for nodes)is not recommended, as there is always a chance of custom code being over-written by generated code. Is that not right?
NeilGoldsmith
Joined: Nov 6, 2013
Messages: 902
Offline
To use a servlet node, drop it onto your callflow.  Note: there is a difference between a servlet and vxml servlet node(which are stacked together in the palette).  The servlet node is just a bare bones servlet that allows you to add your own custom code, which is what you want to use.

You then override servletImplementation(), connect to and code your DB operations there.

We intentionally added hooks into the generated code for users to write their own code which will not be overwritten if the code is regenerated.  As long as you override the recommended methods, you should have no problems.

There isn''t a sample showing how to use a servlet.  There is one showing how to use a VXML servlet which is called UserDefineVXML.  You can use that as a guide as long as you override the method I mentioned above and remember to use the servlet node instead.  There''s really only a few steps: drop it on your flow, connect it up, edit the java code by right clicking the servlet node and picking Edit, then override the method mentioned and you are ready to write your code.
SriniKotaru
Joined: Jan 25, 2006
Messages: 0
Offline
Thanks Neil. Tried the following in a Servlet node and looks like it is working now.

   public void servletImplementation(com.avaya.sce.runtimecommon.SCESession mySession) 
   {
      try {
            String driver_class = "oracle.jdbc.driver.OracleDriver"; 
            String connect_string = "jdbc:oracle:thin:@localhost:1521:xyz"; 
            String query = "{? = call sp_cursor(?)}"; 
            Connection conn; 
            Class.forName(driver_class); 
            conn = DriverManager.getConnection(connect_string, "xyz", "xyz"); 
            CallableStatement cstmt = conn.prepareCall(query); 
            cstmt.registerOutParameter(1,OracleTypes.CURSOR); 
            cstmt.setInt(2,1111); 
            cstmt.execute(); 
            ResultSet rset = (ResultSet)cstmt.getObject(1); 

            IVariable var = mySession.getVariable(IProjectVariables.CANDIDATE_INFO);
           var.setCollection(new ComplexCollection(var.getComplexVariable(), IProjectVariables.CANDIDATE_INFO));
           ICollection collection = var.getCollection();
            while (rset.next ()) 
            {
               var.getComplexVariable().getField(IProjectVariables.CANDIDATE_INFO_FIELD_ID).setValue(rset.getString (1));
               var.getComplexVariable().getField(IProjectVariables.CANDIDATE_INFO_FIELD_NAME).setValue(rset.getString (2) );
               var.getComplexVariable().getField(IProjectVariables.CANDIDATE_INFO_FIELD_DETAILS).setValue(rset.getString (3) );
         collection.append();
            }
            //collection.reset();
            cstmt.close();         }
         catch (Exception ex) {
            System.out.println ("\n*** Exception caught ***\n");
         }
   }
NeilGoldsmith
Joined: Nov 6, 2013
Messages: 902
Offline
Great, glad it''s working!  Your code will be a good example for others to learn from.  This question seems to come up alot.
Go to:   
Mobile view