コード例 #1
0
ファイル: AddressDao.java プロジェクト: rnjetnegi/SapeStore
  public List<Address2> retrieveFromId(String userId) {

    List<Address> listUser =
        (List<Address>)
            hibernateTemplate.findByNamedQueryAndNamedParam(
                "Address.findByUserId", "userId", userId);

    List<Address2> listUser2 = new ArrayList<Address2>();

    for (int i = 0; i < listUser.size(); i++) {
      Address2 add = new Address2();
      add.setAddressId(listUser.get(i).getAddressId());
      add.setAddressLine1(listUser.get(i).getAddressLine1());
      add.setAddressLine2(listUser.get(i).getAddressLine2());
      add.setCityId(listUser.get(i).getCityId());
      add.setCountryId(listUser.get(i).getCountryId());
      add.setCreatedDate(listUser.get(i).getCreatedDate());
      add.setIsActive(listUser.get(i).getIsActive());
      add.setName(listUser.get(i).getName());
      add.setPhone(listUser.get(i).getPhone());
      add.setPostalCode(listUser.get(i).getPostalCode());
      add.setUpdatedDate(listUser.get(i).getUpdatedDate());
      add.setUserId(listUser.get(i).getUserId());
      add.setStateId(listUser.get(i).getStateId());
      listUser2.add(add);
    }

    /*
     *Method for fetching CityName using cityId
     */
    for (int i = 0; i < listUser.size(); i++) {
      List<?> cityList =
          (List<?>)
              hibernateTemplate.findByNamedQueryAndNamedParam(
                  "City.findByCityId", "cityId", listUser.get(i).getCityId());
      if (cityList.size() > 0) {
        City city = (City) cityList.get(0);
        String cityName = city.getCityName();
        (listUser2.get(i)).setCityName(cityName);
      }
    }
    /*
     * Method for fetching StateName using stateId
     */
    for (int i = 0; i < listUser.size(); i++) {
      List<?> stateList =
          (List<?>)
              hibernateTemplate.findByNamedQueryAndNamedParam(
                  "State.findByStateId", "stateId", listUser.get(i).getStateId());
      if (stateList.size() > 0) {
        State state = (State) stateList.get(0);
        String stateName = state.getStateName();
        (listUser2.get(i)).setStateName(stateName);
      }
    }

    return listUser2;
  }
コード例 #2
0
ファイル: AddressDao.java プロジェクト: rnjetnegi/SapeStore
 public String getCityName(int id) {
   String cityName = null;
   City city = null;
   List result =
       hibernateTemplate.findByNamedQueryAndNamedParam("City.findByCityId", "cityId", id);
   if (result != null && result.size() > 0) {
     city = (City) result.get(0);
   }
   if (city != null) {
     cityName = city.getCityName();
   }
   return cityName;
 }