/** * Add the tenantId predicate to the query. */ public void addTenant(SpiQuery<?> query, Object tenantId) { query.where().eq(name, tenantId); }
/** * Configure the query for lazy loading execution. */ public void configureQuery(SpiQuery<?> query, List<Object> idList) { query.setMode(SpiQuery.Mode.LAZYLOAD_BEAN); query.setPersistenceContext(loadBuffer.getPersistenceContext()); String mode = isLazy() ? "+lazy" : "+query"; query.setLoadDescription(mode, getDescription()); if (isLazy()) { // cascade the batch size (if set) for further lazy loading query.setLazyLoadBatchSize(getBatchSize()); } loadBuffer.configureQuery(query, lazyLoadProperty); if (idList.size() == 1) { query.where().idEq(idList.get(0)); } else { query.where().idIn(idList); } }
peekExprList().eq(path, bind(value)); break; case IEQ: peekExprList().add(owner.ieq(path, bind(value))); break; case NE: peekExprList().ne(path, bind(value)); break; case INE: peekExprList().add(owner.ine(path, bind(value))); break; case GT: peekExprList().gt(path, bind(value)); break; case LT: peekExprList().lt(path, bind(value)); break; case GTE: peekExprList().ge(path, bind(value)); break; case LTE: peekExprList().le(path, bind(value)); break; case LIKE:
/** * Fetch the destination beans that will be published to. */ void fetchDestinationBeans(List<T> sourceBeans, boolean asDraft) { List<Object> ids = getBeanIds(desc, sourceBeans); Query<T> destQuery = server.find(desc.getBeanType()).where().idIn(ids).query(); if (asDraft) { destQuery.asDraft(); } desc.draftQueryOptimise(destQuery); this.destBeans = server.findMap(destQuery, transaction); }
/** * Returns a set of properties if saving the bean will violate the unique constraints (defined by given properties). */ private Set<Property> checkUniqueness(EntityBean entityBean, BeanDescriptor<?> beanDesc, BeanProperty[] props, Transaction transaction) { BeanProperty idProperty = beanDesc.getIdProperty(); Query<?> query = new DefaultOrmQuery<>(beanDesc, this, expressionFactory); ExpressionList<?> exprList = query.where(); if (!entityBean._ebean_getIntercept().isNew()) { // if model is not new, exclude ourself. exprList.ne(idProperty.getName(), idProperty.getVal(entityBean)); } for (Property prop : props) { Object value = prop.getVal(entityBean); if (value == null) { return null; } exprList.eq(prop.getName(), value); } if (findCount(query, transaction) > 0) { Set<Property> ret = new LinkedHashSet<>(); Collections.addAll(ret, props); return ret; } return null; }
@Override public Optional<T> findByProperty(String propertyName, Object propertyValue) { Assert.notNull(propertyName, PROP_MUST_NOT_BE_NULL); return query() .where() .eq(propertyName, propertyValue) .findOneOrEmpty(); }
/** {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public void apply(Expression expr) { if (expr instanceof HavingExpression) { ExpressionList having = expressionList.query().having(); ((HavingExpression) expr).getExpressionList().forEach(having::add); return; } else if (expr instanceof TextExpression) { TextExpression expression = (TextExpression) expr; ExpressionList et = expressionList.query().text(); expression.getExpressionList().forEach(et::add); return; } else if (expr instanceof DistinctExpression) { expressionList.setDistinct(((DistinctExpression) expr).distinct); return; } else if (expr instanceof AbstractTextExpression) { expressionList.setUseDocStore(true); } else if (expr instanceof FilterExpression) { FilterExpression filter = (FilterExpression) expr; Query query = expressionList.query(); query.filterMany(filter.getPath()).addAll(filter); return; } expressionList.add(expr); } }
/** * Set a list of Id values to match. * <p> * <pre>{@code * * List<Order> orders = * new QOrder() * .setIdIn(42, 43, 44) * .findList(); * * // the order details were eagerly fetched * List<OrderDetail> details = order.getDetails(); * * }</pre> */ public R setIdIn(Object... ids) { query.where().idIn(ids); return root; }
@Override public DefaultOrmQuery<T> where(Expression expression) { where().add(expression); return this; }
protected void addBetween(String path, String value1, String value2) { peekExprList().between(path, bind(value1), bind(value2)); }
private static <T> Query<T> query(EbeanServer ebeanServer, Class<T> entityType, String fetchPath, Object queryObject, Pageable pageable) { Assert.notNull(ebeanServer, "ebeanServer must not null"); Assert.notNull(entityType, "entityType must not null"); Query<T> query = ebeanServer.find(entityType); if (StringUtils.hasText(fetchPath)) { query.apply(PathProperties.parse(fetchPath)); } else { // queryObject IncludePath if (queryObject != null) { if (queryObject.getClass().isAnnotationPresent(IncludeFields.class)) { IncludeFields includeFields = queryObject.getClass().getAnnotation(IncludeFields.class); String ifs = includeFields.value(); if (StringUtils.hasText(ifs)) { query.apply(PathProperties.parse(ifs)); } } } } ExpressionList<T> expressionList = query.where(); applyWhere(expressionList, queryObject); if (pageable != null) { expressionList.setMaxRows(pageable.getPageSize()) .setFirstRow((int) pageable.getOffset()) .setOrder(Converters.convertToEbeanOrderBy(pageable.getSort())); } return expressionList.query(); }
@Override public void enterConditional_expression(EQLParser.Conditional_expressionContext ctx) { if (ctx.getChildCount() > 1) { pushExprList(peekExprList().or()); } }
/** * Apply a filter when fetching these beans. */ public R filterMany(ExpressionList<T> filter) { @SuppressWarnings("unchecked") ExpressionList<T> expressionList = (ExpressionList<T>) expr().filterMany(_name); expressionList.addAll(filter); return _root; }
((HavingExpression) o).expressionList.forEach(having::add); } else if (o instanceof DistinctExpression) { et.setDistinct(((DistinctExpression) o).distinct); } else if (o instanceof Expression) { et.add(args[i].expr()); } else { throw new QuerySyntaxException(Messages.get("dsl.arguments.error3", operator));
/** * Return a ExpressionList specifying propertyName contains value. * * @param expressionList the ExpressionList to add contains expression * @param propertyName the property name of entity bean. * @param value contains value, like %value%. * @param <T> the type of entity. * @return a ExpressionList specifying propertyName contains value. */ public static <T> ExpressionList<T> containsIfNoneBlank(ExpressionList<T> expressionList, String propertyName, String value) { Assert.notNull(expressionList, "expressionList must not null"); Assert.hasText(propertyName, "propertyName must not blank"); if (StringUtils.hasText(value)) { return expressionList.contains(propertyName, value); } return expressionList; }
@Override public void enterConditional_term(EQLParser.Conditional_termContext ctx) { int childCount = ctx.getChildCount(); if (childCount > 1) { pushExprList(peekExprList().and()); } }