当前位置: 首页>>代码示例>>Java>>正文


Java MongoCursor.hasNext方法代码示例

本文整理汇总了Java中org.jongo.MongoCursor.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java MongoCursor.hasNext方法的具体用法?Java MongoCursor.hasNext怎么用?Java MongoCursor.hasNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jongo.MongoCursor的用法示例。


在下文中一共展示了MongoCursor.hasNext方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getModerationLogs

import org.jongo.MongoCursor; //导入方法依赖的package包/类
public static Optional<List<ModerationLog>> getModerationLogs(CurseGUID channelId) {
    try {
        List<ModerationLog> commandRet = new ArrayList<>();
        MongoCursor<ModerationLog> commands = jongo.getCollection(MONGO_MODERATION_LOGGING_COLLECTION).find("{channelID: '" + channelId.serialize() + "'}")
                .as(ModerationLog.class);
        while (commands.hasNext()) {
            commandRet.add(commands.next());
        }
        commands.close();
        return Optional.of(commandRet);
    } catch (IOException | NullPointerException e) {
        log.error("error getting moderation data", e);
        return Optional.empty();
    }

}
 
开发者ID:progwml6,项目名称:FTBCurseBot,代码行数:17,代码来源:MongoConnection.java

示例2: getMessageLog

import org.jongo.MongoCursor; //导入方法依赖的package包/类
public static Optional<List<ModerationLog>> getMessageLog(CurseGUID channelId, Date eventTime) {
    try {
        List<ModerationLog> commandRet = new ArrayList<>();
        MongoCursor<ModerationLog> commands = jongo.getCollection(MONGO_MODERATION_LOGGING_COLLECTION)
                .find("{channelID: '" + channelId.serialize() + "' , messageTime: 'ISODate(" + eventTime.toString() + ")'}")
                .as(ModerationLog.class);
        while (commands.hasNext()) {
            commandRet.add(commands.next());
        }
        commands.close();
        return Optional.of(commandRet);
    } catch (IOException | NullPointerException e) {
        log.error("error getting moderation data", e);
        return Optional.empty();
    }
}
 
开发者ID:progwml6,项目名称:FTBCurseBot,代码行数:17,代码来源:MongoConnection.java

示例3: getCurseChecksForAuthor

import org.jongo.MongoCursor; //导入方法依赖的package包/类
public static Optional<List<MongoCurseforgeCheck>> getCurseChecksForAuthor(@Nonnull String author) {
    try {
        List<MongoCurseforgeCheck> commandRet = new ArrayList<>();
        MongoCursor<MongoCurseforgeCheck> commands = jongo.getCollection(MONGO_COMMANDS_COLLECTION).find("{author: '" + author + "'}")
                .as(MongoCurseforgeCheck.class);
        while (commands.hasNext()) {
            commandRet.add(commands.next());
        }
        commands.close();
        return Optional.of(commandRet);
    } catch (IOException | NullPointerException e) {
        log.error("error getting checks", e);
        return Optional.empty();
    }

}
 
开发者ID:progwml6,项目名称:FTBCurseBot,代码行数:17,代码来源:MongoConnection.java

示例4: getCommandsForServer

import org.jongo.MongoCursor; //导入方法依赖的package包/类
@Nonnull
//TODO should this use streams?
public static Optional<List<MongoCommand>> getCommandsForServer(CurseGUID serverID) {
    try {
        List<MongoCommand> commandRet = new ArrayList<>();
        MongoCursor<MongoCommand> commands = jongo.getCollection(MONGO_COMMANDS_COLLECTION).find("{serverID: '" + serverID.serialize() + "'}")
                .as(MongoCommand.class);
        while (commands.hasNext()) {
            commandRet.add(commands.next());
        }
        commands.close();
        return Optional.of(commandRet);
    } catch (IOException | NullPointerException e) {
        log.error("error getting commands for server", e);
        return Optional.empty();
    }
}
 
开发者ID:progwml6,项目名称:FTBCurseBot,代码行数:18,代码来源:MongoConnection.java

示例5: cursorToArray

import org.jongo.MongoCursor; //导入方法依赖的package包/类
/**
 * Takes a MongoCurson containing User object and moving them to an ArrayList.
 *
 * @param cursor    MongoCursor to be conveted to an ArrayList
 * @return          An ArrayList containing all user object from the cursor
 */
private ArrayList<User> cursorToArray(MongoCursor<User> cursor) {
    ArrayList<User> list = new ArrayList<>();

    while(cursor.hasNext()) {
        list.add(cursor.next());
    }

    return list;
}
 
开发者ID:2DV603NordVisaProject,项目名称:nordvisa_calendar,代码行数:16,代码来源:UserDAOMongo.java

示例6: cursorToArray

import org.jongo.MongoCursor; //导入方法依赖的package包/类
/**
 * Takes a MongoCursor containing Event objects and moves them to an ArrayList.
 *
 * @param cursor    MongoCursor to be converted to an ArrayList.
 * @return          An ArrayList containing all Event objects from the cursor.
 * @author Axel Nilsson (axnion)
 */
private static List<Event> cursorToArray(MongoCursor<Event> cursor) {
    List<Event> list = new ArrayList<>();

    while(cursor.hasNext()) {
        list.add(cursor.next());
    }

    return list;
}
 
开发者ID:2DV603NordVisaProject,项目名称:nordvisa_calendar,代码行数:17,代码来源:EventDAOMongo.java

示例7: getCurseChecks

import org.jongo.MongoCursor; //导入方法依赖的package包/类
public static Optional<List<MongoCurseforgeCheck>> getCurseChecks() {
    try {
        List<MongoCurseforgeCheck> commandRet = new ArrayList<>();
        MongoCursor<MongoCurseforgeCheck> commands = jongo.getCollection(MONGO_CURSECHECKS_COLLECTION).find()
                .as(MongoCurseforgeCheck.class);
        while (commands.hasNext()) {
            commandRet.add(commands.next());
        }
        commands.close();
        return Optional.of(commandRet);
    } catch (IOException | NullPointerException e) {
        log.error("error getting checks", e);
        return Optional.empty();
    }
}
 
开发者ID:progwml6,项目名称:FTBCurseBot,代码行数:16,代码来源:MongoConnection.java

示例8: process

import org.jongo.MongoCursor; //导入方法依赖的package包/类
@Override
public void process() {
    Map<String, StatusChangedProcessorConfigDTO> jobs = getJobs();

    MongoCollection collection = mongoDBService.getCollection(Constants.DB.BUILDS);
    for (Map.Entry<String, StatusChangedProcessorConfigDTO> entry : jobs.entrySet()) {
        String toSendQuery = "{jobId:'" + entry.getKey() + "', processed:'false'}";
        try {
            MongoCursor<CiReport> ciReports = collection.find(toSendQuery).as(CiReport.class);
            int count = ciReports.count();
            CiReport firstReport = null;
            for (int i = 0; i < count - 1; i++) {
                CiReport report = ciReports.next();
                if (firstReport == null) {
                    firstReport = report;
                }
                report.setProcessed(true);
                collection.update("{id:'" + report.getId() + "'}", report);
            }
            if (ciReports.hasNext()) {
                CiReport lastReport = ciReports.next();
                CiReport.Status firstStatus = firstReport.getStatus();
                generateMessage(entry.getKey(), entry.getValue(), firstStatus, lastReport);

            }
            ciReports.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
 
开发者ID:eliogrin,项目名称:CISEN,代码行数:33,代码来源:StatusChangedProcessor.java

示例9: markReportsAsProcessed

import org.jongo.MongoCursor; //导入方法依赖的package包/类
private void markReportsAsProcessed(MongoCollection builds, MongoCursor<CiReport> ciReports) {
    while (ciReports.hasNext()) {
        CiReport report = ciReports.next();
        report.setProcessed(true);
        builds.update(String.format("{id:'%s'}", report.getId()), report);
    }
}
 
开发者ID:eliogrin,项目名称:CISEN,代码行数:8,代码来源:StatusWatchdogProcessor.java

示例10: check

import org.jongo.MongoCursor; //导入方法依赖的package包/类
@Override
public void check(CommandLine commandLine) throws Exception {
	
	// get url
	String url = commandLine.getOptionValue(MongoParameter.URL.toString());
	
	// get query
	String query = commandLine.getOptionValue(MongoParameter.QUERY.toString());
	
	// get database name
	String database = commandLine.getOptionValue(MongoParameter.DATABASE.toString());
	
	// get collection name
	String collection = commandLine.getOptionValue(MongoParameter.COLLECTION.toString());
	
	// get connect timeout
	int connectTimeout = (Integer) ElasticSearchParameter.CONNECT_TIMEOUT.getDefaultValue();
	String connectTimeoutString = commandLine.getOptionValue(ElasticSearchParameter.CONNECT_TIMEOUT.toString());
	if (StringUtils.isNotEmpty(connectTimeoutString)) {
		connectTimeout = Integer.parseInt(connectTimeoutString);
	}
	
	// get response timeout
	int responseTimeout = (Integer) ElasticSearchParameter.RESPONSE_TIMEOUT.getDefaultValue();
	String responseTimeoutString = commandLine.getOptionValue(ElasticSearchParameter.RESPONSE_TIMEOUT.toString());
	if (StringUtils.isNotEmpty(responseTimeoutString)) {
		responseTimeout = Integer.parseInt(connectTimeoutString);
	}		
	
	// get pattern 
	Pattern pattern = (Pattern) MongoParameter.PATTERN.getDefaultValue();
	String patternString = commandLine.getOptionValue(MongoParameter.PATTERN.toString());
	if (StringUtils.isNotEmpty(patternString)) {
		pattern = Pattern.compile(patternString);
	}
	
	// create MongoDB options builder
	MongoClientOptions.Builder builder = new MongoClientOptions.Builder()
	.connectTimeout(connectTimeout)
	.socketTimeout(responseTimeout);
	
	// create client for MongoDB server
	MongoClient mongoClient = new MongoClient(new MongoClientURI(url, builder));
	
	// get MongoDB database
	DB mongoDb = mongoClient.getDB(database);
	
	// get MongoDB collection
	Jongo jongo = new Jongo(mongoDb);
	MongoCollection mongoCollection = jongo.getCollection(collection);
	
	// execute MongoDB query
	StringBuffer resultBuffer = new StringBuffer();
	MongoCursor<Object> mongoCursor = mongoCollection.find(query).as(Object.class);
	while(mongoCursor.hasNext()) {
		resultBuffer.append(mongoCursor.next());
		resultBuffer.append("\n");
	}
	
	// get result as string
	String result = resultBuffer.toString();
	if (StringUtils.isNotEmpty(result)) {
		
		System.out.println(result);
		
		// check if query result matches the given pattern
		Matcher matcher = pattern.matcher(result);
		if (!matcher.find()) {
			throw new Exception("The pattern does not match the query result");
		}
	}
}
 
开发者ID:chrisipa,项目名称:health-checker,代码行数:73,代码来源:MongoHealthChecker.java

示例11: process

import org.jongo.MongoCursor; //导入方法依赖的package包/类
@Override
public void process() {

    if (!disableForDemo) {
        // if (lastRun == null) {
        // lastRun = LocalDate.now();
        // } else {
        // if (Duration.between(lastRun, LocalDate.now()).toDays() == 0) {
        // return;
        // }
        // }
    }

    Map<String, DailyReportProcessorConfigDTO> jobs = getJobs();

    MongoCollection collection = mongoDBService.getCollection(Constants.DB.BUILDS);
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    long timeInMills = calendar.getTimeInMillis();

    for (Map.Entry<String, DailyReportProcessorConfigDTO> entry : jobs.entrySet()) {
        String query = String.format("{ $and : [" + "   {jobId : '%s'}, " + "   {startTime : {$gt: %d}}, "
                + "   {processed:false}" + "]}", entry.getKey(), timeInMills);
        DailyStatistic statistic = new DailyStatistic();
        try {
            MongoCursor<CiReport> dailyReports = collection.find(query).as(CiReport.class);
            if (dailyReports.count() > 0) {
                while (dailyReports.hasNext()) {
                    CiReport report = dailyReports.next();
                    statistic.putReportToStatistic(report);
                }
                if (statistic.isNotEmpty()) {
                    generateReport(entry.getKey(), statistic);
                }
                dailyReports.close();
                collection.update(query).with("{processed:true}");
            }
        } catch (IOException ex) {
            LOGGER.error("Fail to close db cursor", ex);
        }
    }
}
 
开发者ID:eliogrin,项目名称:CISEN,代码行数:43,代码来源:DailyReportProcessor.java


注:本文中的org.jongo.MongoCursor.hasNext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。