com.hazelcast.query.Predicates Java Examples
The following examples show how to use
com.hazelcast.query.Predicates.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapPredicateTest.java From hazelcast-simulator with Apache License 2.0 | 6 votes |
@TimeStep(prob = 0.2) public void pagePredicate(ThreadState state) { double maxSalary = state.randomDouble() * Employee.MAX_SALARY; Predicate predicate = Predicates.lessThan("salary", maxSalary); SalaryComparator salaryComparator = new SalaryComparator(); PagingPredicate pagingPredicate = new PagingPredicateImpl(predicate, salaryComparator, pageSize); Collection<Employee> employees; List<Employee> employeeList; do { employees = map.values(pagingPredicate); employeeList = fillListWithQueryResultSet(employees); Employee nextEmployee; Employee currentEmployee; for (int i = 0; i < employeeList.size() - 1; i++) { currentEmployee = employeeList.get(i); nextEmployee = employeeList.get(i + 1); // check the order & max salary assertTrue(format(baseAssertMessage, currentEmployee.getSalary(), predicate), currentEmployee.getSalary() <= nextEmployee.getSalary() && nextEmployee.getSalary() < maxSalary); } pagingPredicate.nextPage(); } while (!employees.isEmpty()); state.operationCounter.pagePredicateCount++; }
Example #2
Source File: MultiValueMapTest.java From hazelcast-simulator with Apache License 2.0 | 6 votes |
@TimeStep(prob = -1) public void query(ThreadState state, Probe probe, @StartNanos long startNanos) { int key = state.getRandomKey(); Predicate predicate = Predicates.equal("payloadField[any]", key); Collection<Object> result = null; try { result = map.values(predicate); } finally { probe.done(startNanos); } if (throttlingLogger.requestLogSlot()) { throttlingLogger.logInSlot(Level.INFO, format("Query 'payloadField[any]= %d' returned %d results.", key, result.size())); } for (Object resultSillySequence : result) { state.assertValidSequence(resultSillySequence); } }
Example #3
Source File: ClientServerIT.java From spring-data-hazelcast with Apache License 2.0 | 6 votes |
@Test public void notJavaDuke() { String FIRST_NAME_IS_JOHN = "John"; String LAST_NAME_IS_WAYNE = "Wayne"; String NINETEEN_SIXTY_NINE = "1969"; Predicate<?, ?> predicate = Predicates .and(Predicates.equal("firstname", FIRST_NAME_IS_JOHN), Predicates.equal("lastname", LAST_NAME_IS_WAYNE)); // Force operation to server's content, not remote Set<String> localKeySet = super.server_personMap.localKeySet((Predicate<String, Person>) predicate); assertThat("Entry exists", localKeySet.size(), equalTo(1)); String key = localKeySet.iterator().next(); assertThat("Correct key", key, equalTo(NINETEEN_SIXTY_NINE)); Person person = super.server_personMap.get(key); assertThat("Not invalidated", person, notNullValue()); assertThat("@Id matches key", person.getId(), equalTo(key)); assertThat("First name", person.getFirstname(), equalTo(FIRST_NAME_IS_JOHN)); assertThat("Last name", person.getLastname(), equalTo(LAST_NAME_IS_WAYNE)); }
Example #4
Source File: HazelcastQueryCreator.java From spring-data-hazelcast with Apache License 2.0 | 6 votes |
private Predicate<?, ?> fromInequalityVariant(Type type, String property, Iterator<Comparable<?>> iterator) { switch (type) { case AFTER: case GREATER_THAN: return Predicates.greaterThan(property, iterator.next()); case GREATER_THAN_EQUAL: return Predicates.greaterEqual(property, iterator.next()); case BEFORE: case LESS_THAN: return Predicates.lessThan(property, iterator.next()); case LESS_THAN_EQUAL: return Predicates.lessEqual(property, iterator.next()); case BETWEEN: Comparable<?> first = iterator.next(); Comparable<?> second = iterator.next(); return Predicates.between(property, first, second); default: throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type)); } }
Example #5
Source File: HazelcastQueryCreator.java From spring-data-hazelcast with Apache License 2.0 | 6 votes |
private Predicate<?, ?> fromEqualityVariant(Type type, boolean ignoreCase, String property, Iterator<Comparable<?>> iterator) { switch (type) { case SIMPLE_PROPERTY: if (ignoreCase) { return Predicates.ilike(property, iterator.next().toString()); } else { return Predicates.equal(property, iterator.next()); } case NEGATING_SIMPLE_PROPERTY: if (ignoreCase) { return Predicates.not(Predicates.ilike(property, iterator.next().toString())); } else { return Predicates.notEqual(property, iterator.next()); } default: throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type)); } }
Example #6
Source File: HazelcastQueryCreator.java From spring-data-hazelcast with Apache License 2.0 | 6 votes |
private Predicate<?, ?> fromLikeVariant(Type type, boolean ignoreCase, String property, Iterator<Comparable<?>> iterator) { String likeExpression = iterator.next().toString(); switch (type) { case CONTAINING: case NOT_CONTAINING: likeExpression = String.join("", "%", likeExpression, "%"); break; case STARTING_WITH: likeExpression = String.join("", likeExpression, "%"); break; case ENDING_WITH: likeExpression = String.join("", "%", likeExpression); break; case LIKE: case NOT_LIKE: break; default: throw new InvalidDataAccessApiUsageException(String.format("'%s' is not supported for LIKE style query", type)); } Predicate likePredicate = ignoreCase ? Predicates.ilike(property, likeExpression) : Predicates .like(property, likeExpression); return type.equals(NOT_LIKE) || type.equals(NOT_CONTAINING) ? Predicates.not(likePredicate) : likePredicate; }
Example #7
Source File: CallOutQuene.java From youkefu with Apache License 2.0 | 5 votes |
/** * 预测式外呼坐席 * @param agentStatus */ @SuppressWarnings("unchecked") public static List<CallCenterAgent> forecast(String forecastid){ List<CallCenterAgent> agentList = new ArrayList<CallCenterAgent>(); if(CacheHelper.getCallCenterAgentCacheBean()!=null && CacheHelper.getCallCenterAgentCacheBean().getCache()!=null) { PagingPredicate<String, CallCenterAgent> pagingPredicate = new PagingPredicate<String, CallCenterAgent>( Predicates.like("forecastvalue", forecastid) , 1 ) ; agentList.addAll(((IMap<String , CallCenterAgent>) CacheHelper.getCallCenterAgentCacheBean().getCache()).values(pagingPredicate)) ; } return agentList ; }
Example #8
Source File: SerializationStrategyTest.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
@TimeStep(prob = 1) public void getByStringIndex(ThreadState state) { String string = state.getUniqueString(); Predicate predicate = Predicates.equal("stringVal", string); Set<Map.Entry<String, DomainObject>> entries = map.entrySet(predicate); throttlingLogger.log(Level.INFO, "GetByStringIndex: " + entries.size() + " entries"); }
Example #9
Source File: HazelcastIndexedSessionRepository.java From spring-session with Apache License 2.0 | 5 votes |
@Override public Map<String, HazelcastSession> findByIndexNameAndIndexValue(String indexName, String indexValue) { if (!PRINCIPAL_NAME_INDEX_NAME.equals(indexName)) { return Collections.emptyMap(); } Collection<MapSession> sessions = this.sessions.values(Predicates.equal(PRINCIPAL_NAME_ATTRIBUTE, indexValue)); Map<String, HazelcastSession> sessionMap = new HashMap<>(sessions.size()); for (MapSession session : sessions) { sessionMap.put(session.getId(), new HazelcastSession(session, false)); } return sessionMap; }
Example #10
Source File: HazelcastQueryCreator.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
private Predicate<?, ?> fromBooleanVariant(Type type, String property) { switch (type) { case TRUE: return Predicates.equal(property, true); case FALSE: return Predicates.equal(property, false); default: throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type)); } }
Example #11
Source File: HazelcastQueryCreator.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
private Predicate<?, ?> fromCollectionVariant(Type type, String property, Iterator<Comparable<?>> iterator) { switch (type) { case IN: return Predicates.in(property, collectToArray(type, iterator)); case NOT_IN: return Predicates.not(Predicates.in(property, collectToArray(type, iterator))); default: throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type)); } }
Example #12
Source File: HazelcastQueryCreator.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
private Predicate<?, ?> fromNullVariant(Type type, String property) { switch (type) { case IS_NULL: return Predicates.equal(property, null); case IS_NOT_NULL: return Predicates.notEqual(property, null); default: throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type)); } }
Example #13
Source File: HazelcastQueryCreator.java From spring-data-hazelcast with Apache License 2.0 | 5 votes |
private Predicate<?, ?> fromEmptyVariant(Type type, String property) { switch (type) { case IS_EMPTY: return Predicates.equal(property, ""); case IS_NOT_EMPTY: return Predicates.notEqual(property, ""); default: throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type)); } }
Example #14
Source File: HazelcastHelper.java From devicehive-java-server with Apache License 2.0 | 4 votes |
private <T extends HazelcastEntity> Predicate prepareFilters(Long id, Collection<String> deviceIds, Collection<Long> networkIds, Collection<Long> deviceTypeIds, Collection<String> names, Date timestampSt, Date timestampEnd, boolean returnUpdated, String status, Class<T> entityClass) { final List<Predicate> predicates = new ArrayList<>(); if (id != null) { predicates.add(Predicates.equal(ID.getField(), id)); } if (deviceIds != null && !deviceIds.isEmpty()) { predicates.add(Predicates.in(DEVICE_IDS.getField(), deviceIds.toArray(new String[deviceIds.size()]))); } if (networkIds != null && !networkIds.isEmpty()) { predicates.add(Predicates.in(NETWORK_IDS.getField(), networkIds.toArray(new Long[networkIds.size()]))); } if (deviceTypeIds != null && !deviceTypeIds.isEmpty()) { predicates.add(Predicates.in(DEVICE_TYPE_IDS.getField(), deviceTypeIds.toArray(new Long[deviceTypeIds.size()]))); } String searchableField = entityClass.equals(DeviceCommand.class) ? COMMAND.getField() : NOTIFICATION.getField(); if (!CollectionUtils.isEmpty(names)) { predicates.add(Predicates.in(searchableField, names.toArray(new String[names.size()]))); } if (returnUpdated) { predicates.add(Predicates.equal(IS_UPDATED.getField(), returnUpdated)); } if (timestampSt != null) { String searchableFieldSt = returnUpdated ? LAST_UPDATED.getField() : TIMESTAMP.getField(); predicates.add(Predicates.greaterThan(searchableFieldSt, timestampSt.getTime())); } if (timestampEnd != null) { String searchableFieldEnd = returnUpdated ? LAST_UPDATED.getField() : TIMESTAMP.getField(); predicates.add(Predicates.lessThan(searchableFieldEnd, timestampEnd.getTime())); } if (StringUtils.isNotEmpty(status)) { predicates.add(Predicates.equal(STATUS.getField(), status)); } final Predicate[] predicatesArray = new Predicate[predicates.size()]; for (int i = 0; i < predicates.size(); i++) { predicatesArray[i] = predicates.get(i); } return Predicates.and(predicatesArray); }
Example #15
Source File: HazelcastQueryCreator.java From spring-data-hazelcast with Apache License 2.0 | 4 votes |
private Predicate<?, ?> from(Part part, Iterator<Comparable<?>> iterator) { String property = part.getProperty().toDotPath(); Type type = part.getType(); boolean ignoreCase = ifIgnoreCase(part); switch (type) { case AFTER: case GREATER_THAN: case GREATER_THAN_EQUAL: case BEFORE: case LESS_THAN: case LESS_THAN_EQUAL: case BETWEEN: return fromInequalityVariant(type, property, iterator); case IS_NULL: case IS_NOT_NULL: return fromNullVariant(type, property); case IN: case NOT_IN: return fromCollectionVariant(type, property, iterator); case CONTAINING: case NOT_CONTAINING: case STARTING_WITH: case ENDING_WITH: case LIKE: case NOT_LIKE: return fromLikeVariant(type, ignoreCase, property, iterator); case TRUE: case FALSE: return fromBooleanVariant(type, property); case SIMPLE_PROPERTY: case NEGATING_SIMPLE_PROPERTY: return fromEqualityVariant(type, ignoreCase, property, iterator); case REGEX: return Predicates.regex(property, iterator.next().toString()); case IS_EMPTY: case IS_NOT_EMPTY: return fromEmptyVariant(type, property); /* case EXISTS:*/ case NEAR: case WITHIN: return fromGeoVariant(type, property, iterator); default: throw new InvalidDataAccessApiUsageException(String.format("Unsupported type '%s'", type)); } }
Example #16
Source File: HazelcastQueryCreator.java From spring-data-hazelcast with Apache License 2.0 | 4 votes |
@Override protected Predicate<?, ?> or(Predicate<?, ?> base, Predicate<?, ?> criteria) { return Predicates.or(base, criteria); }
Example #17
Source File: HazelcastQueryCreator.java From spring-data-hazelcast with Apache License 2.0 | 4 votes |
@SuppressWarnings({"rawtypes", "unchecked"}) @Override protected Predicate<?, ?> and(Part part, Predicate<?, ?> base, Iterator<Object> iterator) { Predicate<?, ?> criteria = this.from(part, (Iterator<Comparable<?>>) (Iterator) iterator); return Predicates.and(base, criteria); }
Example #18
Source File: ClientManager.java From openmeetings with Apache License 2.0 | 4 votes |
@Override public Collection<Client> listByUser(Long userId) { return map().values(Predicates.equal("userId", userId)); }
Example #19
Source File: MatchDetailHandler.java From match-trade with Apache License 2.0 | 4 votes |
/** * @Title: outMatchDepth 保证了原子操作,无需事务 * @Description: TODO(out订单处理) * @param @param order 入单 * @return void 返回类型 * @throws */ @Async public void outMatchDepth(MatchOrder order) { List<LevelMatch> list = order.getList(); try { if (null!=list&&list.size()>0) { Iterator<LevelMatch> itr = list.iterator(); while (itr.hasNext()){ LevelMatch lm = itr.next(); itr.remove(); BigDecimal dealNumber = lm.getNumber(); while (dealNumber.compareTo(BigDecimal.ZERO)>0) { //对手盘 IMap<Long, MatchOrder> order_map = hzInstance.getMap(HazelcastUtil.getOrderBookKey(order.getCoinTeam(), !order.getIsBuy())); @SuppressWarnings("rawtypes") Predicate pricePredicate = Predicates.equal("price", lm.getPrice()); Collection<MatchOrder> orders = order_map.values(pricePredicate); for (MatchOrder mor : orders) { MatchOrder out = order_map.remove(mor.getId()); if (null!=out) { int cpr = dealNumber.compareTo(out.getUnFinishNumber()); if (cpr>0) { dealNumber=dealNumber.subtract(out.getUnFinishNumber()); this.updateOutOder(out, OrderState.ALL, out.getUnFinishNumber()); }else if (cpr==0) { this.updateOutOder(out, OrderState.ALL, dealNumber); dealNumber = BigDecimal.ZERO; break; }else { out = this.updateOutOder(out, OrderState.PART, dealNumber); order_map.put(out.getId(), out); dealNumber = BigDecimal.ZERO; break; } } } } } } } catch (Exception e) { log.error("===出单数据处理异常,数据原型:"+order.toJsonString()+" 本次异常:"+e); } }