List of usage examples for org.springframework.data.mongodb.core WriteResultChecking EXCEPTION
WriteResultChecking EXCEPTION
To view the source code for org.springframework.data.mongodb.core WriteResultChecking EXCEPTION.
Click Source Link
From source file:com.porvak.bracket.config.EmbeddedDataConfig.java
@Bean @Override/* w w w . j a v a 2 s. c o m*/ public MongoTemplate mongoTemplate() throws Exception { MongoTemplate mongoTemplate = super.mongoTemplate(); mongoTemplate.setWriteConcern(WriteConcern.JOURNAL_SAFE); mongoTemplate.setWriteResultChecking(WriteResultChecking.EXCEPTION); return mongoTemplate; }
From source file:com.bosch.iot.things.example.historian.Collector.java
@PostConstruct public void start() { mongoTemplate.setWriteResultChecking(WriteResultChecking.EXCEPTION); if (!mongoTemplate.collectionExists("history")) { mongoTemplate.createCollection("history"); }/*from www . java2s .co m*/ Thread thread = new Thread(this); thread.start(); LOGGER.info("Historian collector started"); }
From source file:com.bosch.iot.things.example.historian.Controller.java
@PostConstruct public void postConstruct() { mongoTemplate.setWriteResultChecking(WriteResultChecking.EXCEPTION); }
From source file:org.springframework.data.mongodb.core.MongoTemplate.java
/** * Checks and handles any errors.// ww w.j a v a2 s .c om * <p/> * Current implementation logs errors. Future version may make this configurable to log warning, errors or throw * exception. */ protected void handleAnyWriteResultErrors(WriteResult wr, DBObject query, String operation) { if (WriteResultChecking.NONE == this.writeResultChecking) { return; } String error = wr.getError(); if (error != null) { String message; if (operation.equals("insert") || operation.equals("save")) { // assuming the insert operations will begin with insert string message = String.format("Insert/Save for %s failed: %s", query, error); } else if (operation.equals("insert_list")) { message = String.format("Insert list failed: %s", error); } else { message = String.format("Execution of %s%s failed: %s", operation, query == null ? "" : "' using '" + query.toString() + "' query", error); } if (WriteResultChecking.EXCEPTION == this.writeResultChecking) { throw new DataIntegrityViolationException(message); } else { LOGGER.error(message); return; } } }