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

The following examples show how to use org.springframework.jdbc.core.ColumnMapRowMapper. 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
Source Project: opscenter   Source File: ProcedureJdbcTemplate.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 创建结果集列表
 * @param cstmt
 * @param rs
 * @return List<List<Map<String, Object>>>
 * @throws IOException
 */
public List<List<Map<String, Object>>> createRows(PreparedStatement ps, ResultSet rs) throws IOException{
	List<List<Map<String, Object>>> list = new ArrayList<>();
	RowMapperResultSetExtractor<Map<String, Object>> rse = new RowMapperResultSetExtractor<>(new ColumnMapRowMapper());
	boolean label = true;
	int health = 0;
	while(label){
		try {
			rs=ps.getResultSet();
			if(rs !=null){
				list.add(rse.extractData(rs));
		    	label = ps.getMoreResults();
		    	health++;
		    	if(health > MAX_LOOP) break;
				continue;
		    }
		    label = false;
		} catch (SQLException e) {
			label = false;
		}
	}
	return list;
}
 
Example 2
Source Project: compass   Source File: ShardJdbcTemplate.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
   public List<Map<String, Object>> query(String sql, Object[] args, AggregationDescriptor descriptor) {
	Assert.notNull(sql, "sql must not be null");
	Assert.notNull(descriptor, "AggregationDescriptor must not be null");
	
       ShardOperationProcessor processor = null;

       if (descriptor.needGroupBy() || descriptor.needAggregation()) {
           processor = this.getAggregationProcessor(descriptor);
       } else {
           processor = this.getNonAggregationProcessor(new ColumnMapRowMapper());
       }

       List<Map<String, Object>> resultList = (List<Map<String, Object>>) this.process(sql, args, processor);
       AggregationUtil.sortIfNecessary(descriptor, resultList);

       return AggregationUtil.limitIfNecessary(descriptor, resultList);
   }
 
Example 3
Source Project: tddl5   Source File: ThreadLocalDataSourceIndexTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test_不设i() {
    JdbcTemplate jt = new JdbcTemplate(createGroupDataSource("ds0:rw, ds1:r, ds2:r, ds3:r"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(1);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds1", "select 1 from dual"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(2);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds2", "select 1 from dual"));
}
 
Example 4
Source Project: tddl5   Source File: ThreadLocalDataSourceIndexTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test_设单个in() {
    JdbcTemplate jt = new JdbcTemplate(createGroupDataSource("ds0:rwi5, ds1:ri6, ds2:ri7, ds3:ri8"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(6);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds1", "select 1 from dual"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(8);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds3", "select 1 from dual"));
}
 
Example 5
Source Project: tddl5   Source File: ThreadLocalDataSourceIndexTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test_设多个i分流() {
    JdbcTemplate jt = new JdbcTemplate(createGroupDataSource("ds0:rwi0, ds1:ri0, ds2:ri1, ds3:ri1"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds0", "select") || MockDataSource.hasTrace("", "ds1", "select"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(1);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds2", "select") || MockDataSource.hasTrace("", "ds3", "select"));
}
 
Example 6
Source Project: tddl5   Source File: ThreadLocalDataSourceIndexTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test_1个ds设多个i() {
    JdbcTemplate jt = new JdbcTemplate(createGroupDataSource("ds0:rwi0, ds1:ri0i1, ds2:ri1, ds3:r, ds4:ri3"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds0", "select") || MockDataSource.hasTrace("", "ds1", "select"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(1);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds1", "select") || MockDataSource.hasTrace("", "ds2", "select"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(3);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds3", "select") || MockDataSource.hasTrace("", "ds4", "select"));
}
 
Example 7
Source Project: tddl   Source File: ThreadLocalDataSourceIndexTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test_不设i() {
    JdbcTemplate jt = new JdbcTemplate(createGroupDataSource("ds0:rw, ds1:r, ds2:r, ds3:r"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(1);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds1", "select 1 from dual"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(2);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds2", "select 1 from dual"));
}
 
Example 8
Source Project: tddl   Source File: ThreadLocalDataSourceIndexTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test_设单个in() {
    JdbcTemplate jt = new JdbcTemplate(createGroupDataSource("ds0:rwi5, ds1:ri6, ds2:ri7, ds3:ri8"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(6);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds1", "select 1 from dual"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(8);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds3", "select 1 from dual"));
}
 
Example 9
Source Project: tddl   Source File: ThreadLocalDataSourceIndexTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test_设多个i分流() {
    JdbcTemplate jt = new JdbcTemplate(createGroupDataSource("ds0:rwi0, ds1:ri0, ds2:ri1, ds3:ri1"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds0", "select") || MockDataSource.hasTrace("", "ds1", "select"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(1);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds2", "select") || MockDataSource.hasTrace("", "ds3", "select"));
}
 
Example 10
Source Project: tddl   Source File: ThreadLocalDataSourceIndexTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test_1个ds设多个i() {
    JdbcTemplate jt = new JdbcTemplate(createGroupDataSource("ds0:rwi0, ds1:ri0i1, ds2:ri1, ds3:r, ds4:ri3"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds0", "select") || MockDataSource.hasTrace("", "ds1", "select"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(1);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds1", "select") || MockDataSource.hasTrace("", "ds2", "select"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(3);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds3", "select") || MockDataSource.hasTrace("", "ds4", "select"));
}
 
Example 11
Source Project: spring-analysis-note   Source File: OracleCallMetaDataProvider.java    License: MIT License 5 votes vote down vote up
@Override
public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) {
	if (meta.getSqlType() == Types.OTHER && REF_CURSOR_NAME.equals(meta.getTypeName())) {
		return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper());
	}
	else {
		return super.createDefaultOutParameter(parameterName, meta);
	}
}
 
Example 12
@Override
public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) {
	if (meta.getSqlType() == Types.OTHER && "refcursor".equals(meta.getTypeName())) {
		return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper());
	}
	else {
		return super.createDefaultOutParameter(parameterName, meta);
	}
}
 
Example 13
Source Project: java-technology-stack   Source File: OracleCallMetaDataProvider.java    License: MIT License 5 votes vote down vote up
@Override
public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) {
	if (meta.getSqlType() == Types.OTHER && REF_CURSOR_NAME.equals(meta.getTypeName())) {
		return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper());
	}
	else {
		return super.createDefaultOutParameter(parameterName, meta);
	}
}
 
Example 14
@Override
public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) {
	if (meta.getSqlType() == Types.OTHER && "refcursor".equals(meta.getTypeName())) {
		return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper());
	}
	else {
		return super.createDefaultOutParameter(parameterName, meta);
	}
}
 
Example 15
Source Project: distributed-lock   Source File: SimpleJdbcLockTest.java    License: MIT License 5 votes vote down vote up
@Test
public void shouldLock() {
  final var now = System.currentTimeMillis();
  final var token = lock.acquire(Collections.singletonList("1"), "locks", 1000);
  assertThat(token).isEqualTo("abc");

  final var acquiredLockMap = jdbcTemplate.queryForObject("SELECT * FROM locks WHERE id = 1", new ColumnMapRowMapper());
  assertThat(acquiredLockMap).containsAllEntriesOf(values("1", "abc"));

  final var expireAt = acquiredLockMap.get("expireAt");
  assertThat(((Date) expireAt).getTime()).isCloseTo(now + 1000, Offset.offset(100L));
}
 
Example 16
Source Project: distributed-lock   Source File: SimpleJdbcLockTest.java    License: MIT License 5 votes vote down vote up
@Test
public void shouldNotLock() {
  new SimpleJdbcInsert(jdbcTemplate)
    .withTableName("locks")
    .usingGeneratedKeyColumns("id")
    .executeAndReturnKey(values("1", "def"));

  final var token = lock.acquire(Collections.singletonList("1"), "locks", 1000);
  assertThat(token).isNull();

  final var acquiredLockMap = jdbcTemplate.queryForObject("SELECT * FROM locks WHERE id = 1", new ColumnMapRowMapper());
  assertThat(acquiredLockMap).containsAllEntriesOf(values("1", "def"));
}
 
Example 17
Source Project: distributed-lock   Source File: SimpleJdbcLockTest.java    License: MIT License 5 votes vote down vote up
@Test
public void shouldNotRelease() {
  new SimpleJdbcInsert(jdbcTemplate)
    .withTableName("locks")
    .usingGeneratedKeyColumns("id")
    .executeAndReturnKey(values("1", "def"));

  lock.release(Collections.singletonList("1"), "locks", "abc");

  final var acquiredLockMap = jdbcTemplate.queryForObject("SELECT * FROM locks WHERE id = 1", new ColumnMapRowMapper());
  assertThat(acquiredLockMap).containsAllEntriesOf(values("1", "def"));
}
 
Example 18
Source Project: distributed-lock   Source File: SimpleJdbcLockTest.java    License: MIT License 5 votes vote down vote up
@Test
public void shouldRefresh() throws InterruptedException {
  var expectedExpiration = LocalDateTime.now().plus(1, ChronoUnit.SECONDS);

  final var token = lock.acquire(Collections.singletonList("1"), "locks", 1000);
  var acquiredLockMap = jdbcTemplate.queryForObject("SELECT * FROM locks WHERE id = 1", new ColumnMapRowMapper());
  assertThat((Timestamp) acquiredLockMap.get("expireAt")).isCloseTo(expectedExpiration.toString(), TimeUnit.SECONDS.toMillis(1));
  Thread.sleep(500);
  acquiredLockMap = jdbcTemplate.queryForObject("SELECT * FROM locks WHERE id = 1", new ColumnMapRowMapper());
  assertThat((Timestamp) acquiredLockMap.get("expireAt")).isCloseTo(expectedExpiration.toString(), TimeUnit.SECONDS.toMillis(1));
  expectedExpiration = LocalDateTime.now().plus(1000, ChronoUnit.MILLIS);
  assertThat(lock.refresh(Collections.singletonList("1"), "locks", token, 1000)).isTrue();
  acquiredLockMap = jdbcTemplate.queryForObject("SELECT * FROM locks WHERE id = 1", new ColumnMapRowMapper());
  assertThat((Timestamp) acquiredLockMap.get("expireAt")).isCloseTo(expectedExpiration.toString(), TimeUnit.SECONDS.toMillis(1));
}
 
Example 19
Source Project: distributed-lock   Source File: SimpleJdbcLockTest.java    License: MIT License 5 votes vote down vote up
@Test
public void shouldNotRefreshBecauseTokenDoesNotMatch() {
  final var keys = Collections.singletonList("1");

  final var token = lock.acquire(keys, "locks", 1000);
  final var acquiredLockMap = jdbcTemplate.queryForObject("SELECT * FROM locks WHERE id = 1", new ColumnMapRowMapper());

  assertThat(acquiredLockMap).containsAllEntriesOf(values("1", token));
  assertThat(lock.refresh(keys, "locks", "wrong-token", 1000)).isFalse();
  assertThat(jdbcTemplate.queryForList("SELECT * FROM locks")).hasSize(1);
}
 
Example 20
@Override
public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) {
	if (meta.getSqlType() == Types.OTHER && REF_CURSOR_NAME.equals(meta.getTypeName())) {
		return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper());
	}
	else {
		return super.createDefaultOutParameter(parameterName, meta);
	}
}
 
Example 21
@Override
public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) {
	if (meta.getSqlType() == Types.OTHER && "refcursor".equals(meta.getTypeName())) {
		return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper());
	}
	else {
		return super.createDefaultOutParameter(parameterName, meta);
	}
}
 
Example 22
@Override
public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) {
	if (meta.getSqlType() == Types.OTHER && REF_CURSOR_NAME.equals(meta.getTypeName())) {
		return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper());
	}
	else {
		return super.createDefaultOutParameter(parameterName, meta);
	}
}
 
Example 23
@Override
public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) {
	if (meta.getSqlType() == Types.OTHER && "refcursor".equals(meta.getTypeName())) {
		return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper());
	}
	else {
		return super.createDefaultOutParameter(parameterName, meta);
	}
}
 
Example 24
Source Project: spring-boot   Source File: JdbcTemplateUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Map 包装
 */
public static PageBean queryPageByMapMapperNativeSqlString(final JdbcTemplate jdbcTemplate, final SqlUtils.Dialect dbDialect,
                                                           final String queryNativeSql, Object[] queryArgs,
                                                           final String countNativeSql, Object[] countArgs,
                                                           int currentPageNo, int pageSize) {
    return queryPageByNativeSqlString(jdbcTemplate, dbDialect,
            queryNativeSql, queryArgs,
            countNativeSql, countArgs,
            currentPageNo, pageSize, new ColumnMapRowMapper());
}
 
Example 25
Source Project: tddl5   Source File: ThreadLocalDataSourceIndexTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test_设单个i不加数字等同于没设() {
    JdbcTemplate jt = new JdbcTemplate(createGroupDataSource("ds0:rwi, ds1:ri, ds2:ri, ds3:ri"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(1);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds1", "select 1 from dual"));
}
 
Example 26
Source Project: tddl   Source File: ThreadLocalDataSourceIndexTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test_设单个i不加数字等同于没设() {
    JdbcTemplate jt = new JdbcTemplate(createGroupDataSource("ds0:rwi, ds1:ri, ds2:ri, ds3:ri"));

    MockDataSource.clearTrace();
    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(1);
    jt.query("select 1 from dual", new Object[] {}, new ColumnMapRowMapper());
    MockDataSource.showTrace();
    Assert.assertTrue(MockDataSource.hasTrace("", "ds1", "select 1 from dual"));
}
 
Example 27
Source Project: effectivejava   Source File: OracleCallMetaDataProvider.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) {
	if (meta.getSqlType() == Types.OTHER && REF_CURSOR_NAME.equals(meta.getTypeName())) {
		return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper());
	}
	else {
		return super.createDefaultOutParameter(parameterName, meta);
	}
}
 
Example 28
@Override
public SqlParameter createDefaultOutParameter(String parameterName, CallParameterMetaData meta) {
	if (meta.getSqlType() == Types.OTHER && "refcursor".equals(meta.getTypeName())) {
		return new SqlOutParameter(parameterName, getRefCursorSqlType(), new ColumnMapRowMapper());
	}
	else {
		return super.createDefaultOutParameter(parameterName, meta);
	}
}
 
Example 29
Source Project: spring-analysis-note   Source File: NamedParameterJdbcTemplate.java    License: MIT License 4 votes vote down vote up
@Override
public Map<String, Object> queryForMap(String sql, SqlParameterSource paramSource) throws DataAccessException {
	Map<String, Object> result = queryForObject(sql, paramSource, new ColumnMapRowMapper());
	Assert.state(result != null, "No result map");
	return result;
}
 
Example 30
Source Project: spring-analysis-note   Source File: NamedParameterJdbcTemplate.java    License: MIT License 4 votes vote down vote up
@Override
public Map<String, Object> queryForMap(String sql, Map<String, ?> paramMap) throws DataAccessException {
	Map<String, Object> result = queryForObject(sql, paramMap, new ColumnMapRowMapper());
	Assert.state(result != null, "No result map");
	return result;
}