Browse Source

updated both dropwizard and dropwizard-mongo DW version to version 0.7.1. Updated mongojack version to 2.10 which uses Jackson 2.3.3. Copied across all test scenarios for dropwizard-mongo

Yun Zhi Lin 10 years ago
parent
commit
1cf1363526
22 changed files with 350 additions and 160 deletions
  1. 13 15
      frameworks/Java/dropwizard-mongodb/hello-world.yml
  2. 15 4
      frameworks/Java/dropwizard-mongodb/pom.xml
  3. 17 5
      frameworks/Java/dropwizard-mongodb/source_code
  4. 36 35
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/HelloWorldService.java
  5. 12 0
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/config/HelloWorldConfiguration.java
  6. 10 15
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/config/MongoConfiguration.java
  7. 20 0
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/db/FortuneDAO.java
  8. 2 3
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/db/MongoHealthCheck.java
  9. 5 5
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/db/MongoManaged.java
  10. 23 0
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/db/WorldDAO.java
  11. 35 0
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/db/model/Fortune.java
  12. 5 4
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/db/model/World.java
  13. 36 0
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/resources/FortuneResource.java
  14. 6 17
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/resources/JsonResource.java
  15. 26 0
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/resources/TextResource.java
  16. 39 50
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/resources/WorldResource.java
  17. 17 0
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/resources/api/HelloMessage.java
  18. 23 0
      frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/resources/views/FortuneView.java
  19. 4 1
      frameworks/Java/dropwizard/hello-world.yml
  20. 2 2
      frameworks/Java/dropwizard/pom.xml
  21. 1 0
      frameworks/Java/dropwizard/source_code
  22. 3 4
      frameworks/Java/dropwizard/src/main/java/com/example/helloworld/resources/WorldResource.java

+ 13 - 15
frameworks/Java/dropwizard-mongodb/hello-world.yml

@@ -1,20 +1,18 @@
-http:
-  port: 9000
+server:
+  type: simple
+  applicationContextPath: /
+  connector:
+    type: http
+    port: 9000
+    useServerHeader: true
 
 
   requestLog:
   requestLog:
-
-    # Settings for logging to stdout.
-    console:
-      # If true, log requests to stdout.
-      enabled: false
+    appenders: []
 
 
 logging:
 logging:
+  appenders: []
 
 
-  # The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
-  level: OFF
-
-  console:
-
-    # If true, write log statements to stdout.
-    enabled: false
-
+mongo:
+  host: 127.0.0.1
+  port: 27017
+  db: hello_world

+ 15 - 4
frameworks/Java/dropwizard-mongodb/pom.xml

@@ -8,16 +8,27 @@
     <artifactId>dropwizard-mongodb</artifactId>
     <artifactId>dropwizard-mongodb</artifactId>
     <version>0.0.1-SNAPSHOT</version>
     <version>0.0.1-SNAPSHOT</version>
 
 
+    <properties>
+        <jdk.version>1.7</jdk.version>
+
+        <dropwizard.version>0.7.1</dropwizard.version>
+    </properties>
+
     <dependencies>
     <dependencies>
         <dependency>
         <dependency>
-            <groupId>com.yammer.dropwizard</groupId>
+            <groupId>io.dropwizard</groupId>
             <artifactId>dropwizard-core</artifactId>
             <artifactId>dropwizard-core</artifactId>
-            <version>0.6.2</version>
+            <version>${dropwizard.version}</version>
         </dependency>
         </dependency>
-		<dependency>
+        <dependency>
+            <groupId>io.dropwizard</groupId>
+            <artifactId>dropwizard-views-mustache</artifactId>
+            <version>${dropwizard.version}</version>
+        </dependency>
+        <dependency>
 			<groupId>org.mongojack</groupId>
 			<groupId>org.mongojack</groupId>
 			<artifactId>mongojack</artifactId>
 			<artifactId>mongojack</artifactId>
-			<version>2.0.0</version>
+			<version>2.1.0</version>
 		</dependency>
 		</dependency>
 
 
     </dependencies>
     </dependencies>

+ 17 - 5
frameworks/Java/dropwizard-mongodb/source_code

@@ -1,11 +1,23 @@
 ./dropwizard-mongodb/src/main/java/com/example/helloworld/
 ./dropwizard-mongodb/src/main/java/com/example/helloworld/
+./dropwizard-mongodb/src/main/java/com/example/helloworld/config/HelloWorldConfiguration.java
+./dropwizard-mongodb/src/main/java/com/example/helloworld/config/MongoConfiguration.java
 ./dropwizard-mongodb/src/main/java/com/example/helloworld/db
 ./dropwizard-mongodb/src/main/java/com/example/helloworld/db
+./dropwizard-mongodb/src/main/java/com/example/helloworld/db/model
+./dropwizard-mongodb/src/main/java/com/example/helloworld/db/model/Fortune.java
+./dropwizard-mongodb/src/main/java/com/example/helloworld/db/model/World.java
+./dropwizard-mongodb/src/main/java/com/example/helloworld/db/FortuneDAO.java
+./dropwizard-mongodb/src/main/java/com/example/helloworld/db/WorldDAO.java
 ./dropwizard-mongodb/src/main/java/com/example/helloworld/db/MongoHealthCheck.java
 ./dropwizard-mongodb/src/main/java/com/example/helloworld/db/MongoHealthCheck.java
 ./dropwizard-mongodb/src/main/java/com/example/helloworld/db/MongoManaged.java
 ./dropwizard-mongodb/src/main/java/com/example/helloworld/db/MongoManaged.java
-./dropwizard-mongodb/src/main/java/com/example/helloworld/HelloWorldService.java
 ./dropwizard-mongodb/src/main/java/com/example/helloworld/resources
 ./dropwizard-mongodb/src/main/java/com/example/helloworld/resources
-./dropwizard-mongodb/src/main/java/com/example/helloworld/resources/WorldResource.java
+./dropwizard-mongodb/src/main/java/com/example/helloworld/resources/api
+./dropwizard-mongodb/src/main/java/com/example/helloworld/resources/api/HelloMessage
+./dropwizard-mongodb/src/main/java/com/example/helloworld/resources/views
+./dropwizard-mongodb/src/main/java/com/example/helloworld/resources/views/FortuneView
+./dropwizard-mongodb/src/main/java/com/example/helloworld/resources/FortuneResource.java
 ./dropwizard-mongodb/src/main/java/com/example/helloworld/resources/JsonResource.java
 ./dropwizard-mongodb/src/main/java/com/example/helloworld/resources/JsonResource.java
-./dropwizard-mongodb/src/main/java/com/example/helloworld/core
-./dropwizard-mongodb/src/main/java/com/example/helloworld/core/World.java
-./dropwizard-mongodb/src/main/java/com/example/helloworld/HelloWorldConfiguration.java
+./dropwizard-mongodb/src/main/java/com/example/helloworld/resources/TextResource.java
+./dropwizard-mongodb/src/main/java/com/example/helloworld/resources/WorldResource.java
+./dropwizard-mongodb/src/main/java/com/example/helloworld/resources/Helper.java
+./dropwizard-mongodb/src/main/java/com/example/helloworld/HelloWorldService.java
+./dropwizard/src/main/resources/fortunes.mustache

+ 36 - 35
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/HelloWorldService.java

@@ -1,47 +1,48 @@
 
 
 package com.example.helloworld;
 package com.example.helloworld;
 
 
-import java.net.UnknownHostException;
-
-import org.mongojack.JacksonDBCollection;
-
-import com.example.helloworld.core.World;
+import com.example.helloworld.config.HelloWorldConfiguration;
+import com.example.helloworld.db.FortuneDAO;
 import com.example.helloworld.db.MongoHealthCheck;
 import com.example.helloworld.db.MongoHealthCheck;
 import com.example.helloworld.db.MongoManaged;
 import com.example.helloworld.db.MongoManaged;
+import com.example.helloworld.db.WorldDAO;
+import com.example.helloworld.resources.FortuneResource;
 import com.example.helloworld.resources.JsonResource;
 import com.example.helloworld.resources.JsonResource;
+import com.example.helloworld.resources.TextResource;
 import com.example.helloworld.resources.WorldResource;
 import com.example.helloworld.resources.WorldResource;
 import com.mongodb.DB;
 import com.mongodb.DB;
-import com.mongodb.Mongo;
-import com.yammer.dropwizard.Service;
-import com.yammer.dropwizard.config.Bootstrap;
-import com.yammer.dropwizard.config.Environment;
+import com.mongodb.MongoClient;
+import io.dropwizard.Application;
+import io.dropwizard.setup.Bootstrap;
+import io.dropwizard.setup.Environment;
+
+import java.net.UnknownHostException;
 
 
 public class HelloWorldService
 public class HelloWorldService
-    extends Service<HelloWorldConfiguration>
-{
-
-  public static void main(String[] args) throws Exception
-  {
-    new HelloWorldService().run(args);
-  }
-
-  @Override
-  public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap)
-  {
-    bootstrap.setName("hello-world");
-  }
-
-  @Override
-  public void run(HelloWorldConfiguration config, Environment environment) throws UnknownHostException
-  {
-    Mongo mongo = new Mongo(config.mongohost, config.mongoport);
-    MongoManaged mongoManaged = new MongoManaged(mongo);
-    environment.manage(mongoManaged);
-    environment.addHealthCheck(new MongoHealthCheck(mongo));
-    DB db = mongo.getDB(config.mongodb);
-    JacksonDBCollection<World, String> worlds = JacksonDBCollection.wrap(db.getCollection("world"), World.class, String.class);
-    environment.addResource(new WorldResource(worlds));
-    environment.addResource(new JsonResource());
-  }
+        extends Application<HelloWorldConfiguration> {
+
+    public static void main(String[] args) throws Exception {
+        new HelloWorldService().run(args);
+    }
+
+    @Override
+    public void run(HelloWorldConfiguration config, Environment environment) throws UnknownHostException {
+        MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
+        environment.lifecycle().manage(new MongoManaged(mongoClient));
+        environment.healthChecks().register("mongo", new MongoHealthCheck(mongoClient));
+
+        DB db = mongoClient.getDB(config.mongo.db);
+        WorldDAO worldDAO = new WorldDAO(db);
+        FortuneDAO fortuneDAO = new FortuneDAO(db);
+
+        environment.jersey().register(new JsonResource());
+        environment.jersey().register(new WorldResource(worldDAO));
+        environment.jersey().register(new FortuneResource(fortuneDAO));
+        environment.jersey().register(new TextResource());
+    }
+
+    @Override
+    public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {
 
 
+    }
 }
 }

+ 12 - 0
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/config/HelloWorldConfiguration.java

@@ -0,0 +1,12 @@
+
+package com.example.helloworld.config;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.dropwizard.Configuration;
+
+public class HelloWorldConfiguration extends Configuration {
+    @JsonProperty
+    public MongoConfiguration mongo;
+
+
+}

+ 10 - 15
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/HelloWorldConfiguration.java → frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/config/MongoConfiguration.java

@@ -1,27 +1,22 @@
+package com.example.helloworld.config;
 
 
-package com.example.helloworld;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.hibernate.validator.constraints.NotEmpty;
 
 
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Min;
 import javax.validation.constraints.Min;
 
 
-import org.hibernate.validator.constraints.NotEmpty;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.yammer.dropwizard.config.Configuration;
-
-public class HelloWorldConfiguration
-    extends Configuration
-{
-	@JsonProperty
+public class MongoConfiguration {
+    @JsonProperty
     @NotEmpty
     @NotEmpty
-    public String mongohost = "localhost";
- 
+    public String host;
+
     @JsonProperty
     @JsonProperty
     @Min(1)
     @Min(1)
     @Max(65535)
     @Max(65535)
-    public int mongoport = 27017;
- 
+    public int port;
+
     @JsonProperty
     @JsonProperty
     @NotEmpty
     @NotEmpty
-    public String mongodb = "hello_world";
+    public String db;
 }
 }

+ 20 - 0
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/db/FortuneDAO.java

@@ -0,0 +1,20 @@
+package com.example.helloworld.db;
+
+import com.example.helloworld.db.model.Fortune;
+import com.mongodb.DB;
+import org.mongojack.JacksonDBCollection;
+
+import java.util.Collection;
+
+public class FortuneDAO {
+
+
+    private final JacksonDBCollection<Fortune, String> fortunes;
+    public FortuneDAO(DB db) {
+        fortunes = JacksonDBCollection.wrap(db.getCollection("fortunes"), Fortune.class, String.class);
+    }
+
+    public Collection<? extends Fortune> list() {
+        return null;
+    }
+}

+ 2 - 3
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/db/MongoHealthCheck.java

@@ -1,14 +1,13 @@
 package com.example.helloworld.db;
 package com.example.helloworld.db;
 
 
+import com.codahale.metrics.health.HealthCheck;
 import com.mongodb.Mongo;
 import com.mongodb.Mongo;
-import com.yammer.metrics.core.HealthCheck;
- 
+
 public class MongoHealthCheck extends HealthCheck {
 public class MongoHealthCheck extends HealthCheck {
  
  
     private Mongo mongo;
     private Mongo mongo;
  
  
     public MongoHealthCheck(Mongo mongo) {
     public MongoHealthCheck(Mongo mongo) {
-        super("MongoDBHealthCheck");
         this.mongo = mongo;
         this.mongo = mongo;
     }
     }
  
  

+ 5 - 5
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/db/MongoManaged.java

@@ -1,13 +1,13 @@
 package com.example.helloworld.db;
 package com.example.helloworld.db;
 
 
-import com.mongodb.Mongo;
-import com.yammer.dropwizard.lifecycle.Managed;
- 
+import com.mongodb.MongoClient;
+import io.dropwizard.lifecycle.Managed;
+
 public class MongoManaged implements Managed {
 public class MongoManaged implements Managed {
  
  
-    private Mongo mongo;
+    private MongoClient mongo;
  
  
-    public MongoManaged(Mongo mongo) {
+    public MongoManaged(MongoClient mongo) {
         this.mongo = mongo;
         this.mongo = mongo;
     }
     }
  
  

+ 23 - 0
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/db/WorldDAO.java

@@ -0,0 +1,23 @@
+package com.example.helloworld.db;
+
+import com.example.helloworld.db.model.World;
+import com.google.common.base.Optional;
+import com.mongodb.DB;
+import org.mongojack.JacksonDBCollection;
+
+public class WorldDAO {
+
+    private final JacksonDBCollection<World, String> worlds;
+
+    public WorldDAO(DB db) {
+        worlds = JacksonDBCollection.wrap(db.getCollection("world"), World.class, String.class);
+    }
+
+    public Optional<World> findById(long worldId) {
+        return Optional.fromNullable(worlds.findOneById(String.valueOf(worldId)));
+    }
+
+    public World update(World world) {
+        return worlds.insert(world).getSavedObject();
+    }
+}

+ 35 - 0
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/db/model/Fortune.java

@@ -0,0 +1,35 @@
+package com.example.helloworld.db.model;
+
+import javax.persistence.*;
+
+@Entity
+@Table(name = "Fortune")
+public class Fortune implements Comparable<Fortune> {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    private long id;
+
+    @Column(name = "message", nullable = false)
+    private String message;
+
+    @SuppressWarnings("unused")
+    public Fortune() {}
+
+    public Fortune(String message) {
+        this.message = message;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    @Override
+    public int compareTo(Fortune o) {
+        return message.compareTo(o.message);
+    }
+}

+ 5 - 4
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/core/World.java → frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/db/model/World.java

@@ -1,11 +1,12 @@
 
 
-package com.example.helloworld.core;
-
-import javax.persistence.*;
+package com.example.helloworld.db.model;
 
 
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import org.mongojack.Id;
 import org.mongojack.Id;
 
 
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Table;
 
 
 @Entity
 @Entity
 @Table(name = "World")
 @Table(name = "World")

+ 36 - 0
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/resources/FortuneResource.java

@@ -0,0 +1,36 @@
+package com.example.helloworld.resources;
+
+import com.example.helloworld.db.FortuneDAO;
+import com.example.helloworld.db.model.Fortune;
+import com.example.helloworld.resources.views.FortuneView;
+import com.google.common.collect.Lists;
+import com.mongodb.DB;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import java.util.Collections;
+import java.util.List;
+
+@Path("/fortunes")
+@Produces(MediaType.TEXT_HTML + ";charset=UTF-8")
+public class FortuneResource {
+
+    private final FortuneDAO fortuneDAO;
+
+    public FortuneResource(FortuneDAO fortuneDAO) {
+        this.fortuneDAO = fortuneDAO;
+    }
+
+    @GET
+    public FortuneView dbTest() {
+        final List<Fortune> fortunes = Lists.newArrayListWithExpectedSize(32);
+
+        fortunes.addAll(fortuneDAO.list());
+        fortunes.add(new Fortune("Additional fortune added at request time."));
+
+        Collections.sort(fortunes);
+        return new FortuneView(fortunes);
+    }
+}

+ 6 - 17
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/resources/JsonResource.java

@@ -1,8 +1,7 @@
 
 
 package com.example.helloworld.resources;
 package com.example.helloworld.resources;
 
 
-import java.util.HashMap;
-import java.util.Map;
+import com.example.helloworld.resources.api.HelloMessage;
 
 
 import javax.ws.rs.GET;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Path;
@@ -11,20 +10,10 @@ import javax.ws.rs.core.MediaType;
 
 
 @Path("/json")
 @Path("/json")
 @Produces(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
-public class JsonResource
-{
-  // Response message class (copied from 'servlet' test)
-  public final static class HelloMessage {
-    public final String message;
+public class JsonResource {
 
 
-    public HelloMessage(String m) { message = m; }
-  }
-
-  public JsonResource() { }
-
-  @GET
-  public HelloMessage sayHello()
-  {
-    return new HelloMessage("Hello, World!");
-  }
+    @GET
+    public HelloMessage sayHello() {
+        return new HelloMessage("Hello, World!");
+    }
 }
 }

+ 26 - 0
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/resources/TextResource.java

@@ -0,0 +1,26 @@
+package com.example.helloworld.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+@Path("/plaintext")
+@Produces(MediaType.TEXT_PLAIN)
+public class TextResource {
+	private static final String MESSAGE = "Hello, World!";
+	private static final byte[] buffer;
+
+	static {
+		try {
+			buffer = MESSAGE.getBytes("US-ASCII");
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	@GET
+	public byte[] sayHello() {
+		return buffer;
+	}
+}

+ 39 - 50
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/resources/WorldResource.java

@@ -1,66 +1,55 @@
 package com.example.helloworld.resources;
 package com.example.helloworld.resources;
 
 
+import com.example.helloworld.db.WorldDAO;
+import com.example.helloworld.db.model.World;
+import com.google.common.base.Optional;
+
 import javax.ws.rs.GET;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MediaType;
 
 
-import org.mongojack.DBCursor;
-import org.mongojack.JacksonDBCollection;
-
-import com.example.helloworld.core.World;
-import com.google.common.base.Optional;
-import com.google.common.primitives.Ints;
-import com.mongodb.BasicDBObject;
-import com.mongodb.DBObject;
-
 @Path("/db")
 @Path("/db")
 @Produces(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
-public class WorldResource
-{
+public class WorldResource {
+    private final WorldDAO worldDAO;
 
 
-  private JacksonDBCollection<World, String> collection;
- 
-  public WorldResource(JacksonDBCollection<World, String> collection)
-  {
-    this.collection = collection;
-  }
+    public WorldResource(WorldDAO worldDAO) {
+        this.worldDAO = worldDAO;
 
 
-  @GET
-  public Object dbTest(@QueryParam("queries") Optional<String> queries)
-  {
-    if (!queries.isPresent()) 
-    {
-      DBObject query = new BasicDBObject();
-      query.put("_id", Helper.randomWorld());
-      DBCursor<World> dbCursor = collection.find(query);
-      return (dbCursor.hasNext()) ? dbCursor.next() : null;
     }
     }
-    Integer totalQueries = Ints.tryParse(queries.orNull());
-    if (totalQueries != null) 
-    {
-      if (totalQueries > 500) 
-      {
-        totalQueries = 500;
-      }
-      else if (totalQueries < 1) 
-      {
-        totalQueries = 1;
-      }
-    } 
-    else 
-    {
-      totalQueries = 1;
+
+    @GET
+    public Object dbTest(@QueryParam("queries") Optional<String> queries) {
+        int totalQueries = Helper.getQueries(queries);
+        final World[] worlds = new World[totalQueries];
+
+        for (int i = 0; i < totalQueries; i++) {
+            final long worldId = Helper.randomWorld();
+            worlds[i] = worldDAO.findById(worldId).orNull();
+        }
+        if (!queries.isPresent()) {
+            return worlds[0];
+        } else {
+            return worlds;
+        }
     }
     }
-    final World[] worlds = new World[totalQueries];
-    for (int i = 0; i < totalQueries; i++)
-    {
-      DBObject query = new BasicDBObject();
-      query.put("_id", Helper.randomWorld());
-      DBCursor<World> dbCursor = collection.find(query);
-      worlds[i] = (dbCursor.hasNext()) ? dbCursor.next() : null;
+
+    @GET
+    @Path("/update")
+    public World[] updateTest(@QueryParam("queries") Optional<String> queries) {
+        int totalQueries = Helper.getQueries(queries);
+        final World[] worlds = new World[totalQueries];
+
+        for (int i = 0; i < totalQueries; i++) {
+            final long worldId = Helper.randomWorld();
+
+            final World world = worldDAO.findById(worldId).orNull();
+            world.setRandomNumber(Helper.randomWorld());
+            worlds[i] = worldDAO.update(world);
+        }
+
+        return worlds;
     }
     }
-    return worlds;
-  }
 }
 }

+ 17 - 0
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/resources/api/HelloMessage.java

@@ -0,0 +1,17 @@
+package com.example.helloworld.resources.api;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public final class HelloMessage {
+
+    @JsonProperty
+    private final String message;
+
+    public HelloMessage(String m) {
+        message = m;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+}

+ 23 - 0
frameworks/Java/dropwizard-mongodb/src/main/java/com/example/helloworld/resources/views/FortuneView.java

@@ -0,0 +1,23 @@
+package com.example.helloworld.resources.views;
+
+import com.example.helloworld.db.model.Fortune;
+import io.dropwizard.views.View;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+public class FortuneView extends View {
+
+    private final List<Fortune> fortunes;
+
+    public FortuneView(List<Fortune> fortunes) {
+        super("/fortunes.mustache", StandardCharsets.UTF_8);
+
+        this.fortunes = fortunes;
+    }
+
+    @SuppressWarnings("unused")
+    public List<Fortune> getFortunes() {
+        return fortunes;
+    }
+}

+ 4 - 1
frameworks/Java/dropwizard/hello-world.yml

@@ -23,7 +23,7 @@ database:
   password: benchmarkdbpass
   password: benchmarkdbpass
 
 
   # the JDBC URL
   # the JDBC URL
-  url: jdbc:mysql://localhost:3306/hello_world?jdbcCompliantTruncation=false&elideSetAutoCommits=true&useLocalSessionState=true&cachePrepStmts=true&cacheCallableStmts=true&alwaysSendSetIsolation=false&prepStmtCacheSize=4096&cacheServerConfiguration=true&prepStmtCacheSqlLimit=2048&zeroDateTimeBehavior=convertToNull&traceProtocol=false&useUnbufferedInput=false&useReadAheadInput=false&maintainTimeStats=false&useServerPrepStmts&cacheRSMetadata=true
+  url: jdbc:mysql://127.0.0.1:3306/hello_world?jdbcCompliantTruncation=false&elideSetAutoCommits=true&useLocalSessionState=true&cachePrepStmts=true&cacheCallableStmts=true&alwaysSendSetIsolation=false&prepStmtCacheSize=4096&cacheServerConfiguration=true&prepStmtCacheSqlLimit=2048&zeroDateTimeBehavior=convertToNull&traceProtocol=false&useUnbufferedInput=false&useReadAheadInput=false&maintainTimeStats=false&useServerPrepStmts&cacheRSMetadata=true
 
 
   # any properties specific to your JDBC driver:
   # any properties specific to your JDBC driver:
   properties:
   properties:
@@ -40,3 +40,6 @@ database:
 
 
   # whether or not idle connections should be validated
   # whether or not idle connections should be validated
   checkConnectionWhileIdle: false
   checkConnectionWhileIdle: false
+
+  properties:
+    hibernate.dialect: org.hibernate.dialect.MySQLDialect

+ 2 - 2
frameworks/Java/dropwizard/pom.xml

@@ -9,8 +9,8 @@
     <properties>
     <properties>
         <jdk.version>1.7</jdk.version>
         <jdk.version>1.7</jdk.version>
 
 
-        <dropwizard.version>0.7.0</dropwizard.version>
-        <mysql-connector-java.version>5.1.30</mysql-connector-java.version>
+        <dropwizard.version>0.7.1</dropwizard.version>
+        <mysql-connector-java.version>5.1.35</mysql-connector-java.version>
     </properties>
     </properties>
 
 
     <dependencies>
     <dependencies>

+ 1 - 0
frameworks/Java/dropwizard/source_code

@@ -16,5 +16,6 @@
 ./dropwizard/src/main/java/com/example/helloworld/resources/JsonResource.java
 ./dropwizard/src/main/java/com/example/helloworld/resources/JsonResource.java
 ./dropwizard/src/main/java/com/example/helloworld/resources/TextResource.java
 ./dropwizard/src/main/java/com/example/helloworld/resources/TextResource.java
 ./dropwizard/src/main/java/com/example/helloworld/resources/WorldResource.java
 ./dropwizard/src/main/java/com/example/helloworld/resources/WorldResource.java
+./dropwizard/src/main/java/com/example/helloworld/resources/Helper.java
 ./dropwizard/src/main/java/com/example/helloworld/HelloWorldService.java
 ./dropwizard/src/main/java/com/example/helloworld/HelloWorldService.java
 ./dropwizard/src/main/resources/fortunes.mustache
 ./dropwizard/src/main/resources/fortunes.mustache

+ 3 - 4
frameworks/Java/dropwizard/src/main/java/com/example/helloworld/resources/WorldResource.java

@@ -1,5 +1,8 @@
 package com.example.helloworld.resources;
 package com.example.helloworld.resources;
 
 
+import com.example.helloworld.db.WorldDAO;
+import com.example.helloworld.db.model.World;
+import com.google.common.base.Optional;
 import io.dropwizard.hibernate.UnitOfWork;
 import io.dropwizard.hibernate.UnitOfWork;
 
 
 import javax.ws.rs.GET;
 import javax.ws.rs.GET;
@@ -8,10 +11,6 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MediaType;
 
 
-import com.example.helloworld.db.WorldDAO;
-import com.example.helloworld.db.model.World;
-import com.google.common.base.Optional;
-
 @Path("/db")
 @Path("/db")
 @Produces(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 public class WorldResource {
 public class WorldResource {