import java.sql.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Map;

import java.net.URI;
import java.net.URISyntaxException;

import static spark.Spark.*;
import spark.template.freemarker.FreeMarkerEngine;
import spark.ModelAndView;
import static spark.Spark.get;

import static javax.measure.unit.SI.KILOGRAM;
import javax.measure.quantity.Mass;
import org.jscience.physics.model.RelativisticModel;
import org.jscience.physics.amount.Amount;
import com.heroku.sdk.jdbc.DatabaseUrl;

import routes.*;

public class Main {

  public static void main(String[] args) {

    port(Integer.valueOf(System.getenv("PORT")));
    staticFileLocation("/public");

    Object r = new RouteTest();

    new UserController(new UserService());

    get("/hello", (req, res) -> {
          RelativisticModel.select();

        //   String energy = System.getenv().get("ENERGY");
          //
        //   Amount<Mass> m = Amount.valueOf(energy).to(KILOGRAM);
        //   return "E=mc^2: " + energy + " = " + m.toString();
        return "Hello !!!!!!!";
        });

    get("/try", (request, response) -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("message", "Hello World!");

            return new ModelAndView(attributes, "try.ftl");
        }, new FreeMarkerEngine());

    get("/db", (req, res) -> {
      Connection connection = null;
      Map<String, Object> attributes = new HashMap<>();
      try {
        connection = DatabaseUrl.extract().getConnection();

        Statement stmt = connection.createStatement();
        stmt.executeUpdate("CREATE TABLE IF NOT EXISTS ticks (tick timestamp)");
        stmt.executeUpdate("INSERT INTO ticks VALUES (now())");
        ResultSet rs = stmt.executeQuery("SELECT tick FROM ticks");

        ArrayList<String> output = new ArrayList<String>();
        while (rs.next()) {
          output.add( "Read from DB: " + rs.getTimestamp("tick"));
        }

        attributes.put("results", output);
        return new ModelAndView(attributes, "db.ftl");
      } catch (Exception e) {
        attributes.put("message", "There was an error: " + e);
        return new ModelAndView(attributes, "error.ftl");
      } finally {
        if (connection != null) try{connection.close();} catch(SQLException e){}
      }
    }, new FreeMarkerEngine());

  }

}

@@ -710,16 +710,19 @@
 ();%0A%0A   
+ //
  new Use
@@ -754,24 +754,26 @@
 ce());%0A%0A    
+//
 get(%22/hello%22
@@ -790,24 +790,26 @@
 s) -%3E %7B%0A    
+//
       Relati
@@ -1035,24 +1035,26 @@
 ring();%0A    
+//
     return %22
@@ -1077,16 +1077,18 @@
     
+//
     %7D);%0A
 %0A   
@@ -1083,16 +1083,18 @@
     %7D);%0A
+/*
 %0A    get
@@ -2364,13 +2364,19 @@
 ());
+%0A    */
 %0A%0A  %7D%0A
-%0A
 %7D%0A

add comment