Package com.centraview.common

Examples of com.centraview.common.CVDal


   * @param tableID to identify the table
   */
  public int getSearchFieldID(int tableID)
  {
    int searchFieldID = -1;
    CVDal cvdal = new CVDal(this.dataSource);
    Vector fieldsValueList = new Vector();
    try
    {
      String sqlQuery = "Select SearchFieldID from searchfield where SearchtableID = ? and FieldName = ?";
      cvdal.setSqlQuery(sqlQuery);
      cvdal.setInt(1,tableID);
      cvdal.setString(2,GlobalReplaceConstantKeys.SEARCH_MARKETING_FIELD_NAME);

      Collection resultsCollection = cvdal.executeQuery();
      if (resultsCollection != null)
      {
      Iterator resultsIterator = resultsCollection.iterator();
      while (resultsIterator.hasNext())
      {
        HashMap resultsHashMap = (HashMap) resultsIterator.next();
        searchFieldID = ((Number) resultsHashMap.get("SearchFieldID")).intValue();
      } //end of while statement (resultsIterator.hasNext())
      } //end of if statement (resultsCollection != null)
    } //end of try block
    catch (Exception e)
    {
    logger.error("[Exception] GlobalReplaceEJB.getSearchFieldID:", e);
    } //end of catch block (Exception)
    finally
    {
    cvdal.setSqlQueryToNull();
    cvdal.destroy();
    cvdal = null;
    } //end of finally block

    return searchFieldID;
  }//end of getSearchFieldID
View Full Code Here


   *
   * @return A Vector with bean object contains tableID & TableName.
   */
  public Vector getPrimaryReplaceTables()
  {
    CVDal cvdal = new CVDal(this.dataSource);
    Vector replaceTablesList = new Vector();
    try
    {
      //We will get the list of table id, for which we can preform the Global Replace
    String sqlQuery = "SELECT SearchTableID,DisplayName,TableName " +
      " FROM searchtable WHERE IsOnGlobalReplaceTable = 'Y' ";
    cvdal.setSqlQuery(sqlQuery);
    Collection resultsCollection = cvdal.executeQuery();
    if (resultsCollection != null)
    {
      Iterator resultsIterator = resultsCollection.iterator();
      while (resultsIterator.hasNext())
      {
      HashMap resultsHashMap = (HashMap) resultsIterator.next();
      Number tableID = (Number) resultsHashMap.get("SearchTableID");
      String tableDisplayName = (String) resultsHashMap.get("DisplayName");
      String tableName = (String) resultsHashMap.get("TableName");
      if(tableID != null && tableName != null && !tableName.equals("") + tableDisplayName != null && !tableDisplayName.equals("")){
        String keyValue = tableID.toString() + "#" + tableName;
        DDNameValue tableInfo = new DDNameValue(keyValue,tableDisplayName);
        replaceTablesList.add(tableInfo);
      }
      } //end of while statement (resultsIterator.hasNext())
    } //end of if statement (resultsCollection != null)
    } //end of try block
    catch (Exception e)
    {
    logger.error("[Exception] GlobalReplaceEJB.getPrimaryReplaceTables:", e);
    } //end of catch block (Exception)
    finally
    {
    cvdal.setSqlQueryToNull();
    cvdal.destroy();
    cvdal = null;
    } //end of finally block

    return replaceTablesList;
  } //end of getPrimaryReplaceTables method
View Full Code Here

   * 1) ID contains two information tableID and fieldId seperated by "*"
   * 2) Name is the FieldName.
   */
  public Vector getReplaceTableFields(int replaceTableID)
  {
    CVDal cvdal = new CVDal(this.dataSource);
    Vector replaceFieldsList = new Vector();
    boolean flagMethodOfContact = false;
    boolean flagCustomFields = false;
    StringBuffer tableIDs = new StringBuffer();
    tableIDs.append(replaceTableID+"");
    try
    {
    //We will get the list of fields which are associate to the table which is selected.
    String sqlQuery = "SELECT RelateTableID,IsRelateTable " +
      " FROM globalreplacerelate WHERE SearchTableID = ? ";
    cvdal.setSqlQuery(sqlQuery);
    cvdal.setInt(1,replaceTableID);
    Collection resultsCollection = cvdal.executeQuery();
    if (resultsCollection != null)
    {
      Iterator resultsIterator = resultsCollection.iterator();
      while (resultsIterator.hasNext())
      {
      HashMap resultsHashMap = (HashMap) resultsIterator.next();
      Number relateTableID = (Number) resultsHashMap.get("RelateTableID");
      int tableID = relateTableID.intValue();
      String isRelateTable = (String) resultsHashMap.get("IsRelateTable");
      if(tableID != 0 && isRelateTable != null && isRelateTable.equals("Y")){
        tableIDs.append("," + tableID);
      }else if(tableID != 0){
        if(tableID == GlobalReplaceConstantKeys.CUSTOM_FIELD_TABLEID ){
          flagCustomFields = true;
        }
      }
      } //end of while statement (resultsIterator.hasNext())
    } //end of if statement (resultsCollection != null)

    cvdal.setSqlQueryToNull();
    cvdal.clearParameters();
    sqlQuery = "SELECT SearchTableID,SearchFieldID,DisplayName,FieldType " +
      " FROM searchfield WHERE SearchTableID in ("+tableIDs.toString()+")  and IsGlobalReplaceField ='Y'";
    cvdal.setSqlQuery(sqlQuery);
    Collection fieldCollections = cvdal.executeQuery();
    if (fieldCollections != null)
    {
      Iterator fieldsIterator = fieldCollections.iterator();
      while (fieldsIterator.hasNext())
      {
        HashMap fieldsHashMap = (HashMap) fieldsIterator.next();
        Number tableID = (Number) fieldsHashMap.get("SearchTableID");
        Number fieldID = (Number) fieldsHashMap.get("SearchFieldID");
        Number fieldType = (Number) fieldsHashMap.get("FieldType");
        String fieldDisplayName = (String) fieldsHashMap.get("DisplayName");
        String keyValue = tableID.toString() + "*" + fieldID.toString()+ "*" + fieldType.toString();
        DDNameValue tableInfo = new DDNameValue(keyValue,fieldDisplayName);
        replaceFieldsList.add(tableInfo);
      } //end of while statement (fieldsIterator.hasNext())
    } //end of if statement (fieldCollections != null)

    // If we found the tableId for the customfield associated to the selected table.
    // We must have to get all the fields associated to the table.
    if(flagCustomFields){
      cvdal.setSqlQueryToNull();
      cvdal.clearParameters();

      sqlQuery = "SELECT CustomFieldID , Name, FieldType FROM" +
             " customfield where RecordType = ?;";
      cvdal.setSqlQuery(sqlQuery);
      cvdal.setInt(1,replaceTableID);
      fieldCollections = cvdal.executeQuery();
      if (fieldCollections != null)
      {
        Iterator fieldsIterator = fieldCollections.iterator();
        while (fieldsIterator.hasNext())
        {
        HashMap fieldsHashMap = (HashMap) fieldsIterator.next();
        Number customFieldID = (Number) fieldsHashMap.get("CustomFieldID");
        String fieldDisplayName = (String) fieldsHashMap.get("Name");
        String fieldType = (String) fieldsHashMap.get("FieldType");
        int scalarOrMultiple = 0;
        if(fieldType != null && fieldType.equals("MULTIPLE")){
          scalarOrMultiple = GlobalReplaceConstantKeys.FIELD_TYPE_MULTIPLE;
        }
        String keyValue = GlobalReplaceConstantKeys.CUSTOM_FIELD_TABLEID  + "*" + customFieldID.toString() + "*" + scalarOrMultiple;
        DDNameValue tableInfo = new DDNameValue(keyValue,fieldDisplayName);
        replaceFieldsList.add(tableInfo);
        } //end of while statement (fieldsIterator.hasNext())
      } //end of if statement (fieldCollections != null)
    }
    } //end of try block
    catch (Exception e)
    {
    logger.error("[Exception] GlobalReplaceEJB.getReplaceTableFields:", e);
    } //end of catch block (Exception)
    finally
    {
    cvdal.setSqlQueryToNull();
    cvdal.destroy();
    cvdal = null;
    } //end of finally block

    return replaceFieldsList;
  } //end of getReplaceTableFields method
View Full Code Here

   * @return The number of messages copied (should always be 1 or 0).
   */
  public int copyMessageToFolder(int individualID, int messageID, int newFolderID)
  {
    int numberCopied = 0;
    CVDal cvdal = new CVDal(this.dataSource);

    MailMessageVO messageVO = this.getEmailMessageVO(individualID, messageID);
    MailAccountVO accountVO = this.getMailAccountVO(messageVO.getEmailAccountID());

    int oldFolderID = messageVO.getEmailFolderID();
    String serverType = accountVO.getAccountType();

    if (serverType.equalsIgnoreCase(MailAccountVO.IMAP_TYPE)) {
      try {
        Session session = null;
        IMAPStore store = this.setupIMAPConnection(accountVO, session);
        MailFolderVO toFolderVO = getEmailFolder(newFolderID);
        MailFolderVO fromFolderVO = getEmailFolder(oldFolderID);

        String name = toFolderVO.getFolderFullName();
        if (name == null) {
          name = toFolderVO.getFolderName();
        }
        IMAPFolder toFolder = (IMAPFolder)store.getFolder(name);

        name = fromFolderVO.getFolderFullName();
        if (name == null) {
          name = fromFolderVO.getFolderName();
        }
        IMAPFolder fromFolder = (IMAPFolder)store.getFolder(name);

        fromFolder.open(IMAPFolder.READ_ONLY);
        Message msg = fromFolder.getMessageByUID(Long.parseLong(messageVO.getMessageUID()));
        fromFolder.copyMessages(new Message[] {msg}, toFolder);
        fromFolder.close(false);
      } catch(Exception e) {
        System.out.println("Exception thrown in copyMessageToFolder()");
        e.printStackTrace();
        return(0);
      }
    }

    try {
      String insertQuery = "INSERT INTO emailmessagefolder (MessageID, FolderID) VALUES (?, ?)";
      cvdal.setSqlQuery(insertQuery);
      cvdal.setInt(1, messageID);
      cvdal.setInt(2, newFolderID);
      numberCopied = cvdal.executeUpdate();
      cvdal.setSqlQueryToNull();

      String updateQuery = "UPDATE emailmessage SET LocallyModified='YES', CopiedToFolder=? WHERE MessageID=?";
      cvdal.setSqlQuery(updateQuery);
      cvdal.setInt(1, newFolderID);
      cvdal.setInt(2, messageID);
      cvdal.executeUpdate();
      cvdal.setSqlQueryToNull();
    }catch (Exception e){
      logger.error("[copyMessageToFolder]: Exception", e);
    }finally{
      cvdal.destroy();
      cvdal = null;
    }
    return numberCopied;
  }
View Full Code Here

   *
   * @return A Vector with bean object contains fieldValueID & fieldValue.
   */
  public Vector getFieldValues(int tableID, int fieldID)
  {
    CVDal cvdal = new CVDal(this.dataSource);
    Vector fieldsValueList = new Vector();
    try
    {
      if(tableID == GlobalReplaceConstantKeys.CUSTOM_FIELD_TABLEID ){
      String sqlQuery = "SELECT ValueID , Value " +
        " FROM customfieldvalue WHERE CustomFieldID = ? ";
      cvdal.setSqlQuery(sqlQuery);
      cvdal.setInt(1,fieldID);

      Collection resultsCollection = cvdal.executeQuery();
      if (resultsCollection != null)
      {
        Iterator resultsIterator = resultsCollection.iterator();
        while (resultsIterator.hasNext())
        {
        HashMap resultsHashMap = (HashMap) resultsIterator.next();
        Number valueID = (Number) resultsHashMap.get("ValueID");
        String value = (String) resultsHashMap.get("Value");
        if(valueID != null && value != null && !value.equals("")){
          String keyValue = valueID.toString();
          DDNameValue tableInfo = new DDNameValue(keyValue,value);
          fieldsValueList.add(tableInfo);
        }
        } //end of while statement (resultsIterator.hasNext())
      } //end of if statement (resultsCollection != null)
      }//end of if(tableID == GlobalReplaceConstantKeys.CUSTOM_FIELD_TABLEID )
      else{
        // We must have to put a unique entry for the tableID and fieldId in the globalreplacerelate table.
        // which should have the fieldname and tablename.
        // fieldname should be like this for Example StatusID as ValueID and StatusTitle As Value
      String sqlQuery = "SELECT fieldName,tableName " +
        " FROM Globalreplacevalue WHERE tableID = ? and fieldID= ?";
      cvdal.setSqlQuery(sqlQuery);
      cvdal.setInt(1,tableID);
      cvdal.setInt(2,fieldID);
      String fieldName = null;
      String tableName = null;
      Collection resultsCollection = cvdal.executeQuery();
      if (resultsCollection != null)
      {
        Iterator resultsIterator = resultsCollection.iterator();
        while (resultsIterator.hasNext())
        {
        HashMap resultsHashMap = (HashMap) resultsIterator.next();
        fieldName = (String) resultsHashMap.get("fieldName");
        tableName = (String) resultsHashMap.get("tableName");
        } //end of while statement (resultsIterator.hasNext())
      } //end of if statement (resultsCollection != null)
      if(fieldName != null && tableName != null){
        sqlQuery = "SELECT " + fieldName + " FROM " + tableName;
        cvdal.setSqlQuery(sqlQuery);
        resultsCollection = cvdal.executeQuery();
        if (resultsCollection != null)
        {
          Iterator resultsIterator = resultsCollection.iterator();
          while (resultsIterator.hasNext())
          {
          HashMap resultsHashMap = (HashMap) resultsIterator.next();
          Number valueID = (Number) resultsHashMap.get("ValueID");
          String value = (String) resultsHashMap.get("Value");
          if(valueID != null && value != null && !value.equals("")){
            String keyValue = valueID.toString();
            DDNameValue tableInfo = new DDNameValue(keyValue,value);
            fieldsValueList.add(tableInfo);
          }//end of if(valueID != null && value != null && !value.equals(""))
          } //end of while statement (resultsIterator.hasNext())
        } //end of if statement (resultsCollection != null)
      }//end of if(fieldName != null && tableName != null)
      }//end of else for if(tableID == GlobalReplaceConstantKeys.CUSTOM_FIELD_TABLEID )
    } //end of try block
    catch (Exception e)
    {
    logger.error("[Exception] GlobalReplaceEJB.getFieldValues:", e);
    } //end of catch block (Exception)
    finally
    {
    cvdal.setSqlQueryToNull();
    cvdal.destroy();
    cvdal = null;
    } //end of finally block

    return fieldsValueList;
  } //end of getFieldValues method
View Full Code Here

   * @return updateFlag if any thing goes wrong then it will return false else it will return true.
   */
  public boolean performGlobalReplace(HashMap replaceInfo)
  {
    boolean updateFlag = true;
    CVDal cvdal = new CVDal(this.dataSource);
    Collection allTables = new ArrayList();
    batchQuery = new ArrayList();

    try {

      int individualID = ((Integer) replaceInfo.get("individualID")).intValue();
      Integer primaryTableID = (Integer) replaceInfo.get("tableID");
      SearchVO searchVO = (SearchVO) replaceInfo.get("searchVO");
      String fieldInfo = (String) replaceInfo.get("fieldInfo");
      String fieldValue = (String) replaceInfo.get("fieldValue");
      String fieldName = (String) replaceInfo.get("fieldName");

      InitialContext ic = CVUtility.getInitialContext();
      AdvancedSearchLocalHome home = (AdvancedSearchLocalHome) ic.lookup("local/AdvancedSearch");
      AdvancedSearchLocal remote = (AdvancedSearchLocal) home.create();
      remote.setDataSource(dataSource);
      ArrayList resultsIDs = new ArrayList();
      resultsIDs.addAll(remote.performSearch(individualID,searchVO));

      //Parse out the field Information which are fieldtableid, fieldID and fieldType
      // Field type as its own idenfication
      // for example  "6" is a phone type field. "8" is a multiple selection field type
      int fieldTableID = 0;
      int replaceFieldID = 0;
      int replaceFieldType = 0;
      if(fieldInfo != null){
        StringTokenizer fieldToken = new StringTokenizer(fieldInfo, "*");
        String fieldIDString = null;
        String tableIDString = null;
        String fieldTypeString = null;
        if(fieldToken != null){
          while (fieldToken.hasMoreTokens())
          {
            tableIDString = (String) fieldToken.nextToken();
            fieldIDString = (String) fieldToken.nextToken();
            fieldTypeString = (String) fieldToken.nextToken();
          }//end of while (fieldInfo.hasMoreTokens())
          if(fieldIDString != null && fieldTypeString != null && !fieldIDString.equals("") && !fieldTypeString.equals("")){
            fieldTableID = Integer.parseInt(tableIDString);
            replaceFieldID = Integer.parseInt(fieldIDString);
            replaceFieldType =  Integer.parseInt(fieldTypeString);
          }//end of if(fieldIDString != null && fieldTypeString != null && !fieldIDString.equals("") && !fieldTypeString.equals(""))
        }//end of if(fieldToken != null)
      }//end of if(fieldInfo != null)


    String primaryTable = null;
    String primaryKey = null;
    String relateTable = null;
    int queryTableID = 0;
    String displayName = null;
    String relateKey = null;
    String relationShipQuery = null;
    String isOnGlobalReplaceTable = null;
    String realTableName = null;
    String updateField = null;
    String subRelationShipQuery = null;

    //Get the Primary Table for this module.
    String mainTableQuery = "SELECT TablePrimaryKey,  TableName FROM "+
          "searchtable where SearchTableID = ?";
    cvdal.setSqlQueryToNull();
    cvdal.clearParameters();
    cvdal.setSqlQuery(mainTableQuery);
    cvdal.setInt(1, primaryTableID.intValue());
    Collection mainTableResults = cvdal.executeQuery();
    cvdal.setSqlQueryToNull();
    if (mainTableResults != null)
    {
      Iterator mainTableIterator = mainTableResults.iterator();
      //Only get the first one.
      if (mainTableIterator.hasNext())
      {
      HashMap mainTableHashMap = (HashMap) mainTableIterator.next();
      primaryTable = (String) mainTableHashMap.get("TableName");
      primaryKey = (String) mainTableHashMap.get("TablePrimaryKey");
      if (!allTables.contains(primaryTable))
      {
        allTables.add(primaryTable);
      } //end of if statement (!tables.contains(tableName))
      } //end of while loop (mainTableIterator.hasNext())
    } //end of if statement (mainTableResults != null)
    //end of Get the Primary Table for this module.

    //Get the Primary Table for this module.
    mainTableQuery = "SELECT sf.RealFieldName, sf.SearchTableID , sf.DisplayName , st.TableName, sf.RelationshipQuery, " +
          " sf.IsOnGlobalReplaceTable, sf.RealTableName, sf.SubRelationshipQuery FROM searchtable st,searchfield sf where sf.SearchTableID "+
          " = st.SearchTableID and sf.searchFieldID = ?";
    cvdal.setSqlQueryToNull();
    cvdal.clearParameters();
    cvdal.setSqlQuery(mainTableQuery);
    cvdal.setInt(1, replaceFieldID);
    mainTableResults = cvdal.executeQuery();
    cvdal.setSqlQueryToNull();
    if (mainTableResults != null)
    {
      Iterator mainTableIterator = mainTableResults.iterator();
      //Only get the first one.
      if (mainTableIterator.hasNext())
      {
      HashMap mainTableHashMap = (HashMap) mainTableIterator.next();
      relateTable = (String) mainTableHashMap.get("TableName");
      relateKey = (String) mainTableHashMap.get("RealFieldName");
      queryTableID = ((Number) mainTableHashMap.get("SearchTableID")).intValue();
      displayName = (String) mainTableHashMap.get("DisplayName");
      relationShipQuery = (String)mainTableHashMap.get("RelationshipQuery");
      isOnGlobalReplaceTable = (String)mainTableHashMap.get("IsOnGlobalReplaceTable");
      realTableName = (String)mainTableHashMap.get("RealTableName");
      subRelationShipQuery = (String)mainTableHashMap.get("SubRelationshipQuery");
     
      if (!allTables.contains(primaryTable))
      {
        allTables.add(primaryTable);
      } //end of if statement (!tables.contains(tableName))
      } //end of while loop (mainTableIterator.hasNext())
    } //end of if statement (mainTableResults != null)
    //end of Get the Primary Table for this module.
   
    // Update the Custom Field Table with its values.
    if(fieldTableID == GlobalReplaceConstantKeys.CUSTOM_FIELD_TABLEID ){
      for (int i = 0; i < resultsIDs.size(); i++)
      {
        int recordID =((Number)resultsIDs.get(i)).intValue();
        if(replaceFieldType == GlobalReplaceConstantKeys.FIELD_TYPE_MULTIPLE){
          String finalTableQuery = "UPDATE customfieldmultiple SET ValueID = ? WHERE " +
          " CustomFieldID = ? AND RecordID in (?) ";
          cvdal.setSqlQueryToNull();
          cvdal.clearParameters();
          cvdal.setSqlQuery(finalTableQuery);
          cvdal.setString(1, fieldValue);
          cvdal.setInt(2, replaceFieldID);
          cvdal.setInt(3, recordID);
          int rowsAffected = cvdal.executeUpdate();
          if(rowsAffected == 0){
            batchQuery.add("insert into customfieldmultiple " +
            "(customfieldid,recordid,valueid) values " +
            "(" + replaceFieldID + "," + recordID + "," + fieldValue +
            ")");
          }//end of if(rowsAffected == 0)
        }//end of if(replaceFieldType == GlobalReplaceConstantKeys.FIELD_TYPE_MULTIPLE)
        else{
          String finalTableQuery = "UPDATE customfieldscalar SET Value = ? "
                +" cf.CustomFieldID = ? AND RecordID in (?) ";
          cvdal.setSqlQueryToNull();
          cvdal.clearParameters();
          cvdal.setSqlQuery(finalTableQuery);
          cvdal.setString(1, fieldValue);
          cvdal.setInt(2, replaceFieldID);
          cvdal.setInt(3, recordID);
          int rowsAffected = cvdal.executeUpdate();
          if(rowsAffected == 0){
            batchQuery.add("insert into customfieldscalar " +
            "(customfieldid,recordid,value) values " + "(" +
            replaceFieldID + "," + recordID + ",'" +
            fieldValue + "')");
          }//end of if(rowsAffected == 0)
        }//end of else for if(replaceFieldType == GlobalReplaceConstantKeys.FIELD_TYPE_MULTIPLE)
      }//end of for (int i = 0; i < resultsIDs.size(); i++)
    }else {
      updateField = relateTable + "." + relateKey;
      String thisRelationship = "";

      //We must check wheather the field is occuring in the table.
      // If it not occuring in the table then  we must have to get the alias table name &
      // collect the Relationship to that table build a relationship information.
      if (isOnGlobalReplaceTable != null && isOnGlobalReplaceTable.equals("N")){

        //We must have to do this because the tablename is attached to the field name.
        updateField = relateKey;

        if (!allTables.contains(realTableName))
        {
          allTables.add(realTableName);
        } //end of if (!allTables.contains(realTableName))

        // alias determination
        Collection alias = new ArrayList();
        StringTokenizer aliasCommaTokens = new StringTokenizer(realTableName, ",");
        while(aliasCommaTokens.hasMoreTokens()){
          String aliasRealTable = aliasCommaTokens.nextToken();
          StringTokenizer aliasTokens = new StringTokenizer(aliasRealTable, " ");
          String tempTableName = aliasTokens.nextToken();
          if(aliasTokens.hasMoreTokens())
          {
            alias.add(aliasTokens.nextToken());
          }//end of if(aliasTokens.hasMoreTokens())
        }//end of while(aliasCommaTokens.hasMoreTokens())

        if (relationShipQuery != null)
        {
          thisRelationship = relationShipQuery;
          StringTokenizer relationshipTokens = new StringTokenizer(relationShipQuery, " ");
          while (relationshipTokens.hasMoreTokens())
          {
            String thisToken = relationshipTokens.nextToken();
            int index = thisToken.indexOf(".");
            if (index > -1)
            {
            String tableName = thisToken.substring(0, index);
            //Incase if you added the new line to the Query then before
            //check for the occurance. We will eliminate the new line return character.
            tableName = tableName.replaceAll("\n","");
            if ((!allTables.contains(tableName)) && (!alias.contains(tableName)))
            {
              allTables.add(tableName);
            } //end of if statement (!tables.contains(tableName))
            } //end of if statement (index > -1)
          } //end of while loop (relationshipTokens.hasMoreTokens())
          } //end of if statement (thisRelationship != null)
         
          if(subRelationShipQuery != null && !subRelationShipQuery.equals("")){
          thisRelationship += subRelationShipQuery;
          }
      }//end of if (isOnTable != null && isOnTable.equals("N"))


      // We must have to identify the relation of the table
      // incase for some reason if the record is not occuring for the table then
      // we must have add new record for that related table.
      int index = updateField.indexOf(".");
      int insertType = 0;

      if (index > -1)
      {
        int lenField = updateField.length();
        String tableName = updateField.substring(0, index);
        if (tableName != null && tableName.startsWith("moc")){
          insertType = GlobalReplaceConstantKeys.METHOD_OF_CONTACT_TABLEID;
        }
        if (tableName != null && tableName.startsWith("address")){
          insertType = GlobalReplaceConstantKeys.ADDRESS_TABLEID;
          fieldName = updateField.substring(index+1,lenField);
        }

      } //end of if statement (index > -1)

      //building the final query
      StringBuffer selectQuery = new StringBuffer();
      selectQuery.append("UPDATE ");
      Iterator thisTableIterator = allTables.iterator();
      while (thisTableIterator.hasNext())
      {
        String currentTable = (String) thisTableIterator.next();
        selectQuery.append(currentTable);
        if (thisTableIterator.hasNext())
        {
        selectQuery.append(", ");
        } //end of if statement (thisTableIterator.hasNext())
      } //end of while loop (thisTableIterator.hasNext())
      selectQuery.append(" SET " + updateField + " = ? ");
      selectQuery.append(" WHERE ");
      if (thisRelationship != null && thisRelationship.length() > 0)
      {
        selectQuery.append(thisRelationship);
        selectQuery.append(" AND ");
      } //end of if statement (thisRelationship != null ...
      selectQuery.append( primaryTable + "." + primaryKey + " in ( ? )");

      for (int i = 0; i < resultsIDs.size(); i++)
      {
        int recordID =((Number)resultsIDs.get(i)).intValue();
        cvdal.setSqlQueryToNull();
        cvdal.clearParameters();
        cvdal.setSqlQuery(selectQuery.toString());
        cvdal.setString(1,fieldValue);
        cvdal.setInt(2,recordID);
        int rowsAffected = cvdal.executeUpdate();
        if(rowsAffected == 0){
          HashMap fieldDetails = new HashMap();
          fieldDetails.put("contactID",new Integer(recordID));
          fieldDetails.put("contactType",primaryTableID);
          fieldDetails.put("insertType",new Integer(insertType));
          fieldDetails.put("fieldName",fieldName);
          fieldDetails.put("fieldValue",fieldValue);
          this.insertGlobalReplaceRecord(fieldDetails,cvdal);
        }
      }//end of for (int i = 0; i < resultsIDs.size(); i++)
    }//end of else block

    // In-case if we are updating the individual's List then we must have to update the entity's List ID
    // same thing for entity.
    if(displayName != null && displayName.equals("Marketing List") && queryTableID != 0){
     
      //intialize the ContactHelperLocal
      ContactHelperLocalHome contactHelperLocalHome = (ContactHelperLocalHome)ic.lookup("local/ContactHelper");
      ContactHelperLocal contactHelperLocal =  contactHelperLocalHome.create();
      contactHelperLocal.setDataSource(this.dataSource);

      ArrayList recordIDs= new ArrayList();     
      for (int i = 0; i < resultsIDs.size(); i++)
      {
        int recordID =((Number)resultsIDs.get(i)).intValue();
        // If we are processing the Individual then we must have to get
        // Entity ID. So that we can move the entity as well as all associated individual
        // to the new List selected by the user.
        if(queryTableID == 2){
          recordID = contactHelperLocal.getEntityIDForIndividual(recordID);
        }//end of if(queryTableID == 2)
        recordIDs.add(recordID+"");
      }//end of for (int i = 0; i < resultsIDs.size(); i++)
      String entityIDs[] = new String[recordIDs.size()];
      for(int i = 0; i < recordIDs.size(); i++){
        entityIDs[i]= (String) recordIDs.get(i);
      }//end of for(int i = 0; i < recordIDs.size(); i++)
      int marketingListID = Integer.parseInt(fieldValue);
      if(marketingListID != 0 && entityIDs.length != ){
        // Reason for adminIndividualID to set as -1. We know that admin is a super user
        // he can move any thing. thats why its hard coded to -1
        int adminIndividualID = -1;
        contactHelperLocal.entityMove(adminIndividualID, marketingListID, entityIDs );
      }//end of if(marketingListID != 0 && entityIDs.length != 0  )     
    }//end of if(displayName != null && displayName.equals("Marketing List") && queryTableID != 0)

    // inserting the batched query to the database.
    int[] batchResult = cvdal.batchProcess(batchQuery);

    } //end of try block
    catch (Exception e)
    {
    logger.error("[Exception] GlobalReplaceEJB.performGlobalReplace:", e);
    updateFlag = false;
    } //end of catch block (Exception)
    finally
    {
    cvdal.destroy();
    cvdal = null;
    } //end of finally block
    return updateFlag;
  } //end of performGlobalReplace method
View Full Code Here

   */
  public boolean emailFolderExists(int accountID, String folderName)
  {
    // TODO: make emailFolderExists() require the full path instead of the folder name.
    boolean exists = false;
    CVDal cvdal = new CVDal(this.dataSource);
    try {
      exists = this.emailFolderExists(accountID, folderName, cvdal);
    }catch(Exception e){
      System.out.println("[Exception] MailEJB.emailFolderExists: "  + e.toString());
      //e.printStackTrace();
    }finally{
      cvdal.destroy();
      cvdal = null;
    }
    return(exists);
  }
View Full Code Here

   */
  public MailMessageVO getEmailMessageVO(int individualID, int messageID)
  {
    MailMessageVO mailMessageVO = new MailMessageVO();
    mailMessageVO.setMessageID(-1);
    CVDal cvdal = new CVDal(this.dataSource);

    try {
      mailMessageVO = this.getEmailMessageVO(individualID, messageID, cvdal);
    }catch(Exception e){
      System.out.println("[Exception] MailEJB.getEmailMessageVO: " + e.toString());
      //e.printStackTrace();
    }finally{
      cvdal.destroy();
      cvdal = null;
    }
    return(mailMessageVO);
  }   // end getEmailMessageVO(int,int) method
View Full Code Here

   * @return true if the message exists, false otherwise.
   */
  public boolean emailMessageExists(int accountID, int folderID, String messageUID)
  {
    boolean exists = false;
    CVDal cvdal = new CVDal(this.dataSource);
    try {
      exists = this.emailMessageExists(accountID, folderID, messageUID, cvdal);
    }catch(Exception e){
      logger.error("[emailMessageExists] Exception thrown.", e);
    }finally{
      cvdal.destroy();
      cvdal = null;
    }
    return exists;
  }   // end emailMessageExists(int,int,String) method
View Full Code Here

   *        on the remote IMAP server as well as in our local database.
   * @return The ID of the new Folder.
   */
  public int addEmailFolder(MailFolderVO mailFolderVO, boolean createOnRemoteServer)
  {
    CVDal cvdal = new CVDal(this.dataSource);
    int newFolderID = -1;

    try {
      newFolderID = this.addEmailFolder(mailFolderVO, createOnRemoteServer, cvdal);
    }catch (Exception e){
      System.out.println("[Exception][MailEJB] Exception thrown in addEmailFolder(MailFolderVO): " + e);
      e.printStackTrace();
    }finally{
      cvdal.destroy();
      cvdal = null;
    }

    return newFolderID;
  }
View Full Code Here

TOP

Related Classes of com.centraview.common.CVDal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.