List of usage examples for org.hibernate.criterion Restrictions isNull
public static Criterion isNull(String propertyName)
From source file:com.abiquo.abiserver.commands.impl.InfrastructureCommandImpl.java
License:Open Source License
@Override @SuppressWarnings("unchecked") @Deprecated/* w w w . j ava2 s . co 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 w ww .j av a2 s .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; }
From source file:com.abiquo.server.core.appslibrary.VirtualImageConversionDAO.java
License:Open Source License
private static Criterion sourceFormatNull() { return Restrictions.isNull(VirtualImageConversion.SOURCE_TYPE_PROPERTY); }
From source file:com.abiquo.server.core.appslibrary.VirtualMachineTemplateDAO.java
License:Open Source License
private static Criterion repositoryNull() { return Restrictions.isNull(VirtualMachineTemplate.REPOSITORY_PROPERTY); }
From source file:com.abiquo.server.core.enterprise.EnterpriseDAO.java
License:Open Source License
private Criterion differentPricingTemplateOrNull(final PricingTemplate pricingTemplate) { Disjunction filterDisjunction = Restrictions.disjunction(); filterDisjunction.add(Restrictions.ne(Enterprise.PRICING_PROPERTY, pricingTemplate)); filterDisjunction.add(Restrictions.isNull(Enterprise.PRICING_PROPERTY)); return filterDisjunction; // return Restrictions.eq(Enterprise.PRICING_PROPERTY, pricingTemplate); }
From source file:com.abiquo.server.core.enterprise.EnterpriseDAO.java
License:Open Source License
private Criterion withoutPricingTemplate() { Disjunction filterDisjunction = Restrictions.disjunction(); filterDisjunction.add(Restrictions.isNull(Enterprise.PRICING_PROPERTY)); return filterDisjunction; }
From source file:com.abiquo.server.core.enterprise.RoleDAO.java
License:Open Source License
public static Criterion sameEnterpriseOrNull(final Enterprise enterprise) { Disjunction filterDisjunction = Restrictions.disjunction(); filterDisjunction.add(Restrictions.eq(Role.ENTERPRISE_PROPERTY, enterprise)); filterDisjunction.add(Restrictions.isNull(Role.ENTERPRISE_PROPERTY)); return filterDisjunction; }
From source file:com.abiquo.server.core.enterprise.RoleDAO.java
License:Open Source License
public static Criterion genericRole() { return Restrictions.isNull(Role.ENTERPRISE_PROPERTY); }
From source file:com.abiquo.server.core.infrastructure.network.IpPoolManagementDAO.java
License:Open Source License
public List<IpPoolManagement> findFreeIpsByVlan(final VLANNetwork vlan) { Criterion freeIps = Restrictions.eq(IpPoolManagement.VLAN_NETWORK_PROPERTY, vlan); Criteria criteria = getSession().createCriteria(IpPoolManagement.class).add(freeIps); criteria.add(Restrictions.isNull(IpPoolManagement.MAC_PROPERTY)); return criteria.list(); }
From source file:com.abiquo.server.core.infrastructure.storage.VolumeManagementDAO.java
License:Open Source License
public List<VolumeManagement> getStatefulCandidates(final VirtualDatacenter vdc) { // Filters on the VolumeManagement entity Criteria crit = createCriteria();/* w w w . j a v a 2s. c om*/ crit.createAlias(VolumeManagement.STORAGE_POOL_PROPERTY, "pool"); crit.createAlias("pool." + StoragePool.DEVICE_PROPERTY, "device"); crit.add(sameVirtualDatacenter(vdc)); crit.add(Restrictions.isNull(VolumeManagement.VIRTUAL_MACHINE_TEMPLATE_PROPERTY)); crit.add(Restrictions.eq(VolumeManagement.STATE_PROPERTY, VolumeState.DETACHED)); crit.add(Restrictions.eq("device." + StorageDevice.STORAGE_TECHNOLOGY_PROPERTY, StorageTechnologyType.GENERIC_ISCSI)); return getResultList(crit); }