@Override @Transactional(readOnly = true) public Customer findById(Long id) { if (id == null) { return null; } return findOne(qCustomer.id.eq(id)); }
return numberExpression.eq((N) valueConverted); return numberExpression.gt((N) valueConverted); return numberExpression.lt((N) valueConverted); return numberExpression.goe((N) valueConverted); return numberExpression.loe((N) valueConverted); return numberExpression.ne((N) valueConverted); return numberExpression.between((N) valueFromConverted, (N) valueToConverted); Matcher isNullMatcher = isNullOperator.matcher(searchStr); if (isNullMatcher.matches()) { return numberExpression.isNull(); Matcher isNotNullMatcher = isNotNullOperator.matcher(searchStr); if (isNotNullMatcher.matches()) { return numberExpression.isNotNull();
public List<ApaVwPersonasItems> getItemsAccesiblesByPersona(String codigoAplicacion, Long personaId) { JPAQuery query = new JPAQuery(entityManager); QApaVwPersonasItems apaVWPersonasItems = QApaVwPersonasItems.apaVwPersonasItems; query.from(apaVWPersonasItems) .where(apaVWPersonasItems.personaId.eq(new BigDecimal(personaId)).and( apaVWPersonasItems.aplicacionCodigo.eq(codigoAplicacion))) .orderBy(apaVWPersonasItems.orden.asc()); return query.list(apaVWPersonasItems); }
@Override public Set<Worklog> getWorklogsForIds(final Set<Long> worklogIds, final int maxResults) { return dbConnectionManager.executeQuery(dbConnection -> dbConnection.newSqlQuery() .from(WORKLOG) .leftJoin(QProjectRole.PROJECT_ROLE) .on(QProjectRole.PROJECT_ROLE.id.eq(WORKLOG.rolelevel)) .where(WORKLOG.id.in(worklogIds)) .limit(maxResults) .list(WORKLOG_ALIASED_PROJECT_ROLE_TUPLE) ).stream() .map(queryDSLWorklogFactory::createWorklogWithAliasedIdColumn) .collect(Collectors.toSet()); }
@Test @ExcludeIn(MYSQL) // doesn't work in Eclipselink public void Case4() { NumberExpression<Float> numExpression = cat.bodyWeight.floatValue().divide(otherCat.bodyWeight.floatValue()).multiply(100); NumberExpression<Float> numExpression2 = cat.id.when(0).then(0.0F).otherwise(numExpression); assertEquals(ImmutableList.of(200, 150, 133, 125, 120), query().from(cat, otherCat) .where(cat.id.eq(otherCat.id.add(1))) .orderBy(cat.id.asc(), otherCat.id.asc()) .list(numExpression2.intValue())); }
public ConstantsCache<Priority> get() { final List<PriorityDTO> priorityList = dbConnectionManager.executeQuery(dbConnection -> dbConnection.newSqlQuery().from(PRIORITY) .orderBy(PRIORITY.sequence.asc()).list(PRIORITY)); final ImmutableMap.Builder<String, Priority> builder = ImmutableMap.builder(); priorityList.stream().map(issueConstantFactory::createPriority).forEach(p -> builder.put(p.getId(), p)); return new ConstantsCache<>(builder.build()); } }
.from(a) .where(a.avatarType.eq(ISSUE_TYPE_AVATAR) .and(a.systemAvatar.eq(TRUE)) .and(a.fileName.in(issueTypeIconsToReplace.keySet()))) .groupBy(a.fileName) .map(a.fileName, a.id.min()); .and(a.systemAvatar.eq(TRUE)) .and(a.fileName.in(issueTypeIconsToReplace.values()))) .groupBy(a.fileName) .map(a.fileName, a.id.min()); .where(it.avatar.eq(iconToReplaceId)) .set(it.avatar, replacementIconId) .execute(); .delete(a) .where(a.avatarType.eq(ISSUE_TYPE_AVATAR) .and(a.systemAvatar.eq(TRUE)) .and(a.fileName.in(issueTypeIconsToReplace.keySet()))) .execute(); .update(a) .where(a.avatarType.eq(ISSUE_TYPE_AVATAR) .and(a.systemAvatar.eq(TRUE)) .and(a.fileName.eq(oldIconName))) .set(a.fileName, newIconName) .from(a)
@Override public List<Worklog> getByIssue(final Issue issue) { checkArgument(issue != null, "Cannot resolve worklogs for null issue."); final BooleanExpression query = issue.getId() != null ? WORKLOG.issue.eq(issue.getId()) : WORKLOG.issue.isNull(); return dbConnectionManager.executeQuery(dc -> dc.newSqlQuery() .from(WORKLOG) .leftJoin(QProjectRole.PROJECT_ROLE) .on(QProjectRole.PROJECT_ROLE.id.eq(WORKLOG.rolelevel)) .where(query) .orderBy(WORKLOG.created.asc()) .list(WORKLOG_PROJECT_ROLE_TUPLE) ).stream() .map(t -> queryDSLWorklogFactory.createWorklog(issue, t)) .collect(Collectors.toList()); }
@Test public void OrderBy() { JPQLQuery query = query().from(cat1).where(cat1.alive); NumberSubQuery<Double> subquery = sub().from(cat).where(cat.mate.id.eq(cat1.id)).unique(cat.floatProperty.avg()); query.orderBy(subquery.subtract(-1.0f).asc()); assertEquals("select cat1 from Cat cat1 where cat1.alive order by (select avg(cat.floatProperty) from Cat cat where cat.mate.id = cat1.id) - ?1 asc", query.toString().replace("\n", " ")); }
@Test @Ignore // isn't a valid JPQL query public void Subquery_UniqueResult() { QCat cat2 = new QCat("cat2"); BooleanExpression exists = new JPASubQuery().from(cat2).where(cat2.eyecolor.isNotNull()).exists(); assertNotNull(query().from(cat) .where(cat.breed.eq(0).not()) .singleResult(new QCatSummary(cat.breed.count(), exists))); }
Number value = NumberUtils.createNumber((String) searchObj); if (StringUtils.equalsIgnoreCase(operator, OPERATOR_GOE)) { return numberExpression.goe(value); return numberExpression.gt(value); return numberExpression.like((String) searchObj); return numberExpression.loe(value); return numberExpression.lt(value);
@Override public void removeProductsMoreExpensiveThan(BigDecimal price) { delete(product).where(product.price.gt(price)).execute(); } }
@Test public void Order() { NumberPath<Double> weight = new NumberPath<Double>(Double.class, "weight"); query().from(cat).orderBy(weight.asc()).list(cat.bodyWeight.as(weight)); }
@Test public void GroupingOperationsAndNullChecks() { // in, not in, between, is null, is not null, is empty, is not empty, // member of and not member of // in, // not in, // between, // is null, // is not null, // is empty, // is not empty, // member of // not member of kitten.in(cat.kittens); kitten.in(cat.kittens).not(); kitten.bodyWeight.between(10, 20); kitten.bodyWeight.isNull(); kitten.bodyWeight.isNotNull(); cat.kittens.isEmpty(); cat.kittens.isNotEmpty(); }
@Override @Nonnull public Set<ProjectRoleActor> getAllRoleActorsForUser(@Nullable final ApplicationUser user) { if (user == null) { return ImmutableSet.of(); } final List<String> groupNames = groupManager.getGroupNamesForUser(user).stream().map(IdentifierUtils::toLowerCase).collect(Collectors.toList()); final ImmutableSet.Builder<ProjectRoleActor> resultsBuilder = ImmutableSet.builder(); dbConnectionManager.execute(dbConnection -> { final QProjectRoleActor pra = new QProjectRoleActor("pra"); //We are not going to filter group names here because we need to compare them using IdentifierUtils.toLowerCase try (CloseableIterator<Tuple> roleActorTuples = dbConnection.newSqlQuery(). from(pra). where(pra.roletype.eq(ProjectRoleActor.GROUP_ROLE_ACTOR_TYPE).and(pra.pid.isNotNull())). iterate(Projections.tuple(pra.id, pra.pid, pra.projectroleid, pra.roletype, pra.roletypeparameter))) { addMatchingActors(roleActorTuples, pra, groupNames, resultsBuilder); } }); return resultsBuilder.build(); }
private void deleteMinusOneUserLocaleProperty(List<Long> ids, DbConnection dbConnection) { QOSPropertyEntry propertyEntry = QOSPropertyEntry.O_S_PROPERTY_ENTRY; QOSPropertyString propertyString = QOSPropertyString.O_S_PROPERTY_STRING; dbConnection.delete(propertyString).where(propertyString.id.in(ids)).execute(); dbConnection.delete(propertyEntry).where(propertyEntry.id.in(ids)).execute(); }