Example usage for org.hibernate.criterion Restrictions and

List of usage examples for org.hibernate.criterion Restrictions and

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions and.

Prototype

public static LogicalExpression and(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the conjuction of two expressions

Usage

From source file:com.abiquo.server.core.appslibrary.VirtualMachineTemplateDAO.java

License:Open Source License

private static Criterion sameEnterpriseOrSharedInRepo(final Enterprise enterprise,
        final com.abiquo.server.core.infrastructure.Repository repository) {
    return Restrictions.and(sameRepositoryAndNotStatefull(repository),
            Restrictions.or(sameEnterprise(enterprise), sharedVirtualMachineTemplate()));
}

From source file:com.abiquo.server.core.appslibrary.VirtualMachineTemplateDAO.java

License:Open Source License

private static Criterion sameEnterpriseOrSharedInRepo(final Enterprise enterprise,
        final com.abiquo.server.core.infrastructure.Repository repository, final String path) {
    Criterion sameEnterpriseOrSharedInRepo = Restrictions.and(sameRepositoryAndNotStatefull(repository),
            Restrictions.or(sameEnterprise(enterprise), sharedVirtualMachineTemplate()));

    return Restrictions.and(Restrictions.eq(VirtualMachineTemplate.PATH_PROPERTY, path),
            sameEnterpriseOrSharedInRepo);
}

From source file:com.abiquo.server.core.cloud.VirtualMachineDAO.java

License:Open Source License

public List<VirtualMachine> findVirtualMachinesNotAllocatedCompatibleHypervisor(final Hypervisor hypervisor) {
    Criteria criteria = createCriteria();
    criteria.createAlias(VirtualMachine.VIRTUAL_MACHINE_TEMPLATE_PROPERTY, "template");
    Restrictions.and(Restrictions.eq(VirtualMachine.HYPERVISOR_PROPERTY, null),
            Restrictions.in("template." + VirtualMachineTemplate.DISKFORMAT_TYPE_PROPERTY,
                    Arrays.asList(hypervisor.getType().compatibleFormats)));
    criteria.addOrder(Order.asc(VirtualMachine.NAME_PROPERTY));
    List<VirtualMachine> result = getResultList(criteria);
    return result;
}

From source file:com.abiquo.server.core.scheduler.MachineLoadRuleDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<MachineLoadRule> findByRack(final Rack rack, final boolean includeMachineRules) {
    final Criteria criteria;
    if (includeMachineRules) {
        // Rules from racks and machines
        criteria = createCriteria().add(sameRack(rack));
    } else {//www  . j  a v  a 2  s . c om
        // Rules from racks
        criteria = createCriteria().add(Restrictions.and(sameRack(rack), nullMachine()));
    }
    return criteria.list();
}

From source file:com.aistor.modules.cms.service.ArticleService.java

License:Open Source License

public Page<Article> find(Page<Article> page, Article article) {
    DetachedCriteria dc = articleDao.createDetachedCriteria();
    dc.createAlias("category", "category");
    dc.createAlias("category.site", "category.site");
    if (article.getCategory() != null && article.getCategory().getId() != null
            && !Category.isRoot(article.getCategory().getId())) {
        Category category = categoryDao.findOne(article.getCategory().getId());
        if (category != null) {
            dc.add(Restrictions.or(Restrictions.eq("category.id", category.getId()),
                    Restrictions.eq("category.parent.id", category.getId()),
                    Restrictions.like("category.parentIds", "%," + category.getId() + ",%")));
            dc.add(Restrictions.eq("category.site.id", category.getSite().getId()));
            article.setCategory(category);
        } else {/*from w  w  w.j  ava 2 s . co  m*/
            dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
        }
    } else {
        dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
    }
    if (StringUtils.isNotEmpty(article.getTitle())) {
        dc.add(Restrictions.like("title", "%" + article.getTitle() + "%"));
    }
    if (StringUtils.isNotEmpty(article.getPosid())) {
        dc.add(Restrictions.like("posid", "%," + article.getPosid() + ",%"));
    }
    if (StringUtils.isNotEmpty(article.getThumb()) && "1".equals(article.getThumb())) {
        dc.add(Restrictions.and(Restrictions.isNotNull("thumb"), Restrictions.ne("thumb", "")));
    }
    if (article.getUser() != null && article.getUser().getId() > 0) {
        dc.add(Restrictions.eq("user.id", article.getUser().getId()));
    }
    dc.add(Restrictions.eq("status", article.getStatus()));
    dc.addOrder(Order.desc("weight"));
    dc.addOrder(Order.desc("updateDate"));
    return articleDao.find(page, dc);
}

From source file:com.almuradev.backpack.backend.DatabaseManager.java

License:MIT License

public static void saveSlot(Session session, Backpacks backpack, int slotIndex, DataContainer slotData)
        throws IOException, SQLException {
    Slots slotsRecord = (Slots) session.createCriteria(Slots.class)
            .add(Restrictions.and(Restrictions.eq("backpacks", backpack), Restrictions.eq("slot", slotIndex)))
            .uniqueResult();//from   w w w. j av a 2s .com

    if (slotData == null && slotsRecord != null) {
        session.delete(slotsRecord);
    } else if (slotData != null && slotsRecord != null) {
        final StringWriter writer = new StringWriter();
        HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
                .setSink(() -> new BufferedWriter(writer)).build();
        loader.save(ConfigurateTranslator.instance().translateData(slotData));
        slotsRecord.setData(new SerialClob(writer.toString().toCharArray()));
        session.saveOrUpdate(slotsRecord);
    } else if (slotData != null) {
        slotsRecord = new Slots();
        slotsRecord.setBackpacks(backpack);
        slotsRecord.setSlot(slotIndex);
        final StringWriter writer = new StringWriter();
        HoconConfigurationLoader loader = HoconConfigurationLoader.builder()
                .setSink(() -> new BufferedWriter(writer)).build();
        loader.save(ConfigurateTranslator.instance().translateData(slotData));
        slotsRecord.setData(new SerialClob(writer.toString().toCharArray()));
        session.saveOrUpdate(slotsRecord);
    }
}

From source file:com.almuradev.backpack.backend.DatabaseManager.java

License:MIT License

public static void loadSlot(Session session, BackpackInventory inventory, int slotIndex)
        throws IOException, SQLException {
    Slots slotsRecord = (Slots) session.createCriteria(Slots.class).add(Restrictions
            .and(Restrictions.eq("backpacks", inventory.getRecord()), Restrictions.eq("slot", slotIndex)))
            .uniqueResult();//w w  w .  j ava2 s  .  co  m
    if (slotsRecord == null) {
        return;
    }
    final DataView view = ConfigurateTranslator.instance()
            .translateFrom(HoconConfigurationLoader.builder()
                    .setSource(() -> new BufferedReader(new StringReader(clobToString(slotsRecord.getData()))))
                    .build().load());
    final ItemStack slotStack = ItemStack.builder().fromContainer(view).build();
    inventory.setInventorySlotContents(slotIndex, (net.minecraft.item.ItemStack) (Object) slotStack);
}

From source file:com.almuradev.backpack.BackpackFactory.java

License:MIT License

public static BackpackInventory load(World world, Player player) throws IOException, SQLException {
    final Session session = DatabaseManager.getSessionFactory().openSession();
    final Criteria criteria = session.createCriteria(Backpacks.class);
    Backpacks record = (Backpacks) criteria
            .add(Restrictions.and(Restrictions.eq("worldUniqueId", world.getUniqueId()),
                    Restrictions.eq("playerUniqueId", player.getUniqueId())))
            .uniqueResult();/*  w  ww.j  a va  2  s .  co  m*/

    if (record == null) {
        record = new Backpacks();
        record.setWorldUniqueId(world.getUniqueId());
        record.setPlayerUniqueId(player.getUniqueId());
        record.setSize(9);
        record.setTitle("My Backpack");
        session.beginTransaction();
        session.saveOrUpdate(record);
        session.getTransaction().commit();
    }
    final BackpackInventory inventory = new BackpackInventory(record);
    for (int i = 0; i < inventory.getSizeInventory(); i++) {
        DatabaseManager.loadSlot(session, inventory, i);
    }
    session.close();
    BACKPACKS.add(inventory);
    return new BackpackInventory(record);
}

From source file:com.amalto.core.storage.hibernate.StandardQueryHandler.java

License:Open Source License

private static Criterion makeAnd(Criterion... criterions) {
    if (criterions.length == 1) {
        return criterions[0];
    }/*from ww  w  .  j  a va  2  s.com*/
    Criterion current = TRUE_CRITERION;
    for (Criterion cri : criterions) {
        current = Restrictions.and(current, cri);
    }
    return current;
}

From source file:com.bean.FavoriteBean.java

public boolean checkHaveFavorite() {
    Dao dao = new Dao();
    Users u = (Users) SessionUtils.getSession().getAttribute("login");
    Property p = (Property) dao.getById(Property.class, propertyId);
    if (u != null && p.getProId() != 0) {
        Criterion cU = Restrictions.eq("users", u);
        Criterion cP = Restrictions.eq("property", p);
        LogicalExpression logic = Restrictions.and(cP, cU);
        List<FavoriteProperty> f = dao.getByCondition(FavoriteProperty.class, logic);
        if (f.size() > 0) {
            return true;
        } else {// www .  ja va  2  s .c om
            return false;
        }
    }
    return false;
}