7 Replies Latest reply on Jan 23, 2007 11:12 AM by Wolfgang Knauf

    Stateless Session bean throwing error

    vis hnu Newbie

      Hi

      I am getting error from the statless session bean after some subsequent request to the bean, First 10 or 20 calls works fine, after some time it gives the below error

      And also please tell me how i can check the number of instances created for a Bean in Jboss Web Console.

      message <font face='Verdana, Arial, Helvetica' size='2'>Sorry, an error has occurred: null</font><br><br><font face='Verdana, Arial, Helvetica' size='1'>com.tlc.report.ReportException<br> at com.tlc.report.ReportBean.load(ReportBean.java:1087)<br> at com.tlc.report.ReportBean.load(ReportBean.java:1244)<br> at sun.reflect.GeneratedMethodAccessor160.invoke(Unknown Source)<br> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br> at java.lang.reflect.Method.invoke(Method.java:585)<br> at org.jboss.invocation.Invocation.performCall(Invocation.java:359)<br> at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:237)<br> at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:158)<br> at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:169)<br> at org.jboss.ws.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:64)<br> at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:63)<br> at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:121)<br> at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:315)<br> at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181)<br> at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:168)<br> at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205)<br> at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:136)<br> at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:648)<br> at org.jboss.ejb.Container.invoke(Container.java:954)<br> at sun.reflect.GeneratedMethodAccessor125.invoke(Unknown Source)<br> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br> at java.lang.reflect.Method.invoke(Method.java:585)<br> at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)<br> at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)<br> at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)<br> at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)<br> at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)<br> at org.jboss.invocation.local.LocalInvoker$MBeanServerAction.invoke(LocalInvoker.java:169)<br> at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:118)<br> at org.jboss.invocation.InvokerInterceptor.invokeLocal(InvokerInterceptor.java:206)<br> at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:192)<br> at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:61)<br> at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:70)<br> at org.jboss.proxy.ejb.StatelessSessionInterceptor.invoke(StatelessSessionInterceptor.java:112)<br> at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:100)<br> at $Proxy106.load(Unknown Source)<br> at com.tlc.isupport.ISupport.reportCaseLogged(ISupport.java:503)<br> at com.tlc.isupport.ISupport.service(ISupport.java:219)<br> at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)<br> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)<br> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)<br> at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)<br> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)<br> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)<br> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)<br> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)<br> at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)<br> at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)<br> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)<br> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)<br> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)<br> at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)<br> at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:199)<br> at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:282)<br> at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:754)<br> at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:684)<br> at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:876)<br> at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)<br> at java.lang.Thread.run(Thread.java:595)</font>
      

      This error does not come for the first time , it comes after subsequent calls to the Reportbean [argh]

      Somebody please help

        • 1. Re: Stateless Session bean throwing error
          vis hnu Newbie

          Any updates

          Somebody Please help

          • 2. Re: Stateless Session bean throwing error
            Wolfgang Knauf Master

            Hi Vishnu,

            seems a Null pointer exception has occured in ReportBean.java:1087. Could you post the code of this method ?

            Wolfgang

            • 3. Re: Stateless Session bean throwing error
              vis hnu Newbie

              Hi Wolfgang

              Thanks for your reply


              Below is the code of reportbean

              ----------------------------------------------
              package com.tlc.report;


              import javax.ejb.*;
              import javax.naming.*;
              import javax.transaction.*;
              import java.lang.reflect.*;
              import javax.rmi.*;
              import java.io.*;
              import java.rmi.RemoteException;
              import java.util.*;
              import java.sql.*;
              import javax.sql.DataSource;
              import java.text.*;

              import com.tlc.utils.*;
              import com.tlc.tlomm.*;

              import org.apache.log4j.*;

              public class ReportBean implements SessionBean {
              private static Category logger = Category.getInstance(ReportBean.class.getName());
              private static final String dsKey = "ds." + ReportBean.class.getName();
              private SessionContext ctx;
              private Context jctx;
              private String cid;
              private ClientInfo client;

              private TableTree tree;
              private String query;

              private Vector qualifiers;
              private Vector formats;
              private Vector heading_formats;

              private String selectPart;
              private String fromPart;
              private String wherePart;
              private String orderPart;
              private int groupInd; /* indicates which column is the 'group' column */
              private String groupByOrder;

              private String basetab;
              private String title;
              private String description;
              private String type;
              private String filename;
              private String xtab_groupby;
              private String xtab_grouporder;
              private String xtab_toprow;
              private Vector xtab_values;
              private boolean xtab_totals;

              private String filter; /* because this is complex, we can't store it in a tree */
              private String filterText;

              private DataSource ds;

              private int reportId;
              private int catId;

              private String temptablename;

              private boolean namechanged;
              private Vector objectlist; /* just so we can tell if a saved report has been modified */
              private Vector object_filter_list; /* as above, but so that we can tell if
              an object used in a filter has been removed */
              boolean popup_links_exist = true;

              private Vector pkeys; /* primary keys of the top-level objects */
              private int rowcount;

              private String dbserver_type = null;

              private Vector filterConditions = null;
              private HashMap dateParameter = null;
              private String expression = null;
              private Vector parameters = null;
              private Vector dateQualifiers = null;
              private String dateQuery = null;

              public void clear() {

              groupInd = 0;
              basetab = null;
              type = null;
              filename = null;
              title = null;
              description = null;
              tree = null;
              filter = null;
              filterText = null;
              xtab_values = new Vector(16, 16);
              xtab_groupby = null;
              xtab_toprow = null;
              namechanged = false;
              pkeys = new Vector(16, 16);
              objectlist = new Vector(16, 16);
              object_filter_list = new Vector(16, 16);
              xtab_totals = false;
              xtab_grouporder = null;
              rowcount = 0;
              filterConditions = null;
              dateParameter = null;
              expression = null;
              parameters = null;
              dateQualifiers = null;
              dateQuery = null;
              }

              public void ejbCreate() throws CreateException {
              try {
              Properties globalProps = Utility.getTLProps();
              String dsName = globalProps.getProperty(dsKey);//"ds_jndiname.report");
              ds = (DataSource)jctx.lookup(dsName);//"java:comp/env/jdbc/TLReportDataSource"
              dbserver_type = globalProps.getProperty(Utility.TLPROP_DBSERVER_TYPE);
              if (dbserver_type == null) dbserver_type = Utility.TL_MSSQL;
              }
              catch (Exception ex) {
              throw new CreateException(ex.getMessage());
              }
              }

              public void ejbActivate() {
              //not used
              }

              public void ejbPassivate() {
              //not used
              }

              public void ejbRemove() {
              //does nothing
              }

              public void setSessionContext(SessionContext ctx) throws RemoteException {
              try {
              if (ctx == null) return;

              this.ctx = ctx;
              this.jctx = new InitialContext();
              }
              catch (Exception ex) {
              logger.error(ex);
              throw new RemoteException("ReportBean.setSessionContext: " + ex.getMessage());
              }

              }


              public void setCid(String s) {
              cid = s;
              client = ClientCache.getClientInfo(cid);
              }

              public void setType(String t) {
              type = t;
              }

              public String getType() {
              return type;
              }

              public void setFileName(String fn) {
              filename = fn;
              }

              public String getFileName() {
              return filename;
              }

              public ReportBean() {

              }

              public void setQualifiers(Vector v) {
              qualifiers = v;
              }

              /* tree-mutating functions */
              public void createTree(String cid, String tlomm_type, String roleName, SimpleDateFormat udf)
              throws Exception {

              tree = new TableTree(tlomm_type, null, true);
              tree.setTlommType(tlomm_type);
              tree.setCid(cid, roleName, udf);
              }

              public TableTree addSubtree(String name, boolean is_table,
              boolean is_restriction, int sort_order,
              String sort_dir, String cfunc, int sel_ord)
              throws Exception {

              /* returns the node we're interested */
              TableTree node = tree.addSubtree(name, is_table, is_restriction, sort_order, sort_dir);

              logger.debug("cfunc is " + cfunc);

              /* in case nothing actually got added... */
              if(!is_restriction)
              node.is_selection = true;
              if(sort_order != 0) {
              node.sortOrd = sort_order;
              node.sortDir = sort_dir;
              }
              if(sel_ord != 0) {
              node.selOrd = sel_ord;
              }
              if(cfunc != null)
              node.summary = cfunc;


              tree.makeSqlIdentifiers();
              tree.calcTlommTypes();
              logger.debug("returning for : " + name + ": node is :" + node);
              return node;
              }


              public void makeSqlIdentifiers() {
              tree.makeSqlIdentifiers();
              }


              /* tree-accessor functions */
              private TableTree getTableTree(String name)
              throws ReportException {

              return tree.findNode(name); /* yes, this is right, silly person */
              }


              public String fromClause() throws Exception {
              return tree.fromClause();
              }


              public void setQuery(String q) {
              query = q;
              }

              public Vector execute(int startrow, int endrow)
              throws ReportException {
              logger.debug("execute(startrow,endrow)");
              return execute(startrow, endrow, false);
              }

              private Vector execute(int startrow, int endrow, boolean allrows)
              throws ReportException {

              logger.debug("entering execute(startrow,endrow,boolean) with :" +
              startrow + " : " + endrow + " : " + allrows);

              Connection con = null;
              PreparedStatement pstmt = null;
              Vector v = null;
              DBUtil dbutil = null;
              if (allrows == true) {
              v = new Vector(1000,1000);
              pkeys = new Vector(1000,1000);
              }
              else {
              v = new Vector(endrow - startrow, 2); /* the rows */
              pkeys = new Vector(endrow - startrow, 2);
              }

              try{
              logger.debug("Group ind is: " + groupInd);
              con = ds.getConnection();
              //Oracle 9i supports only TRANSACTION_READ_COMMITTED(default) and TRANSACTION_SERIALIZABLE
              if (!(Utility.TL_ORACLE.equalsIgnoreCase(dbserver_type) ||
              Utility.TL_PGSQL.equalsIgnoreCase(dbserver_type)))
              con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);

              logger.debug("columnarQuery without dateparameter substitution is : " + query);

              String columnarQuery = query;
              if ((query.indexOf("tldateparameter") != -1) && (dateQuery != null)) {

              //replacing dateParamter.
              columnarQuery = query.substring(0,query.indexOf("tldateparameter")) +
              dateQuery +
              query.substring(query.indexOf("tldateparameter") + 15, query.length());

              }
              logger.debug("Final columnarQuery is : " + columnarQuery);

              pstmt = con.prepareStatement(columnarQuery);

              int qualifierCount = 0;
              /* put in the values */
              for (int i = 0; i < qualifiers.size(); i++) {
              //This is to support 321 and prior reports.
              Object obj = qualifiers.elementAt(i);
              String pq = obj.toString();
              if ((filterConditions != null) && (pq.indexOf("$") != -1)) {
              String fpos = pq.substring(pq.indexOf("$") + 1, pq.length());
              String parampos = pq.substring(pq.indexOf("_") + 1, pq.indexOf("$"));
              HashMap fCond = (HashMap) filterConditions.elementAt(Integer.parseInt(fpos));
              Object qualifier = fCond.get("attrObjValue");
              logger.debug("Setting qualifier object " + Integer.parseInt(parampos) + " to " + qualifier.toString());
              pstmt.setObject(Integer.parseInt(parampos), qualifier);
              qualifierCount++;
              } else {
              qualifierCount++;
              logger.debug("Setting qualifier(321) object " + qualifierCount + " to " + obj.toString());
              pstmt.setObject(qualifierCount, obj);
              }
              }

              /* set parameter values */
              if (parameters != null) {
              for (int i = 0; i < parameters.size(); i++) {
              String pq = (String) parameters.elementAt(i);
              if (pq.indexOf("$") != -1) {
              String fpos = pq.substring(pq.indexOf("$") + 1, pq.length());
              String parampos = pq.substring(pq.indexOf("_") + 1, pq.indexOf("$"));
              HashMap fCond = (HashMap) filterConditions.elementAt(Integer.parseInt(fpos));
              Object qualifier = fCond.get("attrObjValue");
              logger.debug("Setting parameter qualifier object " + Integer.parseInt(parampos) + " to " + qualifier.toString());
              pstmt.setObject(Integer.parseInt(parampos), qualifier);
              qualifierCount++;
              }
              }
              }

              //For date qualifiers.
              if (dateQualifiers != null) {
              for (int i = 0; i < dateQualifiers.size(); i++) {
              Object qualifier = dateQualifiers.elementAt(i);
              logger.debug("setting dateParameter qualifier : " + qualifier);
              qualifierCount++;
              pstmt.setObject(qualifierCount, qualifier);
              }
              }

              ResultSet rs = pstmt.executeQuery();

              Vector selected = tree.selections();
              int ncols = selected.size();

              Row labelRow = new Row();
              labelRow.cells = tree.selectionLabels();
              labelRow.type = "labels";
              if (popup_links_exist) pkeys.addElement("");
              v.addElement(labelRow);

              Vector nvlists = tree.nvlists();
              formats = tree.formats();
              heading_formats = formats; /* for a normal report, these are the same */

              logger.debug("Got formats");

              Vector subtotals = new Vector(16, 16); /* keep a running count of the subtotals */
              Vector totals = new Vector(16, 16); /* keep a running count of the totals */
              for(int i = 0; i < labelRow.cells.size(); ++i) {
              subtotals.addElement(new Float(0.0));
              totals.addElement(new Float(0.0));
              }
              int subaveragectr = 0;
              int averagectr = 0;

              Object lastGroup = null;
              boolean firstrow = true;
              rowcount = 0;
              if (Utility.TL_ORACLE.equalsIgnoreCase(dbserver_type))
              dbutil = DBUtilFactory.getDBUtil();

              while(rs.next()) {

              if(groupInd != 0) {
              Object testForBreak = rs.getObject(groupInd);
              if( (testForBreak != null && !testForBreak.equals(lastGroup)) ||
              (testForBreak == null && lastGroup != null)) {
              if(!firstrow) {
              /* add the subtotals */
              Row strow = new Row();
              strow.cells = new Vector(ncols, 1);
              strow.type = "subtotal";
              strow.subrowcnt = new Integer(subaveragectr);
              for(int i = 0; i < ncols; ++i) {
              ColumnSelection cs = (ColumnSelection)selected.elementAt(i);
              if(cs.summary != null && cs.summary.equalsIgnoreCase("sum")) {
              strow.cells.addElement( subtotals.elementAt(i));
              }
              else if(cs.summary != null && cs.summary.equalsIgnoreCase("avg")) {
              float f = ((Number)subtotals.elementAt(i)).floatValue();
              strow.cells.addElement( new Float(f/subaveragectr));
              }
              else {
              strow.cells.addElement(" ");
              }
              subtotals.setElementAt(new Float(0.0), i);
              }
              if ((allrows == true) || ((startrow < rowcount) && (rowcount <= endrow + 1))) {
              v.addElement(strow);
              if(popup_links_exist) pkeys.addElement("");
              }
              }
              lastGroup = testForBreak;
              subaveragectr = 0;
              }
              }
              firstrow = false;
              for(int i = 1; i <= ncols; ++i) {
              Object o = rs.getObject(i);
              if(o instanceof Number ) {
              float f = ((Number)subtotals.elementAt(i - 1)).floatValue();
              float g = ((Number)o).floatValue();

              subtotals.setElementAt(new Float( f + g ), i - 1);

              f = ((Number)totals.elementAt(i - 1)).floatValue();
              totals.setElementAt(new Float( f + g ) , i - 1);
              }
              }

              if ((allrows == true) || ((startrow <= rowcount) && (rowcount <= endrow))) {
              Row row = new Row();
              row.cells = new Vector(ncols, 1);
              row.type = "normal";
              row.subrowcnt = null;

              for(int i = 1; i <= ncols; ++i) {
              Object o = rs.getObject(i);
              if(o == null) o = "";
              if ((o instanceof Clob) && (Utility.TL_ORACLE.equalsIgnoreCase(dbserver_type))) {
              String str = dbutil.readClob((Clob)o);
              row.cells.addElement(str);
              } else {
              /* now see if we need to look this up from the nvlist */
              Hashtable nvlist = (Hashtable)nvlists.elementAt(i - 1);
              if (nvlist != null) {
              Object oo = nvlist.get(o.toString());
              if(oo != null) o = oo;
              }
              row.cells.addElement(o);
              }
              }

              logger.debug("Adding row " + (rowcount+1) + " to results");
              v.addElement(row);
              if (popup_links_exist) {
              String pkey = (String)rs.getString("ID");
              pkeys.addElement(pkey);
              }
              }
              ++subaveragectr;
              ++averagectr;
              ++rowcount;
              }

              /* final subtotals for the final grouping */
              if(groupInd != 0) {
              Row strow = new Row();
              strow.cells = new Vector(ncols, 1);
              strow.type = "subtotal";
              strow.subrowcnt = new Integer(subaveragectr);
              for(int i = 0; i < ncols; ++i) {
              ColumnSelection cs = (ColumnSelection)selected.elementAt(i);

              if(cs.summary != null && cs.summary.equalsIgnoreCase("sum")) {
              strow.cells.addElement( subtotals.elementAt(i));
              }
              else if(cs.summary != null && cs.summary.equalsIgnoreCase("avg")) {
              float f = ((Number)subtotals.elementAt(i)).floatValue();
              strow.cells.addElement( new Float(f/subaveragectr));
              }
              else {
              strow.cells.addElement(" ");
              }
              }
              if ((allrows == true) || (endrow + 1 >= rowcount)) {
              if(popup_links_exist) pkeys.addElement("");
              v.addElement(strow);
              }
              }

              /* final totals */
              Row trow = new Row();
              trow.cells = new Vector(ncols, 1);
              trow.type = "total";
              trow.subrowcnt = new Integer(averagectr);
              for(int i = 0; i < ncols; ++i) {
              ColumnSelection cs = (ColumnSelection)selected.elementAt(i);
              if(cs.summary != null && cs.summary.equalsIgnoreCase("sum")) {
              trow.cells.addElement( totals.elementAt(i));
              }
              else if(cs.summary != null && cs.summary.equalsIgnoreCase("avg")) {
              float f = ((Number)totals.elementAt(i)).floatValue();
              trow.cells.addElement( new Float(f/averagectr));
              }
              else {
              trow.cells.addElement("");
              }
              }
              if ((allrows == true) || (endrow + 1 >= rowcount)) {
              v.addElement(trow);
              if(popup_links_exist) pkeys.addElement("");
              }
              }
              catch(Exception ex) {
              logger.error(ex);
              throw new ReportException(ex.getMessage());
              }
              finally {
              try {
              if (pstmt != null) pstmt.close();
              if (con != null) con.close();
              }
              catch (Exception ignore) {}
              }
              logger.debug("About to return a vector");
              if(popup_links_exist) {
              logger.debug("Dumping primary key vector");
              for(int pctr = 0; pctr < pkeys.size(); ++pctr){
              logger.debug("This pkey is " + pkeys.elementAt(pctr).toString());
              }
              }
              return v;
              }

              public void processColumns(HashMap req) throws ReportException {
              try {
              StringBuffer sb = new StringBuffer();
              String groupPart = (String)req.get("group");
              String t_gbo = (String)req.get("group_order");
              if (t_gbo != null) groupByOrder = t_gbo;

              int i = 0;
              boolean more_columns = true;

              while(more_columns) {
              if(i > 0)
              sb.append(", ");

              String html = (String)req.get("column_" + i);

              if(html != null) {
              if (!html.equals("null")) {
              logger.debug("html is " + html + ", group part is " + groupPart);
              if(html.equals(groupPart)) {
              logger.debug("Setting groupind to " + (new Integer(i)).toString());
              groupInd = i + 1;
              }

              int sortord = 0;
              String sortdir = "ASC";

              String soparam = (String)req.get("orderby_" + i);
              String sdparam = (String)req.get("order_" + i);
              String suparam = (String)req.get("columnfunc_" + i);
              logger.debug("Column func for " + i + " part is " + suparam);
              if(suparam != null && suparam.length() == 0)
              suparam = null;

              logger.debug("Got orderby_" + i + " it is " + soparam);
              if(soparam != null && soparam.length() > 0) sortord = Integer.parseInt(soparam);
              if(sdparam != null && sdparam.length() > 0) sortdir = sdparam;

              this.addSubtree(html, false, false, sortord, sortdir, suparam, i + 1);
              sb.append(tree.html_to_sql(html));
              }
              }
              else
              more_columns = false;

              ++i;
              }

              if(groupPart != null && groupPart.length() > 0)
              this.addSubtree(groupPart, false, false, -1, (groupByOrder == null ? "ASC" : groupByOrder), null, 0);

              if(groupPart == null) groupPart = "this should not appear anywhere at all, says Bill Gates.";

              tree.adjustSelectionOrders();
              TableTree grouptree = tree.findNode(groupPart);
              if(grouptree != null)
              groupInd = grouptree.selOrd;
              else
              groupInd = 0;
              StringBuffer buf = new StringBuffer();

              if (Utility.TL_ORACLE.equalsIgnoreCase(dbserver_type)) {
              String f_clause = tree.fromORAClause();
              String s_clause = tree.selectORAClause();
              //Use the in-line view until the user saves the report.
              buf.append("SELECT * FROM ( SELECT ");
              buf.append(s_clause);
              if(popup_links_exist)
              buf.append(", t.ID as ID ");
              buf.append(" FROM ");
              buf.append(f_clause);
              //wherePart is the filter criteria created by the user
              String j_clause = tree.joinORAConnectiveToChildren();
              if (j_clause.trim().length() > 0) {
              //substring is for chopping the front " and"
              buf.append(" where ").append(j_clause.substring(4));
              buf.append(" ) ");
              if ((wherePart != null) && (wherePart.length() > 3))
              buf.append(" where ").append(wherePart);
              } else if ((wherePart != null) && (wherePart.length() > 3)) {
              buf.append(" ) ");
              buf.append(" where ").append(wherePart);
              } else {
              buf.append(" ) ");
              }
              String oby = tree.orderORAClause();
              logger.debug("order clause is " + oby);
              if(oby.length() > 0) {
              buf.append(" ORDER BY ");
              buf.append(oby);
              }
              logger.debug("in-line view query is : " + buf.toString());
              } else {
              String f_clause = this.fromClause();
              String s_clause = tree.selectClause();

              buf.append("SELECT ");
              buf.append(s_clause);
              if(popup_links_exist)
              buf.append(", t.ID ");
              buf.append(" FROM ");
              buf.append(f_clause);
              if(wherePart != null && wherePart.length() > 3)
              buf.append(" WHERE ");
              buf.append(wherePart);
              String oby = tree.orderClause();
              logger.debug("order clause is " + oby);
              if(oby.length() > 0) {
              buf.append(" ORDER BY ");
              buf.append(oby);
              }
              }
              setQuery(buf.toString());
              }
              catch (Exception ex) {
              logger.error(ex);
              throw new ReportException(ex.getMessage());
              }
              }


              public void setWhere(String s) {
              wherePart = s;
              }

              //This method is used by Old report(3.2 and prior)
              public void processCriteria(String rawfilter) throws ReportException {
              try {
              this.object_filter_list = new Vector(16, 16);
              this.filter = rawfilter;

              Vector values = new Vector(16, 16);
              StringBuffer sb = new StringBuffer();
              Hashtable h = new Hashtable();
              h.put("$", "'");
              CriteriaFilterTokenizer tokenizer = new CriteriaFilterTokenizer(rawfilter, basetab);
              String token;

              while((token = tokenizer.nextToken()) != null) {
              if(tokenizer.last_token_type == CriteriaFilterTokenizer.CFT_LITERAL) {
              sb.append(" ? ");
              Object val = tree.parseLiteral(token);
              logger.debug("Adding literal " + val.toString() + " to values vector.");
              values.addElement(val);
              }
              else if (tokenizer.last_token_type == CriteriaFilterTokenizer.CFT_ATTRIB) {
              /* perhaps we do sql id lookup here */
              logger.debug("Adding attrib " + token + " to tree.");
              TableTree node = this.addSubtree(token, false, true, 0, "ASC", null, 0);
              sb.append(" ").append(node.parent.sql_identifier + "." + node.visibleName).append(" ");
              logger.debug("sb at this point is " + sb.toString());
              logger.debug("Adding " + token + " to object_filter_list");
              object_filter_list.addElement(token);
              }
              else {
              if (token.indexOf("$") != -1) {
              String replaceStr = Utility.substituteString(token,h);
              sb.append(replaceStr).append(" ");
              }
              else {
              sb.append(token).append(" ");
              }
              }
              }

              makeSqlIdentifiers();
              setQualifiers(values);

              /* this still hasn't resolved everything */
              String sofar = sb.toString(); /* we still need to substitute computed columns */
              logger.debug("so far is : " + sofar);
              StringTokenizer stk = new StringTokenizer(sofar, " (),", true);

              sb = new StringBuffer();
              while (stk.hasMoreTokens()) {

              token = stk.nextToken();
              if(token.indexOf(".") != -1) {
              logger.debug("Processing stage two with " + token);
              int ldpos = token.lastIndexOf(".");
              String sqlid = token.substring(0, ldpos);
              String colname = token.substring(ldpos + 1);
              //Do the calculated substitution for non oracle else substitue the alias name
              if (!Utility.TL_ORACLE.equalsIgnoreCase(dbserver_type)) {
              logger.debug("Finding node by sql for " + sqlid);
              TableTree node = tree.findNodeBySqlid(sqlid);
              logger.debug("Finding sqlform for " + node.tlomm_type + " " + colname);
              String result = node.metatlomm().sqlForm(node.tlomm_type, colname, sqlid);
              sb.append(result);
              } else {
              sb.append(sqlid + "_" + colname);
              }
              }
              else {
              sb.append(token);
              }
              }

              wherePart = sb.toString();
              logger.debug("wherePart : " + wherePart);
              }
              catch (Exception ex) {
              logger.error(Utility.getStackTrace(ex));
              throw new ReportException(ex.getMessage());
              }
              }

              public void setBasetab(String s) {
              basetab = s;
              }

              public String getBasetab() {
              return basetab;
              }

              public void wipeCriteria() {
              wherePart = null;
              }


              public void wipeColumns() {
              selectPart = null;
              wipeOrdering();
              }

              public void wipeOrdering() {
              orderPart = null;
              }

              public void wipeTables() {
              fromPart = null;
              tree = null;
              wipeColumns(); /* necessitates killing everything */
              wipeOrdering();
              wipeCriteria();
              }


              public void setTitleAndDescription(String t, String d) {
              if(title != null && !title.equals(t) && title.length() > 0) namechanged = true;
              title = t;
              description = d;
              }

              public void setReportId(int rid) {
              reportId = rid;
              }

              public int getReportId() {
              return reportId;
              }


              public void setCategoryId(int catid) {
              catId = catid;
              }

              public Properties propFmt(SimpleDateFormat udf) throws ReportException {
              Properties p = null;
              try {
              p = tree.propFmt("report.0", "");
              p.put("report.title", title);
              p.put("report.description", description);
              //Commenting the 3.2 filter and Filtertext
              //p.put("report.filter", filter);
              //p.put("report.filterText", (filterText == null ? "" : filterText));

              //This is to identify old(3.2 and prior) and new reports
              p.put("report.parameterization", "true");
              //For filters
              StringBuffer fcs = new StringBuffer();
              for (int i = 0; i < filterConditions.size(); i++) {
              if (i != 0)
              fcs.append(",");
              fcs.append(i);
              HashMap hm = (HashMap)filterConditions.elementAt(i);
              String attrName = (String)hm.get("attrName");
              String attrValue = (String)hm.get("attrValue");
              String attrOpr = (String)hm.get("attrOpr");
              Integer attrType = (Integer)hm.get("attrType");
              boolean isParam = hm.get("isParam") != null ? ((Boolean)hm.get("isParam")).booleanValue() : false;
              p.put("report.filter.attrName." + i, attrName);
              //Date values are in userDateFormatter, so store it in iDateFormatter
              if ((attrType.intValue() == TLConst.TLO_DATETIME) && (attrValue.trim().length() > 0)) {
              java.util.Date date = udf.parse(attrValue);
              p.put("report.filter.attrValue." + i, client.iDateFormatter.format(date));
              } else {
              p.put("report.filter.attrValue." + i, attrValue);
              }
              p.put("report.filter.attrOpr." + i, attrOpr);
              p.put("report.filter.attrType." + i, attrType.toString());
              p.put("report.filter.isParam." + i, isParam ? "true" : "false");
              if (isParam == true) {
              String paramLabel = (String)hm.get("paramLabel");
              p.put("report.filter.paramLabel." + i, paramLabel);
              }

              }
              p.put("report.filters", fcs.toString());
              p.put("report.expression", expression != null ? expression : "");
              //For dateParameter.
              if (dateParameter != null) {
              String datePField = (String)dateParameter.get("datePField");
              p.put("report.dateparam.field",datePField);
              if (!"-1".equals(datePField)) {
              String datePRelative = (String)dateParameter.get("datePRelative");
              p.put("report.dateparam.relative",datePRelative);
              String datePLabel = (String)dateParameter.get("datePLabel");
              p.put("report.dateparam.label",datePLabel);
              if ("-1".equals(datePRelative)) {
              //Date values are in userDateFormatter, so store it in iDateFormatter
              String datePFDate = (String)dateParameter.get("datePFDate");
              String datePTDate = (String)dateParameter.get("datePTDate");
              java.util.Date date = udf.parse(datePFDate);
              p.put("report.dateparam.fromdate",client.iDateFormatter.format(date));
              date = udf.parse(datePTDate);
              p.put("report.dateparam.todate",client.iDateFormatter.format(date));
              }
              }
              }

              p.put("report.type", type);
              p.put("report.groupid", (new Integer(groupInd)).toString());
              p.put("report.groupord", (groupByOrder == null ? "" : groupByOrder));
              p.put("report.catid", String.valueOf(catId));
              p.put("report.xtabgroupby", (xtab_groupby == null ? "" : xtab_groupby));
              p.put("report.xtabtoprow", (xtab_toprow == null ? "" : xtab_toprow));
              p.put("report.xtabgrouporder", (xtab_grouporder == null ? "" : xtab_grouporder));
              p.put("report.xtabtotals", (xtab_totals ? "true" : "false"));

              for(int i = 0; i < xtab_values.size(); ++i) {

              p.put("report.xtabval." + (new Integer(i)).toString(), (String)xtab_values.elementAt(i));
              }
              } catch (Exception ex) {
              throw new ReportException("Exception in PropFmt :" + ex.getMessage());
              }
              return p;
              }

              public void load(String fname, String roleName, SimpleDateFormat udf) throws ReportException {
              try{
              Properties globalprops = Utility.getTLProps();
              String path = globalprops.getProperty(Utility.TLPROP_REPORTFILES_HOME) + File.separator
              + "client" + cid + File.separator + fname;
              File f = new File(path);
              FileInputStream fis = new FileInputStream(f);

              Properties p = new Properties();
              p.load(fis);
              fis.close();

              description = p.getProperty("report.description");
              title = p.getProperty("report.title");
              basetab = p.getProperty("report.0.vis");
              type = p.getProperty("report.type");

              xtab_groupby = p.getProperty("report.xtabgroupby");
              xtab_toprow = p.getProperty("report.xtabtoprow");
              xtab_grouporder = p.getProperty("report.xtabgrouporder");
              String sxtab_totals = p.getProperty("report.xtabtotals");
              if(sxtab_totals.equalsIgnoreCase("true"))
              xtab_totals = true;
              else
              xtab_totals = false;

              logger.debug("During restore, xtab stuff is " + xtab_groupby + ", " + xtab_toprow);
              groupInd = Integer.parseInt(p.getProperty("report.groupid"));
              groupByOrder = p.getProperty("report.groupord");
              catId = Integer.parseInt(p.getProperty("report.catid"));
              tree = new TableTree(p, "report.0", null);

              /* get the x-tab value stuff */
              xtab_values = new Vector(16, 16);
              boolean more_xtab = true;
              int i = 0;
              while(more_xtab) {
              String xtabv = p.getProperty("report.xtabval." + (new Integer(i++)).toString());
              logger.debug("Adding an xtab value: " + xtabv);
              if(xtabv != null)
              xtab_values.addElement(xtabv);
              else
              more_xtab = false;
              }

              tree.setRoots(tree);
              tree.setCid(cid, roleName, udf);
              tree.calcTlommTypes();
              tree.makeSqlIdentifiers();

              String parameterRpt = p.getProperty("report.parameterization");
              if ((parameterRpt != null) && "true".equals(parameterRpt)) {
              String fcs = p.getProperty("report.filters");
              StringTokenizer stk = new StringTokenizer(fcs,",");
              filterConditions = new Vector();
              logger.debug("During restore, Filters is " + fcs);
              while (stk.hasMoreTokens()) {
              String token = stk.nextToken();
              HashMap hm = new HashMap();
              String attrName = p.getProperty("report.filter.attrName." + token);
              String attrValue = p.getProperty("report.filter.attrValue." + token);
              String attrOpr = p.getProperty("report.filter.attrOpr." + token);
              String attrType = p.getProperty("report.filter.attrType." + token);
              String param = p.getProperty("report.filter.isParam." + token);
              Boolean isParam = ((param != null) && "true".equals(param)) ? Boolean.TRUE : Boolean.FALSE;
              hm.put("attrName",attrName);
              //Date values are stored in iDateFormatter.
              if ((Integer.parseInt(attrType) == TLConst.TLO_DATETIME) && (attrValue.trim().length() > 0)) {
              java.util.Date date = client.iDateFormatter.parse(attrValue);
              hm.put("attrValue",udf.format(date));
              } else {
              hm.put("attrValue",attrValue);
              }

              hm.put("attrOpr",attrOpr);
              hm.put("attrType", new Integer(attrType));
              hm.put("isParam",isParam);
              if (isParam.booleanValue() == true) {
              hm.put("paramLabel", p.getProperty("report.filter.paramLabel." + token));
              }
              filterConditions.addElement(hm);
              }
              expression = p.getProperty("report.expression");
              dateParameter = new HashMap();
              String datePField = p.getProperty("report.dateparam.field");
              dateParameter.put("datePField", datePField);
              if (!"-1".equals(datePField)) {
              String datePRelative = p.getProperty("report.dateparam.relative");
              dateParameter.put("datePRelative",datePRelative);
              String datePLabel = p.getProperty("report.dateparam.label");
              dateParameter.put("datePLabel",datePLabel);
              if ("-1".equals(datePRelative)) {
              //Date values are stored in iDateFormatter, so parse it to UserDateFormatter
              String datePStr = p.getProperty("report.dateparam.fromdate");
              java.util.Date date = client.iDateFormatter.parse(datePStr);
              dateParameter.put("datePFDate", udf.format(date));
              datePStr = p.getProperty("report.dateparam.todate");
              date = client.iDateFormatter.parse(datePStr);
              dateParameter.put("datePTDate", udf.format(date));
              }
              }
              processFilterConditions();
              }
              else {
              //for old report.
              filter = p.getProperty("report.filter");
              filterText = p.getProperty("report.filterText");
              filterConditions = null;
              dateParameter = null;
              expression = null;
              parameters = null;
              dateQualifiers = null;
              dateQuery = null;
              processCriteria(filter);
              }

              StringBuffer buf = new StringBuffer();
              if ("detail".equals(type)) {
              String oby = "";
              if (Utility.TL_ORACLE.equalsIgnoreCase(dbserver_type)) {
              //Using in-line view so that we can use OR condition in the filter criteria.
              buf.append("SELECT * FROM ( SELECT ");
              buf.append(tree.selectORAClause());
              buf.append(", t.ID as ID ");
              buf.append(" FROM ");
              buf.append(tree.fromORAClause());
              //wherePart is the filter criteria created by the user
              String j_clause = tree.joinORAConnectiveToChildren();
              if (j_clause.trim().length() > 0) {
              //substring is for chopping the front " and"
              buf.append(" where ").append(j_clause.substring(4));
              buf.append(" ) ");
              if ((wherePart != null) && (wherePart.length() > 3))
              buf.append(" where ").append(wherePart);
              } else if ((wherePart != null) && (wherePart.length() > 3)) {
              buf.append(" ) ");
              buf.append(" where ").append(wherePart);
              } else {
              buf.append(" ) ");
              }
              oby = tree.orderORAClause();
              } else {
              String s_clause = tree.selectClause();
              buf.append("SELECT ");
              buf.append(s_clause);
              buf.append(", t.ID");
              buf.append(" FROM ");
              buf.append(tree.fromClause());
              if(wherePart != null && wherePart.length() > 3)
              buf.append(" WHERE ");
              buf.append(wherePart);
              oby = tree.orderClause();
              }
              if(oby.length() > 0) {
              buf.append(" ORDER BY ");
              buf.append(oby);
              }
              } else {
              if (Utility.TL_ORACLE.equalsIgnoreCase(dbserver_type)) {
              //Using in-line view so that we can use OR condition in the filter criteria.
              String f_clause = tree.fromORAClause();
              String sql[] = tree.selectClauseORAXTab(xtab_toprow, xtab_groupby, xtab_values);
              buf.append("SELECT " + sql[0] + " FROM ( SELECT " + sql[1] + " FROM " + f_clause);
              //wherePart is the filter criteria created by the user
              String j_clause = tree.joinORAConnectiveToChildren();
              if (j_clause.trim().length() > 0) {
              //substring is for chopping the front " and"
              buf.append(" where ").append(j_clause.substring(4));
              buf.append(" ) ");
              if ((wherePart != null) && (wherePart.length() > 3))
              buf.append(" where ").append(wherePart);
              } else if ((wherePart != null) && (wherePart.length() > 3)) {
              buf.append(" ) ");
              buf.append(" where ").append(wherePart);
              } else {
              buf.append(" ) ");
              }

              buf.append(" GROUP BY ");
              String leftAlias = sql[2];
              buf.append(leftAlias);
              if(xtab_grouporder != null && xtab_grouporder.length() > 0) {
              buf.append(" ORDER BY ");
              buf.append((client.caseSensitive) ? leftAlias : "UPPER(" + leftAlias + ")");
              buf.append(" ").append(xtab_grouporder);
              }
              } else {
              String f_clause = tree.fromClause();
              String sql = tree.selectClauseXTab(xtab_toprow, xtab_groupby, xtab_values);
              logger.debug("From clause is " + f_clause);
              logger.debug("Select clause is " + sql);
              buf.append("SELECT ");
              buf.append(sql);
              buf.append(" FROM ");
              buf.append(f_clause);
              if(wherePart != null && wherePart.length() > 0) {
              buf.append(" WHERE ");
              buf.append(wherePart);
              }
              buf.append(" GROUP BY ");
              buf.append(tree.html_to_sql(xtab_groupby));
              if(xtab_grouporder != null && xtab_grouporder.length() > 0)
              buf.append(" ORDER BY ").append(tree.html_to_sql(xtab_groupby)).append(" ").append(xtab_grouporder);
              }
              }
              logger.debug("Restoring report query : \n" + buf.toString());
              setQuery(buf.toString());

              }
              catch(Exception e) {
              logger.error(e);
              throw new ReportException(e.getMessage());
              }

              }

              /* gives us the next available report id */
              private int maxId() throws Exception {
              Connection con = null;
              Statement stmt = null;
              ResultSet rs = null;
              int maxId = 1;
              try {
              String query = "SELECT MAX(ID) from REPORT_" + cid;
              con = ds.getConnection();
              stmt = con.createStatement();
              rs = stmt.executeQuery(query);
              if (rs != null && rs.next()) maxId = rs.getInt(1) + 1;
              }
              catch (Exception ex) {
              logger.debug(Utility.getStackTrace(ex));
              throw ex;
              }
              finally {
              try {
              if (rs != null) rs.close();
              if (stmt != null) stmt.close();
              if (con != null) con.close();
              }
              catch (Exception ignore) {}
              }
              return maxId;
              }

              public void saveNew(SimpleDateFormat udf) throws ReportException {
              if(namechanged)
              reportId = 0; /* force getting the next highest report id */
              save(udf);
              }

              /**
              *
              * saves the report.
              */
              public void save(SimpleDateFormat udf) throws ReportException {
              save(null, udf);
              }

              public void save(String excelFileName, SimpleDateFormat udf) throws ReportException {
              Connection con = null;
              PreparedStatement pstmt = null;
              try {
              logger.debug("Saving report " + title + " current id is " + (new Integer(reportId)).toString());
              con = ds.getConnection();
              pstmt = null;
              String query = null;
              String fname = null;
              if (reportId == 0) {
              reportId = maxId();
              if (Report.RPT_EXCEL.equals(type) && (excelFileName != null))
              fname = reportId + "_" + excelFileName;
              else
              fname = "report" + reportId + ".prop";
              query = "insert into REPORT_" + cid + " (ID, TITLE, DESCRIPTION, CATEGORY_ID, PROP_FILE, TYPE) values " +
              "( ?, ?, ?, ?, ?, ?)";
              pstmt = con.prepareStatement(query);
              pstmt.setInt( 1, reportId);
              pstmt.setString(2, title);
              pstmt.setString(3, description);
              pstmt.setInt( 4, catId);
              pstmt.setString(5, fname);
              pstmt.setString(6, type);
              pstmt.executeUpdate();
              }
              else {
              if (Report.RPT_EXCEL.equals(type) && (excelFileName != null))
              fname = reportId + "_" + excelFileName;
              else
              fname = "report" + reportId + ".prop";
              query = "update REPORT_" + cid + " set TITLE = ?, DESCRIPTION = ?, PROP_FILE = ?, CATEGORY_ID = ? where ID = ? ";
              pstmt = con.prepareStatement(query);
              pstmt.setString(1, title);
              pstmt.setString(2, description);
              pstmt.setString(3, fname);
              pstmt.setInt( 4, catId);
              pstmt.setInt( 5, reportId);
              pstmt.executeUpdate();
              }

              if (!Report.RPT_EXCEL.equals(type)) {
              logger.debug("Saving report properties.");
              Properties globalprops = Utility.getTLProps();
              String path = globalprops.getProperty(Utility.TLPROP_REPORTFILES_HOME) + File.separator
              + "client" + cid + File.separator + fname;
              File f = new File(path);
              FileOutputStream fos = new FileOutputStream(f);

              Properties reportprops = propFmt(udf);
              Enumeration e = reportprops.propertyNames();
              while(e.hasMoreElements()) {
              String key = (String)e.nextElement();
              String val = reportprops.getProperty(key);
              logger.debug("keyval pair is " + key + "," + val);
              String total = key + "=" + val + "\n";

              byte[] bytes = new byte[total.length() + 1];

              bytes = total.getBytes();

              fos.write(bytes, 0, total.length());
              }
              fos.close();
              }
              }
              catch (Exception ex) {
              logger.error(ex);
              throw new ReportException(ex.getMessage());
              }
              finally {
              try {
              if (pstmt != null) pstmt.close();
              if (con != null) con.close();
              }
              catch (Exception ignore) {}
              }
              }

              public void load(int report_id, String roleName, SimpleDateFormat udf) throws ReportException {
              reportId = report_id;
              if (Report.RPT_EXCEL.equals(type)) {
              Connection con = null;
              PreparedStatement pstmt = null;
              try{
              con = ds.getConnection();
              pstmt = con.prepareStatement("select TITLE, DESCRIPTION, PROP_FILE, CATEGORY_ID from REPORT_" + cid + " WHERE ID = ?");
              pstmt.setInt(1, report_id);
              ResultSet rs = pstmt.executeQuery();
              if ((rs != null) && rs.next()) {
              title = rs.getString(1);
              description = rs.getString(2);
              filename = rs.getString(3);
              catId = rs.getInt(4);
              }
              if (rs != null) rs.close();
              }
              catch (Exception e) {
              logger.error(e);
              throw new ReportException(e.getMessage());
              }
              finally {
              try {
              if (pstmt != null) pstmt.close();
              if (con != null) con.close();
              }
              catch (Exception ignore) {}
              }
              } else {
              pkeys = new Vector(16, 16); /* restored reports need pkeys too */
              this.load("report" + report_id + ".prop", roleName, udf);
              }
              }

              public void processXTabColumns(HashMap req) throws ReportException {
              try {
              logger.debug("Processing xtab columns");
              /* the column for which we will get all distinct values */
              String p_xtab_toprow = (String)req.get("attribute");
              String p_xtab_groupby = (String)req.get("group");
              String p_xtab_grouporder = (String)req.get("group_order");

              String stotls = (String)req.get("showTotals");
              if (stotls == null)
              stotls = "false";
              if(stotls.equalsIgnoreCase("true"))
              xtab_totals = true;
              else
              xtab_totals = false;

              if(p_xtab_toprow != null) {
              xtab_toprow = p_xtab_toprow;
              this.addSubtree(xtab_toprow, false, false, 0, "", "", 0);

              }
              if(p_xtab_groupby != null) {
              xtab_groupby = p_xtab_groupby;
              this.addSubtree(xtab_groupby, false, false, 0, "", "", 0);
              }

              if(p_xtab_grouporder != null) {
              this.xtab_grouporder = p_xtab_grouporder;
              }

              logger.debug("toprow + groupby:" + xtab_toprow + " " + xtab_groupby);
              int i = 0;
              boolean more = true;
              String test = (String)req.get("column_0");

              /* only frob this when we have something to replace the old values */

              if(test != null)
              xtab_values = new Vector(16, 16);
              while(more) {
              String xtabval = (String)req.get("column_" + new Integer(i++).toString());
              if(xtabval == null) {
              more = false;
              continue;
              }
              else if (!xtabval.equals("null"))
              xtab_values.addElement(xtabval);
              }
              StringBuffer sb = new StringBuffer();
              if (Utility.TL_ORACLE.equalsIgnoreCase(dbserver_type)) {
              String f_clause = tree.fromORAClause();
              String sql[] = tree.selectClauseORAXTab(xtab_toprow, xtab_groupby, xtab_values);

              logger.debug("From clause is " + f_clause);
              logger.debug("outerSelect : " + sql[0]);
              logger.debug("inlineSelect : " + sql[1]);
              logger.debug("leftAlias : " + sql[2]);
              sb.append("SELECT " + sql[0] + " FROM ( SELECT " + sql[1] + " FROM " + f_clause);
              //wherePart is the filter criteria created by the user
              String j_clause = tree.joinORAConnectiveToChildren();
              if (j_clause.trim().length() > 0) {
              //substring is for chopping the front " and"
              sb.append(" where ").append(j_clause.substring(4));
              sb.append(" ) ");
              if ((wherePart != null) && (wherePart.length() > 3))
              sb.append(" where ").append(wherePart);
              } else if ((wherePart != null) && (wherePart.length() > 3)) {
              sb.append(" ) ");
              sb.append(" where ").append(wherePart);
              } else {
              sb.append(" ) ");
              }
              sb.append(" GROUP BY ");
              String leftAlias = sql[2];
              sb.append(leftAlias);
              if(xtab_grouporder != null && xtab_grouporder.length() > 0) {
              sb.append(" ORDER BY ");
              sb.append((client.caseSensitive) ? leftAlias : "UPPER(" + leftAlias + ")");
              sb.append(" ").append(xtab_grouporder);
              }
              } else {
              String f_clause = tree.fromClause();
              String sql = tree.selectClauseXTab(xtab_toprow, xtab_groupby, xtab_values);
              logger.debug("From clause is " + f_clause);
              logger.debug("Select clause is " + sql);
              sb.append("SELECT ");
              sb.append(sql);
              sb.append(" FROM ");
              sb.append(f_clause);
              if(wherePart != null && wherePart.length() > 0) {
              sb.append(" WHERE ");
              sb.append(wherePart);
              }
              sb.append(" GROUP BY ");
              sb.append(tree.html_to_sql(xtab_groupby));

              if(xtab_grouporder != null && xtab_grouporder.length() > 0)
              sb.append(" ORDER BY ").append(tree.html_to_sql(xtab_groupby)).append(" ").append(xtab_grouporder);
              }

              logger.debug("processXTabColumns Crosstab query :" + sb.toString());
              setQuery(sb.toString());
              }
              catch (Exception ex) {
              logger.error(ex);
              throw new ReportException(ex.getMessage());
              }
              }

              public Vector executeXTab(int startrow, int endrow) throws ReportException {
              logger.debug("executeXTab(startrow,endrow)");
              return executeXTab(startrow, endrow, false);
              }

              private Vector executeXTab(int startrow, int endrow, boolean allrows) throws ReportException {
              logger.debug("entering executeXTab(startrow,endrow,boolean) with :" + startrow + " : " + endrow + " : " + allrows);
              Connection con = null;
              PreparedStatement pstmt = null;
              Vector v = null;
              if (allrows == true)
              v = new Vector(50,10);
              else
              v = new Vector(endrow - startrow, 2);

              try {
              con = ds.getConnection();
              //Oracle 9i supports only TRANSACTION_READ_COMMITTED(default) and TRANSACTION_SERIALIZABLE
              if (!(Utility.TL_ORACLE.equalsIgnoreCase(dbserver_type) ||
              Utility.TL_PGSQL.equalsIgnoreCase(dbserver_type)))
              con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);

              logger.debug("Crosstab query without dateParameter Substitution : " + query);

              String xtabQuery = query;
              if ((query.indexOf("tldateparameter") != -1) && (dateQuery != null)) {
              //replacing dateParamter.
              xtabQuery = query.substring(0,query.indexOf("tldateparameter")) + dateQuery +
              query.substring(query.indexOf("tldateparameter") + 15, query.length());
              }
              logger.debug("Final Crosstab query : " + xtabQuery);

              pstmt = con.prepareStatement(xtabQuery);

              Row labels = new Row();
              labels.type = "labels";
              labels.cells = new Vector(16, 16);

              Row totals = new Row(); /* the totalling row at the bottom, if req'd */
              totals.type = "total";
              totals.cells = new Vector(16, 16);
              totals.cells.addElement("Total");
              TableTree labelNode = tree.findNode(xtab_groupby);
              TableTree rowNode = tree.findNode(xtab_toprow);

              Hashtable nvlist = rowNode.nvlist();
              Hashtable groupnvlist = labelNode.nvlist();

              labels.cells.addElement(labelNode.completeLabel());
              v.addElement(labels);

              formats = new Vector(16, 16);
              heading_formats = new Vector(16, 16);

              formats.addElement(labelNode.format());
              heading_formats.addElement(labelNode.format());

              logger.debug("Adding format " + labelNode.format());

              /* explanation : with the advent of computed xtab values, the list of literal values to
              assign in the query and the labels along the first row no longer have all that
              much to do with each other. TableTree::xtabParsedValues returns a vector
              of the parsed literals for the query, and xtabParsedLabels returns a list
              of values to display across the top */
              Vector xtpv = tree.xtabParsedValues(xtab_values, xtab_toprow);
              for(int i = 0; i < xtpv.size(); ++i) {
              logger.debug("xtpv elt is " + xtpv.elementAt(i).toString());
              Object o = xtpv.elementAt(i);
              pstmt.setObject(i + 1, o);
              }

              /* this is not the most efficient way of doing this */
              xtpv = tree.xtabParsedLabels(xtab_values, xtab_toprow);
              for(int i = 0; i < xtpv.size(); ++i) {
              Object o = xtpv.elementAt(i);
              Object oo = xtpv.elementAt(i);
              if(nvlist != null) {
              oo = (String)nvlist.get(xtpv.elementAt(i).toString());
              if(oo == null) oo = o;
              }

              labels.cells.addElement(oo);
              totals.cells.addElement(new Long(0));
              }

              if(xtab_totals) {
              labels.cells.addElement("Total");
              totals.cells.addElement(new Long(0));
              }

              /* setting Qualifiers */
              int qualifierCount = xtab_values.size();
              int xtab_size = qualifierCount;
              for (int i = 0; i < qualifiers.size(); ++i) {
              //This is to support 321 and prior reports.
              Object obj = qualifiers.elementAt(i);
              String pq = obj.toString();
              if ((filterConditions != null) && (pq.indexOf("$") != -1)) {
              String fpos = pq.substring(pq.indexOf("$") + 1, pq.length());
              String parampos = pq.substring(pq.indexOf("_") + 1, pq.indexOf("$"));
              int ppos = Integer.parseInt(parampos);
              HashMap fCond = (HashMap) filterConditions.elementAt(Integer.parseInt(fpos));
              Object qualifier = fCond.get("attrObjValue");
              logger.debug("Setting qualifier object " + ppos + " to " + qualifier.toString());
              pstmt.setObject((xtab_size + ppos), qualifier);
              qualifierCount++;
              } else {
              qualifierCount++;
              logger.debug("Setting qualifier(321) object " + qualifierCount + " to " + obj.toString());
              pstmt.setObject(qualifierCount, obj);
              }
              }

              /* setting parameter Qualifiers */
              if (parameters != null) {
              for (int i = 0; i < parameters.size(); i++) {
              String pq = (String) parameters.elementAt(i);
              if (pq.indexOf("$") != -1) {
              String fpos = pq.substring(pq.indexOf("$") + 1, pq.length());
              String parampos = pq.substring(pq.indexOf("_") + 1, pq.indexOf("$"));
              int ppos = Integer.parseInt(parampos);
              HashMap fCond = (HashMap) filterConditions.elementAt(Integer.parseInt(fpos));
              Object qualifier = fCond.get("attrObjValue");
              logger.debug("setting parameter qualifier object " + ppos + " to " + qualifier);
              pstmt.setObject((xtab_size + ppos), qualifier);
              qualifierCount++;
              }
              }
              }

              /* For date qualifiers. */
              if (dateQualifiers != null) {
              for (int i = 0; i < dateQualifiers.size(); i++) {
              Object qualifier = dateQualifiers.elementAt(i);
              logger.debug("setting dateParameter qualifier : " + qualifier);
              qualifierCount++;
              pstmt.setObject(qualifierCount, qualifier);
              }
              }

              ResultSet rs = pstmt.executeQuery();
              String otherformats = rowNode.format(); /* all other columns have the same format */

              ResultSetMetaData metadata = rs.getMetaData();

              int ncols = metadata.getColumnCount();

              xtpv = tree.xtabParsedFormats(xtab_values, xtab_toprow);
              for(int i = 0; i < xtpv.size(); ++i) {
              formats.addElement(xtpv.elementAt(i));
              heading_formats.addElement(otherformats);
              }

              if(xtab_totals) {
              formats.addElement(otherformats); /* add a dummy if we're doing totalling as well */
              heading_formats.addElement(otherformats);
              }

              rowcount = 0;
              while(rs.next()) {
              Row row = new Row();
              row.type = "normal";
              row.cells = new Vector(16, 16);
              long rowtotal = 0;
              for(int j = 1; j <= ncols; ++j) {
              Object o = rs.getObject(j);
              if (o != null) {
              if(xtab_totals && j > 1) {
              Object l = tree.parseLiteral(o.toString());
              if(l instanceof Number) {
              rowtotal += ((Nu

              • 4. Re: Stateless Session bean throwing error
                vis hnu Newbie

                Hi Wolfgang

                I am attaching the code of only the method which has the error(i.e line number 1244)

                ------------------------------------------------------------

                public void load(int report_id, String roleName, SimpleDateFormat udf) throws ReportException {
                reportId = report_id;
                if (Report.RPT_EXCEL.equals(type)) {
                Connection con = null;
                PreparedStatement pstmt = null;
                try{
                con = ds.getConnection();
                pstmt = con.prepareStatement("select TITLE, DESCRIPTION, PROP_FILE, CATEGORY_ID from REPORT_" + cid + " WHERE ID = ?");
                pstmt.setInt(1, report_id);
                ResultSet rs = pstmt.executeQuery();
                if ((rs != null) && rs.next()) {
                title = rs.getString(1);
                description = rs.getString(2);
                filename = rs.getString(3);
                catId = rs.getInt(4);
                }
                if (rs != null) rs.close();
                }
                catch (Exception e) {
                logger.error(e);
                throw new ReportException(e.getMessage());
                }
                finally {
                try {
                if (pstmt != null) pstmt.close();
                if (con != null) con.close();
                }
                catch (Exception ignore) {}
                }
                } else {
                pkeys = new Vector(16, 16); /* restored reports need pkeys too */
                this.load("report" + report_id + ".prop", roleName, udf);
                }
                }

                -------------------------------------------------------------

                line 1244 is : this.load("report" + report_id + ".prop", roleName, udf);

                Please please help

                Vishnu

                • 6. Re: Stateless Session bean throwing error
                  Wolfgang Knauf Master

                  Hi Vishnu,

                  what is the code in ReportBean.java line 1087 (this is where the actual error occurs) ?

                  It seems you use EJB2.1, so maybe you should post your problem in the "EJB/JBoss" forum if nobody here can help you.

                  If you paste code use the "Post reply" button and embrace it with "

                  ...
                  ", so that formatting is not lost. Makes it easier to read.

                  Wolfgang

                  • 7. Re: Stateless Session bean throwing error
                    Wolfgang Knauf Master

                    I meant "code" in square brackets ...