本文整理汇总了Java中com.couchbase.client.java.query.N1qlQuery类的典型用法代码示例。如果您正苦于以下问题:Java N1qlQuery类的具体用法?Java N1qlQuery怎么用?Java N1qlQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
N1qlQuery类属于com.couchbase.client.java.query包,在下文中一共展示了N1qlQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
public Cart get(String cartId) {
N1qlParams params = N1qlParams.build().adhoc(false).consistency(ScanConsistency.STATEMENT_PLUS);
JsonObject values = JsonObject.create().put("id", cartId);
N1qlQuery query = N1qlQuery.parameterized("select "+ cartBucketName + ".* from `" + cartBucketName + "` where docType='"+ DocTypes.CartAggregateView.name() +"' and id=$id", values, params);
List<Cart> carts = db.getBucket().async().query(query)
.flatMap(AsyncN1qlQueryResult::rows)
.map(result -> {
return createObject(result.value().toString());
})
.toList()
.timeout(10, TimeUnit.SECONDS)
.toBlocking()
.single();
if(carts.isEmpty()) {
return null;
} else {
return carts.get(0);
}
}
示例2: getCartEvents
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
public List<Event> getCartEvents(String cartId, long snapshotEventSequenceNumber) {
N1qlParams params = N1qlParams.build().adhoc(false).consistency(ScanConsistency.STATEMENT_PLUS);
JsonObject values = JsonObject.create().put("cartId", cartId)
.put("snapshotEventNumber", snapshotEventSequenceNumber);
N1qlQuery query = N1qlQuery.parameterized("select "+ eventBucketName +".* from `"+ eventBucketName +"` where docType='CartEvent' and cartId=$cartId and eventNumber > $snapshotEventNumber order by eventNumber", values, params);
List<Event> events = db.getBucket().async().query(query)
.flatMap(AsyncN1qlQueryResult::rows)
.map(result -> {
return createEvent(result.value().toString());
})
.toList()
.timeout(10, TimeUnit.SECONDS)
.toBlocking()
.single();
return events;
}
示例3: get
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
public Cart get(String cartId) {
N1qlParams params = N1qlParams.build().adhoc(false).consistency(ScanConsistency.STATEMENT_PLUS);
JsonObject values = JsonObject.create().put("id", cartId);
N1qlQuery query = N1qlQuery.parameterized("select "+ cartBucketName + ".* from `" + cartBucketName + "` where docType='" + DocTypes.CartQueryView.name()+ "' and id=$id", values, params);
List<Cart> carts = db.getBucket().async().query(query)
.flatMap(AsyncN1qlQueryResult::rows)
.map(result -> {
return createObject(result.value().toString());
})
.toList()
.timeout(10, TimeUnit.SECONDS)
.toBlocking()
.single();
if(carts.isEmpty()) {
return null;
} else {
return carts.get(0);
}
}
示例4: searchDevelopers
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
@ResponseBody
@RequestMapping("/developer/search")
public String searchDevelopers(final @RequestParam("firstname") String firstName, final @RequestParam("lastname") String lastName) throws Exception {
String statement = "SELECT developer.* FROM `" + bucket.name() + "` AS developer WHERE developer.type = 'developer'";
JsonObject params = JsonObject.create();
if (!firstName.equals("")) {
params.put("firstName", firstName.toLowerCase() + "%");
statement += " AND lower(developer.developerInfo.firstName) LIKE $firstName";
}
if (!lastName.equals("")) {
params.put("lastName", lastName.toLowerCase() + "%");
statement += " AND lower(developer.developerInfo.lastName) LIKE $lastName";
}
N1qlQuery developerByEmail = N1qlQuery.parameterized(statement, params);
return rawQueryExecutor.n1qlToRawJson(developerByEmail);
}
示例5: query
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
@Override
public void query(String n1qlStatement) {
String parametrizedStatement = injectParameters(n1qlStatement);
logger.debug("Execute n1ql request : \n{}", parametrizedStatement);
try {
AsyncN1qlQueryResult result = runAsync(bucket -> bucket
.query(N1qlQuery.simple(parametrizedStatement,
N1qlParams.build().consistency(STATEMENT_PLUS))));
if (!result.parseSuccess()) {
logger.error("Invalid N1QL request '{}' : {}", parametrizedStatement, single(result.errors()));
throw new CouchmoveException("Invalid n1ql request");
}
if (!single(result.finalSuccess())) {
logger.error("Unable to execute n1ql request '{}'. Status : {}, errors : {}", parametrizedStatement, single(result.status()), single(result.errors()));
throw new CouchmoveException("Unable to execute n1ql request");
}
} catch (Exception e) {
throw new CouchmoveException("Unable to execute n1ql request", e);
}
}
示例6: queryFailure
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
@SuppressWarnings({"unchecked" })
@Test(expected = QueryExecutionException.class)
public void queryFailure() throws Exception {
new MockUnit(AsyncBucket.class, AsyncRepository.class, Function.class, JacksonMapper.class,
N1qlQuery.class, AsyncN1qlQueryResult.class, AsyncN1qlQueryRow.class)
.expect(unit -> {
AsyncN1qlQueryRow row = unit.get(AsyncN1qlQueryRow.class);
AsyncN1qlQueryResult result = unit.get(AsyncN1qlQueryResult.class);
expect(result.rows()).andReturn(Observable.just(row));
expect(result.errors())
.andReturn(Observable.just(JsonObject.create().put("foo", "bar")));
expect(result.finalSuccess()).andReturn(Observable.just(false));
AsyncBucket bucket = unit.get(AsyncBucket.class);
expect(bucket.query(unit.get(N1qlQuery.class))).andReturn(Observable.just(result));
})
.run(unit -> {
new AsyncDatastoreImpl(unit.get(AsyncBucket.class),
unit.get(AsyncRepository.class),
unit.get(Function.class), unit.get(JacksonMapper.class))
.<Entity> query(unit.get(N1qlQuery.class))
.toBlocking()
.single();
});
}
示例7: queryFailureNoError
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
@SuppressWarnings({"unchecked" })
@Test(expected = QueryExecutionException.class)
public void queryFailureNoError() throws Exception {
new MockUnit(AsyncBucket.class, AsyncRepository.class, Function.class, JacksonMapper.class,
N1qlQuery.class, AsyncN1qlQueryResult.class, AsyncN1qlQueryRow.class)
.expect(unit -> {
AsyncN1qlQueryRow row = unit.get(AsyncN1qlQueryRow.class);
AsyncN1qlQueryResult result = unit.get(AsyncN1qlQueryResult.class);
expect(result.rows()).andReturn(Observable.just(row));
expect(result.errors()).andReturn(Observable.empty());
expect(result.finalSuccess()).andReturn(Observable.just(false));
AsyncBucket bucket = unit.get(AsyncBucket.class);
expect(bucket.query(unit.get(N1qlQuery.class))).andReturn(Observable.just(result));
})
.run(unit -> {
new AsyncDatastoreImpl(unit.get(AsyncBucket.class),
unit.get(AsyncRepository.class),
unit.get(Function.class), unit.get(JacksonMapper.class))
.<Entity> query(unit.get(N1qlQuery.class))
.toBlocking()
.single();
});
}
示例8: query
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void query() throws Exception {
String gid = "id";
Object entity = new Object() {
String id = gid;
@Override
public String toString() {
return id;
}
};
new MockUnit(AsyncDatastore.class, N1qlQuery.class)
.expect(unit -> {
AsyncDatastore store = unit.get(AsyncDatastore.class);
expect(store.query(unit.get(N1qlQuery.class)))
.andReturn(just(Arrays.asList(entity)));
})
.run(unit -> {
List<Object> result = new DatastoreImpl(unit.get(AsyncDatastore.class))
.query(unit.get(N1qlQuery.class));
assertEquals(Arrays.asList(entity), result);
});
}
示例9: developer
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
@ResponseBody
@RequestMapping("/developer/fullcontact/{developerId}")
public String developer(final @PathVariable String developerId) throws Exception {
JsonArray params = JsonArray.create();
params.add(developerId);
N1qlQuery developerWithContacts = N1qlQuery.parameterized("SELECT customer.*, (SELECT contact.* FROM `" + bucket.name() + "` AS contact USE KEYS customer.contacts) AS contacts, (SELECT ticket.* FROM `" + bucket.name() + "` AS ticket USE KEYS customer.history) AS history FROM `" + bucket.name() + "` AS customer WHERE customer.type = 'developer' AND customer.id = $1", params);
return rawQueryExecutor.n1qlToRawJson(developerWithContacts);
}
示例10: getDeveloperContact
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
@ResponseBody
@RequestMapping("/developer/contacts/{contactId}")
public String getDeveloperContact(final @PathVariable String contactId) throws Exception {
JsonArray params = JsonArray.create();
params.add(contactId);
N1qlQuery developerWithContacts = N1qlQuery.parameterized("SELECT " +
"(SELECT contact.* FROM `" + bucket.name() + "` AS contact USE KEYS customer.contacts) AS contacts, " +
"(SELECT ticket.* FROM `" + bucket.name() + "` AS ticket USE KEYS customer.history) AS tickets " +
"FROM `" + bucket.name() + "` AS customer " +
"WHERE customer.type = 'developer' AND customer.id = $1", params);
return rawQueryExecutor.n1qlToRawJson(developerWithContacts);
}
示例11: getCustomerByEmail
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
@ResponseBody
@RequestMapping("/developer/getByEmail")
public String getCustomerByEmail(final @RequestParam("email") String email) throws Exception {
JsonArray params = JsonArray.create();
params.add(email);
N1qlQuery developerByEmail = N1qlQuery.parameterized("SELECT customer.* " +
"FROM `" + bucket.name() + "` AS customer " +
"WHERE customer.type = 'developer' AND customer.developerInfo.email = $1", params);
return rawQueryExecutor.n1qlToRawJson(developerByEmail);
}
示例12: getTicket
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
@ResponseBody
@RequestMapping("/developer/tickets/{developerId}")
public String getTicket(final @PathVariable String developerId) throws Exception {
JsonArray params = JsonArray.create();
params.add(developerId);
N1qlQuery developerWithContacts = N1qlQuery.parameterized("SELECT (SELECT ticket.* FROM `" + bucket.name() + "` AS ticket USE KEYS customer.history) AS history FROM `" + bucket.name() + "` AS customer WHERE customer.type = 'developer' AND customer.id = $1", params);
return rawQueryExecutor.n1qlToRawJson(developerWithContacts);
}
示例13: find
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
public Page<T> find(Parameters params, Pageable pageable, Class<T> clazz) {
CouchbaseTemplate template = createTemplate();
Statement query = createQueryStatement(params, pageable);
N1qlQuery queryWithParameter = N1qlQuery.parameterized(query, params.toJsonObject());
List<T> data = convertToDataList(template.findByN1QLProjection(queryWithParameter, LinkedHashMap.class), clazz);
Integer count = count(params);
return new PageImpl<>(data, pageable, count);
}
示例14: count
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
public Integer count(Parameters params) {
CouchbaseTemplate template = createTemplate();
Statement query = createCountStatement(params);
N1qlQuery queryWithParams = N1qlQuery.parameterized(query, params.toJsonObject());
LinkedHashMap countMap = ((LinkedHashMap) template.findByN1QLProjection(queryWithParams, Object.class).get(0));
return ((Integer) countMap.get("count"));
}
示例15: sum
import com.couchbase.client.java.query.N1qlQuery; //导入依赖的package包/类
public Integer sum(Parameters params, String field) {
CouchbaseTemplate template = createTemplate();
Statement query = createSumStatement(params, field);
N1qlQuery queryWithParams = N1qlQuery.parameterized(query, params.toJsonObject());
LinkedHashMap sumMap = ((LinkedHashMap) template.findByN1QLProjection(queryWithParams, Object.class).get(0));
return ((Integer) sumMap.get("sum"));
}