/**
   * Retrieves the records for class name in sourceObjectName according to field values passed in
   * the passed session.
   *
   * @param whereColumnName An array of field names.
   * @param whereColumnCondition The comparision condition for the field values.
   * @param whereColumnValue An array of field values.
   * @param joinCondition The join condition.
   * @param The session object.
   */
  public List retrieve(
      String sourceObjectName,
      String[] selectColumnName,
      String[] whereColumnName,
      String[] whereColumnCondition,
      Object[] whereColumnValue,
      String joinCondition)
      throws DAOException {
    List list = null;
    try {
      StringBuffer sqlBuff = new StringBuffer();

      String className = Utility.parseClassName(sourceObjectName);

      // Logger.out.debug("***********className:"+className);
      if (selectColumnName != null && selectColumnName.length > 0) {
        sqlBuff.append("Select ");

        // Added by Aarti
        // --------------------------------
        //                if(sourceObjectName.equals(Site.class.getName()))
        //                {
        //                    sqlBuff.append(className + "." + Constants.SYSTEM_IDENTIFIER);
        //                    sqlBuff.append(", ");
        //                }
        // ---------------------------------
        for (int i = 0; i < selectColumnName.length; i++) {
          sqlBuff.append(className + "." + selectColumnName[i]);
          if (i != selectColumnName.length - 1) {
            sqlBuff.append(", ");
          }
        }
        sqlBuff.append(" ");
      }
      // Logger.out.debug(" String : "+sqlBuff.toString());

      Query query = null;
      sqlBuff.append("from " + sourceObjectName + " " + className);
      // Logger.out.debug(" String : "+sqlBuff.toString());

      if ((whereColumnName != null && whereColumnName.length > 0)
          && (whereColumnCondition != null && whereColumnCondition.length == whereColumnName.length)
          && (whereColumnValue != null)) {
        if (joinCondition == null) joinCondition = Constants.AND_JOIN_CONDITION;

        sqlBuff.append(" where ");

        // Adds the column name and search condition in where clause.
        for (int i = 0; i < whereColumnName.length; i++) {
          sqlBuff.append(className + "." + whereColumnName[i] + " ");
          if (whereColumnCondition[i].indexOf("in") != -1) {
            sqlBuff.append(whereColumnCondition[i] + "(  ");
            Object valArr[] = (Object[]) whereColumnValue[i];
            for (int j = 0; j < valArr.length; j++) {
              // Logger.out.debug(sqlBuff);
              sqlBuff.append("? ");
              if ((j + 1) < valArr.length) sqlBuff.append(", ");
            }
            sqlBuff.append(") ");
          } else if (whereColumnCondition[i].indexOf("is not null") != -1) {
            sqlBuff.append(whereColumnCondition[i]);
          } else if (whereColumnCondition[i].indexOf("is null") != -1) {
            sqlBuff.append(whereColumnCondition[i]);
          } else {
            sqlBuff.append(whereColumnCondition[i] + " ? ");
          }

          if (i < (whereColumnName.length - 1)) sqlBuff.append(" " + joinCondition + " ");
        }

        // Logger.out.debug(sqlBuff.toString());

        query = session.createQuery(sqlBuff.toString());

        int index = 0;
        // Adds the column values in where clause
        for (int i = 0; i < whereColumnValue.length; i++) {
          // Logger.out.debug("whereColumnValue[i]. " + whereColumnValue[i]);
          if (whereColumnCondition[i].equals("is null")
              || whereColumnCondition[i].equals("is not null")) {
          } else {

            Object obj = whereColumnValue[i];
            if (obj instanceof Object[]) {
              Object[] valArr = (Object[]) obj;
              for (int j = 0; j < valArr.length; j++) {
                query.setParameter(index, valArr[j]);
                index++;
              }
            } else {
              query.setParameter(index, obj);
              index++;
            }
          }
        }
      } else {
        query = session.createQuery(sqlBuff.toString());
      }

      list = query.list();

      //          Added by Aarti
      // --------------------------------

      //            if(sourceObjectName.equals(Site.class.getName()))
      //            {
      //                boolean isAuthorized;
      //                Object[] objects = null;
      //                Object[] newObjects = null;
      //                Long id;
      //                Site site;
      //
      //                if (selectColumnName != null && selectColumnName.length > 0)
      //                {
      //                    if(list != null)
      //                    {
      //                        for(int i=0; i<list.size();)
      //                        {
      //                            objects = (Object[]) list.get(i);
      //
      //                            if(objects != null)
      //                            {
      //                                newObjects = new Object[objects.length-1];
      //                                id = (Long) objects[0];
      //                                isAuthorized = SecurityManager.getInstance(this.getClass())
      //                                .isAuthorized("*****@*****.**",
      //                                        sourceObjectName+"_"+id,
      //                                        Permissions.USE);
      //                                Logger.out.debug(" User's Authorization to update
      // "+sourceObjectName+"_"+id+" "+isAuthorized);
      //                                list.remove(i);
      //                                if(isAuthorized)
      //                                {
      //                                    for(int x = 1;x<objects.length;x++ )
      //                                    {
      //                                        newObjects[x-1] = objects[x];
      //                                    }
      //                                    list.add(i,newObjects);
      //                                    i++;
      //                                }
      //                            }
      //                        }
      //                    }
      //                }
      //                else
      //                {
      //                    if(list != null)
      //                    {
      //                        for(int i=0; i<list.size();)
      //                        {
      //                            site = (Site) list.get(i);
      //                            if(site !=null)
      //                            {
      //                                isAuthorized = SecurityManager.getInstance(this.getClass())
      //                                .isAuthorized("*****@*****.**",
      //                                        sourceObjectName+"_"+site.getId(),
      //                                        Permissions.USE);
      //                                Logger.out.debug(" User's Authorization to update
      // "+sourceObjectName+"_"+site.getId()+" "+isAuthorized);
      //
      //                                if(isAuthorized)
      //                                {
      //                                    i++;
      //                                }
      //                                else
      //                                {
      //                                    list.remove(i);
      //                                }
      //                            }
      //                        }
      //                    }
      //                }
      //            }
      // ---------------------------------

      // Logger.out.debug(" String : " + sqlBuff.toString());
    } catch (HibernateException hibExp) {
      Logger.out.error(hibExp.getMessage(), hibExp);
      throw new DAOException("Error in retrieve " + hibExp.getMessage(), hibExp);
    } catch (Exception exp) {
      Logger.out.error(exp.getMessage(), exp);
      throw new DAOException("Logical Erroe in retrieve method " + exp.getMessage(), exp);
    }
    return list;
  }