<%@ page import="java.util.*" %> <%@ page import="org.osoa.sca.CompositeContext" %> <%@ page import="org.osoa.sca.CurrentCompositeContext" %> <%@ page import="commonj.sdo.*" %> <%@ page import="org.apache.tuscany.samples.das.orders.*" %> <%@ page language="java" contentType="text/html;charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> DAS - SCA Container Test

Tuscany DAS - SCA container Test

(demo for static service API approach e.g. getAllCustomers())

<% CompositeContext context = CurrentCompositeContext.getContext(); CustomersOrdersService service = context.locateService(CustomersOrdersService.class, "CustomersOrdersComponent"); List customers = null; Map inParams = new Hashtable(); Vector params = new Vector(); %> <%! //common code to display latest results public Iterator getResult(){ List custList = null; java.util.Iterator i = null; try{ Map inParams = new Hashtable(); Vector params = new Vector(); CompositeContext context = CurrentCompositeContext.getContext(); CustomersOrdersService service = context.locateService(CustomersOrdersService.class, "CustomersOrdersComponent"); params.clear(); params.add("");//of no use - as is derived using CommandMapper params.add("select"); //is needed to understand whether execute/executeQuery/applyChanges inParams.clear(); inParams.put(1, new Integer(1)); params.add(inParams); DataObject root = service.getRangeCustomers(params); custList = root.getList("CUSTOMER"); if(custList != null){ i = custList.iterator(); return i; } }catch(Exception e){ e.printStackTrace(); //TODO: handle case where dasService can't be initiated properly }finally{ } return i; } %>
<%if(request.getParameter("doSelectStatic") != null){%> <% java.util.Iterator i = getResult(); while (i.hasNext()) { DataObject customer = (DataObject)i.next(); %> <% }//while %>
ID LastName
<%=customer.getInt("ID")%> <%=customer.getString("LASTNAME")%>
<%}//doSelectStatic %> <%if(request.getParameter("doInsertExecute") != null){%> <%try{ params.clear(); inParams.clear(); System.out.println("Calling InsertCustomerExecute"); params.clear(); inParams.clear(); params.add(""); params.add("insert"); inParams.put(1, new Integer(4)); inParams.put(2, new String("11")); inParams.put(3, new String("111")); params.add(inParams); service.getInsertCustomerExecute(params); }catch(Exception e){ e.printStackTrace(); }%> <% java.util.Iterator i = getResult(); while (i.hasNext()) { DataObject customer = (DataObject)i.next(); %> <% }//while %>
ID LastName
<%=customer.getInt("ID")%> <%=customer.getString("LASTNAME")%>
<%}//doInsertExecute %> <%if(request.getParameter("doInsertApplyChanges") != null){%> <%try{ Map insertParams = new Hashtable(); System.out.println("Calling InsertCustomerApplyChanges"); params.clear(); insertParams.clear(); params.add(""); params.add("insert:CUSTOMER"); insertParams.put("ID", new Integer("9")); insertParams.put("LASTNAME", "222"); insertParams.put("ADDRESS", "2222"); params.add(insertParams); service.getInsertCustomerApplyChanges(params); }catch(Exception e){ e.printStackTrace(); }%> <% java.util.Iterator i = getResult(); while (i.hasNext()) { DataObject customer = (DataObject)i.next(); %> <% }//while %>
ID LastName
<%=customer.getInt("ID")%> <%=customer.getString("LASTNAME")%>
<%}//doInsertApplyChanges %> <%if(request.getParameter("doDeleteExecute") != null){%> <% try{ System.out.println("Calling DeleteCustomerExecute"); params.clear(); inParams.clear(); params.add(""); params.add("delete"); inParams.put(1, new Integer(9)); params.add(inParams); service.getDeleteCustomerExecute(params); }catch(Exception e){ e.printStackTrace(); }%> <% java.util.Iterator i = getResult(); while (i.hasNext()) { DataObject customer = (DataObject)i.next(); %> <% }//while %>
ID LastName
<%=customer.getInt("ID")%> <%=customer.getString("LASTNAME")%>
<%}//doDeleteExecute %> <%if(request.getParameter("doDeleteApplyChanges") != null){%> <%try{ Map whereParams = new Hashtable(); params.clear(); whereParams.clear(); whereParams.put("ID", new Integer(1)); params.add(""); params.add("delete:CUSTOMER");//command type:tableName params.add(whereParams); service.getDeleteCustomerApplyChanges(params); }catch(Exception e){ e.printStackTrace(); }%> <% java.util.Iterator i = getResult(); while (i.hasNext()) { DataObject customer = (DataObject)i.next(); %> <% }//while %>
ID LastName
<%=customer.getInt("ID")%> <%=customer.getString("LASTNAME")%>
<%}//doDeleteApplyChanges %> <%if(request.getParameter("doUpdateApplyChanges") != null){%> <%try{ Map updParams = new Hashtable();//as its not position based but name based Map whereParams = new Hashtable(); params.clear(); updParams.clear(); updParams.put("LASTNAME", "Berry"); whereParams.put("ID", new Integer(1)); params.add(""); params.add("update:CUSTOMER");//command type:tableName params.add(updParams); params.add(whereParams); System.out.println("whereParams:"+whereParams.get("ID")); service.getUpdateCustomer(params); }catch(Exception e){ e.printStackTrace(); }%> <% java.util.Iterator i = getResult(); while (i.hasNext()) { DataObject customer = (DataObject)i.next(); %> <% }//while %>
ID LastName
<%=customer.getInt("ID")%> <%=customer.getString("LASTNAME")%>
<%}//doUpdateApplyChanges %> <%if(request.getParameter("doSP") != null){%> <%try{ Map outParams = new Hashtable(); System.out.println("Calling getNamedCustomers"); params.clear(); inParams.clear(); outParams.clear(); inParams.put(1, new String("Berry")); outParams.put(2, new Object()); params.add(""); params.add("procedure"); params.add(inParams); params.add(outParams); Object returnObj = service.getNamedCustomers(params); //check values in OUT params Map resParams = (Map )params.get(3); int cnt = 0; if(resParams.size() != 0){ Set resSet = (Set)resParams.keySet(); Iterator res = resSet.iterator(); Object resObj = null; while(res.hasNext()){ Integer rdx = (Integer)res.next(); resObj = (Object)resParams.get(rdx); System.out.println("result :"+rdx +","+resObj); cnt = ((Integer)resObj).intValue(); } } //check value in return result if(cnt > 0){ if(returnObj instanceof DataObject){ DataObject doResult = (DataObject)returnObj; customers = doResult.getList("CUSTOMER"); java.util.Iterator i = customers.iterator(); System.out.println("customers:"+customers.size()); %> <% while (i.hasNext()) { DataObject customer = (DataObject)i.next(); %> <%}//while }//if DataObj }//if cnt }catch(Exception e){ e.printStackTrace(); }%> <%}//doSP %>
ID LastName
<%=customer.getInt("ID")%> <%=customer.getString("LASTNAME")%>