Java tutorial
/** * Copyright (c) 2001-2012 "Redbasin Networks, INC" [http://redbasin.org] * * This file is part of Redbasin OpenDocShare community project. * * Redbasin OpenDocShare is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package dao; import java.sql.Connection; import java.util.List; import javax.sql.DataSource; import model.Contact; import model.Hdlogin; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jboss.cache.Fqn; import util.DbConstants; import util.RegexStrUtil; /** * <B>ColTrafficDaoDb</B> <BR> * This object implements ContactDao interface * * @author Smitha Gudur (smitha@redbasin.com) * @version $Revision: 1.1 $ */ public class ContactDaoDb extends BaseDao implements ContactDao { protected final Log logger = LogFactory.getLog(getClass()); private volatile ContactAddQuery addQuery; private volatile ContactDeleteQuery deleteQuery; private volatile ContactAlphabetQuery getAlphabetQuery; private volatile ContactAlphabetShareQuery getMyAlphabetShareQuery; private volatile ContactIdQuery contactIdQuery; private volatile ContactUpdateQuery updateQuery; private volatile ContactAllQuery getAllQuery; private volatile ContactAddShareMemberQuery addShareMemberQuery; private volatile ContactDeleteShareMemberQuery deleteShareMemberQuery; private volatile ContactAddShareQuery addShareQuery; private volatile ContactDeleteShareQuery deleteShareQuery; private volatile ContactDeleteShareByIdQuery deleteShareContactByIdQuery; private volatile ContactGetSharedQuery getSharedContacts; private volatile ContactGetMySharedQuery getMySharedContacts; private volatile IsContactSharedQuery isContactSharedQuery; private volatile ContactTagAddQuery addTagQuery; private volatile ContactTagUpdateQuery updateTagQuery; private volatile ContactTagDeleteQuery deleteTagQuery; private volatile ContactTagExistsQuery contactTagExistsQuery; private volatile ContactGetSharedPublishedQuery getSharedPublishedQuery; private volatile ContactMyPublishedQuery getMyPublishedQuery; private volatile ContactAlphabetSharedContactsQuery getAlphabetSharedContacts; private volatile ContactCSVMyPublishedQuery getMyPublishedCSVQuery; private volatile ContactCSVSharedPublishedQuery getSharedPublishedCSVQuery; private volatile ContactNoNameQuery getContactNoNameQuery; private volatile ContactSharedNoNameQuery getContactSharedNoNameQuery; private volatile ContactShareQuery getContactShareQuery; /** * Given a login return the updated personal info page. * @param loginId * @param dob * @param title * @param industry * @param company * @param pwebsite * @param cwebsite * @param blogsite * @param city * @param state * @param country * @param description * @param zipcode * @param fname * @param lname * @param mname * @param email * @param gender * @param nickname * @param designation * @param bcity * @param bstate * @param bcountry * @param bzipcode * @param hphone * @param cphone * @param bphone * @param yim * @param aim * @param msn * @param icq * @param fax * @param netphone * @param relation * @param publish * @param tags * @param alphabet - the first letter of firstname or lastname * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void addContact(String loginId, String dob, String title, String industry, String company, String pwebsite, String cwebsite, String blogsite, String city, String state, String country, String description, String zipcode, String fname, String lname, String mname, String email, String gender, String nickname, String designation, String bcity, String bstate, String bcountry, String bzipcode, String hphone, String cphone, String bphone, String yim, String aim, String msn, String icq, String fax, String netphone, String relation, String publish, String tags, String alphabet, String street, String bstreet) throws BaseDaoException { /** * Get scalability datasource for hdcontacts */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, addContact() " + sourceName); } boolean canPublish = false; if (!RegexStrUtil.isNull(publish)) { if (publish.equals("1")) { canPublish = true; } } Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); if (canPublish) { addQuery.run(conn, fname, lname, mname, dob, title, industry, company, pwebsite, cwebsite, blogsite, city, state, country, description, zipcode, gender, nickname, designation, bcity, bstate, bcountry, bzipcode, hphone, cphone, bphone, yim, aim, msn, icq, loginId, fax, netphone, relation, email, publish, "", street, bstreet); addTagQuery.run(conn, "LAST_INSERT_ID()", tags); } else { addQuery.run(conn, fname, lname, mname, dob, title, industry, company, pwebsite, cwebsite, blogsite, city, state, country, description, zipcode, gender, nickname, designation, bcity, bstate, bcountry, bzipcode, hphone, cphone, bphone, yim, aim, msn, icq, loginId, fax, netphone, relation, email, publish, tags, street, bstreet); } } catch (Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { throw new BaseDaoException("connection close exception", e2); } throw new BaseDaoException("conn.rollback() exception", e1); } throw new BaseDaoException("exception", e); } // connection commit try { conn.commit(); } catch (Exception e3) { throw new BaseDaoException("commit() exception, for add contact loginid = " + loginId, e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e3) { throw new BaseDaoException( "setAutocommit()/conn.close() exception, for add contact loginid = " + loginId, e3); } Fqn fqn = cacheUtil.fqn(DbConstants.CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.CONTACTS_ALPHABET); if (!RegexStrUtil.isNull(alphabet)) { StringBuffer sb = new StringBuffer(alphabet); sb.append("-"); sb.append(loginId); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } } fqn = cacheUtil.fqn(DbConstants.SHARED_PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } } /** * This method deletes shared member contact * @param loginId - the login id whose contact info is shared. * @param member - the member with whom the contact is shared with * @throws BaseDaoException - when error occurs * this method is not being used */ public void deleteMemberContact(String loginId, String member) throws BaseDaoException { if (RegexStrUtil.isNull(loginId) || RegexStrUtil.isNull(member)) { throw new BaseDaoException("params are null in deleteMemberContact()"); } Hdlogin memberInfo = getLoginid(member); if (memberInfo == null) { throw new BaseDaoException("memberInfo is null for member" + member); } /** * Get scalability datasource for sharecontacts */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, deleteMemberContact() " + sourceName); } String memberId = memberInfo.getValue(DbConstants.LOGIN_ID); Connection conn = null; try { conn = ds.getConnection(); deleteShareMemberQuery.run(conn, loginId, memberId); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("error in conn.close() loginId=" + loginId, e1); } throw new BaseDaoException("error in deleteMemberContact loginId=" + loginId, e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("conn.close() error, deleteMemberContact loginId=" + loginId, e); } Fqn fqn = cacheUtil.fqn(DbConstants.CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } // DbConstants.CONTACT is skipped as it is not affected /* fqn = cacheUtil.fqn(DbConstants.CONTACTS_ALPHABET); StringBuffer sb = new StringBuffer(alphabet); sb.append("-"); sb.append(loginId); if (treeCache.exists(fqn, sb.toString()) ) { treeCache.remove(fqn, sb.toString()); } */ fqn = cacheUtil.fqn(DbConstants.SHARED_CONTACTS); if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } fqn = cacheUtil.fqn(DbConstants.MY_SHARED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.SHARED_PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } } /** * This method shares one members's contact with another member * @param loginId - the login id whose contact infor is shared. * @param member - the member with whom the contact is shared with * @throws BaseDaoException - when error occurs */ public void shareMemberContact(String loginId, String member) throws BaseDaoException { if (RegexStrUtil.isNull(loginId) || RegexStrUtil.isNull(member)) { throw new BaseDaoException("params are null in shareMemberContact()"); } Hdlogin memberInfo = getLoginid(member); if (memberInfo == null) { throw new BaseDaoException("memberInfo is null for member" + member); } /** * Get scalability datasource for sharecontacts */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, shareMemberContact() " + sourceName); } Connection conn = null; try { conn = ds.getConnection(); addShareMemberQuery.run(conn, loginId, memberInfo.getValue(DbConstants.LOGIN_ID)); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("error in conn.close() loginId=" + loginId, e1); } throw new BaseDaoException("error in shareMemberContact loginId=" + loginId, e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("conn.close() error, shareMemberContact loginId=" + loginId, e); } } /** * This method lists contacts that donot have firstname and lastname, for this login * @param loginId - the login id * @param accessFlag - the access flag * @return List - the list of no name contacts * @throws BaseDaoException - when error occurs */ public List getNoNameContacts(String loginId, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(loginId)) { throw new BaseDaoException("params are null in getNoNameContacts()"); } /** * Get scalability datasource for sharecontacts */ String sourceName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteZeroScalability(); } else { sourceName = scalabilityManager.getReadZeroScalability(); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getNoNameContacts() " + sourceName); } try { Object[] params = { (Object) loginId }; List result = getContactNoNameQuery.execute(params); return result; } catch (Exception e) { throw new BaseDaoException("error in getNoNameContacts loginid=" + loginId, e); } } /** * This method lists contacts that donot have firstname and lastname, * that were shared by others with this login * @param loginId - the login id * @param accessFlag - the access flag * @return List - the list of no names, shared contacts for this login * @throws BaseDaoException - when error occurs */ public List getNoNameSharedContacts(String loginId, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(loginId)) { throw new BaseDaoException("params are null in getNoNameSharedContacts()"); } /** * Get scalability datasource for hdcontacts, sharecontact */ String sourceName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteZeroScalability(); } else { sourceName = scalabilityManager.getReadZeroScalability(); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getNoNameSharedContacts() " + sourceName); } try { Object[] params = { (Object) loginId }; List result = getContactSharedNoNameQuery.execute(params); if (result != null) { for (int i = 0; i < result.size(); i++) { if (((Contact) result.get(i)) != null) { String id = ((Contact) result.get(i)).getValue(DbConstants.OWNER_ID); if (!RegexStrUtil.isNull(id)) { ((Contact) result.get(i)).setObject(DbConstants.OWNER_INFO, (Hdlogin) getLogin(id)); } } } } return result; } catch (Exception e) { throw new BaseDaoException("error in getNoNameSharedContacts loginid=" + loginId, e); } } /** * This method lists all contacts that were shared by others with this login * @param loginId - the login id * @param alphabet - the alphabet * @param accessFlag - the accessFlag * @return List - the list of shared contacts * @throws BaseDaoException - when error occurs */ public List getAlphabetSharedContacts(String loginId, String alphabet, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(loginId) || RegexStrUtil.isNull(alphabet)) { throw new BaseDaoException("params are null in getAlphabetSharedContacts()"); } /** * Get scalability datasource for sharecontacts */ String sourceName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteZeroScalability(); } else { sourceName = scalabilityManager.getReadZeroScalability(); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getAlphabetSharedContacts() " + sourceName); } StringBuffer alphabetString = new StringBuffer("%"); alphabetString.append(alphabet); alphabetString.append("%"); try { Object[] params = { (Object) loginId, (Object) alphabetString.toString(), (Object) alphabetString.toString() }; List result = getAlphabetSharedContacts.execute(params); for (int i = 0; i < result.size(); i++) { String id = ((Contact) result.get(i)).getValue(DbConstants.OWNER_ID); if (!RegexStrUtil.isNull(id)) { Hdlogin hdlogin = getLogin(id); ((Contact) result.get(i)).setObject(DbConstants.OWNER_INFO, hdlogin); } } return result; } catch (Exception e) { throw new BaseDaoException( "error in getAlphabetSharedContacts loginid=" + loginId + " alphabet = " + alphabet, e); } } /** * This method lists all contacts that were shared by others with this login * @param loginId - the login id * @return List - the list of shared contacts * @throws BaseDaoException - when error occurs */ public List getSharedContacts(String loginId) throws BaseDaoException { if (RegexStrUtil.isNull(loginId)) { throw new BaseDaoException("params are null in getSharedContacts()"); } Fqn fqn = cacheUtil.fqn(DbConstants.SHARED_CONTACTS); if (treeCache.exists(fqn, loginId)) { return (List) treeCache.get(fqn, loginId); } /** * Get scalability datasource for sharecontacts */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getSharedContacts() " + sourceName); } try { Object[] params = { (Object) loginId }; List result = getSharedContacts.execute(params); if ((result != null) && (result.size() > 0)) { for (int i = 0; i < result.size(); i++) { String id = ((Contact) result.get(i)).getValue(DbConstants.OWNER_ID); if (!RegexStrUtil.isNull(id)) { Hdlogin hdlogin = getLogin(id); ((Contact) result.get(i)).setObject(DbConstants.OWNER_INFO, hdlogin); } } treeCache.put(fqn, loginId, result); } return result; } catch (Exception e) { throw new BaseDaoException("error in getSharedContacts loginid=" + loginId, e); } } /** * This method deletes a contact that is shared with another member * @param loginId - the login id * @param contactId - the contact id * @param member - the member with whom the contact is shared with * @param alphabet - the first letter of first or last name of the contact * @throws BaseDaoException - when error occurs */ public void deleteShareContact(String loginId, String contactId, String member, String alphabet) throws BaseDaoException { if (RegexStrUtil.isNull(contactId) || RegexStrUtil.isNull(loginId) || RegexStrUtil.isNull(member)) { throw new BaseDaoException("params are null in deleteShareContact()"); } Hdlogin memberInfo = getLoginid(member); if (memberInfo == null) { throw new BaseDaoException("memberInfo null, deleteSharecontact() for member =" + member); } /** * Get scalability datasource for sharecontacts */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, deleteShareContact() " + sourceName); } String memberId = memberInfo.getValue(DbConstants.LOGIN_ID); Connection conn = null; try { conn = ds.getConnection(); deleteShareQuery.run(conn, contactId, memberId); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("error in conn.close() contactId=" + contactId, e1); } throw new BaseDaoException("error in deleteShareContact contactId=" + contactId, e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("conn.close() error, deleteShareContact contactId=" + contactId, e); } Fqn fqn = cacheUtil.fqn(DbConstants.CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } // CONTACT is skipped as it is not affected fqn = cacheUtil.fqn(DbConstants.CONTACTS_ALPHABET); StringBuffer sb = new StringBuffer(alphabet); sb.append("-"); sb.append(loginId); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } fqn = cacheUtil.fqn(DbConstants.SHARED_CONTACTS); if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } fqn = cacheUtil.fqn(DbConstants.MY_SHARED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.SHARED_PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } } /** * This method lists all contacts that this user has shared with others * @param loginId - the login id * @return List - the list of contacts * @throws BaseDaoException - when error occurs */ public List getMySharedContacts(String loginId) throws BaseDaoException { if (RegexStrUtil.isNull(loginId)) { throw new BaseDaoException("params are null in getMySharedContacts()"); } Fqn fqn = cacheUtil.fqn(DbConstants.MY_SHARED_CONTACTS); if (treeCache.exists(fqn, loginId)) { return (List) treeCache.get(fqn, loginId); } /** * Get scalability datasource for sharecontacts */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getMySharedContacts() " + sourceName); } try { Object[] params = { (Object) loginId }; List result = getMySharedContacts.execute(params); if ((result != null) && (result.size() > 0)) { for (int i = 0; i < result.size(); i++) { Contact contact = (Contact) result.get(i); if (contact != null) { Hdlogin hdlogin = getLogin(contact.getValue(DbConstants.DEST_ID)); if (hdlogin != null) { contact.setObject(DbConstants.MEMBER_INFO, hdlogin); } } } treeCache.put(fqn, loginId, result); } return result; } catch (Exception e) { throw new BaseDaoException("error in getMySharedContacts loginid=" + loginId, e); } } /** * This method shares a contact with another member * @param contactId - the contact id * @param loginId - the login id whose contact information is shared. * @param member - the member with whom the contact is shared with * @param alphabet - the first letter of the contact (firstname or last name) * @throws BaseDaoException - when error occurs */ public void shareContact(String contactId, String loginId, String member, String alphabet) throws BaseDaoException { if (RegexStrUtil.isNull(contactId) || RegexStrUtil.isNull(member)) { throw new BaseDaoException("params are null in shareContact()"); } Hdlogin memberInfo = getLoginid(member); if (memberInfo == null) { throw new BaseDaoException("memberInfo is null for member" + member); } /** * Get scalability datasource for sharecontacts */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, shareContact() " + sourceName); } String memberId = memberInfo.getValue(DbConstants.LOGIN_ID); Connection conn = null; try { conn = ds.getConnection(); addShareQuery.run(conn, loginId, contactId, memberId); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("error in conn.close() contactId=" + contactId, e1); } throw new BaseDaoException("error in shareContact contactId=" + contactId, e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("conn.close() error, shareContact contactId=" + contactId, e); } Fqn fqn = cacheUtil.fqn(DbConstants.CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.CONTACT); if (treeCache.exists(fqn, contactId)) { treeCache.remove(fqn, contactId); } fqn = cacheUtil.fqn(DbConstants.CONTACTS_ALPHABET); StringBuffer sb = new StringBuffer(alphabet); sb.append("-"); sb.append(loginId); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } fqn = cacheUtil.fqn(DbConstants.SHARED_CONTACTS); if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } fqn = cacheUtil.fqn(DbConstants.MY_SHARED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.SHARED_PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } } /** * currently not used, required for future * This method returns contacts that are published by login id * @param loginId - the login id to get all the contacts * @param flag - make it cvs compatible (true), or false * @return List - list of all contacts * @throws BaseDaoException - when error occurs */ public List getMyPublishedContacts(String loginId, int accessFlag, boolean flag) throws BaseDaoException { if (RegexStrUtil.isNull(loginId)) { throw new BaseDaoException("params are null in getMyPublishedContacts()"); } Fqn fqn = cacheUtil.fqn(DbConstants.PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { return (List) treeCache.get(fqn, loginId); } /** * Get scalability datasource for hdcontacts */ String sourceName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteZeroScalability(); } else { sourceName = scalabilityManager.getReadZeroScalability(); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getMyPublishedContacts() " + sourceName); } try { Object[] params = { (Object) loginId }; List result = null; if (flag) { result = getMyPublishedCSVQuery.execute(params); } else { result = getMyPublishedQuery.execute(params); } if ((result != null) && (result.size() > 0)) { treeCache.put(fqn, loginId, result); } return result; } catch (Exception e) { throw new BaseDaoException("error in getMyPublishedContacts " + getMyPublishedQuery.getSql(), e); } } /** * Currently not being used, will be required in future * This method returns published contacts that are shared by others with this login * @param loginId - the login id to get all the contacts * @param flag - make it cvs compatible (true), or false * @return List - list of all contacts * @throws BaseDaoException - when error occurs */ public List getSharedPublishedContacts(String loginId, int accessFlag, boolean flag) throws BaseDaoException { if (RegexStrUtil.isNull(loginId)) { throw new BaseDaoException("params are null in getSharedPublishedContacts()"); } Fqn fqn = cacheUtil.fqn(DbConstants.SHARED_PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { return (List) treeCache.get(fqn, loginId); } /** * Get scalability datasource for hdcontacts */ String sourceName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteZeroScalability(); } else { sourceName = scalabilityManager.getReadZeroScalability(); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getSharedPublishedContacts() " + sourceName); } try { Object[] params = { (Object) loginId }; if (flag) { return getSharedPublishedCSVQuery.execute(params); } else { List result = getSharedPublishedQuery.execute(params); if ((result != null) && (result.size() > 0)) { treeCache.put(fqn, loginId, result); } return result; } } catch (Exception e) { throw new BaseDaoException("error in getSharedPublishedContacts " + getSharedPublishedQuery.getSql(), e); } } /** * This method returns contacts that match the loginid * @param loginId - the login id to get all the contacts * @return List - list of all contacts * @throws BaseDaoException - when error occurs */ public byte[] getPublishedContactsAsCSV(String loginId) throws BaseDaoException { List contacts = getMyPublishedContacts(loginId, DbConstants.READ_FROM_SLAVE, false); List sharedContacts = getSharedPublishedContacts(loginId, DbConstants.READ_FROM_SLAVE, false); StringBuffer sb = new StringBuffer(); if ((contacts != null) && (contacts.size() > 0) || (sharedContacts != null) && (sharedContacts.size() > 0)) { getFields(sb); } boolean cExists = false; if ((contacts != null) && (contacts.size() > 0)) { for (int i = 0; i < contacts.size(); i++) { sb.append((String) getFieldValues((Contact) contacts.get(i)).toString()); cExists = true; } } if ((sharedContacts != null) && (sharedContacts.size() > 0)) { if (cExists) { sb.append("\n\r"); } int k = sharedContacts.size(); for (int i = 0; i < k; i++) { sb.append((String) getFieldValues((Contact) sharedContacts.get(i)).toString()); } } return ((String) sb.toString()).getBytes(); } /* public List setDuplicateSharedContacts(List contacts, String memberId) { if (contacts == null && RegexStrUtil.isNull(memberId )) { throw new BaseDaoException("params are null"); } for (int i = 0; i < contacts.size() i++) { isDup = false; String contactid = ((Contact)contacts.get(i)).getValue(DbConstants.CONTACT_ID); String destid = ((Contact)contacts.get(i)).getValue(DbConstants.DEST_ID); if (!RegexStrUtil.isNull(contactid)) { for (int j = 0; j < contacts.size() j++) { if (i != j) { String duplicate = ((Contact)contacts.get(j)).getValue(DbConstants.CONTACT_ID); if (!RegexStrUtil.isNull(duplicate) && contactid.equals(duplicate)) { isDup = true; } } } if (isDup) { contacts.get(i).setValue(DbConstants.IS_DUPLICATE, "1"); } else { contacts.get(i).setValue(DbConstants.IS_DUPLICATE, "0"); } } } } */ /** * This method returns contacts that match the loginid * @param loginId - the login id to get all the contacts * @param accessFlag - the access flag for the data resource * @return List - list of all contacts * @throws BaseDaoException - when error occurs */ public List getAllContacts(String loginId, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(loginId)) { throw new BaseDaoException("params are null in getAllContacts()"); } Fqn fqn = cacheUtil.fqn(DbConstants.CONTACTS); if (treeCache.exists(fqn, loginId)) { return (List) treeCache.get(fqn, loginId); } /** * Get scalability datasource for hdcontacts */ String sourceName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteZeroScalability(); } else { sourceName = scalabilityManager.getReadZeroScalability(); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getAllContacts() " + sourceName); } try { Object[] params = { (Object) loginId }; List result = getAllQuery.execute(params); if ((result != null) && (result.size() > 0)) { treeCache.put(fqn, loginId, result); } return result; } catch (Exception e) { throw new BaseDaoException("error in getAllContacts loginid = " + loginId + getAllQuery.getSql(), e); } } /** * This method returns contacts that match with this alphabet * if alphabet is null, it uses alphabet "a" * @param loginId - the login id to get all the contacts * @param accessFlag - the access flag for the data resource * @param alphabet - the alphabet for which this contact information is to be displayed * @param member - the member with whom the contacts are either shared or will be shared with. * can be null. * @return List - list of all contacts * @throws BaseDaoException - when error occurs */ public List getContacts(String loginId, int accessFlag, String alphabet, String member) throws BaseDaoException { if (RegexStrUtil.isNull(loginId)) { throw new BaseDaoException("params are null in getContacts()"); } if (RegexStrUtil.isNull(alphabet)) { alphabet = "a"; } StringBuffer sb = new StringBuffer(alphabet); sb.append("-"); sb.append(loginId); Fqn fqn = null; if (RegexStrUtil.isNull(member)) { fqn = cacheUtil.fqn(DbConstants.CONTACTS_ALPHABET); if (treeCache.exists(fqn, sb.toString())) { return (List) treeCache.get(fqn, sb.toString()); } } /** * Get scalability datasource for hdcontacts */ String sourceName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteZeroScalability(); } else { sourceName = scalabilityManager.getReadZeroScalability(); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getContacts() " + sourceName); } StringBuffer alphabetString = new StringBuffer("%"); alphabetString.append(alphabet); alphabetString.append("%"); try { List result = null; if (!RegexStrUtil.isNull(member)) { Hdlogin hdlogin = getLoginid(member); if (hdlogin != null) { Object[] params = { (Object) loginId, hdlogin.getValue(DbConstants.LOGIN_ID), (Object) alphabetString.toString(), (Object) alphabetString.toString() }; result = getMyAlphabetShareQuery.execute(params); } } else { Object[] params = { (Object) loginId, (Object) alphabetString.toString(), (Object) alphabetString.toString() }; result = getAlphabetQuery.execute(params); if ((result != null) && (result.size() > 0)) { treeCache.put(fqn, sb.toString(), result); } } return result; } catch (Exception e) { if (!RegexStrUtil.isNull(member)) { throw new BaseDaoException("error in getContacts " + getMyAlphabetShareQuery.getSql(), e); } else { throw new BaseDaoException("error in getContacts " + getAlphabetQuery.getSql(), e); } } } /** * This method returns all contacts in csv format * Compliant with Internet-Draft Common Format and MIME Type for CSV Files * @param loginId - the login id * @throws BaseDaoException - when error occurs */ public byte[] getCSVFormatContacts(String loginId) { List contacts = getAllContacts(loginId, DbConstants.READ_FROM_SLAVE); List sharedContacts = getSharedContacts(loginId); StringBuffer sb = new StringBuffer(); if ((contacts != null) && (contacts.size() > 0) || (sharedContacts != null) && (sharedContacts.size() > 0)) { getFields(sb); } boolean cExists = false; if ((contacts != null) && (contacts.size() > 0)) { for (int i = 0; i < contacts.size(); i++) { sb.append((String) getFieldValues((Contact) contacts.get(i)).toString()); //sb.append(RegexStrUtil.goodCSV( ((Contact)contacts.get(i)).csvString() ); /* if (i != contacts.size() - 1) { sb.append("\n\r"); } */ cExists = true; } } if ((sharedContacts != null) && (sharedContacts.size() > 0)) { if (cExists) { sb.append("\n\r"); } int k = sharedContacts.size(); for (int i = 0; i < k; i++) { sb.append((String) getFieldValues((Contact) sharedContacts.get(i)).toString()); //sb.append(RegexStrUtil.goodCSV( ((Contact)sharedContacts.get(i)).csvString()) ); /* if (i != k - 1) { sb.append("\n\r"); } */ } } return ((String) sb.toString()).getBytes(); } /** * This method returns all contacts in csv format * Compliant with Internet-Draft Common Format and MIME Type for CSV Files * @param contactId - the contact id * @throws BaseDaoException - when error occurs */ private StringBuffer getFieldValues(Contact contact) { StringBuffer sb = new StringBuffer(); //sb.append("\""); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.FIRST_NAME))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.FIRST_NAME))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.LAST_NAME))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.LAST_NAME))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.MIDDLE_NAME))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.MIDDLE_NAME))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.NICKNAME))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.NICKNAME))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.GENDER))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.GENDER))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.DOB))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.DOB))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.EMAIL))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.EMAIL))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.DESIGNATION))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.DESIGNATION))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.TITLE))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.TITLE))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.INDUSTRY))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.INDUSTRY))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.COMPANY))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.COMPANY))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.PWEBSITE))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.PWEBSITE))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.CWEBSITE))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.CWEBSITE))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.BLOGSITE))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.BLOGSITE))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.CITY))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.CITY))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.STATE))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.STATE))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.INDUSTRY))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.INDUSTRY))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.COMPANY))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.COMPANY))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.ZIPCODE))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.ZIPCODE))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.DESCRIPTION))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.DESCRIPTION))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.BCITY))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.BCITY))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.BSTATE))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.BSTATE))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.BCOUNTRY))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.BCOUNTRY))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.BZIPCODE))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.BZIPCODE))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.HPHONE))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.HPHONE))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.CPHONE))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.CPHONE))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.BPHONE))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.BPHONE))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.NETPHONE))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.NETPHONE))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.FAX))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.FAX))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.YIM))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.YIM))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.AIM))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.AIM))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.MSN))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.MSN))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.ICQ))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.ICQ))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.RELATION))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.RELATION))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.PUBLISHED))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.PUBLISHED))); } sb.append(","); if (!RegexStrUtil.isNull(contact.getValue(DbConstants.USER_TAGS))) { sb.append(RegexStrUtil.goodCSV(contact.getValue(DbConstants.USER_TAGS))); } //sb.append("\""); sb.append("\n"); return sb; } /** * This method returns a contact for this user id based on contact id * @param contactId - the contact id * @param loginId - the loginid * @param accessFlag - the access flag for the data resource * @return Contact - the <code>Contact</code> bean /** * This method returns all contacts in csv format * Compliant with Internet-Draft Common Format and MIME Type for CSV Files * @param contactId - the contact id * @throws BaseDaoException - when error occurs */ private void getFields(StringBuffer sb) { //sb.append("\""); sb.append(DbConstants.FIRST_NAME); sb.append(","); sb.append(DbConstants.LAST_NAME); sb.append(","); sb.append(DbConstants.MIDDLE_NAME); sb.append(","); sb.append(DbConstants.NICKNAME); sb.append(","); sb.append(DbConstants.GENDER); sb.append(","); sb.append(DbConstants.DOB); sb.append(","); sb.append(DbConstants.EMAIL); sb.append(","); sb.append(DbConstants.DESIGNATION); sb.append(","); sb.append(DbConstants.TITLE); sb.append(","); sb.append(DbConstants.INDUSTRY); sb.append(","); sb.append(DbConstants.COMPANY); sb.append(","); sb.append(DbConstants.PWEBSITE); sb.append(","); sb.append(DbConstants.CWEBSITE); sb.append(","); sb.append(DbConstants.BLOGSITE); sb.append(","); sb.append(DbConstants.CITY); sb.append(","); sb.append(DbConstants.STATE); sb.append(","); sb.append(DbConstants.INDUSTRY); sb.append(","); sb.append(DbConstants.COMPANY); sb.append(","); sb.append(DbConstants.ZIPCODE); sb.append(","); sb.append(DbConstants.DESCRIPTION); sb.append(","); sb.append(DbConstants.BCITY); sb.append(","); sb.append(DbConstants.BSTATE); sb.append(","); sb.append(DbConstants.BCOUNTRY); sb.append(","); sb.append(DbConstants.BZIPCODE); sb.append(","); sb.append(DbConstants.HPHONE); sb.append(","); sb.append(DbConstants.CPHONE); sb.append(","); sb.append(DbConstants.BPHONE); sb.append(","); sb.append(DbConstants.NETPHONE); sb.append(","); sb.append(DbConstants.FAX); sb.append(","); sb.append(DbConstants.YIM); sb.append(","); sb.append(DbConstants.AIM); sb.append(","); sb.append(DbConstants.MSN); sb.append(","); sb.append(DbConstants.ICQ); sb.append(","); sb.append(DbConstants.RELATION); sb.append(","); sb.append(DbConstants.PUBLISHED); sb.append(","); sb.append(DbConstants.USER_TAGS); //sb.append("\""); //sb.append("\r\n"); sb.append("\n"); } /** * This method returns a contact for this user id based on contact id * @param contactId - the contact id * @param loginId - the loginid * @param accessFlag - the access flag for the data resource * @return Contact - the <code>Contact</code> bean * @throws BaseDaoException - when error occurs */ public Contact getOneContact(String contactId, String loginId, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(loginId) || RegexStrUtil.isNull(contactId)) { throw new BaseDaoException("params are null in getOneContact()"); } Fqn fqn = cacheUtil.fqn(DbConstants.CONTACT); if (treeCache.exists(fqn, contactId)) { return (Contact) treeCache.get(fqn, contactId); } /** * Get scalability datasource for hdcontacts */ String sourceName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteZeroScalability(); } else { sourceName = scalabilityManager.getReadZeroScalability(); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getOneContact() " + sourceName); } try { Object[] params = { (Object) contactId, loginId }; List result = contactIdQuery.execute(params); if ((result != null) && (result.size() > 0)) { treeCache.put(fqn, contactId, (Contact) result.get(0)); return (Contact) result.get(0); } else { return null; } } catch (Exception e) { throw new BaseDaoException("error in getOneContact() " + contactIdQuery.getSql(), e); } } /** * This method clones a contact * @param contactId - the contact id * @param ownerId - the ownerId of the contact * @param memberId - the memberId for whom the contact is shared * @param alphabet - the first letter of firstname or lastname * @throws BaseDaoException - when error occurs */ public void cloneSharedContact(String contactId, String ownerId, String memberId, String alphabet) throws BaseDaoException { if (RegexStrUtil.isNull(memberId) || RegexStrUtil.isNull(ownerId) || RegexStrUtil.isNull(contactId)) { throw new BaseDaoException("params are null in cloneSharedContact()"); } Contact contact = getOneContact(contactId, ownerId, DbConstants.READ_FROM_SLAVE); if (contact != null) { addContact(contact, alphabet, memberId); Fqn fqn = cacheUtil.fqn(DbConstants.CONTACTS); if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } fqn = cacheUtil.fqn(DbConstants.SHARED_PUBLISHED_CONTACTS); if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } fqn = cacheUtil.fqn(DbConstants.PUBLISHED_CONTACTS); if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } fqn = cacheUtil.fqn(DbConstants.CONTACTS_ALPHABET); StringBuffer sb = new StringBuffer(alphabet); sb.append("-"); sb.append(memberId); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } } } /** * This method clones a contact * @param contactId - the contact id * @param loginId - the loginid * @param alphabet - the first letter of firstname or lastname * @throws BaseDaoException - when error occurs */ public void cloneOneContact(String contactId, String loginId, String alphabet) throws BaseDaoException { if (RegexStrUtil.isNull(loginId) || RegexStrUtil.isNull(contactId)) { throw new BaseDaoException("params are null in cloneOneContact()"); } Contact contact = getOneContact(contactId, loginId, DbConstants.READ_FROM_SLAVE); if (contact != null) { addContact(contact, alphabet, ""); Fqn fqn = cacheUtil.fqn(DbConstants.CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.SHARED_PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.CONTACTS_ALPHABET); StringBuffer sb = new StringBuffer(alphabet); sb.append("-"); sb.append(loginId); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } } } /** * This method adds a contact * @param contact - the <code>Contact</code> bean * @param alphabet - the alphabet * @param ownerId - the owner id */ private void addContact(Contact contact, String alphabet, String ownerId) { String tags = null; if (!RegexStrUtil.isNull(contact.getValue(DbConstants.PUBLISHED))) { if ((contact.getValue(DbConstants.PUBLISHED)).equals("1")) { tags = contact.getValue(DbConstants.CONTACTS_TAG); } else { tags = contact.getValue(DbConstants.USER_TAGS); } } if (RegexStrUtil.isNull(ownerId)) { ownerId = contact.getValue(DbConstants.OWNER_ID); } addContact(ownerId, contact.getValue(DbConstants.DOB), contact.getValue(DbConstants.TITLE), contact.getValue(DbConstants.INDUSTRY), contact.getValue(DbConstants.COMPANY), contact.getValue(DbConstants.PWEBSITE), contact.getValue(DbConstants.CWEBSITE), contact.getValue(DbConstants.BLOGSITE), contact.getValue(DbConstants.CITY), contact.getValue(DbConstants.STATE), contact.getValue(DbConstants.COUNTRY), contact.getValue(DbConstants.DESCRIPTION), contact.getValue(DbConstants.ZIPCODE), contact.getValue(DbConstants.FIRST_NAME), contact.getValue(DbConstants.LAST_NAME), contact.getValue(DbConstants.MIDDLE_NAME), contact.getValue(DbConstants.EMAIL), contact.getValue(DbConstants.GENDER), contact.getValue(DbConstants.NICKNAME), contact.getValue(DbConstants.DESIGNATION), contact.getValue(DbConstants.BCITY), contact.getValue(DbConstants.BSTATE), contact.getValue(DbConstants.BCOUNTRY), contact.getValue(DbConstants.BZIPCODE), contact.getValue(DbConstants.HPHONE), contact.getValue(DbConstants.CPHONE), contact.getValue(DbConstants.BPHONE), contact.getValue(DbConstants.YIM), contact.getValue(DbConstants.AIM), contact.getValue(DbConstants.MSN), contact.getValue(DbConstants.ICQ), contact.getValue(DbConstants.FAX), contact.getValue(DbConstants.NETPHONE), contact.getValue(DbConstants.RELATION), contact.getValue(DbConstants.PUBLISHED), tags, alphabet, contact.getValue(DbConstants.STREET), contact.getValue(DbConstants.BSTREET)); } /** * This method updates an existing contact * @param contactId - the contact id * @param loginId - the loginid * @param dob * @param title * @param industry * @param company * @param pwebsite * @param cwebsite * @param blogsite * @param city * @param state * @param country * @param description * @param zipcode * @param fname * @param lname * @param mname * @param email * @param gender * @param nickname * @param designation * @param bcity * @param bstate * @param bcountry * @param bzipcode * @param hphone * @param cphone * @param bphone * @param yim * @param aim * @param msn * @param icq * @param fax * @param netphone * @param relation * @param published * @param usertags * @param alphabet - the first letter of firstname or lastname */ public void updateContact(String contactId, String loginId, String dob, String title, String industry, String company, String pwebsite, String cwebsite, String blogsite, String city, String state, String country, String description, String zipcode, String fname, String lname, String mname, String email, String gender, String nickname, String designation, String bcity, String bstate, String bcountry, String bzipcode, String hphone, String cphone, String bphone, String yim, String aim, String msn, String icq, String fax, String netphone, String relation, String published, String usertags, String alphabet, String street, String bstreet) throws BaseDaoException { /** * Get scalability datasource for hdcontacts */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, updateContact() " + sourceName); } Connection conn = null; try { conn = ds.getConnection(); if (conn == null) { throw new BaseDaoException("conn null, updateContact() "); } conn.setAutoCommit(false); Object[] params = { (Object) contactId }; List result = contactTagExistsQuery.execute(params); boolean contactTagExists = false; if ((result != null) && (result.size() > 0)) { contactTagExists = true; } if (!RegexStrUtil.isNull(published)) { if (published.equals("1")) { if (contactTagExists) { updateTagQuery.run(conn, contactId, usertags); } else { addTagQuery.run(conn, contactId, usertags); } updateQuery.run(conn, fname, lname, mname, dob, title, industry, company, pwebsite, cwebsite, blogsite, city, state, country, description, zipcode, gender, nickname, designation, bcity, bstate, bcountry, bzipcode, hphone, cphone, bphone, yim, aim, msn, icq, loginId, fax, netphone, relation, email, published, "", contactId, street, bstreet); } else { if (contactTagExists) { deleteTagQuery.run(conn, contactId); } updateQuery.run(conn, fname, lname, mname, dob, title, industry, company, pwebsite, cwebsite, blogsite, city, state, country, description, zipcode, gender, nickname, designation, bcity, bstate, bcountry, bzipcode, hphone, cphone, bphone, yim, aim, msn, icq, loginId, fax, netphone, relation, email, published, usertags, contactId, street, bstreet); } } } catch (Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { throw new BaseDaoException( "connection close/autocommit(true) updateContact() loginid = " + loginId, e2); } throw new BaseDaoException("connection rollback exception in updateContact() loginId =" + loginId, e1); } throw new BaseDaoException("connection exception in updateContact() loginId =" + loginId, e); } // conn commit try { conn.commit(); } catch (Exception e3) { throw new BaseDaoException("conn.commit() in updateContact loginid=" + loginId, e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e4) { throw new BaseDaoException("connection close/autocommit(true), updateContact() loginId = " + loginId, e4); } Fqn fqn = cacheUtil.fqn(DbConstants.CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.SHARED_PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.CONTACTS_ALPHABET); StringBuffer sb = new StringBuffer(alphabet); sb.append("-"); sb.append(loginId); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } fqn = cacheUtil.fqn(DbConstants.CONTACT); if (treeCache.exists(fqn, contactId)) { treeCache.remove(fqn, contactId); } } /** * This method deletes a contact based on contactId * @param loginId - the loginid * @param contactId - the contact id * @param alphabet - the first letter of firstname or lastname * @throws BaseDaoException - when error occurs */ public void deleteOneContact(String loginId, String contactId, String alphabet) throws BaseDaoException { if (RegexStrUtil.isNull(loginId) || RegexStrUtil.isNull(contactId)) { throw new BaseDaoException("params are null in deleteOneContact()"); } /** * Get scalability datasource for hdcontacts */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, deleteOneContact() " + sourceName); } Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); deleteQuery.run(conn, contactId, loginId); // delete all sharecontacts that match with this contactId deleteShareContactByIdQuery.run(conn, contactId); deleteTagQuery.run(conn, contactId); } catch (Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { throw new BaseDaoException( "error in deleteOneContact(), contactId " + contactId + " loginId = " + loginId, e2); } throw new BaseDaoException( "error in deleteOneContact(), contactId " + contactId + " loginId = " + loginId, e1); } throw new BaseDaoException( "error in deleteOneContact(), contactId " + contactId + " loginId = " + loginId, e); } // conn commit try { conn.commit(); } catch (Exception e3) { throw new BaseDaoException("conn.commit() in deleteOneContact loginid=" + loginId, e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e) { throw new BaseDaoException( "error in deleteOneContact(), contactId " + contactId + " loginId = " + loginId, e); } Fqn fqn = cacheUtil.fqn(DbConstants.CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.CONTACT); if (treeCache.exists(fqn, contactId)) { treeCache.remove(fqn, contactId); } fqn = cacheUtil.fqn(DbConstants.CONTACTS_ALPHABET); StringBuffer sb = new StringBuffer(alphabet); sb.append("-"); sb.append(loginId); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } // (DbConstants.SHARED_CONTACTS) deleteAllShareContactsByContactId(contactId); fqn = cacheUtil.fqn(DbConstants.MY_SHARED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } fqn = cacheUtil.fqn(DbConstants.SHARED_PUBLISHED_CONTACTS); if (treeCache.exists(fqn, loginId)) { treeCache.remove(fqn, loginId); } } /** * Identify the destid's that share this contact, delete them from cache * Deletes all those destids from cache using contactid * @param contactId - the contact id * @throws BaseDaoException when error occurs */ private void deleteAllShareContactsByContactId(String contactId) { if (RegexStrUtil.isNull(contactId)) { throw new BaseDaoException("params are null"); } List result = null; try { Object[] params = { (Object) contactId }; result = getContactShareQuery.execute(params); if (result == null) { return; } } catch (Exception e) { throw new BaseDaoException("getContactShareQuery error, " + getContactShareQuery.getSql(), e); } for (int i = 0; i < result.size(); i++) { String destId = ((Contact) result.get(i)).getValue(DbConstants.DEST_ID); Fqn fqn = cacheUtil.fqn(DbConstants.SHARED_CONTACTS); if (treeCache.exists(fqn, destId)) { treeCache.remove(fqn, destId); } } } /** * IsContactShared - checks if this contact is shared with this destination id. * @param contactId - contact id * @param destId - destination id * @return boolean - true is this contact is shared with this destid */ public boolean isContactShared(String contactId, String destId) { if (RegexStrUtil.isNull(contactId) || RegexStrUtil.isNull(destId)) { throw new BaseDaoException("params are null"); } /** * Get scalability datasource for sharecontact */ String sourceName = null; sourceName = scalabilityManager.getReadZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, isContactShared() " + sourceName); } try { Object[] params = { (Object) contactId, destId }; List result = isContactSharedQuery.execute(params); if ((result != null) && (result.size() > 0)) { return true; } else { return false; } } catch (Exception e) { throw new BaseDaoException("error in isContactShared() " + isContactSharedQuery.getSql(), e); } } /** } /** * This property is setby spring automatically at web.xml startup * @param ds - this is JDBC datasource bean that is connection from the pool */ public void setJdbcSource(DataSource ds) { this.ds = ds; } public void setcontactaddQuery(ContactAddQuery daq) { this.addQuery = daq; } public void setcontactdeleteQuery(ContactDeleteQuery daq) { this.deleteQuery = daq; } public void setcontactalphabetQuery(ContactAlphabetQuery daq) { this.getAlphabetQuery = daq; } public void setcontactalphabetshareQuery(ContactAlphabetShareQuery daq) { this.getMyAlphabetShareQuery = daq; } public void setcontactidQuery(ContactIdQuery daq) { this.contactIdQuery = daq; } public void setcontactupdateQuery(ContactUpdateQuery daq) { this.updateQuery = daq; } public void setcontacttagaddQuery(ContactTagAddQuery daq) { this.addTagQuery = daq; } public void setcontacttagupdateQuery(ContactTagUpdateQuery daq) { this.updateTagQuery = daq; } public void setcontacttagdeleteQuery(ContactTagDeleteQuery daq) { this.deleteTagQuery = daq; } public void setcontactaddshareQuery(ContactAddShareQuery daq) { this.addShareQuery = daq; } public void setcontactdeleteshareQuery(ContactDeleteShareQuery daq) { this.deleteShareQuery = daq; } public void setcontactaddsharememberQuery(ContactAddShareMemberQuery daq) { this.addShareMemberQuery = daq; } public void setcontactdeletesharememberQuery(ContactDeleteShareMemberQuery daq) { this.deleteShareMemberQuery = daq; } public void setcontactallQuery(ContactAllQuery daq) { this.getAllQuery = daq; } public void setcontacttagexistsQuery(ContactTagExistsQuery daq) { this.contactTagExistsQuery = daq; } public void setcontactgetsharedQuery(ContactGetSharedQuery daq) { this.getSharedContacts = daq; } public void setcontactgetmysharedQuery(ContactGetMySharedQuery daq) { this.getMySharedContacts = daq; } public void setcontactmypublishedQuery(ContactMyPublishedQuery daq) { this.getMyPublishedQuery = daq; } public void setcontactsharedpublicQuery(ContactGetSharedPublishedQuery daq) { this.getSharedPublishedQuery = daq; } public void setcontactcsvmypublishedQuery(ContactCSVMyPublishedQuery daq) { this.getMyPublishedCSVQuery = daq; } public void setcontactcsvsharedpublicQuery(ContactCSVSharedPublishedQuery daq) { this.getSharedPublishedCSVQuery = daq; } public void setcontactalphabetsharedQuery(ContactAlphabetSharedContactsQuery daq) { this.getAlphabetSharedContacts = daq; } public void setcontactnonameQuery(ContactNoNameQuery daq) { this.getContactNoNameQuery = daq; } public void setcontactsharednonameQuery(ContactSharedNoNameQuery daq) { this.getContactSharedNoNameQuery = daq; } public void setcontactdeletesharebyidQuery(ContactDeleteShareByIdQuery daq) { this.deleteShareContactByIdQuery = daq; } public void setiscontactsharedQuery(IsContactSharedQuery daq) { this.isContactSharedQuery = daq; } public void setcontactshareQuery(ContactShareQuery daq) { this.getContactShareQuery = daq; } }