String sql = "from Tax where siteId = :siteId";
Query query = em.createQuery(sql);
query.setParameter("siteId", Constants.SITE_SYSTEM);
Iterator<?> iterator = query.getResultList().iterator();
while (iterator.hasNext()) {
Tax master = (Tax) iterator.next();
Tax tax = new Tax();
Set<Country> countries = tax.getCountries();
Set<State> states = tax.getStates();
PropertyUtils.copyProperties(tax, master);
tax.setSite(site);
tax.setTaxId(null);
tax.setRecUpdateBy(userId);
tax.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
tax.setRecCreateBy(userId);
tax.setRecCreateDatetime(new Date(System.currentTimeMillis()));
tax.setTaxLanguages(null);
tax.setCountries(countries);
tax.setStates(states);
Iterator<?> it = null;
if (master.getCountries() != null) {
it = master.getCountries().iterator();
while (it.hasNext()) {
Country mc = (Country) it.next();
Country country = CountryDAO.loadByCountryName(site.getSiteId(), mc.getCountryName());
tax.getCountries().add(country);
}
}
if (master.getStates() != null) {
it = master.getStates().iterator();
while (it.hasNext()) {
State mc = (State) it.next();
State state = StateDAO.loadByStateName(site.getSiteId(), mc.getStateName());
tax.getStates().add(state);
}
}
em.persist(tax);
}
}