org.springframework.jdbc.core.PreparedStatementSetter Java Examples

The following examples show how to use org.springframework.jdbc.core.PreparedStatementSetter. 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
Source File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 7 votes vote down vote up
@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 #2
Source File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: JdbcConferenceDaoImpl.java    From spring4-sandbox with 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 #4
Source File: JdbcConferenceDaoImpl.java    From spring4-sandbox with 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 #5
Source File: UserController.java    From sqlhelper with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #6
Source File: NamedParamJdbcTemplateConferenceDaoImpl.java    From spring4-sandbox with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: PersistService.java    From diamond with 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 #8
Source File: PersistService.java    From diamond with 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 #9
Source File: PersistService.java    From diamond with 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 #10
Source File: LocalDTSSchedule.java    From dtsopensource with 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 #11
Source File: LocalDTSSchedule.java    From dubbox with 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 #12
Source File: PersistService.java    From diamond with 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 #13
Source File: JdbcApprovalStore.java    From MaxKey with 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 #14
Source File: JdbcApprovalStore.java    From MaxKey with 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 #15
Source File: JdbcTemplateConferenceDaoImpl.java    From spring4-sandbox with Apache License 2.0 6 votes vote down vote up
@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 File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
void getSessionExpired() {
	Session expired = this.repository.createSession();
	expired.setLastAccessedTime(Instant.now().minusSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS + 1));
	given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
			isA(ResultSetExtractor.class))).willReturn(Collections.singletonList(expired));

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

	assertThat(session).isNull();
	verify(this.jdbcOperations, times(1)).query(isA(String.class), isA(PreparedStatementSetter.class),
			isA(ResultSetExtractor.class));
	verify(this.jdbcOperations, times(1)).update(startsWith("DELETE"), eq(expired.getId()));
}
 
Example #17
Source File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void saveNewWithSingleAttribute() {
	JdbcSession session = this.repository.createSession();
	session.setAttribute("testName", "testValue");

	this.repository.save(session);

	assertThat(session.isNew()).isFalse();
	verify(this.jdbcOperations, times(1)).update(startsWith("INSERT INTO SPRING_SESSION("),
			isA(PreparedStatementSetter.class));
	verify(this.jdbcOperations, times(1)).update(startsWith("INSERT INTO SPRING_SESSION_ATTRIBUTES("),
			isA(PreparedStatementSetter.class));
	verifyNoMoreInteractions(this.jdbcOperations);
}
 
Example #18
Source File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
void getSessionNotFound() {
	String sessionId = "testSessionId";
	given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
			isA(ResultSetExtractor.class))).willReturn(Collections.emptyList());

	JdbcSession session = this.repository.findById(sessionId);

	assertThat(session).isNull();
	verify(this.jdbcOperations, times(1)).query(isA(String.class), isA(PreparedStatementSetter.class),
			isA(ResultSetExtractor.class));
}
 
Example #19
Source File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test // gh-1070
void saveUpdatedRemoveAndAddAttribute() {
	JdbcSession session = this.repository.new JdbcSession(new MapSession(), "primaryKey", false);
	session.setAttribute("testName", "testValue1");
	session.clearChangeFlags();
	session.removeAttribute("testName");
	session.setAttribute("testName", "testValue2");

	this.repository.save(session);

	assertThat(session.isNew()).isFalse();
	verify(this.jdbcOperations).update(startsWith("UPDATE SPRING_SESSION_ATTRIBUTES SET"),
			isA(PreparedStatementSetter.class));
	verifyNoMoreInteractions(this.jdbcOperations);
}
 
Example #20
Source File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@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 #21
Source File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test // gh-1070
void saveUpdatedModifyAndRemoveAttribute() {
	JdbcSession session = this.repository.new JdbcSession(new MapSession(), "primaryKey", false);
	session.setAttribute("testName", "testValue1");
	session.clearChangeFlags();
	session.setAttribute("testName", "testValue2");
	session.removeAttribute("testName");

	this.repository.save(session);

	assertThat(session.isNew()).isFalse();
	verify(this.jdbcOperations).update(startsWith("DELETE FROM SPRING_SESSION_ATTRIBUTES WHERE"),
			isA(PreparedStatementSetter.class));
	verifyNoMoreInteractions(this.jdbcOperations);
}
 
Example #22
Source File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test // gh-1070
void saveUpdatedAddAndModifyAttribute() {
	JdbcSession session = this.repository.new JdbcSession(new MapSession(), "primaryKey", false);
	session.setAttribute("testName", "testValue1");
	session.setAttribute("testName", "testValue2");

	this.repository.save(session);

	assertThat(session.isNew()).isFalse();
	verify(this.jdbcOperations).update(startsWith("INSERT INTO SPRING_SESSION_ATTRIBUTES("),
			isA(PreparedStatementSetter.class));
	verifyNoMoreInteractions(this.jdbcOperations);
}
 
Example #23
Source File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #24
Source File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void saveNewWithMultipleAttributes() {
	JdbcSession session = this.repository.createSession();
	session.setAttribute("testName1", "testValue1");
	session.setAttribute("testName2", "testValue2");

	this.repository.save(session);

	assertThat(session.isNew()).isFalse();
	verify(this.jdbcOperations, times(1)).update(startsWith("INSERT INTO SPRING_SESSION("),
			isA(PreparedStatementSetter.class));
	verify(this.jdbcOperations, times(1)).batchUpdate(startsWith("INSERT INTO SPRING_SESSION_ATTRIBUTES("),
			isA(BatchPreparedStatementSetter.class));
	verifyNoMoreInteractions(this.jdbcOperations);
}
 
Example #25
Source File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
void findByIndexNameAndIndexValuePrincipalIndexNameNotFound() {
	String principal = "username";
	given(this.jdbcOperations.query(isA(String.class), isA(PreparedStatementSetter.class),
			isA(ResultSetExtractor.class))).willReturn(Collections.emptyList());

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

	assertThat(sessions).isEmpty();
	verify(this.jdbcOperations, times(1)).query(isA(String.class), isA(PreparedStatementSetter.class),
			isA(ResultSetExtractor.class));
}
 
Example #26
Source File: HibernateDataStatisticsEventStore.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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 #27
Source File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void saveUpdatedAddSingleAttribute() {
	JdbcSession session = this.repository.new JdbcSession(new MapSession(), "primaryKey", false);
	session.setAttribute("testName", "testValue");

	this.repository.save(session);

	assertThat(session.isNew()).isFalse();
	verify(this.jdbcOperations, times(1)).update(startsWith("INSERT INTO SPRING_SESSION_ATTRIBUTES("),
			isA(PreparedStatementSetter.class));
	verifyNoMoreInteractions(this.jdbcOperations);
}
 
Example #28
Source File: JdbcIndexedSessionRepositoryTests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Test
void saveUpdatedModifySingleAttribute() {
	JdbcSession session = this.repository.new JdbcSession(new MapSession(), "primaryKey", false);
	session.setAttribute("testName", "testValue");
	session.clearChangeFlags();
	session.setAttribute("testName", "testValue");

	this.repository.save(session);

	assertThat(session.isNew()).isFalse();
	verify(this.jdbcOperations, times(1)).update(startsWith("UPDATE SPRING_SESSION_ATTRIBUTES SET"),
			isA(PreparedStatementSetter.class));
	verifyNoMoreInteractions(this.jdbcOperations);
}
 
Example #29
Source File: LocalDTSStore.java    From dtsopensource with 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 #30
Source File: JdbcDataAnalysisStore.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 ) );
}