• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java WriteResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.mongojack.WriteResult的典型用法代码示例。如果您正苦于以下问题:Java WriteResult类的具体用法?Java WriteResult怎么用?Java WriteResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: add

import org.mongojack.WriteResult; //导入依赖的package包/类
@POST
public Response add(String in) {
    JSONParser p = new JSONParser(JSONParser.MODE_RFC4627);
    try {
        JSONObject o = (JSONObject) p.parse(in);
        UseCase uc = new UseCase();
        uc.setTitle(o.getAsString("title"));
        uc.setDescription(o.getAsString("description"));
        uc.setScript(o.getAsString("script"));
        uc.setModel(o.getAsString("model"));
        uc.setHits(0);
        uc.setLastHit(System.currentTimeMillis());
        WriteResult<UseCase, String> result = getJacksonDBCollection().insert(uc);
        String id = result.getSavedId();
        return Response.ok(id).build();
    } catch (Exception e) {
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
}
 
开发者ID:btrplace,项目名称:playd,代码行数:20,代码来源:Store.java


示例2: createPlayer

import org.mongojack.WriteResult; //导入依赖的package包/类
/**
 * Returns the id to the player created
 *
 * @return the id of the newly created player
 * @throws PlayerExistException - Throws this exception if username already exists
 */
@SneakyThrows
public String createPlayer(String usernameEncoded, String passwordEncoded, String emailEncoded) throws PlayerExistException {
    Preconditions.checkNotNull(usernameEncoded);
    Preconditions.checkNotNull(passwordEncoded);
    Preconditions.checkNotNull(emailEncoded);

    String username = URLDecoder.decode(usernameEncoded, "UTF-8");
    String email = URLDecoder.decode(emailEncoded, "UTF-8");
    String password = URLDecoder.decode(passwordEncoded, "UTF-8");

    if (CivSingleton.instance().playerCache().asMap().containsValue(username)) {
        throw new PlayerExistException();
    }

    Player player = new Player();
    player.setUsername(username);
    String decodedPassword = new String(Base64.getDecoder().decode(password), "UTF-8");

    player.setPassword(DigestUtils.sha1Hex(decodedPassword));
    player.setEmail(email);
    WriteResult<Player, String> insert = playerCollection.insert(player);
    log.info(String.format("Saving player with id %s", insert.getSavedId()));
    return insert.getSavedId();
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:31,代码来源:PlayerAction.java


示例3: deleteGame

import org.mongojack.WriteResult; //导入依赖的package包/类
public boolean deleteGame(String gameid) {
    Preconditions.checkNotNull(gameid);

    final PBF pbf = findPBFById(gameid);
    WriteResult<PBF, String> writeResult = pbfCollection.removeById(gameid);
    log.warn("Managed to delete game: " + Strings.isNullOrEmpty(writeResult.getWriteResult().toString()));

    List<Player> playerList = playerCollection.find().toArray().stream()
            .filter(p -> p.getGameIds().contains(gameid))
            .collect(toList());

    playerList.forEach(player -> {
        log.info("Deleting game from " + player.getUsername() + "s collection also");
        player.getGameIds().remove(gameid);
        SendEmail.sendMessage(player.getEmail(), "Game deleted", "Your game " + pbf.getName() + " was deleted by the admin. " +
                "If this was incorrect, please contact the admin.", player.getId());
        playerCollection.save(player);
    });

    return true;
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:22,代码来源:GameAction.java


示例4: createNewPBFGame

import org.mongojack.WriteResult; //导入依赖的package包/类
private void createNewPBFGame() throws IOException {
    PBFTestAction pbfTestAction = new PBFTestAction();
    PBF pbf = pbfTestAction.createNewGame("First civ game");
    WriteResult<PBF, String> writeResult = pbfCollection.insert(pbf);
    pbfId = writeResult.getSavedId();

    PBF oneById = pbfCollection.findOneById(pbfId);
    Playerhand cash1981 = createPlayerhand(createPlayer("cash1981", pbfId));
    cash1981.setGameCreator(true);
    cash1981.setYourTurn(true);
    oneById.getPlayers().add(cash1981);
    oneById.getPlayers().add(createPlayerhand(createPlayer("Karandras1", pbfId)));
    oneById.getPlayers().add(createPlayerhand(createPlayer("Itchi", pbfId)));
    oneById.getPlayers().add(createPlayerhand(createPlayer("Chul", pbfId)));
    pbfCollection.updateById(pbfId, oneById);
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:17,代码来源:CivilizationIntegrationTestApplication.java


示例5: createAnotherPBF

import org.mongojack.WriteResult; //导入依赖的package包/类
private void createAnotherPBF() throws IOException {
    PBFTestAction pbfTestAction = new PBFTestAction();
    PBF pbf = pbfTestAction.createNewGame("Second civ game");
    WriteResult<PBF, String> writeResult = pbfCollection.insert(pbf);
    pbfId_2 = writeResult.getSavedId();

    PBF oneById = pbfCollection.findOneById(pbfId_2);
    Playerhand morthai = createPlayerhand(createPlayer("Morthai", pbfId_2));
    morthai.setGameCreator(true);
    morthai.setYourTurn(true);
    oneById.getPlayers().add(morthai);
    oneById.getPlayers().add(createPlayerhand(createPlayer("CJWF", pbfId_2)));
    oneById.getPlayers().add(createPlayerhand(createPlayer("DaveLuca", pbfId_2)));
    oneById.getPlayers().add(createPlayerhand(createPlayer("Foobar", pbfId_2)));
    oneById.setActive(false);
    pbfCollection.updateById(pbfId_2, oneById);
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:18,代码来源:CivilizationIntegrationTestApplication.java


示例6: put

import org.mongojack.WriteResult; //导入依赖的package包/类
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public MongoDocument put(@Valid BasicPage newPage) {

    try {

        final JacksonDBCollection<BasicPage,String> col = JacksonDBCollection.wrap(mongoDb.getCollection("assets"),
                BasicPage.class, String.class);
        WriteResult<BasicPage, String> res = null;
        res = col.insert(newPage);
        MongoDocument d = new MongoDocument();
        d.setId(((ObjectId)res.getDbObject().get("_id")).toString());

        return d;

    } catch(Exception e) {
        Response.ResponseBuilder response = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
        response.entity("{\"message\":\""+e.getMessage()+"\"}");
        //TODO: Add logging
        throw new WebApplicationException(response.build());
    }

}
 
开发者ID:eeb,项目名称:dropwizard-mongo-cms,代码行数:25,代码来源:BasicPageResource.java


示例7: delete

import org.mongojack.WriteResult; //导入依赖的package包/类
@Override
public void delete(String id) {
    final WriteResult<RuleDao, String> result = dbCollection.removeById(id);
    if (result.getN() != 1) {
        log.error("Unable to delete rule {}", id);
    }
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-pipeline-processor,代码行数:8,代码来源:MongoDbRuleService.java


示例8: save

import org.mongojack.WriteResult; //导入依赖的package包/类
String save(@NotNull @Valid GameLog gameLog) {
    Preconditions.checkNotNull(gameLog);

    WriteResult<GameLog, String> insert = this.gameLogCollection.insert(gameLog);
    log.debug("Saved Gamelog with _id " + insert.getSavedId());
    return insert.getSavedId();
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:8,代码来源:GameLogAction.java


示例9: createPlayer

import org.mongojack.WriteResult; //导入依赖的package包/类
private Player createPlayer(String username, String pbfId) throws JsonProcessingException {
    //The Player object should be cached and retrieved from cache
    Player player = new Player();
    player.setUsername(username);
    player.getGameIds().add(pbfId);
    player.setEmail(username + "@mailinator.com");
    player.setPassword(DigestUtils.sha1Hex("foo"));

    WriteResult<Player, String> writeResult = playerCollection.insert(player);
    System.out.println("Saved player " + writeResult.toString());
    player.setId(writeResult.getSavedId());
    return player;
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:14,代码来源:CivilizationIntegrationTestApplication.java


示例10: createPlayer

import org.mongojack.WriteResult; //导入依赖的package包/类
private static Player createPlayer(String username, String pbfId) throws JsonProcessingException {
    //The Player object should be cached and retrieved from cache
    Player player = new Player();
    player.setUsername(username);
    player.setPassword(DigestUtils.sha1Hex("foo"));
    player.getGameIds().add(pbfId);

    WriteResult<Player, String> writeResult = getApp().playerCollection.insert(player);
    System.out.println("Saved player " + writeResult.toString());
    assertNotNull(writeResult.getSavedId());
    return player;
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:13,代码来源:MongoDBTest.java


示例11: save

import org.mongojack.WriteResult; //导入依赖的package包/类
public void save(T object) {
	if (isPersistent(object)) {
		update(object);
	}
	else {
		final WriteResult<T, K> writeResult = dbCollection.insert(object);
		// FIXME: it seems insert() returns n=0 even when the write is successful. Investigate.
		// assertNumberOfChanges(writeResult);
		primaryKeyEncoder.set(object, writeResult.getSavedId());
	}
}
 
开发者ID:thiagohp,项目名称:eloquentia,代码行数:12,代码来源:AbstractDAOImpl.java


示例12: addShipment

import org.mongojack.WriteResult; //导入依赖的package包/类
@Override
public Shipment addShipment(Shipment s) {
	WriteResult<Shipment, String> result = shipments.insert(s);
	return result.getSavedObject();
}
 
开发者ID:IBMDecisionOptimization,项目名称:DOcloud-GreenTruck-sample,代码行数:6,代码来源:TruckingManagerBean.java


示例13: createNewGame

import org.mongojack.WriteResult; //导入依赖的package包/类
public String createNewGame(CreateNewGameDTO dto, String playerId) {
    PBF pbf = new PBF();
    pbf.setName(dto.getName());
    pbf.setType(dto.getType());
    pbf.setNumOfPlayers(dto.getNumOfPlayers());
    ItemReader itemReader = new ItemReader();
    readItemFromExcel(dto.getType(), itemReader);

    pbf.getItems().addAll(itemReader.shuffledCivs);
    pbf.getItems().addAll(itemReader.shuffledCultureI);
    pbf.getItems().addAll(itemReader.shuffledCultureII);
    pbf.getItems().addAll(itemReader.shuffledCultureIII);
    pbf.getItems().addAll(itemReader.shuffledGPs);
    pbf.getItems().addAll(itemReader.shuffledHuts);
    pbf.getItems().addAll(itemReader.shuffledVillages);
    pbf.getItems().addAll(itemReader.shuffledTiles);
    pbf.getItems().addAll(itemReader.shuffledCityStates);
    pbf.getItems().addAll(itemReader.ancientWonders);
    pbf.getItems().addAll(itemReader.medievalWonders);
    pbf.getItems().addAll(itemReader.modernWonders);
    pbf.getItems().addAll(itemReader.mountedList);
    pbf.getItems().addAll(itemReader.aircraftList);
    pbf.getItems().addAll(itemReader.artilleryList);
    pbf.getItems().addAll(itemReader.infantryList);
    pbf.getTechs().addAll(itemReader.allTechs);
    pbf.getSocialPolicies().addAll(itemReader.socialPolicies);

    Collections.shuffle(pbf.getItems(), new Random(System.nanoTime()));
    Collections.shuffle(pbf.getTechs(), new Random(System.nanoTime()));
    Collections.shuffle(pbf.getSocialPolicies(), new Random(System.nanoTime()));

    pbf.getItems().forEach(it -> it.setItemNumber(ItemReader.itemCounter.incrementAndGet()));
    pbf.getTechs().forEach(it -> it.setItemNumber(ItemReader.itemCounter.incrementAndGet()));
    pbf.getSocialPolicies().forEach(it -> it.setItemNumber(ItemReader.itemCounter.incrementAndGet()));

    WriteResult<PBF, String> pbfInsert = pbfCollection.insert(pbf);
    pbf.setId(pbfInsert.getSavedId());
    log.info("PBF game created with id " + pbfInsert.getSavedId());
    joinGame(pbf, playerId, Optional.of(dto.getColor()), true);

    //Do this in a new thread
    Thread thread = new Thread(() -> {
        playerCollection.find().toArray().stream()
                .filter(p -> !p.isDisableEmail())
                .filter(CivUtil::shouldSendEmail)
                .forEach(p -> {
                    SendEmail.sendMessage(p.getEmail(), "New Civilization game created",
                            "A new game by the name " + pbf.getName() + " was just created! Visit " + SendEmail.URL + " to join the game.", p.getId());
                    playerCollection.updateById(p.getId(), p);
                });
    });
    thread.start();
    return pbf.getId();
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:55,代码来源:GameAction.java


示例14: updateGameLogById

import org.mongojack.WriteResult; //导入依赖的package包/类
public WriteResult<GameLog, String> updateGameLogById(GameLog gameLog) {
    return gameLogCollection.updateById(gameLog.getId(), gameLog);
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:4,代码来源:GameLogAction.java


示例15: createEmptyPBF

import org.mongojack.WriteResult; //导入依赖的package包/类
private void createEmptyPBF() throws IOException {
    PBFTestAction pbfTestAction = new PBFTestAction();
    PBF pbf = pbfTestAction.createNewGame("Third civ game");
    WriteResult<PBF, String> writeResult = pbfCollection.insert(pbf);
    pbfId_3 = writeResult.getSavedId();
}
 
开发者ID:cash1981,项目名称:civilization-boardgame-rest,代码行数:7,代码来源:CivilizationIntegrationTestApplication.java


示例16: assertNumberOfChanges

import org.mongojack.WriteResult; //导入依赖的package包/类
protected void assertNumberOfChanges(final WriteResult<T, K> writeResult) {
	final int n = writeResult.getN();
	if (n != 1) {
		throw new MongoException(String.format("AbstractDAOImpl.update() changed %d records instead of 1", n));
	}
}
 
开发者ID:thiagohp,项目名称:eloquentia,代码行数:7,代码来源:AbstractDAOImpl.java


示例17: update

import org.mongojack.WriteResult; //导入依赖的package包/类
public T update(T object) {
	
	if (!isPersistent(object)) {
		throw new RuntimeException("Object is not persistent for update: " + object);
	}
	
	K id = primaryKeyEncoder.get(object);
	final WriteResult<T, K> writeResult = dbCollection.updateById(id, object);
	assertNumberOfChanges(writeResult);

	return object;
	
}
 
开发者ID:thiagohp,项目名称:eloquentia,代码行数:14,代码来源:AbstractDAOImpl.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Resource类代码示例发布时间:2022-05-22
下一篇:
Java Option类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap