コード例 #1
0
ファイル: Sql2oTest.java プロジェクト: rwozniak/sql2o
  /** ************ Helper stuff ***************** */
  private void createAndFillUserTable() {

    int rowCount = 10000;
    sql2o
        .createQuery(
            "create table User(\n"
                + "id int identity primary key,\n"
                + "name varchar(20),\n"
                + "email varchar(255),\n"
                + "text varchar(100))")
        .executeUpdate();

    Query insQuery =
        sql2o.createQuery("insert into User(name, email, text) values (:name, :email, :text)");
    Date before = new Date();
    for (int idx = 0; idx < rowCount; idx++) {
      insQuery
          .addParameter("name", "a name " + idx)
          .addParameter("email", String.format("*****@*****.**", idx))
          .addParameter("text", "some text")
          .addToBatch();
    }
    insQuery.executeBatch();
    Date after = new Date();
    Long span = after.getTime() - before.getTime();

    System.out.println(
        String.format("inserted %d rows into User table. Time used: %s ms", rowCount, span));

    insertIntoUsers += rowCount;
  }
コード例 #2
0
  @Before
  public void setUp() {
    controller = new Controller(35.0);
    Calendar cal = Calendar.getInstance();
    cal.set(2012, Calendar.JANUARY, 1, 1, 1, 0);

    Date d1, d2;
    d1 = cal.getTime();
    t1 = d1.getTime();

    cal.set(2012, Calendar.JANUARY, 1, 1, 1, 2);
    d2 = cal.getTime();
    t2 = d2.getTime();
  }
コード例 #3
0
  @Test
  public void testDecodeQualificationForXML() throws IOException {
    assumeTrue(TestUtil.testdataAvailable());

    Date startDate = Calendar.getInstance().getTime();
    DecodeQualification decodeQualification =
        plugIn.getDecodeQualification(
            TestUtil.getTestFile(productsFolder + "dimap/test_ST4_MT.xml"));
    assertEquals(DecodeQualification.UNABLE, decodeQualification);
    decodeQualification =
        plugIn.getDecodeQualification(
            TestUtil.getTestFile(productsFolder + "SPOT4_HRVIR1_XS_88888888_N1A.tgz"));
    assertEquals(DecodeQualification.INTENDED, decodeQualification);
    Date endDate = Calendar.getInstance().getTime();
    assertTrue(
        "The decoding time for the file is too big!",
        (endDate.getTime() - startDate.getTime()) / 1000 < 30); // 30 sec
  }
コード例 #4
0
  public void planTest() {
    Worker worker = workerDAO.getWorkerById(6);
    Department department = depDAO.getDepartment(2);
    Date date = new Date();
    new Timestamp(date.getTime());

    // plan creating
    Plan plan = new Plan();
    plan.setWorker(worker); // worker
    plan.setDepartment(department); // department
    // set several timestamp attributes
    plan.setCreateTime(new Timestamp(date.getTime()));
    plan.setBeginTime(new Timestamp(date.getTime()));
    plan.setEndTime(new Timestamp(date.getTime()));
    // planCommodityRel creating
    PlanCommodityRel relation1 = new PlanCommodityRel();
    Commodity commodity1 = commoDAO.getCommodityById(1);
    relation1.setCommodity(commodity1);
    relation1.setPlan(plan);
    relation1.setPlanNum(50);
    relation1.setSinglePrice(8);

    PlanCommodityRel relation2 = new PlanCommodityRel();
    Commodity commodity2 = commoDAO.getCommodityById(2);
    relation2.setCommodity(commodity2);
    relation2.setPlan(plan);
    relation2.setPlanNum(50);
    relation2.setSinglePrice(8);

    PlanCommodityRel relation3 = new PlanCommodityRel();
    Commodity commodity3 = commoDAO.getCommodityById(3);
    relation3.setCommodity(commodity3);
    relation3.setPlan(plan);
    relation3.setPlanNum(50);
    relation3.setSinglePrice(8);

    plan.getPlanCommodityRelList().add(relation1);
    plan.getPlanCommodityRelList().add(relation2);
    plan.getPlanCommodityRelList().add(relation3);

    planDAO.createPlan(plan);
  }
コード例 #5
0
ファイル: Sql2oTest.java プロジェクト: rwozniak/sql2o
  @Test
  public void testExecuteAndFetch() {
    createAndFillUserTable();

    Date before = new Date();
    List<User> allUsers = sql2o.createQuery("select * from User").executeAndFetch(User.class);
    Date after = new Date();
    long span = after.getTime() - before.getTime();
    System.out.println(String.format("Fetched %s user: %s ms", insertIntoUsers, span));

    // repeat this
    before = new Date();
    allUsers = sql2o.createQuery("select * from User").executeAndFetch(User.class);
    after = new Date();
    span = after.getTime() - before.getTime();
    System.out.println(String.format("Again Fetched %s user: %s ms", insertIntoUsers, span));

    assertTrue(allUsers.size() == insertIntoUsers);
    deleteUserTable();
  }
コード例 #6
0
 public void convert() {
   // param dateString looks like:2016.2.23
   String dateString = "2016.2.23";
   Date date = new Date();
   DateFormat sdf = new SimpleDateFormat("yyyy.M.d");
   try {
     date = sdf.parse(dateString);
   } catch (ParseException e) {
     e.printStackTrace();
   }
   Timestamp timestamp = new Timestamp(date.getTime());
   System.out.println(timestamp);
 }
コード例 #7
0
ファイル: PrepStmtTest.java プロジェクト: gwenn/sqlitejdbc
  @Test
  public void date2() throws SQLException {
    Date d1 = new Date(1092941466000L);
    stat.execute("create table t (c1);");
    PreparedStatement prep =
        conn.prepareStatement("insert into t values (datetime(?/1000, 'unixepoch'));");
    prep.setDate(1, d1);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select strftime('%s', c1) * 1000 from t;");
    assertTrue(rs.next());
    assertEquals(d1.getTime(), rs.getLong(1));
    assertTrue(rs.getDate(1).equals(d1));
  }
コード例 #8
0
 public void orderTest() {
   Customer customer = customerDAO.getCustomerById(3);
   List<Commodity> commodityList = commoDAO.getCommoditiesByIdString("2;3;4");
   List<OrderCommodityRel> relationLsit = CommodityListTools.commoToRel(commodityList);
   Order order = new Order(customer, relationLsit, 100);
   Map<Integer, Integer> map = new HashMap<Integer, Integer>();
   map.put(2, 2);
   map.put(3, 4);
   map.put(4, 4);
   order.setBuyNum(map);
   Date date = new Date();
   order.setOrderTime(new Timestamp(date.getTime()));
   orderDAO.createOrder(order);
   System.out.println(order.getOrderId());
 }
コード例 #9
0
 @Test
 public void testDate() {
   assertTrue(eval(builder.profileProperty("properties.lastVisit").equalTo(lastVisit).build()));
   assertTrue(
       eval(
           builder
               .profileProperty("properties.lastVisit")
               .greaterThan(new Date(lastVisit.getTime() - 10000))
               .build()));
   assertTrue(
       eval(
           builder
               .profileProperty("properties.lastVisit")
               .lessThan(new Date(lastVisit.getTime() + 10000))
               .build()));
   assertTrue(
       eval(
           builder
               .profileProperty("properties.lastVisit")
               .in(
                   new Date(lastVisit.getTime() + 10000),
                   new Date(lastVisit.getTime() - 10000),
                   lastVisit)
               .build()));
   assertTrue(
       eval(
           builder
               .profileProperty("properties.lastVisit")
               .notIn(new Date(lastVisit.getTime() + 10000), new Date(lastVisit.getTime() - 10000))
               .build()));
   assertFalse(
       eval(
           builder
               .profileProperty("properties.lastVisit")
               .notIn(
                   new Date(lastVisit.getTime() + 10000),
                   new Date(lastVisit.getTime() - 10000),
                   lastVisit)
               .build()));
   assertTrue(eval(builder.profileProperty("properties.lastVisit").all(lastVisit).build()));
   assertFalse(
       eval(
           builder
               .profileProperty("properties.lastVisit")
               .all(new Date(lastVisit.getTime() + 10000), lastVisit)
               .build()));
 }
コード例 #10
0
ファイル: PrepStmtTest.java プロジェクト: gwenn/sqlitejdbc
  @Test
  public void date1() throws SQLException {
    Date d1 = new Date(987654321);

    stat.execute("create table t (c1);");
    PreparedStatement prep = conn.prepareStatement("insert into t values(?);");
    prep.setDate(1, d1);
    prep.executeUpdate();
    prep.setDate(1, null);
    prep.executeUpdate();

    ResultSet rs = stat.executeQuery("select c1 from t;");
    assertTrue(rs.next());
    assertEquals(d1.getTime(), rs.getLong(1));
    assertTrue(rs.getDate(1).equals(d1));
    assertTrue(rs.next());
    assertEquals(null, rs.getDate(1));
    rs.close();
  }