本文整理汇总了Java中org.ojai.store.Query类的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Query类属于org.ojai.store包,在下文中一共展示了Query类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getTotalNumByLanguage
import org.ojai.store.Query; //导入依赖的package包/类
/**
* Returns number of albums according to the specified language.
*
* @param language language code.
* @return number of albums with specified language code.
*/
public long getTotalNumByLanguage(String language) {
return processStore((connection, store) -> {
Stopwatch stopwatch = Stopwatch.createStarted();
QueryCondition languageEqualsCondition = connection.newCondition()
.is("language", QueryCondition.Op.EQUAL, language)
.build();
Query query = connection.newQuery()
.select("_id")
.where(languageEqualsCondition)
.build();
DocumentStream documentStream = store.findQuery(query);
long totalNum = 0;
for (Document ignored : documentStream) {
totalNum++;
}
log.debug("Counting '{}' albums by language '{}' took {}", totalNum, language, stopwatch);
return totalNum;
});
}
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:32,代码来源:AlbumDao.java
示例2: getByUserId
import org.ojai.store.Query; //导入依赖的package包/类
/**
* Returns list of Artist rates by user identifier.
*
* @param userId user's identifier.
* @return list of Artist rates.
*/
public List<ArtistRate> getByUserId(String userId) {
return processStore((connection, store) -> {
Stopwatch stopwatch = Stopwatch.createStarted();
Query query = connection.newQuery().where(
connection.newCondition()
.is("user_id", QueryCondition.Op.EQUAL, userId)
.build()
).build();
// Fetch all OJAI Documents from this store according to the built query
DocumentStream documentStream = store.findQuery(query);
List<ArtistRate> rates = new ArrayList<>();
for (Document document : documentStream) {
ArtistRate rate = mapOjaiDocument(document);
if (rate != null) {
rates.add(rate);
}
}
log.debug("Get '{}' rates by user id '{}' took {}", rates.size(), userId, stopwatch);
return rates;
});
}
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:32,代码来源:ArtistRateDao.java
示例3: getByArtistId
import org.ojai.store.Query; //导入依赖的package包/类
/**
* Returns list of Artist rates by artist identifier.
*
* @param artistId artist's identifier.
* @return list of Artist rates.
*/
public List<ArtistRate> getByArtistId(String artistId) {
return processStore((connection, store) -> {
Stopwatch stopwatch = Stopwatch.createStarted();
Query query = connection.newQuery().where(
connection.newCondition()
.is("document_id", QueryCondition.Op.EQUAL, artistId)
.build()
).build();
// Fetch all OJAI Documents from this store according to the built query
DocumentStream documentStream = store.findQuery(query);
List<ArtistRate> rates = new ArrayList<>();
for (Document document : documentStream) {
ArtistRate rate = mapOjaiDocument(document);
if (rate != null) {
rates.add(rate);
}
}
log.debug("Get '{}' rates by artist id '{}' took {}", rates.size(), artistId, stopwatch);
return rates;
});
}
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:32,代码来源:ArtistRateDao.java
示例4: getByNameStartsWith
import org.ojai.store.Query; //导入依赖的package包/类
/**
* Finds albums, which titles start with the specified name entry.
*
* @param nameEntry specifies query criteria.
* @param limit specified limit.
* @param fields specifies fields that will be fetched.
* @return list of albums which titles start with the specified name entry.
*/
public List<Album> getByNameStartsWith(String nameEntry, long limit, String... fields) {
return processStore((connection, store) -> {
Stopwatch stopwatch = Stopwatch.createStarted();
Query query = connection.newQuery();
// Select only specified field
if (fields != null && fields.length > 0) {
query.select(fields);
} else {
query.select("*");
}
// Build Query Condition to fetch documents by name entry
String nameStartsWithPattern = nameEntry + "%";
QueryCondition nameStartsWithCondition = connection.newCondition()
.like("name", nameStartsWithPattern)
.build();
// Add Condition and specified limit to the Query
query.where(nameStartsWithCondition)
.limit(limit)
.build();
DocumentStream documentStream = store.findQuery(query);
List<Album> albums = new ArrayList<>();
for (Document doc : documentStream) {
albums.add(mapOjaiDocument(doc));
}
log.debug("Get '{}' albums by name entry: '{}' with limit: '{}', fields: '{}'. Elapsed time: {}",
albums.size(), nameEntry, limit, (fields != null) ? Arrays.asList(fields) : "[]", stopwatch);
return albums;
});
}
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:45,代码来源:AlbumDao.java
示例5: getRate
import org.ojai.store.Query; //导入依赖的package包/类
/**
* Returns Artist rate according to the specified user identifier and artist identifier.
*
* @param userId user identifier.
* @param artistId artist identifier.
* @return artist rate.
*/
public ArtistRate getRate(String userId, String artistId) {
return processStore((connection, store) -> {
Stopwatch stopwatch = Stopwatch.createStarted();
QueryCondition condition = connection.newCondition()
.and()
.is("user_id", QueryCondition.Op.EQUAL, userId)
.is("document_id", QueryCondition.Op.EQUAL, artistId)
.close()
.build();
Query query = connection.newQuery().where(condition).build();
// Fetch all OJAI Documents from this store according to the built query
DocumentStream documentStream = store.findQuery(query);
Iterator<Document> documentIterator = documentStream.iterator();
if (!documentIterator.hasNext()) {
return null;
}
log.debug("Get rate by artist id '{}' and user id '{}' took {}", artistId, userId, stopwatch);
return mapOjaiDocument(documentIterator.next());
});
}
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:34,代码来源:ArtistRateDao.java
示例6: getByNameStartsWith
import org.ojai.store.Query; //导入依赖的package包/类
/**
* Finds artists, which names start with the specified name entry.
*
* @param nameEntry specifies query criteria.
* @param limit specified limit.
* @param fields specifies fields that will be fetched.
* @return list of artists which names start with the specified name entry.
*/
public List<Artist> getByNameStartsWith(String nameEntry, long limit, String... fields) {
return processStore((connection, store) -> {
Stopwatch stopwatch = Stopwatch.createStarted();
Query query = connection.newQuery();
// Select only specified field
if (fields != null && fields.length > 0) {
query.select(fields);
} else {
query.select("*");
}
// Build Query Condition to fetch documents by name entry
String nameStartsWithPattern = nameEntry + "%";
QueryCondition nameStartsWithCondition = connection.newCondition()
.like("name", nameStartsWithPattern)
.build();
// Add Condition and specified limit to the Query
query.where(nameStartsWithCondition)
.limit(limit)
.build();
DocumentStream documentStream = store.findQuery(query);
List<Artist> artists = new ArrayList<>();
for (Document doc : documentStream) {
artists.add(mapOjaiDocument(doc));
}
log.debug("Get '{}' artists by name entry: '{}' with limit: '{}', fields: '{}'. Elapsed time: {}",
artists.size(), nameEntry, limit, (fields != null) ? Arrays.asList(fields) : "[]", stopwatch);
return artists;
});
}
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:45,代码来源:ArtistDao.java
示例7: getRate
import org.ojai.store.Query; //导入依赖的package包/类
/**
* Returns Album rate according to the specified user identifier and album identifier.
*
* @param userId user identifier.
* @param albumId album identifier.
* @return album rate.
*/
public AlbumRate getRate(String userId, String albumId) {
return processStore((connection, store) -> {
Stopwatch stopwatch = Stopwatch.createStarted();
QueryCondition condition = connection.newCondition()
.and()
.is("user_id", QueryCondition.Op.EQUAL, userId)
.is("document_id", QueryCondition.Op.EQUAL, albumId)
.close()
.build();
Query query = connection.newQuery().where(condition).build();
// Fetch all OJAI Documents from this store according to the built query
DocumentStream documentStream = store.findQuery(query);
Iterator<Document> documentIterator = documentStream.iterator();
if (!documentIterator.hasNext()) {
return null;
}
log.debug("Get rate by album id '{}' and user id '{}' took {}", albumId, userId, stopwatch);
return mapOjaiDocument(documentIterator.next());
});
}
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:35,代码来源:AlbumRateDao.java
示例8: getByUserId
import org.ojai.store.Query; //导入依赖的package包/类
/**
* Returns list of Album rates by user identifier.
*
* @param userId user's identifier.
* @return list of Album rates.
*/
public List<AlbumRate> getByUserId(String userId) {
return processStore((connection, store) -> {
Stopwatch stopwatch = Stopwatch.createStarted();
Query query = connection.newQuery().where(
connection.newCondition()
.is("user_id", QueryCondition.Op.EQUAL, userId)
.build()
).build();
// Fetch all OJAI Documents from this store according to the built query
DocumentStream documentStream = store.findQuery(query);
List<AlbumRate> rates = new ArrayList<>();
for (Document document : documentStream) {
AlbumRate rate = mapOjaiDocument(document);
if (rate != null) {
rates.add(rate);
}
}
log.debug("Get '{}' rates by user id '{}' took {}", rates.size(), userId, stopwatch);
return rates;
});
}
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:33,代码来源:AlbumRateDao.java
示例9: getByAlbumId
import org.ojai.store.Query; //导入依赖的package包/类
/**
* Returns list of Album rates by album identifier.
*
* @param albumId album's identifier.
* @return list of Album rates.
*/
public List<AlbumRate> getByAlbumId(String albumId) {
return processStore((connection, store) -> {
Stopwatch stopwatch = Stopwatch.createStarted();
Query query = connection.newQuery().where(
connection.newCondition()
.is("document_id", QueryCondition.Op.EQUAL, albumId)
.build()
).build();
// Fetch all OJAI Documents from this store according to the built query
DocumentStream documentStream = store.findQuery(query);
List<AlbumRate> rates = new ArrayList<>();
for (Document document : documentStream) {
AlbumRate rate = mapOjaiDocument(document);
if (rate != null) {
rates.add(rate);
}
}
log.debug("Get '{}' rates by album id '{}' took {}", rates.size(), albumId, stopwatch);
return rates;
});
}
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:33,代码来源:AlbumRateDao.java
示例10: getByLanguage
import org.ojai.store.Query; //导入依赖的package包/类
/**
* Returns list of albums by language code.
*
* @param offset offset value.
* @param limit limit value.
* @param options define the order of documents.
* @param lang language code.
* @param fields list of fields that will present in document.
* @return list of albums with specified language code.
*/
public List<Album> getByLanguage(long offset, long limit, List<SortOption> options, String lang, String... fields) {
return processStore((connection, store) -> {
Stopwatch stopwatch = Stopwatch.createStarted();
Query query = connection.newQuery();
// Select only specified field
if (fields != null && fields.length > 0) {
query.select(fields);
} else {
query.select("*");
}
// Build Query Condition to fetch documents by specified language
QueryCondition languageEqualsCondition = connection.newCondition()
.is("language", QueryCondition.Op.EQUAL, lang)
.build();
// Add Condition to the Query
query.where(languageEqualsCondition);
// Add ordering if sort options specified
if (options != null && !options.isEmpty()) {
for (SortOption opt : options) {
SortOrder ojaiOrder = (SortOption.Order.DESC == opt.getOrder()) ? SortOrder.DESC : SortOrder.ASC;
for (String field : opt.getFields()) {
query = query.orderBy(field, ojaiOrder);
}
}
}
// Add specified offset and limit to the Query
query.offset(offset)
.limit(limit)
.build();
DocumentStream documentStream = store.findQuery(query);
List<Album> albums = new ArrayList<>();
for (Document doc : documentStream) {
albums.add(mapOjaiDocument(doc));
}
log.debug("Get list of '{}' documents from '{}' table by language: '{}' with offset: '{}', limit: '{}', " +
"sortOptions: '{}', fields: '{}'. Elapsed time: {}", albums.size(), tablePath, lang, offset,
limit, options, (fields != null) ? Arrays.asList(fields) : "[]", stopwatch);
return albums;
});
}
开发者ID:mapr-demos,项目名称:mapr-music,代码行数:61,代码来源:AlbumDao.java
示例11: newQuery
import org.ojai.store.Query; //导入依赖的package包/类
@Override
public Query newQuery() {
throw new UnsupportedOperationException();
}
开发者ID:ojai,项目名称:ojai,代码行数:5,代码来源:DummyJsonDriver.java
示例12: newQuery
import org.ojai.store.Query; //导入依赖的package包/类
@Override
public Query newQuery() {
return driver.newQuery();
}
开发者ID:ojai,项目名称:ojai,代码行数:5,代码来源:DummyJsonConnection.java
注:本文中的org.ojai.store.Query类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论