/** * Creates a new {@link N1qlQuery} for the given class, this method build a query like: * * <pre> * select b.* from bucket b where b._class = 'model.Beer' * </pre> * * @param bucket Bucket name. * @param entityClass Entity class. * @return A query. */ public static GroupByPath from(final String bucket, final Class<?> entityClass) { String alias = String.valueOf(entityClass.getSimpleName().charAt(0)); return Select.select(alias + ".*") .from(i(bucket) + " " + alias) .where(path(alias, CLASS).eq(s(entityClass.getName()))); }
asPath.where(x(CouchbaseConstants.KUNDERA_ENTITY).eq(x("'" + m.getTableName() + "'")));
/** * Combines two expressions with the equals operator ("="). * * @param right the expression to combine. * @return the combined expressions. */ public Expression eq(JsonArray right) { return eq(x(right)); }
/** * Combines two expressions with the equals operator ("="). * * @param right the expression to combine. * @return the combined expressions. */ public Expression eq(int right) { return eq(x(right)); }
/** * Combines two expressions with the equals operator ("="). * * @param right the expression to combine. * @return the combined expressions. */ public Expression eq(long right) { return eq(x(right)); }
/** * Combines two expressions with the equals operator ("="). * * @param right the expression to combine. * @return the combined expressions. */ public Expression eq(String right) { return eq(x(right)); }
/** * Combines two expressions with the equals operator ("="). * * @param right the expression to combine. * @return the combined expressions. */ public Expression eq(float right) { return eq(x(right)); }
/** * Combines two expressions with the equals operator ("="). * * @param right the expression to combine. * @return the combined expressions. */ public Expression eq(boolean right) { return eq(x(right)); }
/** * Combines two expressions with the equals operator ("="). * * @param right the expression to combine. * @return the combined expressions. */ public Expression eq(JsonObject right) { return eq(x(right)); }
/** * Combines two expressions with the equals operator ("="). * * @param right the expression to combine. * @return the combined expressions. */ public Expression eq(double right) { return eq(x(right)); }
/** * Query and get a result by username. * * @param usernameAttribute the username attribute * @param usernameValue the username value * @return the n1ql query result * @throws GeneralSecurityException the general security exception */ public N1qlQueryResult query(final String usernameAttribute, final String usernameValue) throws GeneralSecurityException { val theBucket = getBucket(); val statement = Select.select("*") .from(Expression.i(theBucket.name())) .where(Expression.x(usernameAttribute).eq('\'' + usernameValue + '\'')); LOGGER.debug("Running query [{}] on bucket [{}]", statement.toString(), theBucket.name()); val query = N1qlQuery.simple(statement); val result = theBucket.query(query, timeout, TimeUnit.MILLISECONDS); if (!result.finalSuccess()) { LOGGER.error("Couchbase query failed with [{}]", result.errors() .stream() .map(JsonObject::toString) .collect(Collectors.joining(","))); throw new GeneralSecurityException("Could not locate account for user " + usernameValue); } return result; }
/** * Produces an {@link Expression} that can serve as a WHERE clause criteria to only select documents in a bucket * that matches a particular Spring Data entity (as given by the {@link EntityMetadata} parameter). * * @param baseWhereCriteria the other criteria of the WHERE clause, or null if none. * @param converter the {@link CouchbaseConverter} giving the attribute storing the type information can be extracted. * @param entityInformation the expected type information. * @return an {@link Expression} to be used as a WHERE clause, that additionally restricts on the given type. */ public static Expression createWhereFilterForEntity(Expression baseWhereCriteria, CouchbaseConverter converter, EntityMetadata<?> entityInformation) { //add part that filters on type key String typeKey = converter.getTypeKey(); String typeValue = entityInformation.getJavaType().getName(); Expression typeSelector = i(typeKey).eq(s(typeValue)); if (baseWhereCriteria == null) { baseWhereCriteria = typeSelector; } else { baseWhereCriteria = x("(" + baseWhereCriteria.toString() + ")").and(typeSelector); } return baseWhereCriteria; }
/** * Produces an {@link Expression} that can serve as a WHERE clause criteria to only select documents in a bucket * that matches a particular Spring Data entity (as given by the {@link EntityMetadata} parameter). * * @param baseWhereCriteria the other criteria of the WHERE clause, or null if none. * @param converter the {@link CouchbaseConverter} giving the attribute storing the type information can be extracted. * @param entityInformation the expected type information. * @return an {@link Expression} to be used as a WHERE clause, that additionally restricts on the given type. */ public static Expression createWhereFilterForEntity(Expression baseWhereCriteria, CouchbaseConverter converter, EntityMetadata<?> entityInformation) { //add part that filters on type key String typeKey = converter.getTypeKey(); String typeValue = entityInformation.getJavaType().getName(); Expression typeSelector = i(typeKey).eq(s(typeValue)); if (baseWhereCriteria == null) { baseWhereCriteria = typeSelector; } else { baseWhereCriteria = x("(" + baseWhereCriteria.toString() + ")").and(typeSelector); } return baseWhereCriteria; }
public List<User> findAll() { if (useCouchbaseForFindAll && couchbaseBucket != null) { try { Statement statement = Select.select("avatarId", "bio", "displayName", "id", "nickname").from(x("default")) .where(x("type").eq(s("user"))).groupBy(x("displayName")); N1qlQueryResult queryResult = couchbaseBucket.query(statement); List<User> users = new ArrayList<User>(); for (N1qlQueryRow qr : queryResult) { users.add(User.fromJsonObject(qr.value())); } return users; } catch (Exception e) { throw new DogePoolException("Error while getting list of users from database", Error.DATABASE, HttpStatus.INTERNAL_SERVER_ERROR, e); } } else { return Arrays.asList(User.USER, User.OTHERUSER); } } }
.where(x(typeKey).eq(s(type))) .using(IndexType.GSI);
.where(x(typeKey).eq(s(type))) .using(IndexType.GSI);
@Override public Observable<IndexInfo> listN1qlIndexes() { Expression whereClause = x("keyspace_id").eq(s(bucket)) .and(i("using").eq(s("gsi"))); Statement listIndexes = select("idx.*").from(x("system:indexes").as("idx")).where(whereClause) .orderBy(Sort.desc("is_primary"), Sort.asc("name")); final Func1<List<JsonObject>, Observable<AsyncN1qlQueryRow>> errorHandler = errorsToThrowable( "Error while listing indexes: "); return queryExecutor.execute( N1qlQuery.simple(listIndexes, N1qlParams.build().consistency(ScanConsistency.REQUEST_PLUS)), env, env.managementTimeout(), TimeUnit.MILLISECONDS) .flatMap(new Func1<AsyncN1qlQueryResult, Observable<AsyncN1qlQueryRow>>() { @Override public Observable<AsyncN1qlQueryRow> call(final AsyncN1qlQueryResult aqr) { return aqr.finalSuccess() .flatMap(new Func1<Boolean, Observable<AsyncN1qlQueryRow>>() { @Override public Observable<AsyncN1qlQueryRow> call(Boolean success) { if (success) { return aqr.rows(); } else { return aqr.errors().toList().flatMap(errorHandler); } } }); } }).map(ROW_VALUE_TO_INDEXINFO); }
return x(document.getName()).eq(x(PARAM_PREFIX + document.getName())); case LESSER_THAN: return x(document.getName()).lt(x(PARAM_PREFIX + document.getName()));