本文整理汇总了Java中com.couchbase.client.java.view.ViewQuery类的典型用法代码示例。如果您正苦于以下问题:Java ViewQuery类的具体用法?Java ViewQuery怎么用?Java ViewQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ViewQuery类属于com.couchbase.client.java.view包,在下文中一共展示了ViewQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
@Override
public List<RegisteredService> load() {
try {
logger.debug("Loading services");
final Bucket bucket = couchbase.bucket();
final ViewResult allKeys = bucket.query(ViewQuery.from(UTIL_DOCUMENT, ALL_SERVICES_VIEW.name()));
final List<RegisteredService> services = new LinkedList<>();
for (final ViewRow row : allKeys) {
final RawJsonDocument document = row.document(RawJsonDocument.class);
if (document != null) {
final String json = document.content();
logger.debug("Found service: {}", json);
final StringReader stringReader = new StringReader(json);
services.add(registeredServiceJsonSerializer.fromJson(stringReader));
}
}
return services;
} catch (final RuntimeException e) {
logger.error(e.getMessage(), e);
return new LinkedList<>();
}
}
示例2: shouldQueryView
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
@Test
public void shouldQueryView() throws IOException {
final BucketManager bucketManager = bucket.bucketManager();
final View view =
DefaultView.create("byFirstname",
IOUtils.toString(getClass().getResourceAsStream("/byfirstname.js")));
final DesignDocument document = DesignDocument.create("person", ImmutableList.of(view));
try {
bucketManager.upsertDesignDocument(document);
repository.save(person);
final ViewQuery query = ViewQuery.from(document.name(), view.name());
query.stale(Stale.FALSE);
query.debug();
query.key(person.getFirstname());
final Iterable<Person> found = repository.queryView(query);
assertEquals(ImmutableList.of(person), found);
} finally {
bucketManager.removeDesignDocument(document.name());
}
}
示例3: getAllKeys
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
private Observable<String> getAllKeys() {
String[] viewInfo = checkAndGetViewInfo();
return bucket.async()
.query(ViewQuery.from(viewInfo[0], viewInfo[1]))
.flatMap(new Func1<AsyncViewResult, Observable<AsyncViewRow>>() {
@Override
public Observable<AsyncViewRow> call(AsyncViewResult asyncViewResult) {
return asyncViewResult.rows();
}
})
.map(new Func1<AsyncViewRow, String>() {
@Override
public String call(AsyncViewRow asyncViewRow) {
return asyncViewRow.id();
}
});
}
示例4: runQuery
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
private int runQuery(final String prefix) {
final ViewResult allKeys = couchbase.bucket().query(
ViewQuery.from(UTIL_DOCUMENT, "all_tickets")
.startKey(prefix)
.endKey(prefix + END_TOKEN)
.reduce());
final Iterator<ViewRow> iterator = allKeys.iterator();
if (iterator.hasNext()) {
final ViewRow res = iterator.next();
return (Integer) res.value();
} else {
return 0;
}
}
示例5: getViewResultIteratorForPrefixedTickets
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
private ViewResult getViewResultIteratorForPrefixedTickets(final String prefix) {
LOGGER.debug("Running query on document [{}] and view [{}] with prefix [{}]",
UTIL_DOCUMENT, VIEW_NAME_ALL_TICKETS, prefix);
return this.couchbase.bucket().query(
ViewQuery.from(UTIL_DOCUMENT, VIEW_NAME_ALL_TICKETS)
.startKey(prefix)
.endKey(prefix + END_TOKEN)
.reduce());
}
示例6: getSongByArtistAsync
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
@Override
public Observable<Song> getSongByArtistAsync(String query) {
return bucket
.async()
.query(ViewQuery.from("song", "artist").startKey(query).endKey(query + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"))
.limit(100)
.flatMap(AsyncViewResult::rows)
.map(r -> Song.createFromJson(r.value().toString()));
}
示例7: queryView
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
@Override
public Observable<T> queryView(final ViewQuery query) {
return Observable.just(query)
.flatMap(bucket::query)
.flatMap(AsyncViewResult::rows)
.flatMap(row -> row.document(RawJsonDocument.class))
.map(deserializer)
.timeout(timeout, unit);
}
示例8: newQuery
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
@Override
public ViewQuery newQuery(final String designDoc, final String view) {
final ViewQuery query = ViewQuery.from(designDoc, view);
query.debug(debug);
query.stale(stale);
return query;
}
示例9: viewQuery
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void viewQuery() throws Exception {
String gid = "id";
Object entity = new Object() {
String id = gid;
@Override
public String toString() {
return id;
}
};
new MockUnit(AsyncDatastore.class, ViewQuery.class)
.expect(unit -> {
AsyncDatastore store = unit.get(AsyncDatastore.class);
expect(store.query(unit.get(ViewQuery.class)))
.andReturn(just(
new AsyncDatastore.AsyncViewQueryResult<Object>(10,
just(Arrays.asList(entity)))));
})
.run(unit -> {
ViewQueryResult<Object> result = new DatastoreImpl(unit.get(AsyncDatastore.class))
.query(unit.get(ViewQuery.class));
assertEquals(Arrays.asList(entity), result.getRows());
assertEquals(10, result.getTotalRows());
});
}
示例10: executeViewQueryForAllServices
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
private ViewResult executeViewQueryForAllServices() {
return this.couchbase.bucket().query(ViewQuery.from(UTIL_DOCUMENT, ALL_SERVICES_VIEW.name()));
}
示例11: queryView
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
@Override
public List<T> queryView(final ViewQuery query) {
return blocking(async.queryView(query).toList()).single();
}
示例12: findAll
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
@Override
public Observable<T> findAll() {
final ViewQuery query = queries.newQuery(clazz.getSimpleName().toLowerCase(), "all");
query.reduce(false);
return queryView(query);
}
示例13: shouldReturnQuery
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
@Test
public void shouldReturnQuery() {
final SpringQueryService service = new SpringQueryService(true, Stale.TRUE);
final ViewQuery newQuery = service.newQuery("designDoc", "view");
assertNotNull(newQuery);
}
示例14: queryView
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
/**
* Query a database view.
*
* @param query query to execute
* @return an {@link Observable} which emits the results
*/
Observable<T> queryView(ViewQuery query);
示例15: queryView
import com.couchbase.client.java.view.ViewQuery; //导入依赖的package包/类
/**
* Query view.
*
* @param query query to execute
* @return entities found
*/
List<T> queryView(ViewQuery query);