List of usage examples for org.hibernate.criterion Restrictions conjunction
public static Conjunction conjunction()
From source file:ar.com.zauber.commons.repository.query.visitor.CriteriaFilterVisitor.java
License:Apache License
/** * Operacion logica de union de criterions de un composite. * * @param operation operacion de union logica entre componentes * @return un Criterion Junction//from w w w.j a v a2 s . c o m */ private Junction setJunctionCriterion(final Connector operation) { if (operation instanceof AndConnector) { return Restrictions.conjunction(); } else { return Restrictions.disjunction(); } }
From source file:br.com.bean.RestControllers.usuarioController.java
@RequestMapping(value = "atualiza-usuario-nome-senha", method = RequestMethod.POST) @ResponseBody/*from w w w .j ava 2 s. c om*/ public static String atualizaUsuario(String emailAntigo, String senhaAntiga, String emailNovo, String senhaNova) { Session sessao = HibernateUtility.getSession(); Transaction transacao = sessao.beginTransaction(); try { Criteria query = sessao.createCriteria(Usuario.class); Criterion usuarioex = Restrictions.eq("email", emailAntigo); Criterion senhaex = Restrictions.eq("senha", senhaAntiga); Criterion ativoex = Restrictions.eq("ativo", 1); Conjunction andEx = Restrictions.conjunction(); andEx.add(usuarioex); andEx.add(senhaex); andEx.add(ativoex); query.add(andEx); Usuario u = (Usuario) query.uniqueResult(); if (u != null) { u.setEmail(emailNovo); u.setSenha(senhaNova); } sessao.update(u); transacao.commit(); String jsonMensagemSucesso = CriadorJson.criaJsonSucesso("Sucesso"); return jsonMensagemSucesso; } catch (ConstraintViolationException c) { transacao.rollback(); String jsonMensagemErro = CriadorJson.criaJsonErro(c, "Registro Esta Sendo utilizado"); return jsonMensagemErro; } catch (HibernateException e) { transacao.rollback(); String jsonMensagemErro = CriadorJson.criaJsonErro(e, null); return jsonMensagemErro; } finally { sessao.close(); } }
From source file:br.com.ifpe.web2.DAO.MedicoDAO.java
public List<Medico> litarMedicosPorEspecialidade(String especialidade) { Session session = factory.openSession(); Criteria criteria = session.createCriteria(Medico.class); Criterion esp = Restrictions.eq("especialidade", especialidade); Conjunction conjunction = Restrictions.conjunction(); conjunction.add(esp);/*from ww w. ja v a2 s . c om*/ criteria.add(conjunction); return criteria.list(); }
From source file:cloudoutput.dao.ReportDataDAO.java
License:Open Source License
public TreeMap<Double, Double> getHostUsedResources(String type, String datacenterName, int hostId) { List<ReportData> dataList = null; Session session = HibernateUtil.getSession(); try {/* w w w . j a v a2 s .com*/ dataList = (List<ReportData>) session.createCriteria(ReportData.class) .add(Restrictions.conjunction().add(Restrictions.eq("type", type)) .add(Restrictions.eq("datacenterName", datacenterName)) .add(Restrictions.eq("hostId", hostId))) .list(); } catch (HibernateException ex) { Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex); } finally { HibernateUtil.closeSession(session); } TreeMap<Double, Double> hostUsedResources = new TreeMap<Double, Double>(); if (dataList == null) return hostUsedResources; for (ReportData rd : dataList) { if (type.equals("BANDWIDTH")) { //If bandwidth, convert from kbps to Mbps hostUsedResources.put(rd.getTime() / 60, rd.getAmount() / 1000); } else hostUsedResources.put(rd.getTime() / 60, rd.getAmount()); } return hostUsedResources; }
From source file:cloudoutput.dao.ReportDataDAO.java
License:Open Source License
/** * Gets a report of resources usage of a given virtual machine. * * @param type the type of the used resource. * @param customerName the name of the customer that owns the virtual machine. * @param vmId the id of the virtual machine. * @return a map with values of time as keys and values of * used resources as values. * @see ReportData/*from ww w.j a v a 2s.c om*/ * @since 1.0 */ public TreeMap<Double, Double> getVmUsedResources(String type, String customerName, int vmId) { List<ReportData> dataList = null; Session session = HibernateUtil.getSession(); try { dataList = (List<ReportData>) session.createCriteria(ReportData.class) .add(Restrictions.conjunction().add(Restrictions.eq("type", type)) .add(Restrictions.eq("customerName", customerName)).add(Restrictions.eq("vmId", vmId))) .list(); } catch (HibernateException ex) { Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex); } finally { HibernateUtil.closeSession(session); } TreeMap<Double, Double> vmUsedResources = new TreeMap<Double, Double>(); if (dataList == null) return vmUsedResources; for (ReportData rd : dataList) { if (type.equals("BANDWIDTH")) { //If bandwidth, convert from kbps to Mbps vmUsedResources.put(rd.getTime() / 60, rd.getAmount() / 1000); } else { vmUsedResources.put(rd.getTime() / 60, rd.getAmount()); } } return vmUsedResources; }
From source file:cloudoutput.dao.ReportDataDAO.java
License:Open Source License
/** * Gets a report of overall resources usage of a given datacenter. * * @param type the type of the used resource. * @param datacenterName the name of the datacenter. * @return a map with values of time as keys and values of * used resources as values. * @see ReportData// w ww. j a v a 2 s .c om * @since 1.0 */ public TreeMap<Double, Double> getDatacenterOverallData(String type, String datacenterName) { List<ReportData> dataList = null; Session session = HibernateUtil.getSession(); try { dataList = (List<ReportData>) session.createCriteria(ReportData.class) .add(Restrictions.conjunction().add(Restrictions.eq("type", type)) .add(Restrictions.eq("datacenterName", datacenterName)) .add(Restrictions.isNull("hostId"))) .list(); } catch (HibernateException ex) { Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex); } finally { HibernateUtil.closeSession(session); } TreeMap<Double, Double> overallUsedResources = new TreeMap<Double, Double>(); if (dataList == null) return overallUsedResources; for (ReportData rd : dataList) { if (type.equals("BANDWIDTH")) { //If bandwidth, convert from kbps to Mbps overallUsedResources.put(rd.getTime() / 60, rd.getAmount() / 1000); } else { overallUsedResources.put(rd.getTime() / 60, rd.getAmount()); } } return overallUsedResources; }
From source file:cloudoutput.dao.ReportDataDAO.java
License:Open Source License
/** * Gets a report of overall resources usage of a given customer. * * @param type the type of the used resource. * @param customerName the name of the customer. * @return a map with values of time as keys and values of * used resources as values. * @see ReportData/* w ww . j ava2 s .c om*/ * @since 1.0 */ public TreeMap<Double, Double> getCustomerOverallData(String type, String customerName) { List<ReportData> dataList = null; Session session = HibernateUtil.getSession(); try { dataList = (List<ReportData>) session.createCriteria(ReportData.class) .add(Restrictions.conjunction().add(Restrictions.eq("type", type)) .add(Restrictions.eq("customerName", customerName)).add(Restrictions.isNull("vmId"))) .list(); } catch (HibernateException ex) { Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex); } finally { HibernateUtil.closeSession(session); } TreeMap<Double, Double> overallUsedResources = new TreeMap<Double, Double>(); if (dataList == null) return overallUsedResources; for (ReportData rd : dataList) { if (type.equals("BANDWIDTH")) { //If bandwidth, convert from kbps to Mbps overallUsedResources.put(rd.getTime() / 60, rd.getAmount() / 1000); } else { overallUsedResources.put(rd.getTime() / 60, rd.getAmount()); } } return overallUsedResources; }
From source file:cloudreports.dao.ReportDataDAO.java
License:Open Source License
/** * Gets a report of resources usage of a given host. * * @param type the type of the used resource. * @param datacenterName the name of the datacenter that owns the host. * @param hostId the id of the host. * @return a map with values of time as keys and values of * used resources as values. * @see ReportData/* ww w . j av a 2s .c om*/ * @since 1.0 */ public TreeMap<Double, Double> getHostUsedResources(String type, String datacenterName, int hostId) { List<ReportData> dataList = null; Session session = HibernateUtil.getSession(); try { dataList = (List<ReportData>) session.createCriteria(ReportData.class) .add(Restrictions.conjunction().add(Restrictions.eq("type", type)) .add(Restrictions.eq("datacenterName", datacenterName)) .add(Restrictions.eq("hostId", hostId))) .list(); } catch (HibernateException ex) { Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex); } finally { HibernateUtil.closeSession(session); } TreeMap<Double, Double> hostUsedResources = new TreeMap<Double, Double>(); if (dataList == null) return hostUsedResources; for (ReportData rd : dataList) { if (type.equals("BANDWIDTH")) { //If bandwidth, convert from kbps to Mbps hostUsedResources.put(rd.getTime() / 60, rd.getAmount() / 1000); } else hostUsedResources.put(rd.getTime() / 60, rd.getAmount()); } return hostUsedResources; }
From source file:com.abiquo.abiserver.commands.impl.InfrastructureCommandImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") @Deprecated//from w w w.ja v a2s . c o m public DataResult<ArrayList<InfrastructureElement>> getInfrastructureByDataCenter(final DataCenter dataCenter) { DataResult<ArrayList<InfrastructureElement>> dataResult = new DataResult<ArrayList<InfrastructureElement>>(); ArrayList<InfrastructureElement> infrastructures = null; DatacenterHB datacenterPojo = null; Session session = HibernateUtil.getSession(); Transaction transaction = null; try { transaction = session.beginTransaction(); infrastructures = new ArrayList<InfrastructureElement>(); datacenterPojo = (DatacenterHB) session.get(DatacenterHB.class, dataCenter.getId()); // Adding the racks Set<RackHB> racks = datacenterPojo.getRacks(); for (RackHB rackPojo : racks) { Rack rack = rackPojo.toPojo(); rack.setDataCenter(dataCenter); // Adding to the infrastructure list infrastructures.add(rack); // Adding the physicalMachines Set<PhysicalmachineHB> phyMachines = rackPojo.getPhysicalmachines(); for (PhysicalmachineHB phyMachinePojo : phyMachines) { if (phyMachinePojo.getHypervisor() != null) { PhysicalMachine phyMachine = phyMachinePojo.toPojo(); phyMachine.setAssignedTo(rack); infrastructures.add(phyMachine); // Adding the HyperVisor HypervisorHB hypervisorPojo = phyMachinePojo.getHypervisor(); HyperVisor hypervisor = hypervisorPojo.toPojo(); hypervisor.setAssignedTo(phyMachine); infrastructures.add(hypervisor); // Adding the VirtualMachines Set<VirtualmachineHB> virtualMachines = hypervisorPojo.getVirtualmachines(); for (VirtualmachineHB virtualMachinePojo : virtualMachines) { VirtualMachine virtualMachine = virtualMachinePojo.toPojo(); virtualMachine.setAssignedTo(hypervisor); infrastructures.add(virtualMachine); } } } } // Adding the physical machines in this Data Center, without a rack Conjunction conjunction = Restrictions.conjunction(); conjunction.add(Restrictions.isNull("rack")); conjunction.add(Restrictions.eq("dataCenter", datacenterPojo)); ArrayList<PhysicalmachineHB> physicalMachinesWORack = (ArrayList<PhysicalmachineHB>) session .createCriteria(PhysicalmachineHB.class).add(conjunction).list(); for (PhysicalmachineHB physicalMachineHB : physicalMachinesWORack) { infrastructures.add(physicalMachineHB.toPojo()); } // We are done! transaction.commit(); dataResult.setSuccess(true); dataResult.setData(infrastructures); } catch (HibernateException e) { if (transaction != null) { transaction.rollback(); } logger.trace("Unexpected database error when refreshing infrastructure data", e); } return dataResult; }
From source file:com.abiquo.abiserver.commands.InfrastructureCommand.java
License:Mozilla Public License
/** * Returns the whole infrastructure stored in a data center * /*from www.j a v a2s . c o m*/ * @param dataCenter * @return */ @SuppressWarnings("unchecked") protected DataResult<ArrayList<InfrastructureElement>> getInfrastructureByDataCenter(DataCenter dataCenter) { DataResult<ArrayList<InfrastructureElement>> dataResult = new DataResult<ArrayList<InfrastructureElement>>(); ArrayList<InfrastructureElement> infrastructures = null; DatacenterHB datacenterPojo = null; Session session = HibernateUtil.getSession(); Transaction transaction = null; try { transaction = session.beginTransaction(); infrastructures = new ArrayList<InfrastructureElement>(); datacenterPojo = (DatacenterHB) session.get(DatacenterHB.class, dataCenter.getId()); // Adding the racks Set<RackHB> racks = datacenterPojo.getRacks(); for (RackHB rackPojo : racks) { Rack rack = (Rack) rackPojo.toPojo(); rack.setDataCenter(dataCenter); // Adding to the infrastructure list infrastructures.add(rack); // Adding the physicalMachines Set<PhysicalmachineHB> phyMachines = rackPojo.getPhysicalmachines(); for (PhysicalmachineHB phyMachinePojo : phyMachines) { PhysicalMachine phyMachine = (PhysicalMachine) phyMachinePojo.toPojo(); phyMachine.setAssignedTo(rack); infrastructures.add(phyMachine); // Adding the HyperVisors Set<HypervisorHB> hypervisorPhysicalList = phyMachinePojo.getHypervisors(); for (HypervisorHB hypervisorPojo : hypervisorPhysicalList) { HyperVisor hypervisor = (HyperVisor) hypervisorPojo.toPojo(); hypervisor.setAssignedTo(phyMachine); infrastructures.add(hypervisor); // Adding the VirtualMachines Set<VirtualmachineHB> virtualMachines = hypervisorPojo.getVirtualmachines(); for (VirtualmachineHB virtualMachinePojo : virtualMachines) { VirtualMachine virtualMachine = (VirtualMachine) virtualMachinePojo.toPojo(); virtualMachine.setAssignedTo(hypervisor); infrastructures.add(virtualMachine); } } } } // Adding the physical machines in this Data Center, without a rack Conjunction conjunction = Restrictions.conjunction(); conjunction.add(Restrictions.isNull("rack")); conjunction.add(Restrictions.eq("dataCenter", datacenterPojo)); ArrayList<PhysicalmachineHB> physicalMachinesWORack = (ArrayList<PhysicalmachineHB>) session .createCriteria(PhysicalmachineHB.class).add(conjunction).list(); for (PhysicalmachineHB physicalMachineHB : physicalMachinesWORack) { infrastructures.add((PhysicalMachine) physicalMachineHB.toPojo()); } // We are done! transaction.commit(); dataResult.setSuccess(true); dataResult.setData(infrastructures); } catch (HibernateException e) { if (transaction != null) transaction.rollback(); this.errorManager.reportError(InfrastructureCommand.resourceManager, dataResult, "getInfrastructureByDataCenter", e); } return dataResult; }