Ejemplo n.º 1
0
  public static void main(String[] args) {
    OrientDBEnv env = new OrientDBEnv();

    OrientNode node = env.createNode("debate", 1);

    env.getDB().createIndex(INDEX, IndexType.UNIQUE, IndexValueType.LONG, IndexValueType.LONG);

    StopWatch sw = new StopWatch();

    sw.reset();

    sw.start("Create list");
    List<Integer> list = new ArrayList<Integer>(NUMBER);
    for (int i = 0; i < NUMBER; i++) {
      list.add(i);
    }
    sw.stop();

    sw.start("Randomizing");
    // RandomCollections.randomList( list );
    sw.stop();

    sw.start("Adding replies");
    for (int i : list) {
      OrientNode n = env.createNode("id", i);
      node.createEdge(n, TestEdgeType.REPLY).set("order", i).save();
      // System.out.println( "[" + i + "] " + n );
      env.getDB().putToIndex(INDEX, n, 1, i);
    }
    sw.stop();

    sw.start("Pagination #1");
    List<OrientNode> nodes = env.getDB().getFromIndexAbove(INDEX, 50, 1, 100);
    Collections.sort(nodes, new Sorter());
    System.out.println(nodes);
    sw.stop();

    sw.start("Pagination #2");
    List<OrientNode> nodes2 = env.getDB().getFromIndexAbove(INDEX, 50, 1, 100);
    Collections.sort(nodes2, new Sorter());
    System.out.println(nodes2);
    sw.stop();

    System.out.println(sw.print(10000));
  }
Ejemplo n.º 2
0
  public void doRequest(HttpServletRequest rqs, HttpServletResponse rsp)
      throws ServletException, IOException {
    // PrintWriter out = response.getWriter();

    StopWatch sw = new StopWatch();
    sw.reset();

    sw.start(rqs.getRequestURI());

    Core core = (Core) getServletContext().getAttribute("core");

    logger.debug("Query  : {]", rqs.getQueryString());
    logger.debug("URI    : {}", rqs.getRequestURI());
    logger.debug("METHOD : {}", rqs.getMethod());
    logger.debug("CORE   : {}", core);

    /* Instantiating request and response */
    Request request = new Request(rqs, core.getDefaultTemplate());
    request.setLocaleFromCookie("language");

    Response response = new Response(rsp);
    response.setCharacterEncoding("UTF-8");

    request.setStopWatch(sw);

    logger.debug("[Parameters] {}", rqs.getParameterMap());

    /* Instantiating context */
    VelocityContext vc = new VelocityContext();
    vc.put("title", "");

    request.setContext(vc);
    request.getContext().put("request", request);
    request.setRequestParts(rqs.getRequestURI().split("/"));
    logger.debug("------ {} -----", Arrays.asList(request.getRequestParts()));

    vc.put("currentUrl", rqs.getRequestURI());

    request.setUser(core.getAnonymousUser());
    request.setTheme(core.getDefaultTheme());

    request.getStopWatch().stop(rqs.getRequestURI());

    if (request.getRequestParts().length > 0
        && request.getRequestParts()[0].equalsIgnoreCase("static")) {
      try {
        ((Autonomous) core.getRoot().getChild("static")).autonomize(request, response);
      } catch (Throwable e) {
        throw new ServletException(e);
      }
    } else {
      request.getStopWatch().start("Authentication");

      logger.debug("THE USER: {}", request.getUser());
      try {
        logger.debug("AUTHENTICATING");
        core.getAuthentication().authenticate(request, response);
      } catch (AuthenticationException e) {
        logger.warn("Unable to authenticate", e);
      }

      logger.debug("THE USER: {}", request.getUser());
      request.getStopWatch().stop("Getting user");

      request.getStopWatch().stop("Authentication");
      request.getStopWatch().start("Render page");

      try {
        // Render the page
        Runner runner = core.render(request);
        runner.injectContext(request);
        runner.run(response);
        request.getUser().setSeen();
      } catch (CoreException e) {
        e.printStackTrace();
        if (response.isRenderingMain()) {
          response.renderError(request, e);
        } else {
          response.sendError(e.getCode(), e.getMessage());
        }
      } catch (Throwable e) {
        logger.error("CAUGHT ERROR");
        e.printStackTrace();
        generateException(request, rsp.getWriter(), e, e.getMessage());
      }
    }

    sw.stop();
    logger.info("Request response: {}", response.getResponse());

    // Render the bottom
    /*
    if( response.isRenderingMain() ) {
        try {
            vc.put( "seconds", sw.getSeconds() );
            response.getWriter().print( core.getTemplateManager().getRenderer( request ).render( "org/seventyeight/web/bottomPage.vm" ) );
        } catch( TemplateException e ) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
    */

    // logger.info( sw.print( 1000 ) );
    System.out.println(sw.print(10000));
  }