org.springframework.jdbc.core.ColumnMapRowMapper Java Examples

The following examples show how to use org.springframework.jdbc.core.ColumnMapRowMapper. 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: ThreadLocalDataSourceIndexTest.java    From tddl with 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 #2
Source File: ThreadLocalDataSourceIndexTest.java    From tddl with 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 #3
Source File: ThreadLocalDataSourceIndexTest.java    From tddl with 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 #4
Source File: ThreadLocalDataSourceIndexTest.java    From tddl with 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 #5
Source File: ThreadLocalDataSourceIndexTest.java    From tddl5 with 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 #6
Source File: ThreadLocalDataSourceIndexTest.java    From tddl5 with 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 #7
Source File: ThreadLocalDataSourceIndexTest.java    From tddl5 with 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 #8
Source File: ThreadLocalDataSourceIndexTest.java    From tddl5 with 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 #9
Source File: ShardJdbcTemplate.java    From compass with 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 #10
Source File: ProcedureJdbcTemplate.java    From opscenter with 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 #11
Source File: SimpleJdbcLockTest.java    From distributed-lock with 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 #12
Source File: PostgresCallMetaDataProvider.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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 File: OracleCallMetaDataProvider.java    From lams with GNU General Public License v2.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 #14
Source File: OracleCallMetaDataProvider.java    From spring4-understanding with 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 #15
Source File: PostgresCallMetaDataProvider.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: JdbcTemplateUtils.java    From spring-boot with 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 #17
Source File: ThreadLocalDataSourceIndexTest.java    From tddl5 with 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 #18
Source File: ThreadLocalDataSourceIndexTest.java    From tddl with 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 #19
Source File: OracleCallMetaDataProvider.java    From effectivejava with 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 #20
Source File: PostgresCallMetaDataProvider.java    From effectivejava with Apache License 2.0 5 votes vote down vote up
@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 #21
Source File: PostgresCallMetaDataProvider.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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
Source File: PostgresCallMetaDataProvider.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 #23
Source File: SimpleJdbcLockTest.java    From distributed-lock with 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 #24
Source File: OracleCallMetaDataProvider.java    From java-technology-stack with 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 #25
Source File: SimpleJdbcLockTest.java    From distributed-lock with 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 #26
Source File: SimpleJdbcLockTest.java    From distributed-lock with 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 #27
Source File: OracleCallMetaDataProvider.java    From spring-analysis-note with 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 #28
Source File: SimpleJdbcLockTest.java    From distributed-lock with 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 #29
Source File: NamedParameterJdbcTemplate.java    From effectivejava with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, Object> queryForMap(String sql, SqlParameterSource paramSource) throws DataAccessException {
	return queryForObject(sql, paramSource, new ColumnMapRowMapper());
}
 
Example #30
Source File: SheetsReadModel.java    From library with MIT License 4 votes vote down vote up
private List<Map<String, Object>> findHoldsToExpire() {
    return sheets.query(
            "SELECT h.book_id, h.hold_by_patron_id, h.hold_at_branch FROM holds_sheet h WHERE h.status = 'ACTIVE' and h.hold_till <= ?",
            new Object[]{from(Instant.now(clock))},
            new ColumnMapRowMapper());
}