List of usage examples for org.hibernate.criterion Restrictions and
public static LogicalExpression and(Criterion lhs, Criterion rhs)
From source file:au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.RigManagement.java
License:Open Source License
@Override public PutRigOfflineResponse putRigOffline(PutRigOffline putRigOffline) { PutRigOfflineType param = putRigOffline.getPutRigOffline(); this.logger.debug("Received RigManagement#putRigOffline with params: requestor ID=" + param.getRequestorID() + "requestor namespace=" + param.getRequestorNameSpace() + ", requestor name" + param.getRequestorName() + ", rig name=" + param.getRig().getName() + ", offline start=" + param.getStart().getTime() + ", offline end=" + param.getEnd().getTime() + ", reason=" + param.getReason() + '.'); PutRigOfflineResponse response = new PutRigOfflineResponse(); OperationResponseType result = new OperationResponseType(); response.setPutRigOfflineResponse(result); RigDao dao = new RigDao(); try {//from w w w .ja v a 2 s .co m if (!this.isAuthorised(param, dao.getSession())) { this.logger.warn("Unable to put a rig offline because the user is not authorised to perform this " + "operation (not a ADMIN)."); result.setFailureCode(1); result.setFailureReason("Not authorised."); return response; } Rig rig = dao.findByName(param.getRig().getName()); if (rig == null) { this.logger.warn("Unable to put a rig offline because the rig with name " + param.getRig().getName() + " was not found."); result.setFailureCode(2); result.setFailureReason("Rig not found."); return response; } if (param.getStart().after(param.getEnd())) { this.logger .warn("Unable to put a rig offline because the offline start " + param.getStart().getTime() + " is after the offline end " + param.getEnd().getTime() + "."); result.setFailureCode(3); result.setFailureReason("Start after end."); return response; } Date startDate = param.getStart().getTime(); Date endDate = param.getEnd().getTime(); if ((Integer) dao.getSession().createCriteria(RigOfflineSchedule.class) .add(Restrictions.eq("active", Boolean.TRUE)).add(Restrictions.eq("rig", rig)) .add(Restrictions.disjunction() .add(Restrictions.and(Restrictions.gt("startTime", startDate), Restrictions.lt("endTime", endDate))) .add(Restrictions.and(Restrictions.lt("startTime", startDate), Restrictions.gt("endTime", endDate))) .add(Restrictions.and(Restrictions.lt("startTime", startDate), Restrictions.gt("endTime", endDate))) .add(Restrictions.and(Restrictions.lt("startTime", startDate), Restrictions.gt("endTime", endDate)))) .setProjection(Projections.rowCount()).uniqueResult() > 0) { this.logger.warn("Unable to put a rig offline because there is a concurrent rig offline period."); result.setFailureCode(4); result.setFailureReason("Concurrent offline period."); return response; } result.setSuccessful(true); RigOfflineSchedule offline = new RigOfflineSchedule(); offline.setActive(true); offline.setRig(rig); offline.setStartTime(startDate); offline.setEndTime(endDate); offline.setReason(param.getReason()); new RigOfflineScheduleDao(dao.getSession()).persist(offline); /* Notify the booking engine. */ BookingEngineService service = RigManagementActivator.getBookingService(); if (service != null) service.putRigOffline(offline, dao.getSession()); /* If the period is currently active, clear the rig maintenance state. */ Date now = new Date(); if (rig.isActive() && rig.isOnline() && offline.getStartTime().before(now) && offline.getEndTime().after(now)) { this.logger.info("Setting maintenance state on rig " + rig.getName() + '.'); if (this.notTest) new RigMaintenance().putMaintenance(rig, true, dao.getSession()); rig.setOnline(false); rig.setOfflineReason("In maintenance."); new RigLogDao(dao.getSession()).addOfflineLog(rig, "In maintenance."); dao.flush(); } } finally { dao.closeSession(); } return response; }
From source file:backendsw2.BackEndSW2.java
/** * @param userName/* w w w . j av a2 s .c o m*/ * @param passwd * @return return object "account object " */ public static Object login(String userName, String passwd) { boolean flag = false; Account object = new Account(); Session se = databaseManager.SessionsManager.getSessionFactory().openSession(); flag = true; AdminAccount ad = null; Employer em = null; Freelancer f = null; se.getTransaction().begin(); // add criteria to select user Criteria cr = se.createCriteria(Account.class); Criterion name = Restrictions.eq("userName", userName); Criterion pass = Restrictions.eq("password", passwd); LogicalExpression andr = Restrictions.and(name, pass); cr.add(andr); object = (Account) cr.list().get(0); try { ad = (AdminAccount) se.get(AdminAccount.class, object.getId()); } catch (Exception e) { try { em = (Employer) se.get(Employer.class, object.getId()); } catch (Exception ex) { try { f = (Freelancer) se.get(Freelancer.class, object.getId()); } catch (Exception ee) { f = null; } finally { if (flag) { se.close(); } return f; } } finally { if (flag) { se.close(); } return em; } } finally { if (flag) { se.close(); } return ad; } }
From source file:be.wolkmaan.klimtoren.party.PartyRepositoryImpl.java
private Criteria createBidirectional(Party context, Party reference) { Criteria crit = getSession().createCriteria(PartyToPartyRelationship.class).add(Restrictions.or( Restrictions.and(Restrictions.eq("context", context), Restrictions.eq("reference", reference)), Restrictions.and(Restrictions.eq("context", reference), Restrictions.eq("reference", context)))) .add(Restrictions.isNull("end")); //for now only search live relations return crit;// w ww . ja v a 2 s . c om }
From source file:be.wolkmaan.klimtoren.party.PartyRepositoryImpl.java
private Criteria createUnidirectional(Party context, Party reference) { Criteria crit = getSession().createCriteria(PartyToPartyRelationship.class) .add(Restrictions.and(Restrictions.eq("context", context), Restrictions.eq("reference", reference))) .add(Restrictions.isNull("end")); //for now only search live relations return crit;/* w w w. j a v a 2 s .c o m*/ }
From source file:bernardo.venda.controle.CaixaControle.java
public Caixa findStateUser(boolean aberto, Utilizador u) { return (Caixa) getSession().createCriteria(Caixa.class) .add(Restrictions.and(Restrictions.eq("aberto", aberto), Restrictions.eq("utilizador", u))) .uniqueResult();/*from ww w . j a v a 2 s. co m*/ }
From source file:bernardo.venda.controle.UtilizadorControle.java
public Utilizador login(String string, String text) { return (Utilizador) getSession().createCriteria(Utilizador.class) .add(Restrictions.and(Restrictions.eq("senha", string), Restrictions.eq("nomeUtilizador", text))) .uniqueResult();/*from ww w . j a v a2 s. com*/ }
From source file:br.com.hrstatus.dao.impl.BancoDadosDAO.java
License:Open Source License
public int countMySQLOK() { log.fine("[ " + userInfo.getLoggedUsername() + " ] countMySQLOK()"); try {// w w w. ja v a 2 s .co m final Criteria criteria = session().createCriteria(BancoDados.class); criteria.add(Restrictions.and(Restrictions.eq("vendor", "MYSQL"), Restrictions.eq("status", "OK"))); criteria.setProjection(Projections.rowCount()); final int count = ((Long) criteria.uniqueResult()).intValue(); log.fine("[ " + userInfo.getLoggedUsername() + " ] countMySQLOK() -> " + count + " found."); return count; } catch (Exception e) { System.out.println(e); log.severe("[ " + userInfo.getLoggedUsername() + " ] Error: " + e); return 0; } }
From source file:br.com.hrstatus.dao.impl.BancoDadosDAO.java
License:Open Source License
public int countMySQLNOK() { log.fine("[ " + userInfo.getLoggedUsername() + " ] countMySQLNOK()"); try {//from w w w . ja v a 2 s . c om final Criteria criteria = session().createCriteria(BancoDados.class); criteria.add(Restrictions.and(Restrictions.eq("vendor", "MYSQL"), Restrictions.or(Restrictions.eq("trClass", "Error"), Restrictions.eq("status", "NOK")))); criteria.setProjection(Projections.rowCount()); final int count = ((Long) criteria.uniqueResult()).intValue(); log.fine("[ " + userInfo.getLoggedUsername() + " ] countMySQLNOK() -> " + count + " found."); return count; } catch (Exception e) { System.out.println(e); log.severe("[ " + userInfo.getLoggedUsername() + " ] Error: " + e); return 0; } }
From source file:br.com.hrstatus.dao.impl.BancoDadosDAO.java
License:Open Source License
public int countOracleOK() { log.fine("[ " + userInfo.getLoggedUsername() + " ] countOracleOK()"); try {/*from w w w. j a v a 2 s . c o m*/ final Criteria criteria = session().createCriteria(BancoDados.class); criteria.add(Restrictions.and(Restrictions.eq("vendor", "ORACLE"), Restrictions.eq("status", "OK"))); criteria.setProjection(Projections.rowCount()); final int count = ((Long) criteria.uniqueResult()).intValue(); log.fine("[ " + userInfo.getLoggedUsername() + " ] countOracleOK() -> " + count + " found."); return count; } catch (Exception e) { System.out.println(e); log.severe("[ " + userInfo.getLoggedUsername() + " ] Error: " + e); return 0; } }
From source file:br.com.hrstatus.dao.impl.BancoDadosDAO.java
License:Open Source License
public int countOracleNOK() { log.fine("[ " + userInfo.getLoggedUsername() + " ] countOracleNOK()"); try {//from ww w .j a va 2 s.c o m final Criteria criteria = session().createCriteria(BancoDados.class); criteria.add(Restrictions.and(Restrictions.eq("vendor", "ORACLE"), Restrictions.or(Restrictions.eq("trClass", "Error"), Restrictions.eq("status", "NOK")))); criteria.setProjection(Projections.rowCount()); final int count = ((Long) criteria.uniqueResult()).intValue(); log.fine("[ " + userInfo.getLoggedUsername() + " ] countOracleNOK() -> " + count + " found."); return count; } catch (Exception e) { System.out.println(e); log.severe("[ " + userInfo.getLoggedUsername() + " ] Error: " + e); return 0; } }