Java tutorial
/** * "Visual Paradigm: DO NOT MODIFY THIS FILE!" * * This is an automatic generated file. It will be regenerated every time * you generate persistence class. * * Modifying its content may cause the program not work, or your work may lost. */ /** * Licensee: * License Type: Evaluation */ package businesslogic.accounting.user; import java.util.HashSet; import java.util.List; import java.util.Set; import org.hibernate.Query; import org.orm.PersistentException; import org.orm.PersistentSession; import orm.OODPersistentManager; import businesslogic.accounting.job.Job; import businesslogic.accounting.job.JobDAO; import businesslogic.accounting.job.UserJob; import businesslogic.accounting.job.UserJobDAO; public class UserDAO { public static User loadUserByORMID(int ID) throws PersistentException { try { PersistentSession session = OODPersistentManager.instance().getSession(); return loadUserByORMID(session, ID); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User getUserByORMID(int ID) throws PersistentException { try { PersistentSession session = OODPersistentManager.instance().getSession(); return getUserByORMID(session, ID); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User loadUserByORMID(int ID, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = OODPersistentManager.instance().getSession(); return loadUserByORMID(session, ID, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User getUserByORMID(int ID, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = OODPersistentManager.instance().getSession(); return getUserByORMID(session, ID, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User loadUserByORMID(PersistentSession session, int ID) throws PersistentException { try { return (User) session.load(businesslogic.accounting.user.User.class, new Integer(ID)); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User getUserByORMID(PersistentSession session, int ID) throws PersistentException { try { return (User) session.get(businesslogic.accounting.user.User.class, new Integer(ID)); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User loadUserByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode) throws PersistentException { try { return (User) session.load(businesslogic.accounting.user.User.class, new Integer(ID), lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User getUserByORMID(PersistentSession session, int ID, org.hibernate.LockMode lockMode) throws PersistentException { try { return (User) session.get(businesslogic.accounting.user.User.class, new Integer(ID), lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryUser(String condition, String orderBy) throws PersistentException { try { PersistentSession session = OODPersistentManager.instance().getSession(); return queryUser(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryUser(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = OODPersistentManager.instance().getSession(); return queryUser(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User[] listUserByQuery(String condition, String orderBy) throws PersistentException { try { PersistentSession session = OODPersistentManager.instance().getSession(); return listUserByQuery(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User[] listUserByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = OODPersistentManager.instance().getSession(); return listUserByQuery(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryUser(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From businesslogic.accounting.user.User as User"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try { Query query = session.createQuery(sb.toString()); return query.list(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static List queryUser(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From businesslogic.accounting.user.User as User"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try { Query query = session.createQuery(sb.toString()); query.setLockMode("User", lockMode); return query.list(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User[] listUserByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { try { List list = queryUser(session, condition, orderBy); return (User[]) list.toArray(new User[list.size()]); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User[] listUserByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { List list = queryUser(session, condition, orderBy, lockMode); return (User[]) list.toArray(new User[list.size()]); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User loadUserByQuery(String condition, String orderBy) throws PersistentException { try { PersistentSession session = OODPersistentManager.instance().getSession(); return loadUserByQuery(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User loadUserByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = OODPersistentManager.instance().getSession(); return loadUserByQuery(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User loadUserByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { User[] users = listUserByQuery(session, condition, orderBy); if (users != null && users.length > 0) return users[0]; else return null; } public static User loadUserByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { User[] users = listUserByQuery(session, condition, orderBy, lockMode); if (users != null && users.length > 0) return users[0]; else return null; } public static java.util.Iterator iterateUserByQuery(String condition, String orderBy) throws PersistentException { try { PersistentSession session = OODPersistentManager.instance().getSession(); return iterateUserByQuery(session, condition, orderBy); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static java.util.Iterator iterateUserByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { try { PersistentSession session = OODPersistentManager.instance().getSession(); return iterateUserByQuery(session, condition, orderBy, lockMode); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static java.util.Iterator iterateUserByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException { StringBuffer sb = new StringBuffer("From businesslogic.accounting.user.User as User"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try { Query query = session.createQuery(sb.toString()); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static java.util.Iterator iterateUserByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException { StringBuffer sb = new StringBuffer("From businesslogic.accounting.user.User as User"); if (condition != null) sb.append(" Where ").append(condition); if (orderBy != null) sb.append(" Order By ").append(orderBy); try { Query query = session.createQuery(sb.toString()); query.setLockMode("User", lockMode); return query.iterate(); } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User createUser() { return new businesslogic.accounting.user.User(); } public static boolean save(businesslogic.accounting.user.User user) throws PersistentException { try { OODPersistentManager.instance().saveObject(user); return true; } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static boolean delete(businesslogic.accounting.user.User user) throws PersistentException { try { OODPersistentManager.instance().deleteObject(user); return true; } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static boolean refresh(businesslogic.accounting.user.User user) throws PersistentException { try { OODPersistentManager.instance().getSession().refresh(user); return true; } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static boolean evict(businesslogic.accounting.user.User user) throws PersistentException { try { OODPersistentManager.instance().getSession().evict(user); return true; } catch (Exception e) { e.printStackTrace(); throw new PersistentException(e); } } public static User loadUserByCriteria(UserCriteria userCriteria) { User[] users = listUserByCriteria(userCriteria); if (users == null || users.length == 0) { return null; } return users[0]; } public static void fetchJobs(User user) { try { PersistentSession session = OODPersistentManager.instance().getSession(); List<Integer> jobIDs = session .createSQLQuery("SELECT JobID FROM UserJob WHERE UserID = " + user.getID()).list(); Set<Job> result = new HashSet<>(); for (int jID : jobIDs) { result.add(JobDAO.getJobByORMID(jID)); } user.setJobs(result); } catch (PersistentException ex) { ex.printStackTrace(); } } public static void updateJobs(User user) { try { if (user.getID() > 0) { PersistentSession session = OODPersistentManager.instance().getSession(); List<Integer> jobIDs = session .createSQLQuery("SELECT JobID FROM UserJob WHERE UserID = " + user.getID()).list(); for (int jID : jobIDs) { Job job = JobDAO.getJobByORMID(jID); job.getORM_UserJobs().clear(); JobDAO.delete(job); } jobIDs.clear(); List<Integer> userJobIDs = session .createSQLQuery("SELECT ID FROM UserJob WHERE UserID = " + user.getID()).list(); for (int ujID : userJobIDs) { UserJobDAO.delete(UserJobDAO.getUserJobByORMID(ujID)); } userJobIDs.clear(); user.getORM_UserJobs().clear(); } for (Job job : user.getJobs()) { UserJob uj = UserJobDAO.createUserJob(); user.getORM_UserJobs().add(uj); job.getORM_UserJobs().add(uj); } } catch (PersistentException e) { e.printStackTrace(); } } public static User[] listUserByCriteria(UserCriteria userCriteria) { return userCriteria.listUser(); } }