use of com.querydsl.core.types.Path in project spring-data-keyvalue by spring-projects.
the class KeyValueQuerydslUtils method buildOrderPropertyPathFrom.
/**
* 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;
}
use of com.querydsl.core.types.Path in project spring-data-commons by spring-projects.
the class PropertyPathInformation method reifyPath.
private static Path<?> reifyPath(EntityPathResolver resolver, PropertyPath path, Optional<Path<?>> base) {
Optional<Path<?>> map = //
base.filter(it -> it instanceof CollectionPathBase).map(CollectionPathBase.class::cast).map(//
CollectionPathBase::any).map(//
Path.class::cast).map(it -> reifyPath(resolver, path, Optional.of(it)));
return map.orElseGet(() -> {
Path<?> entityPath = base.orElseGet(() -> resolver.createPath(path.getOwningType().getType()));
Field field = org.springframework.data.util.ReflectionUtils.findRequiredField(entityPath.getClass(), path.getSegment());
Object value = ReflectionUtils.getField(field, entityPath);
PropertyPath next = path.next();
if (next != null) {
return reifyPath(resolver, next, Optional.of((Path<?>) value));
}
return (Path<?>) value;
});
}
use of com.querydsl.core.types.Path in project querydsl by querydsl.
the class AbstractHibernateQuery method createQuery.
private Query createQuery(@Nullable QueryModifiers modifiers, boolean forCount) {
JPQLSerializer serializer = serialize(forCount);
String queryString = serializer.toString();
logQuery(queryString);
Query query = session.createQuery(queryString);
HibernateUtil.setConstants(query, serializer.getConstants(), getMetadata().getParams());
if (fetchSize > 0) {
query.setFetchSize(fetchSize);
}
if (timeout > 0) {
query.setTimeout(timeout);
}
if (cacheable != null) {
query.setCacheable(cacheable);
}
if (cacheRegion != null) {
query.setCacheRegion(cacheRegion);
}
if (comment != null) {
query.setComment(comment);
}
if (readOnly != null) {
query.setReadOnly(readOnly);
}
for (Map.Entry<Path<?>, LockMode> entry : lockModes.entrySet()) {
query.setLockMode(entry.getKey().toString(), entry.getValue());
}
if (flushMode != null) {
query.setFlushMode(flushMode);
}
if (modifiers != null && modifiers.isRestricting()) {
Integer limit = modifiers.getLimitAsInteger();
Integer offset = modifiers.getOffsetAsInteger();
if (limit != null) {
query.setMaxResults(limit);
}
if (offset != null) {
query.setFirstResult(offset);
}
}
// set transformer, if necessary
Expression<?> projection = getMetadata().getProjection();
if (!forCount && projection instanceof FactoryExpression) {
query.setResultTransformer(new FactoryExpressionTransformer((FactoryExpression<?>) projection));
}
return query;
}
use of com.querydsl.core.types.Path in project querydsl by querydsl.
the class TypesBase method create_tables.
@Test
public void create_tables() {
Map<Class<?>, Object> instances = new LinkedHashMap<>();
instances.put(BigInteger.class, BigInteger.valueOf(1));
instances.put(Long.class, 1L);
instances.put(Integer.class, 1);
instances.put(Short.class, (short) 1);
instances.put(Byte.class, (byte) 1);
instances.put(BigDecimal.class, BigDecimal.valueOf(1.0));
instances.put(Double.class, 1.0);
instances.put(Float.class, 1.0f);
instances.put(Boolean.class, Boolean.TRUE);
instances.put(Character.class, 'a');
instances.put(String.class, "ABC");
for (Map.Entry<Class<?>, Object> entry : instances.entrySet()) {
String tableName = "test_" + entry.getKey().getSimpleName();
new DropTableClause(connection, configuration, tableName).execute();
CreateTableClause c = new CreateTableClause(connection, configuration, tableName).column("col", entry.getKey());
if (entry.getKey().equals(String.class)) {
c.size(256);
}
c.execute();
RelationalPath<Object> entityPath = new RelationalPathBase<Object>(Object.class, tableName, "PUBLIC", tableName);
Path<?> columnPath = Expressions.path(entry.getKey(), entityPath, "col");
insert(entityPath).set((Path) columnPath, entry.getValue()).execute();
new DropTableClause(connection, configuration, tableName).execute();
}
}
use of com.querydsl.core.types.Path in project querydsl by querydsl.
the class CollUpdateClause method execute.
@Override
public long execute() {
int rv = 0;
for (T match : query.fetch()) {
BeanMap beanMap = new BeanMap(match);
for (Map.Entry<Path<?>, Object> entry : paths.entrySet()) {
// TODO : support deep updates as well
String propertyName = entry.getKey().getMetadata().getName();
beanMap.put(propertyName, entry.getValue());
}
rv++;
}
return rv;
}
Aggregations