本文整理汇总了Java中com.mysema.commons.lang.CloseableIterator类的典型用法代码示例。如果您正苦于以下问题:Java CloseableIterator类的具体用法?Java CloseableIterator怎么用?Java CloseableIterator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CloseableIterator类属于com.mysema.commons.lang包,在下文中一共展示了CloseableIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSetFromTuples
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
public static <T extends Entity> EntitySet<T> createSetFromTuples(entityFromTupleFactory<T> factory, CloseableIterator<Tuple> tuples, Query query, long maxDataSize) {
EntitySet<T> entitySet = new EntitySetImpl<>(factory.getEntityType());
int count = 0;
DataSize size = new DataSize();
int top = query.getTopOrDefault();
while (tuples.hasNext()) {
Tuple tuple = tuples.next();
entitySet.add(factory.create(tuple, query, size));
count++;
if (count >= top) {
return entitySet;
}
if (size.getDataSize() > maxDataSize) {
LOGGER.debug("Size limit reached: {} > {}.", size.getDataSize(), maxDataSize);
return entitySet;
}
}
return entitySet;
}
示例2: iterate
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
@Override
public CloseableIterator<Q> iterate() {
final Iterator<? extends Q> iterator = query().iterator();
return new CloseableIterator<Q>() {
@Override
public boolean hasNext() {
return iterator.hasNext();
}
@Override
public Q next() {
return iterator.next();
}
@Override
public void remove() {
iterator.remove();
}
@Override
public void close() {
}
};
}
示例3: findUtilizationsWithResolution
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
@Transactional(readOnly = true, isolation = READ_COMMITTED, propagation = MANDATORY)
@Override
public List<Utilization> findUtilizationsWithResolution(UtilizationKey utilizationKey, DateTime start, DateTime end, Minutes resolution) {
ArrayList<Utilization> results = new ArrayList<>();
Optional<Utilization> first = findUtilizationAtInstant(utilizationKey, start);
try (CloseableIterator<Utilization> rest = findUtilizationsBetween(utilizationKey, start, end)) {
LinkedList<Utilization> utilizations = Stream.concat(
StreamUtil.asStream(first),
StreamUtil.asStream(rest))
.collect(Collectors.toCollection(LinkedList::new));
Utilization current = null;
for (DateTime instant = start; !instant.isAfter(end); instant = instant.plus(resolution)) {
while (!utilizations.isEmpty() && !utilizations.getFirst().timestamp.isAfter(instant)) {
current = utilizations.removeFirst();
}
if (current != null) {
current.timestamp = instant;
results.add(current.copy());
}
}
}
return results;
}
示例4: sparqlFind
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
protected <T extends BaseNode> List<T> sparqlFind(String qry, String idVar, Class<T> c, boolean first) {
CloseableIterator<Map<String,NODE>> res = _sparql(qry);
ArrayList<T> result = new ArrayList<T>();
while (res.hasNext()) {
for (Map.Entry<String, NODE> n : res.next().entrySet()) {
if (n.getKey().equals(idVar.replace("?",""))) {
if (n.getValue().isResource()) {
result.add(_getById(n.getValue().asResource(), c));
if (first)
return result;
else
break;
}
}
}
}
return result;
}
示例5: sparql
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
private CloseableIterator<Map<String,NODE>> sparql(String q, QueryLanguage queryType, org.openrdf.query.QueryLanguage language) {
String f = "prefix : <" + NS + "> \n";
f += "prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n";
f += "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n";
f += "prefix owl: <http://www.w3.org/2002/07/owl#> \n";
f += "prefix fts: <http://rdf.useekm.com/fts#> \n";
f += q;
if (sparqlVerbose) logger.info(f);
RDFConnection conn = connection;
CloseableIterator<Map<String,NODE>> rows = null;
try {
rows = smr.openConnection().createQuery(QueryLanguage.SPARQL, f).getTuples();
} catch (Exception e) {
logger.error(e.getMessage());
for (StackTraceElement ste : e.getStackTrace()) logger.info(ste.toString());
}
return rows;
}
示例6: selectAll
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
public static ArrayList<NODE> selectAll(String q) {
ArrayList results = new ArrayList<NODE>();
CloseableIterator cl = sparql(q);
while(cl.hasNext()){
Map m = (Map)cl.next();
Object[] objectArray = m.values().toArray();
UID[] n = new UID[objectArray.length];
for(int i = 0; i< objectArray.length; i++){
n[i] = (UID) objectArray[i];
}
results.add(getById(n[0]));
}
return results;
}
示例7: testCustomTransform
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
@Test
@Transactional
public void testCustomTransform() throws Exception {
JPAQuery query = new JPAQuery(em);
QStockKeepingUnit path = QStockKeepingUnit.stockKeepingUnit;
List<SkuDto> results = query.from(path)
.transform(new ResultTransformer<List<SkuDto>>() {
@Override
public List<SkuDto> transform(Projectable arg0) {
List<SkuDto> result = new ArrayList<SkuDto>();
CloseableIterator<StockKeepingUnit> iterator = arg0.iterate(QStockKeepingUnit.stockKeepingUnit);
while (iterator.hasNext()) {
StockKeepingUnit sku = iterator.next();
SkuDto dto = new SkuDto(sku.getSkuId(), sku.getName(), sku.getPrice());
result.add(dto);
}
return result;
}
});
Assert.assertEquals(Integer.valueOf(8), Integer.valueOf(results.size()));
}
示例8: _04Fields
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
@Benchmark
public void _04Fields(LimitParam limit, final Blackhole blackhole, ConnectionParam connectionParam) throws Exception {
SQLQuery query = new SQLQuery(connectionParam.connection, templates);
CloseableIterator<MappedObject4> iterate = query.from(QTestSmallBenchmarkObject.testSmallBenchmarkObject)
.limit(limit.limit)
.iterate(MAPPED_OBJECT_4_Q_BEAN);
while(iterate.hasNext()) {
blackhole.consume(iterate.next());
}
}
示例9: _16Fields
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
@Benchmark
public void _16Fields(LimitParam limit, final Blackhole blackhole, ConnectionParam connectionParam) throws Exception {
SQLQuery query = new SQLQuery(connectionParam.connection, templates);
CloseableIterator<MappedObject16> iterate = query.from(QTestBenchmarkObject16.testBenchmarkObject16)
.limit(limit.limit)
.iterate(MAPPED_OBJECT_16_Q_BEAN);
while(iterate.hasNext()) {
blackhole.consume(iterate.next());
}
}
示例10: transform
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
@Override
public R transform(FetchableQuery<?, ?> query) {
CloseableIterator<T> iter = query.select(groupExpression.getExpression()).iterate();
GroupCollector<T, R> collector = groupExpression.createGroupCollector();
try {
while (iter.hasNext()) {
T collectable = iter.next();
collector.add(collectable);
}
} finally {
iter.close();
}
return collector.get();
}
示例11: findUtilizationsBetween
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
@Transactional(readOnly = true, isolation = READ_COMMITTED, propagation = MANDATORY)
@Override
public CloseableIterator<Utilization> findUtilizationsBetween(UtilizationKey utilizationKey, DateTime start, DateTime end) {
UtilizationSearch search = new UtilizationSearch();
search.facilityIds.add(utilizationKey.facilityId);
search.usages.add(utilizationKey.usage);
search.capacityTypes.add(utilizationKey.capacityType);
search.start = start;
search.end = end;
return findUtilizations(search);
}
示例12: findUtilizations
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
@Transactional(readOnly = true, isolation = READ_COMMITTED, propagation = MANDATORY)
@Override
public CloseableIterator<Utilization> findUtilizations(UtilizationSearch search) {
// TODO: add support for JDBC setFetchSize to QueryDSL, without it PostgreSQL will not stream results, but instead reads all results to memory
final PostgreSQLQuery<Utilization> q = queryFactory.from(qUtilization).select(utilizationMapping);
q.where(qUtilization.ts.between(search.start, search.end));
addCriteria(q, search.facilityIds, qUtilization.facilityId);
addCriteria(q, search.capacityTypes, qUtilization.capacityType);
addCriteria(q, search.usages, qUtilization.usage);
q.setStatementOptions(StatementOptions.builder().setFetchSize(100).build());
return q.orderBy(qUtilization.ts.asc()).iterate();
}
示例13: getFacilityStats
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
private Map<MaxUtilizationReportKeyWithDate, Integer> getFacilityStats(ReportContext ctx, ReportParameters parameters, UtilizationSearch search) {
try (CloseableIterator<Utilization> utilizations = utilizationRepository.findUtilizations(search)) {
return stream(spliteratorUnknownSize(addFilters(utilizations, ctx, parameters), Spliterator.ORDERED), false)
.filter(u -> hasBuiltCapacity(u, ctx.facilities))
.collect(toMap(
u -> new MaxUtilizationReportKeyWithDate(u, ctx.facilities.get(u.facilityId)),
u -> u.spacesAvailable,
Math::min,
LinkedHashMap::new
));
}
}
示例14: predict
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
@Override
public List<Prediction> predict(PredictorState state, UtilizationHistory history, int maxCapacity) {
List<Prediction> predictions = new ArrayList<>();
try (CloseableIterator<Utilization> utilizations = history.getUpdatesSince(state.latestUtilization)) {
stream(spliteratorUnknownSize(utilizations, NONNULL | IMMUTABLE), false)
.reduce((older, newer) -> newer)
.ifPresent(lastUpdate -> {
state.latestUtilization = lastUpdate.timestamp;
predictions.add(new Prediction(lastUpdate.timestamp, lastUpdate.spacesAvailable));
predictions.add(new Prediction(lastUpdate.timestamp.plusDays(1), lastUpdate.spacesAvailable));
});
}
return predictions;
}
示例15: getUpdatesSince
import com.mysema.commons.lang.CloseableIterator; //导入依赖的package包/类
@Override
public CloseableIterator<Utilization> getUpdatesSince(DateTime startExclusive) {
return new IteratorAdapter<Utilization>(
utilizationList.stream()
.filter(utilization -> !utilization.timestamp.isBefore(startExclusive))
.iterator()
);
}