Last active
September 25, 2018 07:06
-
-
Save mak9456/effb5b23bcd7f22c196dde189ef9c6c8 to your computer and use it in GitHub Desktop.
CustomerDao implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Repository | |
public class CustomerDaoimpl implements CustomerDao{ | |
@Autowired | |
public SessionFactory sessionfactory; | |
@Override | |
public List<Customer> getCustomer() { | |
Session currentsession=sessionfactory.getCurrentSession(); | |
List<Customer> customers=currentsession.createQuery("from Customer",Customer.class).getResultList(); | |
return customers; | |
} | |
@Override | |
public Boolean addCustomer(Customer customer) { | |
try { | |
Session currentsession=sessionfactory.getCurrentSession(); | |
currentsession.save(customer); | |
} catch (Exception e) { | |
// TODO: handle exception | |
return false; | |
} | |
return true; | |
} | |
@Override | |
public Customer getSingleCustomer(int theId) { | |
Session currentsession=sessionfactory.getCurrentSession(); | |
return currentsession.get(Customer.class,theId); | |
} | |
@Override | |
public void deleteCustomer(int theId) { | |
Session currentsession=sessionfactory.getCurrentSession(); | |
currentsession.delete(getSingleCustomer(theId)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment