com.querydsl.core.types.dsl.Expressions Java Examples
The following examples show how to use
com.querydsl.core.types.dsl.Expressions.
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: UserService.java From eds-starter6-jpa with Apache License 2.0 | 6 votes |
private boolean isLastAdmin(Long id) { JPAQuery<Integer> query = this.jpaQueryFactory.select(Expressions.ONE) .from(QUser.user); BooleanBuilder bb = new BooleanBuilder(); bb.or(QUser.user.authorities.eq(Authority.ADMIN.name())); bb.or(QUser.user.authorities.endsWith("," + Authority.ADMIN.name())); bb.or(QUser.user.authorities.contains("," + Authority.ADMIN.name() + ",")); bb.or(QUser.user.authorities.startsWith(Authority.ADMIN.name() + ",")); query.where(QUser.user.id.ne(id).and(QUser.user.deleted.isFalse()) .and(QUser.user.enabled.isTrue()).and(bb)); return query.fetchFirst() == null; }
Example #2
Source File: KeyValueQuerydslUtils.java From spring-data-keyvalue with Apache License 2.0 | 6 votes |
/** * Creates an {@link Expression} for the given {@link Order} property. * * @param order must not be {@literal null}. * @param builder must not be {@literal null}. * @return */ private static Expression<?> buildOrderPropertyPathFrom(Order order, PathBuilder<?> builder) { Assert.notNull(order, "Order must not be null!"); Assert.notNull(builder, "Builder must not be null!"); PropertyPath path = PropertyPath.from(order.getProperty(), builder.getType()); Expression<?> sortPropertyExpression = builder; while (path != null) { if (!path.hasNext() && order.isIgnoreCase()) { // if order is ignore-case we have to treat the last path segment as a String. sortPropertyExpression = Expressions.stringPath((Path<?>) sortPropertyExpression, path.getSegment()).lower(); } else { sortPropertyExpression = Expressions.path(path.getType(), (Path<?>) sortPropertyExpression, path.getSegment()); } path = path.next(); } return sortPropertyExpression; }
Example #3
Source File: QueryDSLIntegrationTest.java From tutorials with MIT License | 6 votes |
@Test public void whenGroupingByTitle_thenReturnsTuples() { QBlogPost blogPost = QBlogPost.blogPost; NumberPath<Long> count = Expressions.numberPath(Long.class, "c"); List<Tuple> userTitleCounts = queryFactory.select(blogPost.title, blogPost.id.count().as(count)) .from(blogPost) .groupBy(blogPost.title) .orderBy(count.desc()) .fetch(); assertEquals("Hello World!", userTitleCounts.get(0).get(blogPost.title)); assertEquals(new Long(2), userTitleCounts.get(0).get(count)); assertEquals("My Second Post", userTitleCounts.get(1).get(blogPost.title)); assertEquals(new Long(1), userTitleCounts.get(1).get(count)); }
Example #4
Source File: QuerydslQueryBackend.java From crnk-framework with Apache License 2.0 | 5 votes |
private Expression<?> handleConversions(Expression<?> expression, FilterOperator operator) { // convert to String for LIKE operators if (expression.getType() != String.class && (operator == FilterOperator.LIKE)) { return Expressions.stringOperation(Ops.STRING_CAST, expression); } else { return expression; } }
Example #5
Source File: UserService.java From eds-starter6-jpa with Apache License 2.0 | 5 votes |
public static boolean isEmailUnique(JPAQueryFactory jpaQueryFactory, Long userId, String email) { if (StringUtils.hasText(email)) { BooleanBuilder bb = new BooleanBuilder( QUser.user.email.equalsIgnoreCase(email)); if (userId != null) { bb.and(QUser.user.id.ne(userId)); } return jpaQueryFactory.select(Expressions.ONE).from(QUser.user).where(bb) .fetchFirst() == null; } return true; }
Example #6
Source File: UserService.java From eds-starter6-jpa with Apache License 2.0 | 5 votes |
public static boolean isLoginNameUnique(JPAQueryFactory jpaQueryFactory, Long userId, String loginName) { if (StringUtils.hasText(loginName)) { BooleanBuilder bb = new BooleanBuilder( QUser.user.loginName.equalsIgnoreCase(loginName)); if (userId != null) { bb.and(QUser.user.id.ne(userId)); } return jpaQueryFactory.select(Expressions.ONE).from(QUser.user).where(bb) .fetchFirst() == null; } return true; }
Example #7
Source File: Startup.java From eds-starter6-jpa with Apache License 2.0 | 5 votes |
private void init() { if (this.jpaQueryFactory.select(Expressions.ONE).from(QUser.user) .fetchFirst() == null) { // admin user User adminUser = new User(); adminUser.setLoginName("admin"); adminUser.setEmail("[email protected]"); adminUser.setFirstName("admin"); adminUser.setLastName("admin"); adminUser.setLocale("en"); adminUser.setPasswordHash(this.passwordEncoder.encode("admin")); adminUser.setEnabled(true); adminUser.setDeleted(false); adminUser.setAuthorities(Authority.ADMIN.name()); this.jpaQueryFactory.getEntityManager().persist(adminUser); // normal user User normalUser = new User(); normalUser.setLoginName("user"); normalUser.setEmail("[email protected]"); normalUser.setFirstName("user"); normalUser.setLastName("user"); normalUser.setLocale("de"); normalUser.setPasswordHash(this.passwordEncoder.encode("user")); normalUser.setEnabled(true); adminUser.setDeleted(false); normalUser.setAuthorities(Authority.USER.name()); this.jpaQueryFactory.getEntityManager().persist(normalUser); } }
Example #8
Source File: GlobalFilter.java From spring-data-jpa-datatables with Apache License 2.0 | 4 votes |
@Override public com.querydsl.core.types.Predicate createPredicate(PathBuilder<?> pathBuilder, String attributeName) { StringOperation path = Expressions.stringOperation(Ops.STRING_CAST, pathBuilder.get(attributeName)); return path.lower().like(escapedRawValue, '~'); }
Example #9
Source File: QuerydslUtil.java From codeway_service with GNU General Public License v3.0 | 2 votes |
/** * 根据字符串字段获取排序类 * * @param order:Order.DESC * @param fieldName:排序字段 * @return OrderSpecifier * @see https://stackoverflow.com/questions/39576236/dynamic-sorting-in-querydsl */ public static OrderSpecifier<?> getSortedColumn(Order order, Path<?> parent, String fieldName) { Path<Object> fieldPath = Expressions.path(Object.class, parent, fieldName); return new OrderSpecifier(order, fieldPath); }
Example #10
Source File: QuerydslUtil.java From codeway_service with GNU General Public License v3.0 | 2 votes |
/** * 根据字符串字段获取排序类 * * @param order:Order.DESC * @param fieldName:排序字段 * @return OrderSpecifier * @see https://stackoverflow.com/questions/39576236/dynamic-sorting-in-querydsl */ public static OrderSpecifier<?> getSortedColumn(Order order, Path<?> parent, String fieldName) { Path<Object> fieldPath = Expressions.path(Object.class, parent, fieldName); return new OrderSpecifier(order, fieldPath); }