本文整理汇总了Java中org.mongojack.WriteResult类的典型用法代码示例。如果您正苦于以下问题:Java WriteResult类的具体用法?Java WriteResult怎么用?Java WriteResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WriteResult类属于org.mongojack包,在下文中一共展示了WriteResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例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();
}
示例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;
}
示例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());
}
}
示例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);
}
}
示例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();
}
示例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;
}
示例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());
}
}
示例12: addShipment
import org.mongojack.WriteResult; //导入依赖的package包/类
@Override
public Shipment addShipment(Shipment s) {
WriteResult<Shipment, String> result = shipments.insert(s);
return result.getSavedObject();
}
示例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();
}
示例14: updateGameLogById
import org.mongojack.WriteResult; //导入依赖的package包/类
public WriteResult<GameLog, String> updateGameLogById(GameLog gameLog) {
return gameLogCollection.updateById(gameLog.getId(), gameLog);
}
示例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