Пример #1
0
 // @VisibleForTesting
 DateTime getNthDOWOfMonth(DateTime midnightTomorrow, Integer nthOfMonth, Integer dow) {
   int dtconstDow = dow == 0 ? 7 : dow;
   DateTime first = midnightTomorrow.withDayOfMonth(1);
   if (first.getDayOfWeek() > dtconstDow) {
     return first.plusWeeks(nthOfMonth).withDayOfWeek(dtconstDow);
   } else {
     return first.plusWeeks(nthOfMonth - 1).withDayOfWeek(dtconstDow);
   }
 }
Пример #2
0
  protected static RubyTime s_mload(IRubyObject recv, RubyTime time, IRubyObject from) {
    Ruby runtime = recv.getRuntime();

    DateTime dt = new DateTime(DateTimeZone.UTC);

    byte[] fromAsBytes = null;
    fromAsBytes = from.convertToString().getBytes();
    if (fromAsBytes.length != 8) {
      throw runtime.newTypeError("marshaled time format differ");
    }
    int p = 0;
    int s = 0;
    for (int i = 0; i < 4; i++) {
      p |= ((int) fromAsBytes[i] & 0xFF) << (8 * i);
    }
    for (int i = 4; i < 8; i++) {
      s |= ((int) fromAsBytes[i] & 0xFF) << (8 * (i - 4));
    }
    boolean utc = false;
    if ((p & (1 << 31)) == 0) {
      dt = dt.withMillis(p * 1000L);
      time.setUSec((s & 0xFFFFF) % 1000);
    } else {
      p &= ~(1 << 31);
      utc = ((p >>> 30 & 0x1) == 0x1);
      dt = dt.withYear(((p >>> 14) & 0xFFFF) + 1900);
      dt = dt.withMonthOfYear(((p >>> 10) & 0xF) + 1);
      dt = dt.withDayOfMonth(((p >>> 5) & 0x1F));
      dt = dt.withHourOfDay((p & 0x1F));
      dt = dt.withMinuteOfHour(((s >>> 26) & 0x3F));
      dt = dt.withSecondOfMinute(((s >>> 20) & 0x3F));
      // marsaling dumps usec, not msec
      dt = dt.withMillisOfSecond((s & 0xFFFFF) / 1000);
      time.setUSec((s & 0xFFFFF) % 1000);
    }
    time.setDateTime(dt);
    if (!utc) time.localtime();

    from.getInstanceVariables().copyInstanceVariablesInto(time);
    return time;
  }
Пример #3
0
 public static void backAllByPage(Session sessionBase, Connection countCon) throws SQLException {
   String oriTbName = "log_search_pos_keyword"; // 原表名
   // 查出5月份最大id
   String yearMonth = "201405";
   DateTime dateTime = DateTime.parse(yearMonth, DateTimeFormat.forPattern("yyyyMM"));
   dateTime =
       dateTime
           .withDayOfMonth(dateTime.dayOfMonth().getMaximumValue()) // 最大日期
           .withHourOfDay(23)
           .withMinuteOfHour(59)
           .withSecondOfMinute(59);
   Query maxIdQueryOriTb =
       sessionBase.createSQLQuery(
           "select max(id) from "
               + oriTbName
               + " where cre_date <= '"
               + dateTime.toString("yyyy-MM-dd HH:mm:ss")
               + "'");
   Integer maxId = ((BigInteger) maxIdQueryOriTb.uniqueResult()).intValue();
   // 查出当前备份库中最大id,没有当然为0
   Statement maxIdBackStatement = countCon.createStatement();
   ResultSet rsMaxIdBack =
       maxIdBackStatement.executeQuery("select max(id) from " + BackSearchKeywordTbName);
   Integer maxIdBack = 0;
   if (rsMaxIdBack.next()) {
     maxIdBack = rsMaxIdBack.getInt(1);
     maxIdBack = maxIdBack == null ? 0 : maxIdBack;
   }
   maxIdBack = maxIdBack == null ? 0 : maxIdBack;
   Integer curRangeMaxId = maxIdBack + 10000; // 当前查询范围id
   // 每次范围为当前备份最大id+10000查询(若大于5月最大id为5月最大id)(不一定10000条)
   Query listDataQuery =
       sessionBase.createSQLQuery(
           "select id,keyword,pos_type,cre_date from "
               + oriTbName
               + " where id >  ? and id <= ?  ");
   // 插入每页的每条数据(每条插入前检查是否存在当月的分区,并且更新备份库的最大id)
   String insertSql = "insert into " + BackSearchKeywordTbName + " values(?,?,?,?)";
   PreparedStatement ps = null;
   try {
     ps = countCon.prepareStatement(insertSql);
     Set<String> yearMonthCache = Sets.newHashSet();
     while (maxIdBack < maxId) {
       listDataQuery.setParameter(0, maxIdBack);
       listDataQuery.setParameter(1, curRangeMaxId);
       long b = new Date().getTime();
       List<Object[]> data = listDataQuery.list();
       logger.info("查询【" + data.size() + "】条数据,耗时【" + (new Date().getTime() - b) + "】毫秒");
       sessionBase.clear();
       Integer tempMaxId = batchInsertData(data, countCon, ps, yearMonthCache);
       maxIdBack = tempMaxId == 0 ? curRangeMaxId : tempMaxId;
       curRangeMaxId = maxIdBack + 10000 > maxId ? maxId : maxIdBack + 10000;
     }
   } catch (Exception e) {
     logger.error(e.getMessage(), e);
   } finally {
     if (ps != null) {
       ps.close();
     }
   }
 }
Пример #4
0
 private void setupDate() {
   DateTime date = DateTime.now();
   date = date.withDayOfMonth(1);
   setDate(date);
   mCalendarPager.setCurrentCalendar(date);
 }