Java Code Examples for org.springframework.jdbc.core.PreparedStatementSetter

The following examples show how to use org.springframework.jdbc.core.PreparedStatementSetter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@GetMapping("/custom_BeanRowMapperTests")
public PagingResult custom_BeanRowMapperTests(
        @RequestParam(name = "pageNo", required = false) Integer pageNo,
        @RequestParam(name = "pageSize", required = false) Integer pageSize,
        @RequestParam(name = "sort", required = false) String sort) {
    PagingRequest request = SqlPaginations.preparePagination(pageNo == null ? 1 : pageNo, pageSize == null ? -1 : pageSize, sort);
    StringBuilder sqlBuilder = new StringBuilder("select ID, NAME, AGE from USER where 1=1 and age > ?");

    BeanRowMapper<User> beanRowMapper = new BeanRowMapper(User.class);
    List<User> users = jdbcTemplate.query(sqlBuilder.toString(), new PreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setInt(1, 10);
        }
    }, new SqlHelperRowMapperResultSetExtractor<User>(beanRowMapper));
    String json = JSONBuilderProvider.simplest().toJson(request.getResult());
    System.out.println(json);
    System.out.println(JSONBuilderProvider.simplest().toJson(users));
    return request.getResult();
}
 
Example 2
Source Project: diamond   Source File: PersistService.java    License: Apache License 2.0 6 votes vote down vote up
public void addConfigInfo(final ConfigInfo configInfo) {
    final Timestamp time = TimeUtils.getCurrentTime();

    this.jt.update(
        "insert into config_info (data_id,group_id,content,md5,gmt_create,gmt_modified) values(?,?,?,?,?,?)",
        new PreparedStatementSetter() {
            public void setValues(PreparedStatement ps) throws SQLException {
                int index = 1;
                ps.setString(index++, configInfo.getDataId());
                ps.setString(index++, configInfo.getGroup());
                ps.setString(index++, configInfo.getContent());
                ps.setString(index++, configInfo.getMd5());
                ps.setTimestamp(index++, time);
                ps.setTimestamp(index++, time);
            }
        });
}
 
Example 3
Source Project: diamond   Source File: PersistService.java    License: Apache License 2.0 6 votes vote down vote up
public void updateConfigInfo(final ConfigInfo configInfo) {
    final Timestamp time = TimeUtils.getCurrentTime();

    this.jt.update("update config_info set content=?,md5=?,gmt_modified=? where data_id=? and group_id=?",
        new PreparedStatementSetter() {

            public void setValues(PreparedStatement ps) throws SQLException {
                int index = 1;
                ps.setString(index++, configInfo.getContent());
                ps.setString(index++, configInfo.getMd5());
                ps.setTimestamp(index++, time);
                ps.setString(index++, configInfo.getDataId());
                ps.setString(index++, configInfo.getGroup());
            }
        });
}
 
Example 4
Source Project: dubbox   Source File: LocalDTSSchedule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void closeActivity(final String activityId, final Status orignStatus, final Status targetStatus) {
	log.info("--->start to closeActivity:{},turn status from:{} to:{}", activityId, orignStatus, targetStatus);
	transactionTemplate.execute(new TransactionCallbackWithoutResult() {

		@Override
		protected void doInTransactionWithoutResult(TransactionStatus status) {
			jdbcTemplate.update(ActivitySqlConstance.commit_rollback_activity_by_activity_id,
					new PreparedStatementSetter() {

						@Override
						public void setValues(PreparedStatement ps) throws SQLException {
							ps.setString(1, targetStatus.name());
							ps.setTimestamp(2, new Timestamp(new Date().getTime()));
							ps.setString(3, activityId);
							ps.setString(4, orignStatus.name());
						}
					});
		}
	});
}
 
Example 5
Source Project: diamond   Source File: PersistService.java    License: Apache License 2.0 6 votes vote down vote up
public void addConfigInfo(final ConfigInfo configInfo) {
    final Timestamp time = TimeUtils.getCurrentTime();

    this.jt.update(
        "insert into config_info (data_id,group_id,content,md5,gmt_create,gmt_modified) values(?,?,?,?,?,?)",
        new PreparedStatementSetter() {
            public void setValues(PreparedStatement ps) throws SQLException {
                int index = 1;
                ps.setString(index++, configInfo.getDataId());
                ps.setString(index++, configInfo.getGroup());
                ps.setString(index++, configInfo.getContent());
                ps.setString(index++, configInfo.getMd5());
                ps.setTimestamp(index++, time);
                ps.setTimestamp(index++, time);
            }
        });
}
 
Example 6
Source Project: diamond   Source File: PersistService.java    License: Apache License 2.0 6 votes vote down vote up
public void updateConfigInfo(final ConfigInfo configInfo) {
    final Timestamp time = TimeUtils.getCurrentTime();

    this.jt.update("update config_info set content=?,md5=?,gmt_modified=? where data_id=? and group_id=?",
        new PreparedStatementSetter() {

            public void setValues(PreparedStatement ps) throws SQLException {
                int index = 1;
                ps.setString(index++, configInfo.getContent());
                ps.setString(index++, configInfo.getMd5());
                ps.setTimestamp(index++, time);
                ps.setString(index++, configInfo.getDataId());
                ps.setString(index++, configInfo.getGroup());
            }
        });
}
 
Example 7
Source Project: MaxKey   Source File: JdbcApprovalStore.java    License: Apache License 2.0 6 votes vote down vote up
public boolean purgeExpiredApprovals() {
	logger.debug("Purging expired approvals from database");
	try {
		int deleted = jdbcTemplate.update(deleteApprovalStatment + " where expiresAt <= ?",
				new PreparedStatementSetter() {
					@Override
					public void setValues(PreparedStatement ps) throws SQLException {
						ps.setTimestamp(1, new Timestamp(new Date().getTime()));
					}
				});
		logger.debug(deleted + " expired approvals deleted");
	}
	catch (DataAccessException ex) {
		logger.error("Error purging expired approvals", ex);
		return false;
	}
	return true;
}
 
Example 8
Source Project: MaxKey   Source File: JdbcApprovalStore.java    License: Apache License 2.0 6 votes vote down vote up
private boolean updateApproval(final String sql, final Approval approval) {
	logger.debug(String.format("refreshing approval: [%s]", approval));
	int refreshed = jdbcTemplate.update(sql, new PreparedStatementSetter() {
		@Override
		public void setValues(PreparedStatement ps) throws SQLException {
			ps.setTimestamp(1, new Timestamp(approval.getExpiresAt().getTime()));
			ps.setString(2, (approval.getStatus() == null ? APPROVED : approval.getStatus()).toString());
			ps.setTimestamp(3, new Timestamp(approval.getLastUpdatedAt().getTime()));
			ps.setString(4, approval.getUserId());
			ps.setString(5, approval.getClientId());
			ps.setString(6, approval.getScope());
		}
	});
	if (refreshed != 1) {
		return false;
	}
	return true;
}
 
Example 9
Source Project: dtsopensource   Source File: LocalDTSSchedule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void closeActivity(final String activityId, final Status orignStatus, final Status targetStatus) {
    log.info("--->start to closeActivity:{},turn status from:{} to:{}", activityId, orignStatus, targetStatus);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            jdbcTemplate.update(ActivitySqlConstance.commit_rollback_activity_by_activity_id,
                    new PreparedStatementSetter() {

                        @Override
                        public void setValues(PreparedStatement ps) throws SQLException {
                            ps.setString(1, targetStatus.name());
                            ps.setTimestamp(2, new Timestamp(new Date().getTime()));
                            ps.setString(3, activityId);
                            ps.setString(4, orignStatus.name());
                        }
                    });
        }
    });
}
 
Example 10
@Test
@SuppressWarnings("unchecked")
void getSessionFound() {
	Session saved = this.repository.new JdbcSession(new MapSession(), "primaryKey", false);
	saved.setAttribute("savedName", "savedValue");
	given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
			isA(ResultSetExtractor.class))).willReturn(Collections.singletonList(saved));

	JdbcSession session = this.repository.findById(saved.getId());

	assertThat(session.getId()).isEqualTo(saved.getId());
	assertThat(session.isNew()).isFalse();
	assertThat(session.<String>getAttribute("savedName")).isEqualTo("savedValue");
	verify(this.jdbcOperations, times(1)).query(isA(String.class), isA(PreparedStatementSetter.class),
			isA(ResultSetExtractor.class));
}
 
Example 11
@Test
@SuppressWarnings("unchecked")
void findByIndexNameAndIndexValuePrincipalIndexNameFound() {
	String principal = "username";
	Authentication authentication = new UsernamePasswordAuthenticationToken(principal, "notused",
			AuthorityUtils.createAuthorityList("ROLE_USER"));
	List<Session> saved = new ArrayList<>(2);
	Session saved1 = this.repository.createSession();
	saved1.setAttribute(SPRING_SECURITY_CONTEXT, authentication);
	saved.add(saved1);
	Session saved2 = this.repository.createSession();
	saved2.setAttribute(SPRING_SECURITY_CONTEXT, authentication);
	saved.add(saved2);
	given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
			isA(ResultSetExtractor.class))).willReturn(saved);

	Map<String, JdbcSession> sessions = this.repository
			.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, principal);

	assertThat(sessions).hasSize(2);
	verify(this.jdbcOperations, times(1)).query(isA(String.class), isA(PreparedStatementSetter.class),
			isA(ResultSetExtractor.class));
}
 
Example 12
Source Project: spring4-sandbox   Source File: JdbcConferenceDaoImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void update(final Conference conference) {
	getJdbcTemplate()
			.update("update conference set slug=?, name=?, description=?, started_date=?, ended_date=? where id =? ",
					new PreparedStatementSetter() {

						@Override
						public void setValues(PreparedStatement ps)
								throws SQLException {
							ps.setString(1, conference.getSlug());
							ps.setString(2, conference.getName());
							ps.setString(3, conference.getDescription());
							ps.setTimestamp(4, new java.sql.Timestamp(
									conference.getStartedDate().getTime()));
							ps.setTimestamp(5, new java.sql.Timestamp(
									conference.getEndedDate().getTime()));
							ps.setLong(6, conference.getId());
						}
					});
}
 
Example 13
Source Project: spring4-sandbox   Source File: JdbcConferenceDaoImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void update(final Conference conference) {
	getJdbcTemplate()
			.update("update conference set slug=?, name=?, description=?, started_date=?, ended_date=? where id =? ",
					new PreparedStatementSetter() {

						@Override
						public void setValues(PreparedStatement ps)
								throws SQLException {
							ps.setString(1, conference.getSlug());
							ps.setString(2, conference.getName());
							ps.setString(3, conference.getDescription());
							ps.setTimestamp(4, new java.sql.Timestamp(
									conference.getStartedDate().getTime()));
							ps.setTimestamp(5, new java.sql.Timestamp(
									conference.getEndedDate().getTime()));
							ps.setLong(6, conference.getId());
						}
					});
}
 
Example 14
@Override
public void update(final Conference conference) {
	jdbcTemplate
			.update("update conference set slug=?, name=?, description=?, started_date=?, ended_date=? where id =? ",
					new PreparedStatementSetter() {

						@Override
						public void setValues(PreparedStatement ps)
								throws SQLException {
							ps.setString(1, conference.getSlug());
							ps.setString(2, conference.getName());
							ps.setString(3, conference.getDescription());
							ps.setTimestamp(4, new java.sql.Timestamp(
									conference.getStartedDate().getTime()));
							ps.setTimestamp(5, new java.sql.Timestamp(
									conference.getEndedDate().getTime()));
							ps.setLong(6, conference.getId());
						}
					});
}
 
Example 15
@Override
public void update(final Conference conference) {
	jdbcTemplate
			.update("update conference set slug=?, name=?, description=?, started_date=?, ended_date=? where id =? ",
					new PreparedStatementSetter() {

						@Override
						public void setValues(PreparedStatement ps)
								throws SQLException {
							ps.setString(1, conference.getSlug());
							ps.setString(2, conference.getName());
							ps.setString(3, conference.getDescription());
							ps.setTimestamp(4, new java.sql.Timestamp(
									conference.getStartedDate().getTime()));
							ps.setTimestamp(5, new java.sql.Timestamp(
									conference.getEndedDate().getTime()));
							ps.setLong(6, conference.getId());
						}
					});
}
 
Example 16
Source Project: springboot-link-admin   Source File: AbstractJdbcSupport.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int insertOrUpdateOrDelete(String sql, final Object[] params) {
	int num = 0;
	if (params == null || params.length == 0)
		num = getJdbcTemplate().update(sql);
	else
		num = getJdbcTemplate().update(sql, new PreparedStatementSetter() {
			public void setValues(PreparedStatement ps) throws SQLException {
				for (int i = 0; i < params.length; i++)
					ps.setObject(i + 1, params[i]);
			}
		});
	return num;
}
 
Example 17
Source Project: buffer-slayer   Source File: BatchJdbcTemplate.java    License: Apache License 2.0 5 votes vote down vote up
public MessageFuture<Integer> update(PreparedStatementCreator psc) throws DataAccessException {
  if (psc instanceof SqlProvider) {
    SqlProvider sqlProvider = (SqlProvider) psc;
    String sql = sqlProvider.getSql();

    Builder builder = Sql.builder().sql(sql);
    if (psc instanceof PreparedStatementSetter) {
      PreparedStatementSetter pss = (PreparedStatementSetter) psc;
      builder.preparedStatementSetter(pss);
    }
    return reporter.report(builder.build());
  }
  throw new UnsupportedOperationException("Must be instance of SqlProvider");
}
 
Example 18
Source Project: diamond   Source File: PersistService.java    License: Apache License 2.0 5 votes vote down vote up
public void removeConfigInfo(final ConfigInfo configInfo) {
    this.jt.update("delete from config_info where data_id=? and group_id=?", new PreparedStatementSetter() {
        public void setValues(PreparedStatement ps) throws SQLException {
            int index = 1;
            ps.setString(index++, configInfo.getDataId());
            ps.setString(index++, configInfo.getGroup());
        }
    });
}
 
Example 19
Source Project: dubbox   Source File: LocalDTSStore.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ResultBase<String> updateAction(ActionEntity actionEntity) {
	final ResultBase<String> resultBase = new ResultBase<String>();
	final DtsActionDO actionDO = this.castDtsActionDO(actionEntity);

	transactionTemplate.execute(new TransactionCallback<ResultBase<String>>() {

		@Override
		public ResultBase<String> doInTransaction(TransactionStatus status) {
			try {
				jdbcTemplate.update(ActionSqlConstance.commit_rollback_action_by_activity_id,
						new PreparedStatementSetter() {

							@Override
							public void setValues(PreparedStatement ps) throws SQLException {
								ps.setString(1, actionDO.getStatus());
								ps.setString(2, actionDO.getContext());
								ps.setTimestamp(3, new Timestamp(actionDO.getGmtModified().getTime()));
								ps.setString(4, actionDO.getActionId());
								ps.setString(5, actionDO.getActivityId());
							}
						});
				resultBase.setDtsResultCode(DTSResultCode.SUCCESS);
				resultBase.setValue(actionDO.getActionId());
				return resultBase;
			} catch (Exception e) {
				log.error(e.getMessage(), e);
				status.setRollbackOnly();
				resultBase.setDtsResultCode(DTSResultCode.FAIL);
				resultBase.setMessage("更新action失败,reason:" + e.getMessage());
				return resultBase;
			}
		}

	});
	return resultBase;
}
 
Example 20
Source Project: dubbox   Source File: LocalDTSStore.java    License: Apache License 2.0 5 votes vote down vote up
private ResultBase<String> commitActivity(final DtsActivityDO activityDO) {
	final ResultBase<String> resultBase = new ResultBase<String>();
	resultBase.setValue(activityDO.getActivityId());

	transactionTemplate.execute(new TransactionCallback<ResultBase<String>>() {

		@Override
		public ResultBase<String> doInTransaction(TransactionStatus status) {
			try {
				jdbcTemplate.update(ActivitySqlConstance.commit_rollback_activity_by_activity_id,
						new PreparedStatementSetter() {

							@Override
							public void setValues(PreparedStatement ps) throws SQLException {
								ps.setString(1, Status.T.name());
								ps.setTimestamp(2, new Timestamp(new Date().getTime()));
								ps.setString(3, activityDO.getActivityId());
								ps.setString(4, Status.S.name());
							}
						});
				resultBase.setDtsResultCode(DTSResultCode.SUCCESS);
				return resultBase;
			} catch (Exception e) {
				log.error(e.getMessage(), e);
				status.setRollbackOnly();
				resultBase.setDtsResultCode(DTSResultCode.FAIL);
				resultBase.setMessage("保存业务动作失败,reason:" + e.getMessage());
				return resultBase;
			}
		}

	});
	return resultBase;
}
 
Example 21
Source Project: dubbox   Source File: LocalDTSStore.java    License: Apache License 2.0 5 votes vote down vote up
private ResultBase<String> rollbackActivity(final DtsActivityDO activityDO) {
	final ResultBase<String> resultBase = new ResultBase<String>();
	resultBase.setValue(activityDO.getActivityId());

	transactionTemplate.execute(new TransactionCallback<ResultBase<String>>() {

		@Override
		public ResultBase<String> doInTransaction(TransactionStatus status) {
			try {
				jdbcTemplate.update(ActivitySqlConstance.commit_rollback_activity_by_activity_id,
						new PreparedStatementSetter() {

							@Override
							public void setValues(PreparedStatement ps) throws SQLException {
								ps.setString(1, Status.R.name());
								ps.setTimestamp(2, new Timestamp(new Date().getTime()));
								ps.setString(3, activityDO.getActivityId());
								ps.setString(4, Status.S.name());
							}
						});
				resultBase.setDtsResultCode(DTSResultCode.SUCCESS);
				return resultBase;
			} catch (Exception e) {
				log.error(e.getMessage(), e);
				status.setRollbackOnly();
				resultBase.setDtsResultCode(DTSResultCode.FAIL);
				resultBase.setMessage("回滚业务活动失败,reason:" + e.getMessage());
				return resultBase;
			}
		}

	});
	return resultBase;
}
 
Example 22
Source Project: artemis   Source File: GroupTagDao.java    License: Apache License 2.0 5 votes vote down vote up
public void delete(GroupTagModel filter) {
    ValueCheckers.notNull(filter, "filter");
    final Map<String, String> conditions = Maps.newHashMap();
    conditions.put("group_id=?", filter.getGroupId() == null ? null : Long.toString(filter.getGroupId()));
    conditions.put("tag=?", filter.getTag());
    conditions.put("value=?", filter.getValue());
    Set<String> removed = Sets.newHashSet();
    for (String key : conditions.keySet()) {
        if (StringValues.isNullOrWhitespace(conditions.get(key))) {
            removed.add(key);
        }
    }
    conditions.keySet().removeAll(removed);
    if (conditions.size() == 0) {
        throw new IllegalStateException("forbidden operation.");
    }
    String sql = "delete from service_group_tag where " + Joiner.on(" and ").join(conditions.keySet());
    DataConfig.jdbcTemplate().update(sql, new PreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps) throws SQLException {
            List<String> args = Lists.newArrayList(conditions.values());
            for (int i = 0; i < args.size(); i++) {
                ps.setString(i + 1, args.get(i));
            }
        }
    });
}
 
Example 23
Source Project: diamond   Source File: PersistService.java    License: Apache License 2.0 5 votes vote down vote up
public void removeConfigInfo(final ConfigInfo configInfo) {
    this.jt.update("delete from config_info where data_id=? and group_id=?", new PreparedStatementSetter() {
        public void setValues(PreparedStatement ps) throws SQLException {
            int index = 1;
            ps.setString(index++, configInfo.getDataId());
            ps.setString(index++, configInfo.getGroup());
        }
    });
}
 
Example 24
Source Project: dtsopensource   Source File: LocalDTSStore.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ResultBase<String> updateAction(ActionEntity actionEntity) {
    final ResultBase<String> resultBase = new ResultBase<String>();
    final DtsActionDO actionDO = this.castDtsActionDO(actionEntity);

    transactionTemplate.execute(new TransactionCallback<ResultBase<String>>() {

        @Override
        public ResultBase<String> doInTransaction(TransactionStatus status) {
            try {
                jdbcTemplate.update(ActionSqlConstance.commit_rollback_action_by_activity_id,
                        new PreparedStatementSetter() {

                            @Override
                            public void setValues(PreparedStatement ps) throws SQLException {
                                ps.setString(1, actionDO.getStatus());
                                ps.setString(2, actionDO.getContext());
                                ps.setTimestamp(3, new Timestamp(actionDO.getGmtModified().getTime()));
                                ps.setString(4, actionDO.getActionId());
                                ps.setString(5, actionDO.getActivityId());
                            }
                        });
                resultBase.setDtsResultCode(DTSResultCode.SUCCESS);
                resultBase.setValue(actionDO.getActionId());
                return resultBase;
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                status.setRollbackOnly();
                resultBase.setDtsResultCode(DTSResultCode.FAIL);
                resultBase.setMessage("更新action失败,reason:" + e.getMessage());
                return resultBase;
            }
        }

    });
    return resultBase;
}
 
Example 25
Source Project: dtsopensource   Source File: LocalDTSStore.java    License: Apache License 2.0 5 votes vote down vote up
private ResultBase<String> commitActivity(final DtsActivityDO activityDO) {
    final ResultBase<String> resultBase = new ResultBase<String>();
    resultBase.setValue(activityDO.getActivityId());

    transactionTemplate.execute(new TransactionCallback<ResultBase<String>>() {

        @Override
        public ResultBase<String> doInTransaction(TransactionStatus status) {
            try {
                jdbcTemplate.update(ActivitySqlConstance.commit_rollback_activity_by_activity_id,
                        new PreparedStatementSetter() {

                            @Override
                            public void setValues(PreparedStatement ps) throws SQLException {
                                ps.setString(1, Status.T.name());
                                ps.setTimestamp(2, new Timestamp(new Date().getTime()));
                                ps.setString(3, activityDO.getActivityId());
                                ps.setString(4, Status.S.name());
                            }
                        });
                resultBase.setDtsResultCode(DTSResultCode.SUCCESS);
                return resultBase;
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                status.setRollbackOnly();
                resultBase.setDtsResultCode(DTSResultCode.FAIL);
                resultBase.setMessage("保存业务动作失败,reason:" + e.getMessage());
                return resultBase;
            }
        }

    });
    return resultBase;
}
 
Example 26
Source Project: dtsopensource   Source File: LocalDTSStore.java    License: Apache License 2.0 5 votes vote down vote up
private ResultBase<String> rollbackActivity(final DtsActivityDO activityDO) {
    final ResultBase<String> resultBase = new ResultBase<String>();
    resultBase.setValue(activityDO.getActivityId());

    transactionTemplate.execute(new TransactionCallback<ResultBase<String>>() {

        @Override
        public ResultBase<String> doInTransaction(TransactionStatus status) {
            try {
                jdbcTemplate.update(ActivitySqlConstance.commit_rollback_activity_by_activity_id,
                        new PreparedStatementSetter() {

                            @Override
                            public void setValues(PreparedStatement ps) throws SQLException {
                                ps.setString(1, Status.R.name());
                                ps.setTimestamp(2, new Timestamp(new Date().getTime()));
                                ps.setString(3, activityDO.getActivityId());
                                ps.setString(4, Status.S.name());
                            }
                        });
                resultBase.setDtsResultCode(DTSResultCode.SUCCESS);
                return resultBase;
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                status.setRollbackOnly();
                resultBase.setDtsResultCode(DTSResultCode.FAIL);
                resultBase.setMessage("回滚业务活动失败,reason:" + e.getMessage());
                return resultBase;
            }
        }

    });
    return resultBase;
}
 
Example 27
@Override
public Map<DataStatisticsEventType, Double> getDataStatisticsEventCount( Date startDate, Date endDate )
{
    Map<DataStatisticsEventType, Double> eventTypeCountMap = new HashMap<>();

    final String sql =
        "select eventtype as eventtype, count(eventtype) as numberofviews " +
        "from datastatisticsevent " +
        "where timestamp between ? and ? " +
        "group by eventtype;";

    PreparedStatementSetter pss = ( ps ) -> {
        int i = 1;
        ps.setDate( i++, asSqlDate( startDate ) );
        ps.setDate( i++, asSqlDate( endDate ) );
    };

    jdbcTemplate.query( sql, pss, ( rs, i ) -> {
        eventTypeCountMap.put( DataStatisticsEventType.valueOf( rs.getString( "eventtype" ) ), rs.getDouble( "numberofviews" ) );
        return eventTypeCountMap;
    } );

    final String totalSql =
        "select count(eventtype) as total " +
        "from datastatisticsevent " +
        "where timestamp between ? and ?;";

    jdbcTemplate.query( totalSql, pss, ( resultSet, i ) -> {
        return eventTypeCountMap.put( DataStatisticsEventType.TOTAL_VIEW, resultSet.getDouble( "total" ) );
    } );

    return eventTypeCountMap;
}
 
Example 28
private List<DeflatedDataValue> getDeflatedDataValues( DataElement dataElement,
    CategoryOptionCombo categoryOptionCombo, Collection<Period> periods, List<Long> organisationUnits,
    Map<Long, Integer> lowerBoundMap, Map<Long, Integer> upperBoundMap )
{
    String periodIds = TextUtils.getCommaDelimitedString( getIdentifiers( periods ) );

    String sql = "select dv.dataelementid, dv.periodid, dv.sourceid, dv.categoryoptioncomboid, dv.attributeoptioncomboid, dv.value, dv.storedby, dv.lastupdated, "
        + "dv.created, dv.comment, dv.followup, ou.name as sourcename, "
        + "? as dataelementname, pt.name as periodtypename, pe.startdate, pe.enddate, "
        + "? as categoryoptioncomboname " + "from datavalue dv " + "join period pe on dv.periodid = pe.periodid "
        + "join periodtype pt on pe.periodtypeid = pt.periodtypeid "
        + "join organisationunit ou on dv.sourceid = ou.organisationunitid " + "where dv.dataelementid = "
        + dataElement.getId() + " " + "and dv.categoryoptioncomboid = " + categoryOptionCombo.getId() + " "
        + "and dv.periodid in (" + periodIds + ") and ( ";

    for ( Long orgUnitUid : organisationUnits )
    {
        sql += "( dv.sourceid = " + orgUnitUid + " " + "and ( cast( dv.value as "
            + statementBuilder.getDoubleColumnType() + " ) < " + lowerBoundMap.get( orgUnitUid ) + " "
            + "or cast( dv.value as " + statementBuilder.getDoubleColumnType() + " ) > "
            + upperBoundMap.get( orgUnitUid ) + " ) ) or ";
    }

    sql = TextUtils.removeLastOr( sql ) + " ) ";
    sql += "and dv.deleted is false ";

    PreparedStatementSetter pss = ( ps ) -> {
        ps.setString( 1, dataElement.getName() );
        ps.setString( 2, categoryOptionCombo.getName() );
    };

    return jdbcTemplate.query( sql, pss, new DeflatedDataValueNameMinMaxRowMapper( lowerBoundMap, upperBoundMap ) );
}
 
Example 29
@Test
void createSessionImmediateFlushMode() {
	this.repository.setFlushMode(FlushMode.IMMEDIATE);
	JdbcSession session = this.repository.createSession();
	assertThat(session.isNew()).isFalse();
	verify(this.jdbcOperations).update(startsWith("INSERT"), isA(PreparedStatementSetter.class));
	verifyNoMoreInteractions(this.jdbcOperations);
}
 
Example 30
@Test
void saveNewWithoutAttributes() {
	JdbcSession session = this.repository.createSession();

	this.repository.save(session);

	assertThat(session.isNew()).isFalse();
	verify(this.jdbcOperations, times(1)).update(startsWith("INSERT"), isA(PreparedStatementSetter.class));
	verifyNoMoreInteractions(this.jdbcOperations);
}