Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Singleton
- public class ExecutionDao {
- @Inject MongoClient mongoClient;
- @Inject Mapper mapper;
- MongoCollection mongoCollection;
- @PostConstruct
- public void init() {
- Jongo jongo = new Jongo(mongoClient.getDB("mongo_platform"), mapper);
- mongoCollection = jongo.getCollection("executions");
- mongoCollection.ensureIndex("{creationDate:1}");
- }
- public Optional<Execution> findLastSuccessful(String executionId) {
- Iterable<Execution> lastSuccessfulExecutions = mongoCollection.find(
- "{$and: [ {executionId : #} ," +
- " { $where : \"function() { " +
- " return this.executions.every( function(operation) {" +
- " return (operation.read.executionStatus === 'SUCCESS' " +
- " && operation.process.executionStatus === 'SUCCESS' " +
- " && operation.write.executionStatus === 'SUCCESS') " +
- " }) " +
- " }\"" +
- " } " +
- "] " +
- "}", executionId)
- .sort("{'creationDate' : -1}").limit(1).as(Execution.class);
- return FluentIterable.from(lastSuccessfulExecutions).first();
- }
- }
- public class MongoClientFactory implements Factory<MongoClient> {
- @Override
- public MongoClient provide() {
- MongoClientOptions mongoClientOptions = new MongoClientOptions.Builder()
- .cursorFinalizerEnabled(false) //
- .connectionsPerHost(250).build(); //
- return new MongoClient(new ServerAddress("localhost", 27017), mongoClientOptions);
- }
- @Override
- public void dispose(MongoClient mongoClient) {
- }
- }
- public class JongoMapperFactory implements Factory<Mapper> {
- @Override
- public Mapper provide() {
- return new JacksonMapper.Builder()
- .registerModule(new JodaModule()
- .addSerializer(LocalDateTime.class, new CustomLocalDateTimeSerializer())
- .addDeserializer(LocalDateTime.class, new CustomLocalDateTimeDeserializer())
- ).disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS)
- .build();
- }
- @Override
- public void dispose(Mapper mapper) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment