private Option<Address> findAddressOfOwnerByPhoneNumber(String number, Integer ownerId) {
   if (checkOwner) {
     return addressDAO.findAddressOfOwnerByCategoryAndPhoneNumber(ownerId, category, number);
   } else {
     return addressDAO.findAddressByCategoryAndPhoneNumber(category, number);
   }
 }
 @Override
 public Option<Address> findAddressOfOwnerByPhoneNumber(PhoneNumber number, Integer ownerId) {
   if (checkOwner) {
     return addressDAO.findAddressOfOwnerByCategoryAndPhoneNumber(ownerId, category, number);
   } else {
     return addressDAO.findAddressByCategoryAndPhoneNumber(category, number);
   }
 }
 @Override
 public List<Address> findAddressOfOwnerByNameStartsWith(String name, Integer ownerId) {
   if (checkOwner) {
     return addressDAO.findAddressesOfOwnerByCategoryAndLastNameOrCompanyStartsWith(
         ownerId, category, name);
   } else {
     return addressDAO.findAddressesByCategoryAndNameOrCompanyStartsWith(category, name);
   }
 }
 @Override
 public Option<Address> findAddressByOwnerAndContactNumber(Integer ownerId, String contactNumber) {
   if (ownerId != null && isGlobalStore()) {
     return null;
   }
   return addressDAO.findAddressByOwnerAndCategoryAndContactNumber(
       ownerId, category, contactNumber);
 }
  @Override
  public List<PhoneNumber> findPhoneNumbersOfOwnerEndingWith(String number, Integer ownerId) {
    if (checkOwner) {
      return addressDAO.findPhoneNumbersOfOwnerEndingWith(ownerId, number);
    }

    return new LinkedList<PhoneNumber>();
  }
  @Override
  public List<PhoneNumber> findPhoneNumbersEndingWith(String number) {
    if (!checkOwner) {
      return addressDAO.findPhoneNumbersEndingWith(number);
    }

    return new LinkedList<PhoneNumber>();
  }
  @Override
  public Option<Address> findAddressByPhoneNumber(String number) {
    if (!checkOwner) {
      return addressDAO.findAddressByCategoryAndPhoneNumber(category, number);
    }

    return new Empty();
  }
 @Override
 public Option<Address> findAddressByOnwerAndFirstNameOrLastNameOrCompany(
     Integer ownerId, String firstName, String lastName, String company) {
   if (ownerId != null && isGlobalStore()) {
     return new Empty();
   }
   return addressDAO.findAddressByOwnerAndCategoryAndFirstNameOrLastNameOrCompany(
       ownerId, category, firstName, lastName, company);
 }
 @Override
 public List<Address> createAddressListing(
     Integer userId,
     String search,
     String orderBy,
     SortOrder orderDir,
     int firstResult,
     int maxResults) {
   return addressDAO.createAddressListing(
       userId, category, checkOwner, search, orderBy, orderDir, firstResult, maxResults);
 }
  @Override
  public Object createAddress(Address address, Integer ownerId) {
    if (editable) {
      address.setCategory(category);

      if (checkOwner) {
        address.setOwnerId(ownerId);
      }

      addressDAO.createAddress(address);
      return address.getId();
    }

    return null;
  }
 @Override
 public void deleteAllAddresses() {
   addressDAO.deleteAddressesByCategory(category);
 }
 @Override
 public Option<Address> findAddressByPhoneNumber(PhoneNumber phoneNumber) {
   return addressDAO.findAddressByCategoryAndPhoneNumber(category, phoneNumber);
 }
 @Override
 public List<PhoneNumber> findAllPhoneNumbersByAddressDnSortedByCategoryList(
     String addressDn, String[] categories) {
   return addressDAO.findAllPhoneNumbersByAddressIdSortedByCategories(
       NumberTools.toInt(addressDn, -1), categories);
 }
 @Override
 public List<Address> findAddressByNameStartsWith(String name) {
   return addressDAO.findAddressesByCategoryAndNameOrCompanyStartsWith(category, name);
 }
 @Override
 public Option<Address> findAddressByLastNameOrCompany(String name) {
   return addressDAO.findAddressByCategoryAndLastNameOrCompany(category, name);
 }
 @Override
 public Option<Address> findAddressByDn(Object addressDn) {
   return addressDAO.findAddressByDn(addressDn);
 }
 public void bulkImport(Collection<Address> addresses) {
   addressDAO.bulkImport(addresses);
 }
 @Override
 public void deleteAllAddressesOfOwner(Integer userId) {
   if (checkOwner) {
     addressDAO.deleteAllAddressesOfOnwerByCategory(category, userId);
   }
 }
 @Override
 public boolean canBeDeleted() {
   return addressDAO.countAddressesByCategory(category) == 0;
 }
 @Override
 public long countAddressesByOwnerAndSearch(Integer userId, String search) {
   return addressDAO.countAddressesByOwenrAndCategoryAndSearch(
       userId, checkOwner, category, search);
 }
 @Override
 public void deleteAddressWithDn(Object addressDn) {
   if (editable) {
     addressDAO.deleteAddressWithDn(addressDn);
   }
 }
 @Override
 public void updateAddress(Address address) {
   if (editable) {
     addressDAO.updateAddress(address);
   }
 }