@SuppressWarnings("unchecked") public static <D> EntityPathBase<D> var(D arg) { String var = "var"+ arg.getClass().getSimpleName() + "_" + arg.toString().replace(' ', '_'); return new PathBuilder<D>((Class)arg.getClass(), var); }
/** * {@inheritDoc} */ @Override public <T> BooleanExpression createStringLikeExpression( PathBuilder<T> entityPath, String fieldName, String searchStr) { if (StringUtils.isEmpty(searchStr)) { return null; } String str = "%".concat(searchStr.toLowerCase()).concat("%"); BooleanExpression expression = entityPath.getString(fieldName).lower() .like(str); return expression; }
throw new IllegalArgumentException(String.format( "Can't found field '%s' on entity '%s'", fieldName, entityPath.getType())); return entityPath.get(fieldName).eq(searchObj); return entityPath.get(fieldName).in(searchObj); return entityPath.get(fieldName).ne(searchObj); return entityPath.get(fieldName).notIn(searchObj); return entityPath.get(fieldName).isNull(); return entityPath.get(fieldName).isNotNull(); return entityPath.get(fieldName).eq(searchObj);
/** * @param path * @return */ public BooleanPath get(BooleanPath path) { BooleanPath newPath = getBoolean(toString(path)); return addMetadataOf(newPath, path); }
/** * @param path * @return */ public StringPath get(StringPath path) { StringPath newPath = getString(toString(path)); return addMetadataOf(newPath, path); }
public Projection(Class<T> targetClass) { PathBuilder<T> entity = new PathBuilder<T>( targetClass, "entity" ); Field[] fields = targetClass.getFields(); Expression[] fieldExpressions = new Expression[fields.length]; for( int i = 0; i < fields.length; i++ ) { fieldExpressions[i] = entity.getString( fields[ i ].getName() ); } bean = Projections.fields(targetClass, fieldExpressions); }
default Iterable<CollectorItem> findAllByOptionNameValueAndCollectorIdsIn(String optionName, String optionValue, List<ObjectId> collectorIds) { PathBuilder<CollectorItem> path = new PathBuilder<>(CollectorItem.class, "collectorItem"); BooleanBuilder builder = new BooleanBuilder(); builder.and(path.get("collectorId", ObjectId.class).in(collectorIds)); builder.and(path.get("options", Map.class).get(optionName, String.class).eq(optionValue)); return findAll(builder.getValue()); } }
public static PathBuilder<?> join(JPACommonQuery<?> query, PathBuilder<?> builder, Map<String, PathBuilder<?>> joins, String path) { PathBuilder<?> rv = joins.get(path); if (rv == null) { if (path.contains(".")) { String[] tokens = DOT.split(path); String[] parent = new String[tokens.length - 1]; System.arraycopy(tokens, 0, parent, 0, tokens.length - 1); String parentKey = StringUtils.join(parent, "."); builder = join(query, builder, joins, parentKey); rv = new PathBuilder(Object.class, StringUtils.join(tokens, "_")); query.leftJoin((EntityPath)builder.get(tokens[tokens.length - 1]), rv); } else { rv = new PathBuilder(Object.class, path); query.leftJoin((EntityPath)builder.get(path), rv); } joins.put(path, rv); } return rv; }
/** * {@inheritDoc} */ @Override public <T> BooleanExpression createStringExpression( PathBuilder<T> entityPath, String fieldName, Object searchObj, String operator) { if (StringUtils.equalsIgnoreCase(operator, OPERATOR_GOE)) { return entityPath.getString(fieldName).goe((String) searchObj); } else if (StringUtils.equalsIgnoreCase(operator, "gt")) { return entityPath.getString(fieldName).gt((String) searchObj); } else if (StringUtils.equalsIgnoreCase(operator, OPERATOR_LOE)) { return entityPath.getString(fieldName).loe((String) searchObj); } else if (StringUtils.equalsIgnoreCase(operator, "lt")) { return entityPath.getString(fieldName).lt((String) searchObj); } else if (StringUtils.equalsIgnoreCase(operator, "like")) { return entityPath.getString(fieldName).like((String) searchObj); } return entityPath.get(fieldName).eq(searchObj); }
default List<Component> findByCollectorTypeAndItemIdIn(CollectorType collectorType, List<ObjectId> collectorItemIds) { BooleanBuilder builder = new BooleanBuilder(); PathBuilder<Component> path = new PathBuilder<>(Component.class, "components"); builder.and(path.get("collectorItems", Map.class).get(collectorType.toString(),List.class).get("id", ObjectId.class).in(collectorItemIds)); return (List<Component>) findAll(builder.getValue()); } }
default Iterable<CollectorItem> findAllByOptionNameValue(String optionName, String optionValue) { PathBuilder<CollectorItem> path = new PathBuilder<>(CollectorItem.class, "collectorItem"); BooleanBuilder builder = new BooleanBuilder(); builder.and(path.get("options", Map.class).get(optionName, String.class).eq(optionValue)); return findAll(builder.getValue()); }
/** * {@inheritDoc} */ @Override public <T> BooleanExpression createBooleanExpression( PathBuilder<T> entityPath, String fieldName, Object searchObj, String operator) { Boolean value = BooleanUtils.toBooleanObject((String) searchObj); if (value != null) { if (StringUtils.equalsIgnoreCase(operator, OPERATOR_GOE)) { return entityPath.getBoolean(fieldName).goe(value); } else if (StringUtils.equalsIgnoreCase(operator, "gt")) { return entityPath.getBoolean(fieldName).gt(value); } else if (StringUtils.equalsIgnoreCase(operator, OPERATOR_LOE)) { return entityPath.getBoolean(fieldName).loe(value); } else if (StringUtils.equalsIgnoreCase(operator, "lt")) { return entityPath.getBoolean(fieldName).lt(value); } } return entityPath.get(fieldName).eq(searchObj); }
NumberPath numberExpression = null; if (BigDecimal.class.isAssignableFrom(fieldType)) { numberExpression = entityPath.getNumber(fieldName, (Class<BigDecimal>) fieldType); numberExpression = entityPath.getNumber(fieldName, (Class<BigInteger>) fieldType); numberExpression = entityPath.getNumber(fieldName, (Class<Byte>) fieldType); numberExpression = entityPath.getNumber(fieldName, (Class<Double>) fieldType); numberExpression = entityPath.getNumber(fieldName, (Class<Float>) fieldType); numberExpression = entityPath.getNumber(fieldName, (Class<Integer>) fieldType); numberExpression = entityPath.getNumber(fieldName, (Class<Long>) fieldType); numberExpression = entityPath.getNumber(fieldName, (Class<Short>) fieldType); return entityPath.get(fieldName).eq(searchObj);
/** * Get a PathBuilder for the given property with the given type * * @param <A> * @param property property name * @param type * @return */ @SuppressWarnings("unchecked") public <A> PathBuilder<A> get(String property, Class<A> type) { PathBuilder<A> path = (PathBuilder<A>) properties.get(property); if (path == null || !type.isAssignableFrom(path.getType())) { Class<? extends A> vtype = validate(property, type); path = new PathBuilder<A>(vtype, forProperty(property), validator); properties.put(property, path); } return path; }
PathBuilder<T> entity = new PathBuilder<T>(entityClass, "entity"); LOGGER.debug( "findByCriteria handle baseSearch by map-of-values for entity '{}'...", entity.getType());
/** * Get a PathBuilder instance for the given property * * @param property property name * @return */ @SuppressWarnings("unchecked") public PathBuilder<Object> get(String property) { PathBuilder<Object> path = (PathBuilder) properties.get(property); if (path == null) { Class<?> vtype = validate(property, Object.class); path = new PathBuilder<Object>(vtype, forProperty(property), validator); properties.put(property, path); } return path; }
@Test public void ListAccess() throws Exception { query.from(user); query.where(user.getList("buddyList", User.class).get(0).getString("name").eq("XXX")); assertEquals("SELECT * WHERE { ?user ?_c2 ?_c3 ; ?_c4 ?user_buddyList . ?user_buddyList ?_c6 ?_var_a . ?_var_a ?_c8 ?user_buddyList_0_name }"); }