|
@@ -4,6 +4,7 @@ import java.io.IOException;
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
|
|
import org.apache.wicket.request.resource.AbstractResource;
|
|
|
+import org.hibernate.IdentifierLoadAccess;
|
|
|
import org.hibernate.Session;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
@@ -14,6 +15,7 @@ public class HelloDbResponse extends AbstractResource
|
|
|
|
|
|
private static final int DB_ROWS = 10000;
|
|
|
|
|
|
+ private static final String CONTENT_TYPE = "application/json";
|
|
|
private static final ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
|
protected ResourceResponse newResourceResponse(Attributes attributes)
|
|
@@ -23,16 +25,18 @@ public class HelloDbResponse extends AbstractResource
|
|
|
final ThreadLocalRandom random = ThreadLocalRandom.current();
|
|
|
|
|
|
final ResourceResponse response = new ResourceResponse();
|
|
|
- response.setContentType("application/json");
|
|
|
+ response.setContentType(CONTENT_TYPE);
|
|
|
|
|
|
- response.setWriteCallback(new WriteCallback() {
|
|
|
+ response.setWriteCallback(new WriteCallback()
|
|
|
+ {
|
|
|
public void writeData(Attributes attributes)
|
|
|
{
|
|
|
final Session session = HibernateUtil.getSessionFactory().openSession();
|
|
|
|
|
|
+ IdentifierLoadAccess loader = session.byId(World.class);
|
|
|
for (int i = 0; i < queries; i++)
|
|
|
{
|
|
|
- worlds[i] = (World)session.byId(World.class).load(random.nextInt(DB_ROWS) + 1);
|
|
|
+ worlds[i] = (World) loader.load(random.nextInt(DB_ROWS) + 1);
|
|
|
}
|
|
|
|
|
|
session.close();
|