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; }
public Address getAddressById(Integer addressId) { List addressList = (List<Address>) hibernateTemplate.findByNamedQueryAndNamedParam( "Address.findByAddressId", "addressId", addressId); Address address = (Address) addressList.get(0); return address; }
public Integer getCityIdByName(String cityName) { // TODO Auto-generated method stub List cityId = (List<City>) hibernateTemplate.findByNamedQueryAndNamedParam( "City.findByCityName", "name", cityName); if (cityId != null) { return ((City) cityId.get(0)).getCityId(); } return 0; }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") public List<T> findByNamedQuery(String queryName, Map<String, Object> queryParams) { String[] params = new String[queryParams.size()]; Object[] values = new Object[queryParams.size()]; int index = 0; for (String s : queryParams.keySet()) { params[index] = s; values[index++] = queryParams.get(s); } return hibernateTemplate.findByNamedQueryAndNamedParam(queryName, params, values); }
public String getStateName(int id) { String stateName = null; State state = null; List result = hibernateTemplate.findByNamedQueryAndNamedParam("State.findByStateId", "stateId", id); if (result != null && result.size() > 0) { state = (State) result.get(0); } if (state != null) { stateName = state.getStateName(); } return stateName; }
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; }