Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dao;
- import models.Account;
- import models.Unit;
- import org.hibernate.Session;
- import org.hibernate.Transaction;
- import utils.HibernateSessionFactoryUtil;
- import java.sql.PreparedStatement;
- import java.util.ArrayList;
- import java.util.List;
- public class InvUnitDAO<T> implements InvDAO<T> {
- @Override
- public void add(T data) {
- Session session = HibernateSessionFactoryUtil.getSessionFactory().openSession();
- Transaction unitTransaction = session.beginTransaction();
- session.save(data);
- unitTransaction.commit();
- session.close();
- }
- @Override
- public void del(T data) {
- Session session = HibernateSessionFactoryUtil
- .getSessionFactory()
- .openSession();
- Transaction delTransaction = session.beginTransaction();
- session.delete(data);
- delTransaction.commit();
- session.close();
- }
- @Override
- public List<Account> getAllAccounts() {
- Session session = HibernateSessionFactoryUtil
- .getSessionFactory()
- .openSession();
- List<Account> accounts = (List<Account>) session.createQuery("from Account").getResultList();
- session.close();
- return accounts;
- }
- @Override
- public ArrayList<Unit> getAllUnits() {
- Session session = HibernateSessionFactoryUtil
- .getSessionFactory()
- .openSession();
- ArrayList<Unit> units = (ArrayList<Unit>) session.createQuery("From Unit ").getResultList();
- session.close();
- return units;
- }
- public ArrayList<String> getPasswords(){
- Session session = HibernateSessionFactoryUtil
- .getSessionFactory()
- .openSession();
- ArrayList<String> passwords = (ArrayList<String>) session.createQuery("SELECT password FROM Account ").getResultList();
- session.close();
- return passwords;
- }
- // public ArrayList<T> found(String str){
- // String qwerty = "from inventorydb where invNum = :invNum";
- // Session session = HibernateSessionFactoryUtil
- // .getSessionFactory()
- // .openSession();
- // Transaction transaction = session.beginTransaction();
- // PreparedStatement statement = {
- // }
- // ArrayList<T> results = (ArrayList<T>) session.createQuery(" FROM Account WHERE ")
- // }
- public void update(T data){
- Session session = HibernateSessionFactoryUtil
- .getSessionFactory()
- .openSession();
- Transaction transaction = session.beginTransaction();
- session.update(data);
- transaction.commit();
- session.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement