@Test
  public void activeJobs_shouldRemoveCacheActiveJobOnUpdateJobStatus() {
    final ActiveJob first = new ActiveJob(1L, "pipeline", 1, "label", "stage", "first");
    final ActiveJob second = new ActiveJob(2L, "another", 2, "label", "stage", "job1");
    List<ActiveJob> expectedJobs = Arrays.asList(first, second);

    when(mockTemplate.queryForList("getActiveJobIds")).thenReturn(Arrays.asList(1L, 2L));
    when(mockTemplate.queryForObject("getActiveJobById", arguments("id", 1L).asMap()))
        .thenReturn(first);
    when(mockTemplate.queryForObject("getActiveJobById", arguments("id", 2L).asMap()))
        .thenReturn(second);

    jobInstanceDao.setSqlMapClientTemplate(mockTemplate);
    jobInstanceDao.activeJobs(); // cache it first

    jobInstanceDao.updateStateAndResult(instance(1L)); // should remove from cache

    List<ActiveJob> activeJobs = jobInstanceDao.activeJobs();

    assertThat(expectedJobs, is(activeJobs));

    verify(mockTemplate, times(2)).queryForList("getActiveJobIds");
    verify(mockTemplate, times(2)).queryForObject("getActiveJobById", arguments("id", 1L).asMap());
    verify(mockTemplate, times(1)).queryForObject("getActiveJobById", arguments("id", 2L).asMap());
  }
Esempio n. 2
0
 public int getMaxC_id() {
   int maxC_id = -1;
   if (ibatisTemplate.queryForObject("getMaxC_id") != null) {
     maxC_id = (Integer) ibatisTemplate.queryForObject("getMaxC_id");
   }
   return maxC_id;
 }
  @Test
  public void orderedScheduledBuilds_shouldCacheJobPlan() {
    when(mockTemplate.queryForList(eq("scheduledPlanIds"))).thenReturn(Arrays.asList(1L, 2L));

    final DefaultJobPlan firstJob = jobPlan(1);
    final DefaultJobPlan secondJob = jobPlan(2);
    List<JobPlan> expectedPlans =
        new ArrayList<JobPlan>() {
          {
            add(firstJob);
            add(secondJob);
          }
        };
    when(mockTemplate.queryForObject("scheduledPlan", arguments("id", 1L).asMap()))
        .thenReturn(firstJob);
    when(mockTemplate.queryForObject("scheduledPlan", arguments("id", 2L).asMap()))
        .thenReturn(secondJob);

    jobInstanceDao.setSqlMapClientTemplate(mockTemplate);
    jobInstanceDao.orderedScheduledBuilds();

    List<JobPlan> plans = jobInstanceDao.orderedScheduledBuilds();

    assertThat(plans, is(expectedPlans));

    verify(mockTemplate, times(2)).queryForObject(eq("scheduledPlan"), any());
    verify(mockTemplate, times(2)).queryForList(eq("scheduledPlanIds"));
  }
  @Test
  public void updateStatus_shouldRemoveCachedJobPlan() {
    when(mockTemplate.queryForList(eq("scheduledPlanIds"))).thenReturn(Arrays.asList(1L));

    final DefaultJobPlan firstJob = jobPlan(1);
    List<JobPlan> expectedPlans =
        new ArrayList<JobPlan>() {
          {
            add(firstJob);
          }
        };
    when(mockTemplate.queryForObject("scheduledPlan", arguments("id", 1L).asMap()))
        .thenReturn(firstJob);

    jobInstanceDao.setSqlMapClientTemplate(mockTemplate);
    jobInstanceDao.orderedScheduledBuilds(); // populate the cache

    JobInstance instance = instance(1);
    jobInstanceDao.updateStateAndResult(instance);

    List<JobPlan> plans = jobInstanceDao.orderedScheduledBuilds();

    assertThat(plans, is(expectedPlans));

    verify(mockTemplate, times(2))
        .queryForObject(
            "scheduledPlan", arguments("id", 1L).asMap()); // because the cache is cleared
    verify(mockTemplate, times(2)).queryForList(eq("scheduledPlanIds"));
  }
Esempio n. 5
0
 /** 用户即将到期的订单统计 */
 public int getCountAboutToExpireOrder(Long userId, int dayEnd) {
   Map<String, Object> paramMap = new HashMap<String, Object>();
   paramMap.put("userId", userId);
   paramMap.put("dayEnd", dayEnd);
   paramMap.put("currentDate", new Date());
   Object obj = sqlMapClientTemplate.queryForObject("getCountAboutToExpireOrder", paramMap);
   return obj != null ? Integer.valueOf(obj.toString()) : 0;
 }
Esempio n. 6
0
  public BoardVo getView(long no) {
    // System.out.println("BoardDao getView : " + no);
    BoardVo vo = (BoardVo) sqlMapClientTemplate.queryForObject("board.getView", no);
    return vo;

    /*
    		String sql = "SELECT no, view_cnt, member_no, member_name, title, content, TO_CHAR (reg_date, 'YYYY-MMDD HH:MM:SS') FROM board where no=?";
    */
  }
  @Test
  public void activeJobs_shouldCacheCurrentlyActiveJobIds() {
    final ActiveJob first = new ActiveJob(1L, "pipeline", 1, "label", "stage", "job1");
    final ActiveJob second = new ActiveJob(2L, "another", 2, "label", "stage", "job1");
    List<ActiveJob> expectedJobs = Arrays.asList(first, second);

    when(mockTemplate.queryForList("getActiveJobIds")).thenReturn(Arrays.asList(1L, 2L));
    when(mockTemplate.queryForObject("getActiveJobById", arguments("id", 1L).asMap()))
        .thenReturn(first);
    when(mockTemplate.queryForObject("getActiveJobById", arguments("id", 2L).asMap()))
        .thenReturn(second);

    jobInstanceDao.setSqlMapClientTemplate(mockTemplate);
    jobInstanceDao.activeJobs(); // populate the cache
    List<ActiveJob> activeJobs = jobInstanceDao.activeJobs();

    assertThat(expectedJobs, is(activeJobs));
    verify(mockTemplate, times(1)).queryForList("getActiveJobIds");
    verify(mockTemplate, times(1)).queryForObject("getActiveJobById", arguments("id", 1L).asMap());
    verify(mockTemplate, times(1)).queryForObject("getActiveJobById", arguments("id", 2L).asMap());
  }
  @Test
  public void buildByIdWithTransitions_shouldCacheWhenQueriedFor() {
    jobInstanceDao.setSqlMapClientTemplate(mockTemplate);

    JobInstance job = JobInstanceMother.assigned("job");
    job.setId(1L);
    when(mockTemplate.queryForObject("buildByIdWithTransitions", 1L)).thenReturn(job);

    JobInstance actual = jobInstanceDao.buildByIdWithTransitions(1L);
    assertThat(actual, is(job));
    assertThat(actual == job, is(false));

    jobInstanceDao.buildByIdWithTransitions(1L);
    verify(mockTemplate, times(1)).queryForObject("buildByIdWithTransitions", 1L);
  }
  @Test
  public void buildByIdWithTransitions_shouldClearFromCacheOnUpdateStatusOfJob() {
    jobInstanceDao.setSqlMapClientTemplate(mockTemplate);

    JobInstance job = JobInstanceMother.assigned("job");
    job.setId(1L);
    when(mockTemplate.queryForObject("buildByIdWithTransitions", 1L)).thenReturn(job);

    JobInstance actual = jobInstanceDao.buildByIdWithTransitions(1L);
    assertThat(actual, is(job));
    assertThat(actual == job, is(false));

    jobInstanceDao.updateStateAndResult(job); // Must clear cahced job instance

    jobInstanceDao.buildByIdWithTransitions(1L);
    verify(mockTemplate, times(2)).queryForObject("buildByIdWithTransitions", 1L);
  }
Esempio n. 10
0
 public int getOrdersCount(SysOrderDto dto) {
   Map<String, Object> paraMap = new HashMap<String, Object>();
   try {
     paraMap.put("fromOrderDate", dto.getFromOrderDate());
     paraMap.put("toOrderDate", dto.getToOrderDate());
     paraMap.put("fromPayDate", dto.getFromPayDate());
     paraMap.put("toPayDate", dto.getToPayDate());
     paraMap.put("status", dto.getStatus());
     paraMap.put("payDate", dto.getPayDate());
     paraMap.put("serviceCode", dto.getServiceCode());
     paraMap.put("inOrderName", dto.getInOrderName());
     paraMap.put("itemCode", dto.getItemCode());
     paraMap.put("inOrder", dto.getInOrder());
     paraMap.put("endDate", dto.getEndDate());
     paraMap.put("service1Remains", dto.getService1Remains());
     paraMap.put("service2Remains", dto.getService2Remains());
     paraMap.put("service3Remains", dto.getService3Remains());
   } catch (Exception e) {
     logger.error(e);
   }
   Object obj = sqlMapClientTemplate.queryForObject("queryOrderCount", paraMap);
   return obj != null ? Integer.valueOf(obj.toString()) : 0;
 }
Esempio n. 11
0
 public Object select(Object primaryKey) throws DataAccessException {
   logger.debug("Ruuning statement: " + namespace + SELECT);
   validateNameSpace();
   return sqlMapClientTemplate.queryForObject(namespace + SELECT, primaryKey);
 }
Esempio n. 12
0
 public SysOrderDto queryOrder(SysOrderDto dto) {
   return (SysOrderDto) sqlMapClientTemplate.queryForObject("queryOrder", dto);
 }
Esempio n. 13
0
 /** 用户还未支付订单统计 */
 public int getCountOfHaveNotYetPaidOrder(Long userId) {
   return (Integer) sqlMapClientTemplate.queryForObject("getCountOfHaveNotYetPaidOrder", userId);
 }
Esempio n. 14
0
 /** 当天新增订单数统计 */
 public int getNewOrdersStatisticsToDay() {
   return (Integer) sqlMapClientTemplate.queryForObject("getNewOrdersStatisticsToDay", new Date());
 }
Esempio n. 15
0
 public Integer queryCertAccessHistoryCountByCertId(Long certId) {
   return (Integer)
       sqlMapClientTemplate.queryForObject("queryCertAccessHistoryCountByCertId", certId);
 }