本文整理了Java中com.querydsl.core.types.ExpressionUtils.as()
方法的一些代码示例,展示了ExpressionUtils.as()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ExpressionUtils.as()
方法的具体详情如下:
包路径:com.querydsl.core.types.ExpressionUtils
类名称:ExpressionUtils
方法名:as
[英]Create an alias expression with the given source and alias
[中]使用给定的源和别名创建别名表达式
代码示例来源:origin: querydsl/querydsl
@SuppressWarnings("unchecked")
protected <D> Expression<D> createAlias(Expression<?> expr, Path<D> alias) {
assertRoot(alias);
return ExpressionUtils.as((Expression) expr, alias);
}
代码示例来源:origin: querydsl/querydsl
/**
* Create an alias expression with the given source and alias
*
* @param <D> type of expression
* @param source source
* @param alias alias
* @return source as alias
*/
public static <D> Expression<D> as(Expression<D> source, String alias) {
return as(source, path(source.getType(), alias));
}
代码示例来源:origin: querydsl/querydsl
@SuppressWarnings("unchecked")
public Q on(Predicate... conditions) {
queryMixin.addJoin(JoinType.JOIN, ExpressionUtils.as((Path) ref, target));
queryMixin.on(conditions);
return queryMixin.getSelf();
}
代码示例来源:origin: spring-projects/spring-data-mongodb
/**
* Add the given join conditions.
*
* @param conditions must not be {@literal null}.
* @return the target {@link QueryMixin}.
* @see QueryMixin#on(Predicate)
*/
@SuppressWarnings("unchecked")
public Q on(Predicate... conditions) {
queryMixin.addJoin(JoinType.JOIN, ExpressionUtils.as((Path) ref, target));
queryMixin.on(conditions);
return queryMixin.getSelf();
}
}
代码示例来源:origin: querydsl/querydsl
@Test
public void with_nested_factoryExpression2() {
QBean<Entity> beanProjection = new QBean<Entity>(Entity.class,
age, ExpressionUtils.as(new Concatenation(name, name2), "name"));
FactoryExpression<Entity> wrappedProjection = FactoryExpressionUtils.wrap(beanProjection);
Entity bean = wrappedProjection.newInstance(30, "Fri","tz");
assertEquals("Fritz", bean.getName());
}
代码示例来源:origin: org.springframework.data/spring-data-mongodb
/**
* Add the given join conditions.
*
* @param conditions must not be {@literal null}.
* @return the target {@link QueryMixin}.
* @see QueryMixin#on(Predicate)
*/
@SuppressWarnings("unchecked")
public Q on(Predicate... conditions) {
queryMixin.addJoin(JoinType.JOIN, ExpressionUtils.as((Path) ref, target));
queryMixin.on(conditions);
return queryMixin.getSelf();
}
}
代码示例来源:origin: com.querydsl/querydsl-sql
@Override
public Expression<T> as(Path<T> alias) {
return ExpressionUtils.as(this, alias);
}
代码示例来源:origin: com.querydsl/querydsl-sql
@Override
public Expression<T> as(String alias) {
return ExpressionUtils.as(this, alias);
}
代码示例来源:origin: com.querydsl/querydsl-sql
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public Q from(SubQueryExpression<?> subQuery, Path<?> alias) {
return queryMixin.from(ExpressionUtils.as((Expression) subQuery, alias));
}
代码示例来源:origin: com.querydsl/querydsl-core
@SuppressWarnings("unchecked")
protected <D> Expression<D> createAlias(Expression<?> expr, Path<D> alias) {
assertRoot(alias);
return ExpressionUtils.as((Expression) expr, alias);
}
代码示例来源:origin: com.querydsl/querydsl-sql
public static <T> Expression<T> union(List<SubQueryExpression<T>> union, Path<T> alias,
boolean unionAll) {
final Expression<T> rv = union(union, unionAll);
return ExpressionUtils.as(rv, alias);
}
代码示例来源:origin: com.querydsl/querydsl-sql
public final SQLSerializer handleSelect(final String sep, final List<? extends Expression<?>> expressions) {
if (inSubquery) {
Set<String> names = Sets.newHashSet();
List<Expression<?>> replacements = Lists.newArrayList();
for (Expression<?> expr : expressions) {
if (expr instanceof Path) {
String name = ColumnMetadata.getName((Path<?>) expr);
if (!names.add(name.toLowerCase())) {
expr = ExpressionUtils.as(expr, "col__" + name + replacements.size());
}
}
replacements.add(expr);
}
return handle(sep, replacements);
} else {
return handle(sep, expressions);
}
}
代码示例来源:origin: com.querydsl/querydsl-core
/**
* Create an alias expression with the given source and alias
*
* @param <D> type of expression
* @param source source
* @param alias alias
* @return source as alias
*/
public static <D> Expression<D> as(Expression<D> source, String alias) {
return as(source, path(source.getType(), alias));
}
代码示例来源:origin: com.querydsl/querydsl-sql
rv.add(ExpressionUtils.as(column, "col" + (++counter)));
代码示例来源:origin: com.querydsl/querydsl-sql
@SuppressWarnings("unchecked")
protected SQLSerializer serialize(boolean forCountRow) {
SQLSerializer serializer = createSerializer();
if (union != null) {
if (queryMixin.getMetadata().getProjection() == null ||
expandProjection(queryMixin.getMetadata().getProjection())
.equals(expandProjection(firstUnionSubQuery.getMetadata().getProjection()))) {
serializer.serializeUnion(union, queryMixin.getMetadata(), unionAll);
} else {
QueryMixin<Q> mixin2 = new QueryMixin<Q>(queryMixin.getMetadata().clone());
Set<Path<?>> paths = getRootPaths(expandProjection(mixin2.getMetadata().getProjection()));
if (paths.isEmpty()) {
mixin2.from(ExpressionUtils.as((Expression) union, defaultQueryAlias));
} else if (paths.size() == 1) {
mixin2.from(ExpressionUtils.as((Expression) union, paths.iterator().next()));
} else {
throw new IllegalStateException("Unable to create serialize union");
}
serializer.serialize(mixin2.getMetadata(), forCountRow);
}
} else {
serializer.serialize(queryMixin.getMetadata(), forCountRow);
}
return serializer;
}
代码示例来源:origin: com.querydsl/querydsl-jpa
@SuppressWarnings("unchecked")
@Override
public Expression<?> visit(Path<?> expr, @Nullable Void context) {
expr = (Path<?>) super.visit(expr, null);
PathMetadata pathMetadata = expr.getMetadata();
if (pathMetadata.getPathType() == PathType.LISTVALUE
|| pathMetadata.getPathType() == PathType.LISTVALUE_CONSTANT) {
Path<?> replacement = replacements.get(expr);
if (replacement == null) {
// join parent as path123 on index(path123) = ...
Path parent = shorten(pathMetadata.getParent(), true);
replacement = ExpressionUtils.path(expr.getType(),
ExpressionUtils.createRootVariable(parent, replacements.size()));
metadata.addJoin(JoinType.LEFTJOIN, ExpressionUtils.as(parent, replacement));
metadata.addJoinCondition(ExpressionUtils.eq(
(Expression) Expressions.operation(Integer.class, JPQLOps.INDEX, replacement),
ExpressionUtils.toExpression(pathMetadata.getElement())));
replacements.put(expr, replacement);
}
return replacement;
} else {
return super.visit(expr, context);
}
}
代码示例来源:origin: com.querydsl/querydsl-jpa
@SuppressWarnings("unchecked")
@Override
public Expression<?> visit(Path<?> expr, @Nullable Void context) {
expr = (Path<?>) super.visit(expr, null);
PathMetadata pathMetadata = expr.getMetadata();
if (pathMetadata.getPathType() == PathType.MAPVALUE
|| pathMetadata.getPathType() == PathType.MAPVALUE_CONSTANT) {
Path<?> replacement = replacements.get(expr);
if (replacement == null) {
// join parent as path123 on key(path123) = ...
Path parent = shorten(pathMetadata.getParent(), true);
ParameterizedExpression parExpr = (ParameterizedExpression) pathMetadata.getParent();
replacement = ExpressionUtils.path(parExpr.getParameter(1),
ExpressionUtils.createRootVariable(parent, replacements.size()));
metadata.addJoin(JoinType.LEFTJOIN, ExpressionUtils.as(parent, replacement));
metadata.addJoinCondition(ExpressionUtils.eq(
Expressions.operation(parExpr.getParameter(0), JPQLOps.KEY, replacement),
ExpressionUtils.toExpression(pathMetadata.getElement())));
replacements.put(expr, replacement);
}
return replacement;
} else {
return super.visit(expr, context);
}
}
代码示例来源:origin: com.querydsl/querydsl-jpa
@SuppressWarnings("unchecked")
@Override
public Expression<?> visit(Operation<?> expr, @Nullable Void context) {
if (expr.getOperator() == Ops.CONTAINS_KEY) {
ParameterizedExpression map = (ParameterizedExpression<?>) expr.getArg(0);
Expression key = expr.getArg(1);
Path replacement = ExpressionUtils.path(map.getParameter(1),
ExpressionUtils.createRootVariable((Path<?>) map, Math.abs(expr.hashCode())));
metadata.addJoin(JoinType.LEFTJOIN, ExpressionUtils.as(map, replacement));
metadata.addJoinCondition(ExpressionUtils.eq(
Expressions.operation(map.getParameter(0), JPQLOps.KEY, replacement),
key));
return ExpressionUtils.isNotNull(replacement);
} else if (expr.getOperator() == Ops.CONTAINS_VALUE) {
ParameterizedExpression<?> map = (ParameterizedExpression<?>) expr.getArg(0);
Expression<?> value = expr.getArg(1);
return Expressions.predicate(JPQLOps.MEMBER_OF, value, map);
} else {
return super.visit(expr, context);
}
}
代码示例来源:origin: com.querydsl/querydsl-jpa
/**
* Shorten the parent path to a length of max 2 elements
*/
private Path<?> shorten(Path<?> path, boolean outer) {
if (aliases.containsKey(path)) {
return aliases.get(path);
} else if (path.getMetadata().isRoot()) {
return path;
} else if (path.getMetadata().getParent().getMetadata().isRoot() && outer) {
return path;
} else {
Class<?> type = JPAQueryMixin.getElementTypeOrType(path);
Path<?> parent = shorten(path.getMetadata().getParent(), false);
Path oldPath = ExpressionUtils.path(path.getType(),
new PathMetadata(parent, path.getMetadata().getElement(), path.getMetadata().getPathType()));
if (oldPath.getMetadata().getParent().getMetadata().isRoot() && outer) {
return oldPath;
} else {
Path newPath = ExpressionUtils.path(type, ExpressionUtils.createRootVariable(oldPath));
aliases.put(path, newPath);
metadata.addJoin(JoinType.LEFTJOIN, ExpressionUtils.as(oldPath, newPath));
return newPath;
}
}
}
代码示例来源:origin: com.querydsl/querydsl-jpa
/**
* Shorten the parent path to a length of max 2 elements
*/
private Path<?> shorten(Path<?> path, boolean outer) {
if (aliases.containsKey(path)) {
return aliases.get(path);
} else if (path.getMetadata().isRoot()) {
return path;
} else if (path.getMetadata().getParent().getMetadata().isRoot() && outer) {
return path;
} else {
Class<?> type = JPAQueryMixin.getElementTypeOrType(path);
Path<?> parent = shorten(path.getMetadata().getParent(), false);
Path oldPath = ExpressionUtils.path(path.getType(),
new PathMetadata(parent, path.getMetadata().getElement(), path.getMetadata().getPathType()));
if (oldPath.getMetadata().getParent().getMetadata().isRoot() && outer) {
return oldPath;
} else {
Path newPath = ExpressionUtils.path(type, ExpressionUtils.createRootVariable(oldPath));
aliases.put(path, newPath);
metadata.addJoin(JoinType.LEFTJOIN, ExpressionUtils.as(oldPath, newPath));
return newPath;
}
}
}
内容来源于网络,如有侵权,请联系作者删除!