/** * TNTConcept Easy Enterprise Management by Autentia Real Bussiness Solution S.L. * Copyright (C) 2007 Autentia Real Bussiness Solution S.L. * * This program 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. * * 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 com.autentia.tnt.dao.search; import java.util.ArrayList; import com.autentia.tnt.businessobject.Organization; import com.autentia.tnt.businessobject.Province; import com.autentia.tnt.dao.SearchCriteria; /** * Class to search for Contact objects * * @author stajanov code generator */ public class ContactSearch extends SearchCriteria { /* generated by stajanov (do not edit/delete) */ @Override public String getHQL() { StringBuilder ret = new StringBuilder(); int iArgNum = 0; if (isNameSet()) { ret.append((ret.length() == 0) ? "WHERE " : " AND "); if (getName() == null) { ret.append("name is NULL"); } else { ret.append("name like :arg" + (iArgNum++)); } } if (isEmailSet()) { ret.append((ret.length() == 0) ? "WHERE " : " AND "); if (getEmail() == null) { ret.append("email is NULL"); } else { ret.append("email like :arg" + (iArgNum++)); } } if (isEmail2Set()) { ret.append((ret.length() == 0) ? "WHERE " : " AND "); if (getEmail2() == null) { ret.append("email2 is NULL"); } else { ret.append("email2 like :arg" + (iArgNum++)); } } if (isPhoneSet()) { ret.append((ret.length() == 0) ? "WHERE " : " AND "); if (getPhone() == null) { ret.append("phone is NULL"); } else { ret.append("phone = :arg" + (iArgNum++)); } } if (isPhone2Set()) { ret.append((ret.length() == 0) ? "WHERE " : " AND "); if (getPhone2() == null) { ret.append("phone2 is NULL"); } else { ret.append("phone2 = :arg" + (iArgNum++)); } } if (isMobileSet()) { ret.append((ret.length() == 0) ? "WHERE " : " AND "); if (getMobile() == null) { ret.append("mobile is NULL"); } else { ret.append("mobile = :arg" + (iArgNum++)); } } if (isFaxSet()) { ret.append((ret.length() == 0) ? "WHERE " : " AND "); if (getFax() == null) { ret.append("fax is NULL"); } else { ret.append("fax = :arg" + (iArgNum++)); } } if (isCountrySet()) { ret.append((ret.length() == 0) ? "WHERE " : " AND "); if (getCountry() == null) { ret.append("country is NULL"); } else { ret.append("country = :arg" + (iArgNum++)); } } if (isProvinceSet()) { ret.append((ret.length() == 0) ? "WHERE " : " AND "); if (getProvince() == null) { ret.append("province is NULL"); } else { ret.append("province = :arg" + (iArgNum++)); } } if (isCitySet()) { ret.append((ret.length() == 0) ? "WHERE " : " AND "); if (getCity() == null) { ret.append("city is NULL"); } else { ret.append("city = :arg" + (iArgNum++)); } } if (isPostalCodeSet()) { ret.append((ret.length() == 0) ? "WHERE " : " AND "); if (getPostalCode() == null) { ret.append("postalCode is NULL"); } else { ret.append("postalCode = :arg" + (iArgNum++)); } } if (isAddressSet()) { ret.append((ret.length() == 0) ? "WHERE " : " AND "); if (getAddress() == null) { ret.append("address is NULL"); } else { ret.append("address = :arg" + (iArgNum++)); } } if (isNotifiedSet()) { ret.append((ret.length() == 0) ? "WHERE " : " AND "); if (getNotified() == null) { ret.append("notified is NULL"); } else { ret.append("notified = :arg" + (iArgNum++)); } } customGetHQL(ret, iArgNum); return ret.toString(); } @Override public Object[] getArguments() { ArrayList<Object> ret = new ArrayList<Object>(); if (isNameSet() && getName() != null) { ret.add(name); } if (isEmailSet() && getEmail() != null) { ret.add(email); } if (isEmail2Set() && getEmail2() != null) { ret.add(email2); } if (isPhoneSet() && getPhone() != null) { ret.add(phone); } if (isPhone2Set() && getPhone2() != null) { ret.add(phone2); } if (isMobileSet() && getMobile() != null) { ret.add(mobile); } if (isFaxSet() && getFax() != null) { ret.add(fax); } if (isCountrySet() && getCountry() != null) { ret.add(country); } if (isProvinceSet() && getProvince() != null) { ret.add(province); } if (isCitySet() && getCity() != null) { ret.add(city); } if (isPostalCodeSet() && getPostalCode() != null) { ret.add(postalCode); } if (isAddressSet() && getAddress() != null) { ret.add(address); } if (isNotifiedSet() && getNotified() != null) { ret.add(notified); } if (isOrganizationSet() && getOrganization() != null) { ret.add(organization.getId()); } customGetArguments(ret); return ret.toArray(); } @Override public void reset() { unsetName(); unsetEmail(); unsetEmail2(); unsetPhone(); unsetPhone2(); unsetMobile(); unsetFax(); unsetCountry(); unsetProvince(); unsetCity(); unsetPostalCode(); unsetAddress(); unsetNotified(); unsetOrganization(); customReset(); } @Override public String toString() { StringBuilder ret = new StringBuilder(); ret.append("ContactSearch{"); if (isNameSet()) { ret.append("(name"); ret.append("=" + name); ret.append(")"); } if (isEmailSet()) { ret.append("(email"); ret.append("=" + email); ret.append(")"); } if (isEmail2Set()) { ret.append("(email2"); ret.append("=" + email2); ret.append(")"); } if (isPhoneSet()) { ret.append("(phone"); ret.append("=" + phone); ret.append(")"); } if (isPhone2Set()) { ret.append("(phone2"); ret.append("=" + phone2); ret.append(")"); } if (isMobileSet()) { ret.append("(mobile"); ret.append("=" + mobile); ret.append(")"); } if (isFaxSet()) { ret.append("(fax"); ret.append("=" + fax); ret.append(")"); } if (isCountrySet()) { ret.append("(country"); ret.append("=" + country); ret.append(")"); } if (isProvinceSet()) { ret.append("(province"); ret.append("=" + province); ret.append(")"); } if (isCitySet()) { ret.append("(city"); ret.append("=" + city); ret.append(")"); } if (isPostalCodeSet()) { ret.append("(postalCode"); ret.append("=" + postalCode); ret.append(")"); } if (isAddressSet()) { ret.append("(address"); ret.append("=" + address); ret.append(")"); } if (isNotifiedSet()) { ret.append("(notified"); ret.append("=" + notified); ret.append(")"); } customToString(ret); ret.append("}"); return ret.toString(); } // Getters and setters public boolean isNameSet() { return nameSet; } public String getName() { return name; } public void setName(String name) { this.name = name; this.nameSet = true; } public void unsetName() { this.nameSet = false; } public boolean isEmailSet() { return emailSet; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; this.emailSet = true; } public void unsetEmail() { this.emailSet = false; } public boolean isEmail2Set() { return email2Set; } public String getEmail2() { return email2; } public void setEmail2(String email2) { this.email2 = email2; this.email2Set = true; } public void unsetEmail2() { this.email2Set = false; } public boolean isPhoneSet() { return phoneSet; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; this.phoneSet = true; } public void unsetPhone() { this.phoneSet = false; } public boolean isPhone2Set() { return phone2Set; } public String getPhone2() { return phone2; } public void setPhone2(String phone2) { this.phone2 = phone2; this.phone2Set = true; } public void unsetPhone2() { this.phone2Set = false; } public boolean isMobileSet() { return mobileSet; } public String getMobile() { return mobile; } public void setMobile(String mobile) { this.mobile = mobile; this.mobileSet = true; } public void unsetMobile() { this.mobileSet = false; } public boolean isFaxSet() { return faxSet; } public String getFax() { return fax; } public void setFax(String fax) { this.fax = fax; this.faxSet = true; } public void unsetFax() { this.faxSet = false; } public boolean isCountrySet() { return countrySet; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; this.countrySet = true; } public void unsetCountry() { this.countrySet = false; } public boolean isProvinceSet() { return provinceSet; } public Province getProvince() { return province; } public void setProvince(Province province) { this.province = province; this.provinceSet = true; } public void unsetProvince() { this.provinceSet = false; } public boolean isCitySet() { return citySet; } public String getCity() { return city; } public void setCity(String city) { this.city = city; this.citySet = true; } public void unsetCity() { this.citySet = false; } public boolean isPostalCodeSet() { return postalCodeSet; } public String getPostalCode() { return postalCode; } public void setPostalCode(String postalCode) { this.postalCode = postalCode; this.postalCodeSet = true; } public void unsetPostalCode() { this.postalCodeSet = false; } public boolean isAddressSet() { return addressSet; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; this.addressSet = true; } public void unsetAddress() { this.addressSet = false; } public boolean isNotifiedSet() { return notifiedSet; } public java.lang.Boolean getNotified() { return notified; } public void setNotified(java.lang.Boolean notified) { this.notified = notified; this.notifiedSet = true; } public void unsetNotified() { this.notifiedSet = false; } public boolean isOrganizationSet() { return organizationSet; } public Organization getOrganization() { return organization; } public void setOrganization(Organization organization) { this.organization = organization; this.organizationSet = true; } public void unsetOrganization() { this.organizationSet = false; } // Fields private boolean nameSet; private String name; private boolean emailSet; private String email; private boolean email2Set; private String email2; private boolean phoneSet; private String phone; private boolean phone2Set; private String phone2; private boolean mobileSet; private String mobile; private boolean faxSet; private String fax; private boolean countrySet; private String country; private boolean provinceSet; private Province province; private boolean citySet; private String city; private boolean postalCodeSet; private String postalCode; private boolean addressSet; private String address; private boolean notifiedSet; private java.lang.Boolean notified; private boolean organizationSet; private Organization organization; // Returns if there are a search condition active public boolean isSearchActive() { return customIsSearchActive() || nameSet || emailSet || phoneSet || mobileSet || notifiedSet || email2Set || phone2Set || faxSet || countrySet || provinceSet || citySet || postalCodeSet || addressSet || organizationSet; } /* generated by stajanov (do not edit/delete) */ private void customGetHQL(StringBuilder ret, int iArgNum) { if( isOrganizationSet() ) { ret.append( (ret.length()==0) ? "WHERE " : " AND " ); ret.append( "id IN(SELECT contactInfo.contact.id from ContactInfo as contactInfo join contactInfo.organization organization where organization.id = :arg"+ iArgNum +")" ); } } private boolean customIsSearchActive() { return false; } private void customToString(StringBuilder ret) { } private void customReset() { } private void customGetArguments(ArrayList ret) { } }