0 Replies Latest reply on Apr 16, 2008 12:13 PM by Arbi Sookazian

    using JDBC with SFSB

    Arbi Sookazian Master

      are there any known issues (other than lack of portability) with using JDBC API in EJB3 SFSB's with Seam 2.0.0.GA apps in JBoss4.2.1.GA?

      I am seeing some exceptions related to passivation (see http://www.jboss.com/index.html?module=bb&op=viewtopic&t=97750 )that are difficult to analyze and explain and I'm wondering if the following type of code may cause troubles and I'm better off refactoring all the JDBC code and using EntityManager/DAO instead.

      There is no injection of EntityManager happening in this SFSB. I'm wondering if the transactiontype attribute in this case is REQUIRED for the methods which is the default for EJB3 session beans?

      @Stateful
      //AS 041508 - testing session scope for conversation ended error
      @Scope(ScopeType.SESSION)
      @Name("techDeployToUser")
      public class TechDeployToUserAction implements TechDeployToUserLocal{
      
       @Logger
       Log log;
      
       @In
       private FacesMessages facesMessages;
      
       @In
       Identity identity;
      
       @In (required=false)
       UTbUser user;
      
       @In
       Context sessionContext;
      
       private List<TbHardwareObject> hardwareTableList = new ArrayList();;
       private List<TbHardwareObject> locationsList = new ArrayList();
      
       private List<TbHardwareObject> userLocEquipList = new ArrayList();
       private List<TbHardwareObject> newlyAssignedByTechEquipList= new ArrayList();
       private List<TbHardwareObject> removedFromUserEquipList = new ArrayList();
      
       Connection con = null;
       Statement stmt = null;
       PreparedStatement preparedStmt = null;
       ResultSet rs = null;
       StringBuffer sqlStringBuffer = null;
      
       List assignedToTechHardwareList = new ArrayList();
       String locNo;
       String techLocMsg = "";
       String userLocMsg = SHIMSConstants.USER_MSG;
      
       String month="", day="", year="", localAssignedDate="";
       Map params;
      
       String msgConfirm;
       String compId;
       String compMsg;
       String techLocationName;
       String userLocationName;
       String networkLogin;
      
       boolean isAssignToTechBtn = true;
       boolean isSubmitByTechBtn = true;
      
       Date now = new Date();
       TbLocationEntityDAO tbLocationDAO = null;
       TbHardwareObject tbHardwareObject = null;
      
       //@Begin(join=true)
       //@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
       public List getAssignedToTechHardwareList()
       {
       params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
       if (params != null)
       {
       log.info("inputlocno = " + params.get("inputlocno"));
       log.info("isAssignBtnClicked = " + params.get("isAssignBtnClicked"));
       log.info("isRemoveBtnClicked = " + params.get("isRemoveBtnClicked"));
       //AS 041508 - commenting line below as I'm not sure
       //if (params.get("inputlocno") == null && (params.get("isAssignBtnClicked")== null && params.get("isRemoveBtnClicked") == null))
       if ((params.get("isAssignBtnClicked")== null && params.get("isRemoveBtnClicked") == null))
       {
       try
       {
       if (user != null)
       {
       networkLogin = user.getNetworkLogin();
       }
       else
       {
       networkLogin = (((NtlmPasswordAuthentication) sessionContext.get("NtlmHttpAuth")).getDomain() +"\\"+((NtlmPasswordAuthentication) sessionContext.get("NtlmHttpAuth")).getUsername());
       }
       try
       {
       if (networkLogin != null)
       {
       try
       {
       log.info("Inside getAssignedToTechHardwareList");
       con = DriverManager.getConnection(SHIMSConstants.URL, SHIMSConstants.USERNAME, SHIMSConstants.PASSWORD);
       hardwareTableList = buildAssignedToTechHardwareList(con, preparedStmt, networkLogin);
       }
       catch (SQLException se)
       {
       log.info("We got an exception while creating a statement:" +
       "that probably means we're no longer connected.");
       se.printStackTrace();
       System.exit(1);
       }
       finally
       {
       cleanUp();
       }
       }
       }
       catch (Exception e)
       {
       e.printStackTrace();
       }
       }
       catch(Exception exp)
       {
       exp.printStackTrace();
       }
       }
       }
       if (hardwareTableList !=null && hardwareTableList.size()>0)
       {
       techLocMsg = "";
       }
       return hardwareTableList;
       }
      
       private List buildAssignedToTechHardwareList(Connection con, PreparedStatement preparedStmt, String networkLogin)
       {
       try
       {
       sqlStringBuffer = new StringBuffer();
       sqlStringBuffer.append(" SELECT ");
       sqlStringBuffer.append(" hardware.hardwareid HardwareId ,");
       sqlStringBuffer.append(" location.locationno LocationNo ,");
       sqlStringBuffer.append(" hardware.coxbarcode BarCode ,");
       sqlStringBuffer.append(" owners.ownertypecode OwnerTypeCode ,");
       sqlStringBuffer.append(" owners.ownertypedesc OwnerGroup ,");
       sqlStringBuffer.append(" vendor.hardwarevendordesc Vendor ,");
       sqlStringBuffer.append(" types.hardwaretypedesc HardwareType ,");
       sqlStringBuffer.append(" model.hardwaremodel Model ,");
       sqlStringBuffer.append(" hardware.enteredbyuser AssignedBy ,");
       sqlStringBuffer.append(" hardware.firstentereddate AssignedDate ,");
       sqlStringBuffer.append("'"+SHIMSConstants.AVAILABLE_FOR_DEPLOYMENT+"'"+ " HardwareStatus ");
       sqlStringBuffer.append(" FROM u_tbuser tbuser ,");
       sqlStringBuffer.append(" tblocation location ,");
       sqlStringBuffer.append(" tbhardware hardware ,");
       sqlStringBuffer.append(" tbhardwarevendor vendor ,");
       sqlStringBuffer.append(" trownertype owners ,");
       sqlStringBuffer.append(" trhardwaretype types ,");
       sqlStringBuffer.append(" tbhardwaremodel model ,");
       sqlStringBuffer.append(" trhardwarestatus hwstatus ");
       sqlStringBuffer.append(" WHERE tbuser.networklogin = "+"'"+networkLogin+"'" );
       sqlStringBuffer.append(" AND tbuser.userid = location.userid ");
       sqlStringBuffer.append(" AND location.locationno = hardware.currentlocationno ");
       sqlStringBuffer.append(" AND hardware.currentstatus = "+"'"+SHIMSConstants.ASSIGN_TO_TECH_STATUS_ID+"'");
       sqlStringBuffer.append(" AND hardware.ownertypecode = owners.ownertypecode ");
       sqlStringBuffer.append(" AND hardware.hardwaremodelid = model.hardwaremodelid ");
       sqlStringBuffer.append(" AND model.hardwarevendorid = vendor.hardwarevendorid ");
       sqlStringBuffer.append(" AND model.hardwaretypeid = types.hardwaretypeid ");
       sqlStringBuffer.append(" AND hardware.currentstatus = hwstatus.hardwarestatus ");
      
       log.info("buildAssignedToTechHardwareList(): sqlStringBuffer = " + sqlStringBuffer);
      
       preparedStmt = con.prepareStatement(sqlStringBuffer.toString());
       }
       catch (SQLException se)
       {
       log.info("We got an exception in *** buildAssignedToTechHardwareList()*** while preparing the SQL Query:" +
       "that probably means our SQL is invalid");
       se.printStackTrace();
       System.exit(1);
       }
      
       try
       {
       rs = preparedStmt.executeQuery();
       if (rs!=null)
       {
       //AS 04/11/08 - clear out hardwareTableList b/c there were duplicate entries displaying in the dataTable
       if (hardwareTableList != null) {
       hardwareTableList.clear();
       }
      
       while (rs.next())
       {
       if (rs.getString("AssignedDate") != null)
       {
       month = rs.getString("AssignedDate").toString().substring(5, 7);
       day = rs.getString("AssignedDate").toString().substring(8, 10);
       year = rs.getString("AssignedDate").toString().substring(0, 4);
       localAssignedDate = month + "/"+day+"/"+year;
       }
      
       tbHardwareObject = new TbHardwareObject();
       tbHardwareObject.setHardwareId(rs.getString("HardwareId"));
       tbHardwareObject.setHistoricalStatus(rs.getString("HardwareStatus"));
       tbHardwareObject.setLocationNo(rs.getString("LocationNo"));
       tbHardwareObject.setModifiedByUser("");
       tbHardwareObject.setEnteredByUser("");
       tbHardwareObject.setBarCode(rs.getString("BarCode"));
       tbHardwareObject.setHistoricalOwnerTypeCode(rs.getString("OwnerTypeCode"));
       tbHardwareObject.setHistoricalOwnerTypeDesc(rs.getString("OwnerGroup"));
       tbHardwareObject.setManufacturer(rs.getString("Vendor"));
       tbHardwareObject.setType(rs.getString("HardwareType") );
       tbHardwareObject.setModel(rs.getString("Model"));
       tbHardwareObject.setUnitPrice("");
       tbHardwareObject.setAssignedBy(rs.getString("AssignedBy"));
       tbHardwareObject.setAssignedDate(localAssignedDate);
       tbHardwareObject.setAssignedToTech("");
      
       hardwareTableList.add(tbHardwareObject);
       }
       }
       }
       catch (SQLException se)
       {
       log.info("We got an exception in *** buildAssignedToTechHardwareList()*** while executing a Prepare Statement for SQL Query:" +
       "- Possibly bad SQL, or check the connection.");
       se.printStackTrace();
       System.exit(1);
       }
       finally
       {
       this.cleanUp();
       }
       return hardwareTableList;
       }
      
       public void validateUserLocation(ValueChangeEvent event) throws AbortProcessingException
       {
       HtmlInputText myInput = (HtmlInputText)event.getComponent();
       String userLocation = "";
       FacesContext fc = FacesContext.getCurrentInstance();
       fc.getExternalContext().getRequestMap().put("focusId",(event.getComponent().getClientId(FacesContext.getCurrentInstance())));
      
       boolean invalidFormat = false;
       boolean invalidRangeChk = false;
       boolean invalidLengthChk = false;
       boolean notInInvChk = false;
      
       try
       {
       if (myInput.getValue() != null)
       {
       userLocation = myInput.getValue().toString().trim();
       if (userLocation.length()>0)
       {
       int len= userLocation.length() ;
       int s_charcode = 0;
       for (int i=0;i<len;i++)
       {
       s_charcode = userLocation.charAt(i);
       if(!((s_charcode>=48 && s_charcode<=57)))
       {
       userLocationName = "";
       myInput.setStyle("border-right-color: Red; border-bottom-color: Red; border-top-width: medium; border-top-color: Red; border-right-width: medium; border-left-width: medium; border-left-color: Red; border-bottom-width: medium");
       setCompId(fc.getExternalContext().getRequestMap().get("focusId").toString());
       setCompMsg("YES");
       setTechLocMsg(userLocation+ " HAS INVALID FORMAT - PLEASE ENTER A NUMERIC LOCATION NO (EX: 1234)");
       setUserLocMsg(SHIMSConstants.USER_MSG);
       invalidFormat = true;
       }
       }
       }
      
       if( invalidFormat == false)
       {
       if (userLocation.length()>0 && Integer.valueOf(userLocation) < 1000 && Integer.valueOf(userLocation) > 9999)
       {
       userLocationName = "";
       myInput.setStyle("border-right-color: Red; border-bottom-color: Red; border-top-width: medium; border-top-color: Red; border-right-width: medium; border-left-width: medium; border-left-color: Red; border-bottom-width: medium");
       setCompId(fc.getExternalContext().getRequestMap().get("focusId").toString());
       setCompMsg("YES");
       setTechLocMsg(userLocation+ " - NOT IN PERMITTED RANGE OF 1000 & 99999.");
       setUserLocMsg(SHIMSConstants.USER_MSG);
       invalidRangeChk = true;
       }
       }
       else if (invalidFormat== false && invalidRangeChk== false && (userLocation.length() > 0 && userLocation.length() < 4))
       {
       userLocationName = "";
       myInput.setStyle("border-right-color: Red; border-bottom-color: Red; border-top-width: medium; border-top-color: Red; border-right-width: medium; border-left-width: medium; border-left-color: Red; border-bottom-width: medium");
       setCompId(fc.getExternalContext().getRequestMap().get("focusId").toString());
       setCompMsg("YES");
       setTechLocMsg(userLocation+" INVALID LENGTH "+" - PERMITTED LOCATION LENGTH MUST BE 4.");
       setUserLocMsg(SHIMSConstants.USER_MSG);
       invalidLengthChk = true;
       }
      
      
       if (invalidFormat== false && invalidRangeChk == false && invalidLengthChk == false)
       {
       tbLocationDAO = new TbLocationEntityDAO();
      // List userLocationList = (List<TbLocation>)tbLocationDAO.findLocation(userLocation);
      // if(userLocationList != null && userLocationList.size() == 0)
       if (Integer.valueOf(findLocation(userLocation)) == 0)
       {
       userLocationName = "";
       myInput.setStyle("border-right-color: Red; border-bottom-color: Red; border-top-width: medium; border-top-color: Red; border-right-width: medium; border-left-width: medium; border-left-color: Red; border-bottom-width: medium");
       setCompId(fc.getExternalContext().getRequestMap().get("focusId").toString());
       setCompMsg("YES");
       setTechLocMsg(userLocation+ " - INVALID LOCATION.");
       setUserLocMsg(SHIMSConstants.USER_MSG);
       notInInvChk = true;
       }
       }
      
       if (invalidFormat == false &&
       invalidRangeChk == false &&
       invalidLengthChk == false &&
       notInInvChk == false)
       {
       log.info("ALL VALIDATIONS PASSED");
       userLocationName = getFirstNameLastName(userLocation, SHIMSConstants.USER_MSG_2);
       myInput.setStyle("border-right-color: GREEN; border-bottom-color: GREEN; border-top-width: medium; border-top-color: GREEN; border-right-width: medium; border-left-width: medium; border-left-color: GREEN; border-bottom-width: medium");
       setCompId(fc.getExternalContext().getRequestMap().get("focusId").toString());
       setCompMsg("NO");
       setTechLocMsg("");
       setUserLocMsg("");
       isAssignToTechBtn = false;
       }
       }
       }
       catch (Exception e)
       {
       e.printStackTrace();
       }
       }
      
       private String findLocation(String userLocationNo)
       {
       try
       {
       con = DriverManager.getConnection(SHIMSConstants.URL, SHIMSConstants.USERNAME, SHIMSConstants.PASSWORD);
       sqlStringBuffer = new StringBuffer();
       sqlStringBuffer.append(" SELECT COUNT(*) LOC_CNT FROM TBLOCATION WHERE LOCATIONNO = ").append("'"+userLocationNo+"'");
       preparedStmt = con.prepareStatement(sqlStringBuffer.toString());
       rs = preparedStmt.executeQuery();
       while (rs.next())
       {
       sqlStringBuffer = new StringBuffer();
       sqlStringBuffer.append(rs.getString("LOC_CNT"));
       }
       }
       catch (SQLException se)
       {
       log.info("We got an exception in *** findLocation()*** while executing a Prepare Statement for SQL Query:" +
       "- Possibly bad SQL, or check the connection.");
       se.printStackTrace();
       System.exit(1);
       }
       finally
       {
       cleanUp();
       }
       return sqlStringBuffer.toString();
       }
      
       private String getFirstNameLastName(String userLocationNo, String locMsg)
       {
       try
       {
       con = DriverManager.getConnection(SHIMSConstants.URL, SHIMSConstants.USERNAME, SHIMSConstants.PASSWORD);
       sqlStringBuffer = new StringBuffer();
       sqlStringBuffer.append(" SELECT ");
       sqlStringBuffer.append(" tbuser.LastName NameLast, tbuser.FirstName NameFirst");
       sqlStringBuffer.append(" FROM tblocation location, u_tbuser tbuser ");
       sqlStringBuffer.append(" WHERE location.LocationNo = ").append("'"+userLocationNo+"'");
       sqlStringBuffer.append(" AND location.userid = tbuser.userid ");
      
       preparedStmt = con.prepareStatement(sqlStringBuffer.toString());
       rs = preparedStmt.executeQuery();
       while (rs.next())
       {
       sqlStringBuffer = new StringBuffer();
       sqlStringBuffer.append(rs.getString ("NameLast")).append(", ").append(rs.getString ("NameFirst")).append(locMsg);
       }
       }
       catch (SQLException se)
       {
       log.info("We got an exception in *** getFirstNameLastName()*** while executing a Prepare Statement for SQL Query:" +
       "- Possibly bad SQL, or check the connection.");
       se.printStackTrace();
       System.exit(1);
       }
       finally
       {
       cleanUp();
       }
       return sqlStringBuffer.toString();
       }
       public List autoSuggestLocNosList(Object event)
       {
       String suggestString = event.toString();
       try
       {
       con = DriverManager.getConnection(SHIMSConstants.URL, SHIMSConstants.USERNAME, SHIMSConstants.PASSWORD);
       sqlStringBuffer = new StringBuffer();
       sqlStringBuffer.append("SELECT LocationNo ");
       sqlStringBuffer.append("FROM tblocation ");
       sqlStringBuffer.append("WHERE LocationNo ").append(" LIKE " + " '%"+suggestString+"%' ");
       sqlStringBuffer.append("AND LocationTypeCode ").append(" NOT IN "+"('"+SHIMSConstants.STORAGE_OR_WAREHOUSE+"')");
      
       stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
       rs = stmt.executeQuery(sqlStringBuffer.toString());
       rs.last();
       int count = rs.getRow();
       rs.beforeFirst();
      
       locationsList.clear();
       if (count ==0)
       {
       tbHardwareObject = new TbHardwareObject();
       tbHardwareObject.setHistoricalStatus(SHIMSConstants.NO_MATCHING_LOCATIONS_FOUND);
      
       locationsList.add(tbHardwareObject);
       }
       else if (rs!=null && count > 0)
       {
       while (rs.next())
       {
       tbHardwareObject = new TbHardwareObject();
       tbHardwareObject.setLocationNo(rs.getString("LocationNo"));
       locationsList.add(tbHardwareObject);
       }
       }
       }
       catch (SQLException se)
       {
       log.info("We got an exception in *** autoSuggestLocNosList()*** while executing a Prepare Statement for SQL Query:" +
       "- Possibly bad SQL, or check the connection.");
       se.printStackTrace();
       System.exit(1);
       }
       finally
       {
       cleanUp();
       }
       return locationsList;
       }
      
       public List<TbHardwareObject> getHardwareEquipmentForUserLocation()
       {
       params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
       String userLocationNo = "";
       try
       {
       if (getLocNo() != null && getLocNo().trim().length()>0 && (params.get("isAssignBtnClicked") == null && params.get("isRemoveBtnClicked") == null))
       {
       userLocationNo = getLocNo().trim();
       con = DriverManager.getConnection(SHIMSConstants.URL, SHIMSConstants.USERNAME, SHIMSConstants.PASSWORD);
       sqlStringBuffer = new StringBuffer();
      
       sqlStringBuffer.append(" SELECT hardware.hardwareid HardwareId, ");
       sqlStringBuffer.append(" location.locationno LocationNo ,");
       sqlStringBuffer.append(" hardware.coxbarcode BarCode ,");
       sqlStringBuffer.append(" owners.ownertypecode OwnerTypeCode ,");
       sqlStringBuffer.append(" owners.ownertypedesc OwnerGroup ,");
       sqlStringBuffer.append(" vendor.hardwarevendordesc Vendor ,");
       sqlStringBuffer.append(" types.hardwaretypedesc HardwareType ,");
       sqlStringBuffer.append(" model.hardwaremodel Model ,");
       sqlStringBuffer.append(" hardware.enteredbyuser AssignedBy ,");
       sqlStringBuffer.append(" hardware.firstentereddate AssignedDate ,");
       sqlStringBuffer.append(" '"+SHIMSConstants.CURRENTLY_OWNER_BY_USER+"'"+ " HardwareStatus ");
       sqlStringBuffer.append(" FROM tblocation location ,");
       sqlStringBuffer.append(" tbhardware hardware ,");
       sqlStringBuffer.append(" tbhardwarevendor vendor ,");
       sqlStringBuffer.append(" trownertype owners ,");
       sqlStringBuffer.append(" trhardwaretype types ,");
       sqlStringBuffer.append(" tbhardwaremodel model ,");
       sqlStringBuffer.append(" trhardwarestatus hwstatus ");
       sqlStringBuffer.append(" WHERE location.locationno = ").append("'"+userLocationNo+"'");
       sqlStringBuffer.append(" AND hwstatus.hardwarestatus = ").append("'"+SHIMSConstants.DEPLOYED_TO_USER_STATUS_ID+"'");
       sqlStringBuffer.append(" AND hwstatus.hardwarestatus = hardware.currentstatus ");
       sqlStringBuffer.append(" AND location.locationno = hardware.currentlocationno ");
       sqlStringBuffer.append(" AND hardware.ownertypecode = owners.ownertypecode ");
       sqlStringBuffer.append(" AND hardware.hardwaremodelid = model.hardwaremodelid ");
       sqlStringBuffer.append(" AND model.hardwarevendorid = vendor.hardwarevendorid ");
       sqlStringBuffer.append(" AND model.hardwaretypeid = types.hardwaretypeid ");
       sqlStringBuffer.append(" ORDER BY hardware.coxbarcode ");
      
       Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
       rs = stmt.executeQuery(sqlStringBuffer.toString());
       rs.last();
       int count = rs.getRow();
       rs.beforeFirst();
      
       if (count == 0)
       {
       userLocMsg = SHIMSConstants.USER_MSG;
       userLocEquipList.clear();
       }
       if (rs!=null && count > 0 && params.get("isAssignBtnClicked") == null && params.get("isRemoveBtnClicked") == null)
       {
       userLocMsg = "";
       isAssignToTechBtn = false;
       userLocEquipList.clear();
       while (rs.next())
       {
       if (rs.getString("AssignedDate") != null)
       {
       month = rs.getString("AssignedDate").toString().substring(5, 7);
       day = rs.getString("AssignedDate").toString().substring(8, 10);
       year = rs.getString("AssignedDate").toString().substring(0, 4);
       localAssignedDate = month + "/"+day+"/"+year;
       }
      
       tbHardwareObject = new TbHardwareObject();
       tbHardwareObject.setHardwareId(rs.getString("HardwareId"));
       tbHardwareObject.setHistoricalStatus(rs.getString("HardwareStatus"));
       tbHardwareObject.setLocationNo(rs.getString("LocationNo"));
       tbHardwareObject.setModifiedByUser("");
       tbHardwareObject.setEnteredByUser("");
       tbHardwareObject.setBarCode(rs.getString("BarCode"));
       tbHardwareObject.setHistoricalOwnerTypeCode(rs.getString("OwnerTypeCode"));
       tbHardwareObject.setHistoricalOwnerTypeDesc(rs.getString("OwnerGroup"));
       tbHardwareObject.setManufacturer(rs.getString("Vendor"));
       tbHardwareObject.setType(rs.getString("HardwareType") );
       tbHardwareObject.setModel(rs.getString("Model"));
       tbHardwareObject.setUnitPrice("");
       tbHardwareObject.setAssignedBy(rs.getString("AssignedBy"));
       tbHardwareObject.setAssignedDate(localAssignedDate);
       tbHardwareObject.setAssignedToTech("");
      
       userLocEquipList.add(tbHardwareObject);
       }
       }
       }
       }
       catch (SQLException se)
       {
       log.info("We got an exception in *** getHardwareEquipmentForUserLocation()*** while executing a Prepare Statement for SQL Query:" +
       "- Possibly bad SQL, or check the connection.");
       se.printStackTrace();
       System.exit(1);
       }
       finally
       {
       cleanUp();
       }
       return userLocEquipList;
       }
      
       public void techHardwareAssignmentsToUser()
       {
       log.info("Inside techHardwareAssignmentsToUser() ***** ");
       params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
       if (params.get("isAssignBtnClicked") != null && "Y".equalsIgnoreCase((String)params.get("isAssignBtnClicked")))
       {
       int counter = 0;
       TbHardwareObject assignToUserTbHardwareObject=null;
       String assignParamCode = (String)params.get("paramAssignBarCode");
       log.info("Barcode to be removed = "+assignParamCode);
       if (hardwareTableList!=null)
       {
       for (int i=0;i<hardwareTableList.size();i++)
       {
       if (assignParamCode.trim().equalsIgnoreCase(hardwareTableList.get(i).getBarCode().trim()))
       {
       assignToUserTbHardwareObject = new TbHardwareObject();
      
       assignToUserTbHardwareObject.setHardwareId(hardwareTableList.get(i).getHardwareId());
       assignToUserTbHardwareObject.setHistoricalStatus(SHIMSConstants.NEWLY_ASSIGNED_BY_TECH);
       assignToUserTbHardwareObject.setLocationNo(hardwareTableList.get(i).getLocationNo());
       assignToUserTbHardwareObject.setBarCode(hardwareTableList.get(i).getBarCode());
       assignToUserTbHardwareObject.setHistoricalOwnerTypeCode(hardwareTableList.get(i).getHistoricalOwnerTypeCode());
       assignToUserTbHardwareObject.setHistoricalOwnerTypeDesc(hardwareTableList.get(i).getHistoricalOwnerTypeDesc());
       assignToUserTbHardwareObject.setManufacturer(hardwareTableList.get(i).getManufacturer());
       assignToUserTbHardwareObject.setType(hardwareTableList.get(i).getType());
       assignToUserTbHardwareObject.setModel(hardwareTableList.get(i).getModel());
       assignToUserTbHardwareObject.setAssignedBy(hardwareTableList.get(i).getAssignedBy());
       assignToUserTbHardwareObject.setAssignedDate(hardwareTableList.get(i).getAssignedDate());
      
       userLocEquipList.add(assignToUserTbHardwareObject);
       newlyAssignedByTechEquipList.add(assignToUserTbHardwareObject);
       hardwareTableList.remove(i);
       }
       }
       }
       if (hardwareTableList.size() == 0)
       {
       techLocMsg = SHIMSConstants.TECH_MSG;
       }
       if (userLocEquipList.size() > 0)
       {
       userLocMsg = "";
       }
      
       for (int i=0;i<userLocEquipList.size();i++)
       {
       if (SHIMSConstants.NEWLY_ASSIGNED_BY_TECH.equalsIgnoreCase(userLocEquipList.get(i).getHistoricalStatus().trim()))
       {
       counter = counter + 1;
       }
       }
       if (counter > 0)
       {
       isSubmitByTechBtn = false;
       }
       }
       }
       // AS 041508 - not being used??? no hits in server.log...
       /*
       public void techHardwareAssignmentsToUser(ActionEvent actionEvent)
       {
      
       log.info("Inside techHardwareAssignmentsToUser(ActionEvent actionEvent) ***** ");
      
       try {
       params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
       if (params.get("isAssignBtnClicked") != null && "Y".equalsIgnoreCase((String)params.get("isAssignBtnClicked")))
       {
       int counter = 0;
       TbHardwareObject assignToUserTbHardwareObject=null;
       String assignParamCode = (String)params.get("paramAssignBarCode");
       log.info("Barcode to be removed = "+assignParamCode);
       if (hardwareTableList!=null)
       {
       for (int i=0;i<hardwareTableList.size();i++)
       {
       if (assignParamCode.trim().equalsIgnoreCase(hardwareTableList.get(i).getBarCode().trim()))
       {
       assignToUserTbHardwareObject = new TbHardwareObject();
      
       assignToUserTbHardwareObject.setHardwareId(hardwareTableList.get(i).getHardwareId());
       assignToUserTbHardwareObject.setHistoricalStatus(SHIMSConstants.NEWLY_ASSIGNED_BY_TECH);
       assignToUserTbHardwareObject.setLocationNo(hardwareTableList.get(i).getLocationNo());
       assignToUserTbHardwareObject.setBarCode(hardwareTableList.get(i).getBarCode());
       assignToUserTbHardwareObject.setHistoricalOwnerTypeCode(hardwareTableList.get(i).getHistoricalOwnerTypeCode());
       assignToUserTbHardwareObject.setHistoricalOwnerTypeDesc(hardwareTableList.get(i).getHistoricalOwnerTypeDesc());
       assignToUserTbHardwareObject.setManufacturer(hardwareTableList.get(i).getManufacturer());
       assignToUserTbHardwareObject.setType(hardwareTableList.get(i).getType());
       assignToUserTbHardwareObject.setModel(hardwareTableList.get(i).getModel());
       assignToUserTbHardwareObject.setAssignedBy(hardwareTableList.get(i).getAssignedBy());
       assignToUserTbHardwareObject.setAssignedDate(hardwareTableList.get(i).getAssignedDate());
      
       userLocEquipList.add(assignToUserTbHardwareObject);
       newlyAssignedByTechEquipList.add(assignToUserTbHardwareObject);
       hardwareTableList.remove(i);
       }
       }
       }
       if (hardwareTableList.size() == 0)
       {
       techLocMsg = SHIMSConstants.TECH_MSG;
       }
       if (userLocEquipList.size() > 0)
       {
       userLocMsg = "";
       }
      
       for (int i=0;i<userLocEquipList.size();i++)
       {
       if (SHIMSConstants.NEWLY_ASSIGNED_BY_TECH.equalsIgnoreCase(userLocEquipList.get(i).getHistoricalStatus().trim()))
       {
       counter = counter + 1;
       }
       }
       if (counter > 0)
       {
       isSubmitByTechBtn = false;
       }
       }
       }
       catch(Exception e) {
       log.error("error occurred in techHardwareAssignmentsToUser(): ", e);
       }
       }
       */
      
       public void techHardwareRemovalFromUser()
       {
       try {
       params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
       if (params.get("isRemoveBtnClicked") != null && "Y".equalsIgnoreCase((String)params.get("isRemoveBtnClicked")))
       {
       String paramRemoveBarCode = (String)params.get("paramRemoveBarCode");
       TbHardwareObject assignToTechTbHardwareObject = null;
       if (userLocEquipList != null)
       {
       for (int i=0;i<userLocEquipList.size();i++)
       {
       if (paramRemoveBarCode.trim().equalsIgnoreCase(userLocEquipList.get(i).getBarCode().toString().trim()))
       {
       assignToTechTbHardwareObject = new TbHardwareObject();
       assignToTechTbHardwareObject.setHardwareId(userLocEquipList.get(i).getHardwareId());
       assignToTechTbHardwareObject.setHistoricalStatus(SHIMSConstants.REMOVED_FROM_USER_BY_TECH);
       assignToTechTbHardwareObject.setLocationNo(userLocEquipList.get(i).getLocationNo());
       assignToTechTbHardwareObject.setBarCode(userLocEquipList.get(i).getBarCode());
       assignToTechTbHardwareObject.setHistoricalOwnerTypeCode(userLocEquipList.get(i).getHistoricalOwnerTypeCode());
       assignToTechTbHardwareObject.setHistoricalOwnerTypeDesc(userLocEquipList.get(i).getHistoricalOwnerTypeDesc());
       assignToTechTbHardwareObject.setManufacturer(userLocEquipList.get(i).getManufacturer());
       assignToTechTbHardwareObject.setType(userLocEquipList.get(i).getType());
       assignToTechTbHardwareObject.setModel(userLocEquipList.get(i).getModel());
       assignToTechTbHardwareObject.setAssignedBy(userLocEquipList.get(i).getAssignedBy());
       assignToTechTbHardwareObject.setAssignedDate(userLocEquipList.get(i).getAssignedDate());
      
       hardwareTableList.add(assignToTechTbHardwareObject);
       removedFromUserEquipList.add(assignToTechTbHardwareObject);
       userLocEquipList.remove(i);
       }
       }
       if (userLocEquipList.size() == 0)
       {
       userLocMsg = SHIMSConstants.USER_MSG;
       }
      
       if (hardwareTableList.size() > 0)
       {
       techLocMsg = "";
       }
      
       isSubmitByTechBtn = false;
      
       }
       }
       }
       catch(Exception e) {
       log.error("error occurred in techHardwareRemovalFromUser(): ", e);
       }
       }
      
      
       //@End(beforeRedirect=true)
       //@End
       public void submitNewlyAssignedEquipment()
       {
       try
       {
       params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
       if (params.get("isSubmitBtnClicked") != null && "Y".equalsIgnoreCase((String)params.get("isSubmitBtnClicked")))
       {
       if (newlyAssignedByTechEquipList != null && newlyAssignedByTechEquipList.size()>0)
       {
       populateHardwareHistory(newlyAssignedByTechEquipList, SHIMSConstants.ASSIGN_TO_TECH_STATUS_ID, getLoggedInUserLocationNo() );
       populateHardware(newlyAssignedByTechEquipList, SHIMSConstants.DEPLOYED_TO_USER_STATUS_ID, getLocNo());
       }
      
       if (removedFromUserEquipList != null && removedFromUserEquipList.size()>0)
       {
       populateHardwareHistory(removedFromUserEquipList, SHIMSConstants.DEPLOYED_TO_USER_STATUS_ID, getLocNo());
       populateHardware(removedFromUserEquipList, SHIMSConstants.ASSIGN_TO_TECH_STATUS_ID, getLoggedInUserLocationNo());
       }
       }
       facesMessages.add("Your request processed successfully ....");
       }
       catch (Exception se)
       {
       log.info("We got an exception in *** submitNewlyAssignedEquipment()*** while executing a Statement for UPDATE Query:" +
       "- Possibly bad SQL, or check the connection.");
       se.printStackTrace();
       System.exit(1);
       }
       finally
       {
       cleanUp();
       }
       }
      
       private void populateHardwareHistory(List<TbHardwareObject> populateList, String status, String location)
       {
       sqlStringBuffer = new StringBuffer();
       try
       {
       con = DriverManager.getConnection(SHIMSConstants.URL, SHIMSConstants.USERNAME, SHIMSConstants.PASSWORD);
       if (populateList != null && populateList.size() > 0)
       {
       for (int i=0;i<populateList.size();i++)
       {
       sqlStringBuffer.append(" INSERT INTO TBHARDWAREHISTORY VALUES ( ");
       sqlStringBuffer.append(Integer.valueOf(populateList.get(i).getHardwareId())).append(",");
       sqlStringBuffer.append("'").append(status).append("',");
       sqlStringBuffer.append("'").append(location).append("',");
       sqlStringBuffer.append("'").append(DateFormat.getInstance().format(now)).append("',");
       sqlStringBuffer.append(null+",");
       sqlStringBuffer.append("'").append(populateList.get(i).getAssignedBy()).append("',");
       sqlStringBuffer.append("'").append(populateList.get(i).getHistoricalOwnerTypeCode()).append("') ");
       }
       }
       log.info("populateHardwareHistory(): sqlStringBuffer = " + sqlStringBuffer);
       preparedStmt = con.prepareStatement(sqlStringBuffer.toString());
       preparedStmt.executeUpdate();
       }
       catch (SQLException se)
       {
       log.info("We got an exception in *** populateHardwareHistory()*** while executing a Statement for UPDATE Query:" +
       "- Possibly bad SQL, or check the connection.");
       se.printStackTrace();
       System.exit(1);
       }
       finally
       {
       cleanUp();
       }
       }
      
       private void populateHardware(List<TbHardwareObject> populateList, String status, String location)
       {
       sqlStringBuffer = new StringBuffer();
       try
       {
       con = DriverManager.getConnection(SHIMSConstants.URL, SHIMSConstants.USERNAME, SHIMSConstants.PASSWORD);
       if (populateList != null && populateList.size() > 0)
       {
       for (int i=0;i<populateList.size();i++)
       {
       sqlStringBuffer.append(" UPDATE ");
       sqlStringBuffer.append(" TBHARDWARE ");
       sqlStringBuffer.append(" SET CURRENTLOCATIONNO = ").append("'"+location+"' ,");;
       sqlStringBuffer.append(" CURRENTSTATUS = ").append("'"+status+"' ,");
       sqlStringBuffer.append(" FIRSTENTEREDDATE = ").append("'").append(DateFormat.getInstance().format(now)).append("',");
       sqlStringBuffer.append(" ENTEREDBYUSER = ").append("'").append(populateList.get(i).getAssignedBy()).append("'");
       sqlStringBuffer.append("WHERE COXBARCODE = ").append("'").append(populateList.get(i).getBarCode()).append("'");
       }
       }
       log.info("populateHardware(): sqlStringBuffer = " + sqlStringBuffer);
       preparedStmt = con.prepareStatement(sqlStringBuffer.toString());
       preparedStmt.executeUpdate();
       }
       catch (SQLException se)
       {
       log.info("We got an exception in *** populateHardware()*** while executing a Statement for UPDATE Query:" +
       "- Possibly bad SQL, or check the connection.");
       se.printStackTrace();
       System.exit(1);
       }
       finally
       {
       cleanUp();
       }
       }
      
       private String getLoggedInUserLocationNo()
       {
       String loggedInUserLocationNo = "";
       try
       {
       if (getNetworkLogin() != null)
       {
      // tbLocationDAO = new TbLocationEntityDAO();
      // List userLocationList = (List<TbLocation>)tbLocationDAO.getLoggedInUserLocation(getNetworkLogin());
      
       sqlStringBuffer = new StringBuffer();
       try
       {
       con = DriverManager.getConnection(SHIMSConstants.URL, SHIMSConstants.USERNAME, SHIMSConstants.PASSWORD);
       sqlStringBuffer.append("SELECT LOCATIONNO FROM TBLOCATION WHERE NETWORKLOGIN = ").append("'"+getNetworkLogin()+"'");
       Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
       rs = stmt.executeQuery(sqlStringBuffer.toString());
       rs.last();
       int count = rs.getRow();
       rs.beforeFirst();
      
       if (count >0 && rs!= null)
       {
       while (rs.next())
       {
       loggedInUserLocationNo = rs.getString("LOCATIONNO");
       }
       }
       }
       catch (SQLException se)
       {
       log.info("We got an exception in *** populateHardware()*** while executing a Statement for UPDATE Query:" +
       "- Possibly bad SQL, or check the connection.");
       se.printStackTrace();
       System.exit(1);
       }
       finally
       {
       cleanUp();
       }
      
       }
       }
       catch(Exception e)
       { e.printStackTrace();}
      
       return loggedInUserLocationNo;
       }
      
      
       private void cleanUp()
       {
       try
       {
       if (rs != null)
       {
       rs.close();
       }
       if (preparedStmt != null)
       {
       preparedStmt.close();
       }
       if (stmt != null)
       {
       stmt.close();
       }
       if (con != null)
       {
       con.close();
       }
       }
       catch(SQLException e) {
       e.printStackTrace();
       }
       }
      
       //@End(beforeRedirect=true)
       //@End
       public String cancel()
       {
       log.info("in cancel()");
       return "cancelled";
       }
      
       @PrePassivate
       private void cleanupBeforePassivation() {
      
       }
      
       @Destroy @Remove
       public void destroy()
       {
       log.info("Inside destroy ============>");
       }
      
       public String getLocNo() {
       return locNo;
       }
      
      
       public void setLocNo(String locNo) {
       this.locNo = locNo;
       }
      
      
       public List<TbHardwareObject> getUserLocEquipList() {
       return userLocEquipList;
       }
      
      
       public void setUserLocEquipList(List<TbHardwareObject> userLocEquipList) {
       this.userLocEquipList = userLocEquipList;
       }
      
      
       public String getUserLocMsg() {
       return userLocMsg;
       }
      
      
       public void setUserLocMsg(String userLocMsg) {
       this.userLocMsg = userLocMsg;
       }
      
      
       public String getTechLocMsg() {
       return techLocMsg;
       }
      
      
       public void setTechLocMsg(String techLocMsg) {
       this.techLocMsg = techLocMsg;
       }
      
      
       public String getCompId() {
       return compId;
       }
      
      
       public void setCompId(String compId) {
       this.compId = compId;
       }
      
      
       public String getCompMsg() {
       return compMsg;
       }
      
      
       public void setCompMsg(String compMsg) {
       this.compMsg = compMsg;
       }
      
      
       public String getMsgConfirm() {
       return msgConfirm;
       }
      
      
       public void setMsgConfirm(String msgConfirm) {
       this.msgConfirm = msgConfirm;
       }
      
      
       public boolean isAssignToTechBtn() {
       return isAssignToTechBtn;
       }
      
      
       public void setAssignToTechBtn(boolean isAssignToTechBtn) {
       this.isAssignToTechBtn = isAssignToTechBtn;
       }
      
      
       public boolean isSubmitByTechBtn() {
       return isSubmitByTechBtn;
       }
      
      
       public void setSubmitByTechBtn(boolean isSubmitByTechBtn) {
       this.isSubmitByTechBtn = isSubmitByTechBtn;
       }
      
       //AS 041508 - commenting setNewlyAssignedByTechEquipList and getNewlyAssignedByTechEquipList as they
       // are no longer being referenced...
      
       /*public List<TbHardwareObject> getNewlyAssignedByTechEquipList() {
       return newlyAssignedByTechEquipList;
       }
      
      
       public void setNewlyAssignedByTechEquipList(
       List<TbHardwareObject> newlyAssignedByTechEquipList) {
       this.newlyAssignedByTechEquipList = newlyAssignedByTechEquipList;
       }
      */
      
       public String getUserLocationName() {
       return userLocationName;
       }
      
      
       public void setUserLocationName(String userLocationName) {
       this.userLocationName = userLocationName;
       }
      
      
       public List<TbHardwareObject> getRemovedFromUserEquipList() {
       return removedFromUserEquipList;
       }
      
      
       public void setRemovedFromUserEquipList(
       List<TbHardwareObject> removedFromUserEquipList) {
       this.removedFromUserEquipList = removedFromUserEquipList;
       }
      
      
       public String getNetworkLogin() {
       return networkLogin;
       }
      
      
       public void setNetworkLogin(String networkLogin) {
       this.networkLogin = networkLogin;
       }
      
       public String getTechLocationName() {
      
       if (user != null)
       {
       networkLogin = user.getNetworkLogin();
       log.info("Here...1");
       }
       else
       {
      
      // NtlmPasswordAuthentication npa = (NtlmPasswordAuthentication) sessionContext.get("NtlmHttpAuth");
      // networkLogin = npa.getUsername();
      
       networkLogin = (((NtlmPasswordAuthentication) sessionContext.get("NtlmHttpAuth")).getDomain() +"\\"+((NtlmPasswordAuthentication) sessionContext.get("NtlmHttpAuth")).getUsername());
       }
       techLocationName = getFirstNameLastName(getLoggedInUserLocationNo(), SHIMSConstants.TECH_MSG_2);
       return techLocationName;
       }
      
       public void setTechLocationName(String techLocationName) {
       this.techLocationName = techLocationName;
       }
      
      }