List of usage examples for org.hibernate.criterion Restrictions or
public static LogicalExpression or(Criterion lhs, Criterion rhs)
From source file:net.firejack.platform.core.store.AbstractStore.java
License:Apache License
protected Criterion generateInRestriction(String fieldName, Collection collection) { Criterion criterion = null;/*from w w w . j a v a2s . c o m*/ int size = collection.size(); if (size <= 1000) { criterion = Restrictions.in(fieldName, collection); } else { List list = new ArrayList(collection); int iterations = (int) Math.ceil((double) size / 1000); for (int i = 0; i < iterations; i++) { int fromIndex = i * 1000; int toIndex = (size - (i * 1000)) > 1000 ? ((i + 1) * 1000) : size; List subList = list.subList(fromIndex, toIndex); if (i == 0) { criterion = Restrictions.in(fieldName, subList); } else { criterion = Restrictions.or(criterion, Restrictions.in(fieldName, subList)); } } } return criterion; }
From source file:net.firejack.platform.core.store.AbstractStore.java
License:Apache License
protected LinkedList<Criterion> addFilterCriterion(LinkedList<Criterion> criterionList, SpecifiedIdsFilter filter) {//from www. ja va 2s .com LinkedList<Criterion> resultCriterionList; Criterion filterCriterion = createFilterCriterion(filter); if (criterionList.isEmpty()) { criterionList.add(filterCriterion); resultCriterionList = criterionList; } else { resultCriterionList = new LinkedList<Criterion>(); Criterion criterion = null; for (Criterion cr : criterionList) { criterion = criterion == null ? cr : Restrictions.or(criterion, cr); } resultCriterionList.add(Restrictions.and(filterCriterion, criterion)); } return resultCriterionList; }
From source file:net.firejack.platform.core.store.process.ProcessFieldStore.java
License:Apache License
/** * @see net.firejack.platform.core.store.process.IProcessFieldStore#findByProcessIdPlusGlobal(java.lang.Long) * @param processId - ID of the process for which the fields are being retrieved * @return/* w w w. j a v a 2 s . c o m*/ */ @Override @Transactional(readOnly = true) public List<ProcessFieldModel> findByProcessIdPlusGlobal(Long processId) { Map<String, String> aliases = new HashMap<String, String>(); aliases.put("process", "p"); List<Criterion> criterions = new ArrayList<Criterion>(); Criterion globalFieldCriterion = Restrictions.isNull("p.id"); if (processId != null) { Criterion processFieldCriterion = Restrictions.eq("p.id", processId); criterions.add(Restrictions.or(globalFieldCriterion, processFieldCriterion)); } else { criterions.add(globalFieldCriterion); } Order order = createOrder("orderPosition", SortOrder.ASC); List<String> fetchPaths = Arrays.asList("registryNodeType"); return findAllWithFilter(null, null, criterions, aliases, null, null, null, fetchPaths, order); }
From source file:net.firejack.platform.core.store.registry.EntityStore.java
License:Apache License
private LinkedList<Criterion> getSearchByDomainCriterions(String terms, List<String> domainLookupPrefixes) { LinkedList<Criterion> criterions = new LinkedList<Criterion>(); if (terms != null) { String wildcard = '%' + URLDecoder.decode(terms.trim()) + '%'; criterions.add(Restrictions.like("name", wildcard)); }//from ww w.j a v a 2 s . c o m if (domainLookupPrefixes.size() > 1) { Criterion expression = null; for (String domainLookupPrefix : domainLookupPrefixes) { if (expression == null) { expression = Restrictions.like("lookup", domainLookupPrefix); } else { expression = Restrictions.or(expression, Restrictions.like("lookup", domainLookupPrefix)); } } criterions.add(expression); } else if (domainLookupPrefixes.size() == 1) { criterions.add(Restrictions.like("lookup", domainLookupPrefixes.get(0))); } return criterions; }
From source file:net.firejack.platform.core.store.registry.RelationshipStore.java
License:Apache License
@Override @Transactional(readOnly = true)/*www. ja va 2s. c o m*/ public List<RelationshipModel> findRelatedEntitiesByEntityId(final Long registryNodeId, final SpecifiedIdsFilter<Long> filter) { return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = createCriteriaForFilter(session, filter); Criterion sourceEntityCriterion = Restrictions.eq("sourceEntity.id", registryNodeId); Criterion targetEntityCriterion = Restrictions.eq("targetEntity.id", registryNodeId); criteria.add(Restrictions.or(sourceEntityCriterion, targetEntityCriterion)); criteria.setFetchMode("sourceEntity", FetchMode.JOIN); criteria.setFetchMode("targetEntity", FetchMode.JOIN); return (List<RegistryNodeModel>) criteria.list(); } }); }
From source file:net.firejack.platform.core.store.registry.RelationshipStore.java
License:Apache License
@Override @Transactional/*from www .ja v a 2 s . c o m*/ public void save(RelationshipModel model) { EntityModel sourceEntity = model.getSourceEntity(); EntityModel targetEntity = model.getTargetEntity(); boolean isNew = model.getId() == null; if (isNew && (model.getRelationshipType() == RelationshipType.TREE || model.getRelationshipType() == RelationshipType.PARENT_CHILD)) { Criteria criteria = getSession().createCriteria(RegistryNodeModel.class); criteria.add(Restrictions.eq("sourceEntity.id", sourceEntity.getId())); LogicalExpression expression = Restrictions.or( Restrictions.eq("relationshipType", RelationshipType.TREE), Restrictions.eq("relationshipType", RelationshipType.PARENT_CHILD)); criteria.add(expression); Long count = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); if (count != 0) { throw new BusinessFunctionException( "Source Entity can't has both relationships like Tree and ParentChild"); } } if (isNew && StringUtils.isBlank(model.getSourceConstraintName())) { model.setSourceConstraintName("FK" + SecurityHelper.generateRandomSequence(14)); } if (isNew && StringUtils.isBlank(model.getTargetConstraintName())) { model.setTargetConstraintName("FK" + SecurityHelper.generateRandomSequence(14)); } if ((isNew && sourceEntity != null && StringUtils.isBlank(model.getSourceEntityRefName()))) { EntityModel entityModel = entityStore.findById(sourceEntity.getId()); String columnName = entityModel.getName().toLowerCase(); columnName = columnName.replaceAll("\\s+", "_"); model.setSourceEntityRefName(DefaultSqlNameResolver.ID_PREFIX + columnName); } if (StringUtils.isBlank(model.getTargetEntityRefName())) { if (model.getRelationshipType() == RelationshipType.PARENT_CHILD || model.getRelationshipType() == RelationshipType.TREE) { model.setTargetEntityRefName(LeadIdPrefixNameResolver.ID_PARENT); } else if (targetEntity != null) { EntityModel entityModel = entityStore.findById(targetEntity.getId()); String columnName = entityModel.getName().toLowerCase(); columnName = columnName.replaceAll("\\s+", "_"); model.setTargetEntityRefName(DefaultSqlNameResolver.ID_PREFIX + columnName); } } super.save(model); indexStore.createOrUpdateIndex(model); }
From source file:net.firejack.platform.core.store.statistics.LogEntryStore.java
License:Apache License
private List<Criterion> createCriterionsForTermAndDates(String term, String nodeLookup, Date startDate, Date endDate, LogEntryType logEntryType) { List<Criterion> criterions = new ArrayList<Criterion>(); if (!StringUtils.isEmpty(term)) { Criterion lookupCriterion = Restrictions.like("lookup", "%" + term + "%"); Criterion usernameCriterion = Restrictions.like("username", "%" + term + "%"); Criterion detailsCriterion = Restrictions.like("details", "%" + term + "%"); Criterion termCriterion = Restrictions.or(Restrictions.or(lookupCriterion, usernameCriterion), detailsCriterion);//from ww w . ja va 2s . c om criterions.add(termCriterion); } if (!LogEntryType.ALL.equals(logEntryType)) { criterions.add(Restrictions.eq("type", logEntryType)); } if (!StringUtils.isEmpty(nodeLookup)) { Criterion nodeLookupCriterion = Restrictions.like("lookup", nodeLookup + "%"); criterions.add(nodeLookupCriterion); } if (startDate != null) { Criterion startDateCriterion = Restrictions.ge("created", startDate); criterions.add(startDateCriterion); } if (endDate != null) { Criterion endDateCriterion = Restrictions.lt("created", endDate); criterions.add(endDateCriterion); } return criterions; }
From source file:net.firejack.platform.core.store.statistics.MetricsEntryStore.java
License:Apache License
private List<Criterion> createCriterionsForTermAndDates(String term, String lookup, Date startDate, Date endDate, LogEntryType logEntryType) { List<Criterion> criterions = new ArrayList<Criterion>(); if (StringUtils.isNotEmpty(term)) { Criterion lookupCriterion = Restrictions.sqlRestriction("{alias}.lookup LIKE '%" + term + "%'"); Criterion usernameCriterion = Restrictions.sqlRestriction("{alias}.username LIKE '%" + term + "%'"); Criterion systemAccountNameCriterion = Restrictions .sqlRestriction("{alias}.system_account_name LIKE '%" + term + "%'"); Criterion termCriterion = Restrictions.or(Restrictions.or(lookupCriterion, usernameCriterion), systemAccountNameCriterion); criterions.add(termCriterion);/*www . j av a2s . c om*/ } if (logEntryType != null && !LogEntryType.ALL.equals(logEntryType)) { criterions.add(Restrictions.eq("type", logEntryType)); } if (StringUtils.isNotEmpty(lookup)) { Criterion lookupCriterion = Restrictions.sqlRestriction("{alias}.lookup LIKE '%" + lookup + "%'"); criterions.add(lookupCriterion); } if (startDate != null) { Criterion startDateCriterion = Restrictions.ge("hourPeriod", startDate.getTime()); criterions.add(startDateCriterion); } if (endDate != null) { Criterion endDateCriterion = Restrictions.le("hourPeriod", endDate.getTime()); criterions.add(endDateCriterion); } return criterions; }
From source file:net.firejack.platform.core.store.user.BaseUserStore.java
License:Apache License
@Override @Transactional(readOnly = true)//from w w w .j a v a 2 s.co m public List<M> findAllByRegistryNodeIdsAndSearchTermWithFilter(List<Long> registryNodeIds, String term, SpecifiedIdsFilter<Long> filter) { List<Criterion> criterions = new ArrayList<Criterion>(); Criterion usernameCriterion = Restrictions.like("username", "%" + term + "%"); Criterion emailCriterion = Restrictions.like("email", "%" + term + "%"); Criterion firstNameCriterion = Restrictions.like("firstName", "%" + term + "%"); Criterion lastNameCriterion = Restrictions.like("lastName", "%" + term + "%"); LogicalExpression expression1 = Restrictions.or(usernameCriterion, emailCriterion); LogicalExpression expression2 = Restrictions.or(firstNameCriterion, lastNameCriterion); LogicalExpression expression = Restrictions.or(expression1, expression2); if (registryNodeIds != null) { Criterion registryNodeIdCriterion = Restrictions.in("registryNode.id", registryNodeIds); LogicalExpression expressionAll = Restrictions.and(registryNodeIdCriterion, expression); criterions.add(expressionAll); } else { criterions.add(expression); } return findAllWithFilter(criterions, filter); }
From source file:net.firejack.platform.core.store.user.BaseUserStore.java
License:Apache License
@Override @Transactional(readOnly = true)// w ww. j a va 2 s .c o m public List<M> findAllByRegistryNodeIdsAndSearchTermWithFilter(List<Long> registryNodeIds, String term, SpecifiedIdsFilter<Long> filter, Integer offset, Integer limit, Order... orders) { List<Criterion> criterions = new ArrayList<Criterion>(); Criterion usernameCriterion = Restrictions.like("username", "%" + term + "%"); Criterion emailCriterion = Restrictions.like("email", "%" + term + "%"); Criterion firstNameCriterion = Restrictions.like("firstName", "%" + term + "%"); Criterion lastNameCriterion = Restrictions.like("lastName", "%" + term + "%"); LogicalExpression expression1 = Restrictions.or(usernameCriterion, emailCriterion); LogicalExpression expression2 = Restrictions.or(firstNameCriterion, lastNameCriterion); LogicalExpression expression = Restrictions.or(expression1, expression2); if (registryNodeIds != null) { Criterion registryNodeIdCriterion = Restrictions.in("registryNode.id", registryNodeIds); LogicalExpression expressionAll = Restrictions.and(registryNodeIdCriterion, expression); criterions.add(expressionAll); } else { criterions.add(expression); } return findAllWithFilter(offset, limit, criterions, filter, orders); }