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

The following are top voted examples for showing how to use org.springframework.jdbc.core.ColumnMapRowMapper. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: airsonic   File: DBController.java   Source Code and License 6 votes vote down vote up
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();

    String query = request.getParameter("query");
    if (query != null) {
        map.put("query", query);

        try {
            List<?> result = daoHelper.getJdbcTemplate().query(query, new ColumnMapRowMapper());
            map.put("result", result);
        } catch (DataAccessException x) {
            map.put("error", ExceptionUtils.getRootCause(x).getMessage());
        }
    }

    return new ModelAndView("db","model",map);
}
 
Example 2
Project: compass   File: ShardJdbcTemplate.java   Source Code and License 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
Project: tddl5   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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
Project: tddl5   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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
Project: tddl5   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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
Project: tddl5   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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
Project: TDDL   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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
Project: TDDL   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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
Project: TDDL   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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
Project: TDDL   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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
Project: tddl   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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 12
Project: tddl   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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 13
Project: tddl   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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 14
Project: tddl   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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 15
Project: spring-greenhouse-clickstart   File: NFJSLoaderTest.java   Source Code and License 6 votes vote down vote up
private void assertEventData(String title, String timeZone, String startTime, String endTime, String slug) {
	Map<String, Object> externalEventData = jdbcTemplate.queryForObject("select event, sourceId, source from ExternalEvent where sourceId=? and source='NFJS'", new ColumnMapRowMapper(), SHOW_ID);
	Long eventId = (Long) externalEventData.get("event");
	assertEquals(Long.valueOf(1), eventId);
	assertEquals(Long.valueOf(SHOW_ID), externalEventData.get("sourceId"));
	assertEquals("NFJS", externalEventData.get("source"));
	
	Map<String, Object> eventData = jdbcTemplate.queryForObject("select id,  title, timeZone, startTime, endTime, slug, description, memberGroup from Event where id=?", new ColumnMapRowMapper(), eventId);
	assertEquals(eventId, eventData.get("id"));
	assertEquals(title, eventData.get("title"));
	assertEquals(timeZone, eventData.get("timeZone"));
	assertEquals(startTime, eventData.get("startTime").toString());
	assertEquals(endTime, eventData.get("endTime").toString());
	assertEquals(slug, eventData.get("slug"));
	assertNull(eventData.get("description"));
	assertEquals(1L, eventData.get("memberGroup"));
}
 
Example 16
Project: spring-greenhouse-clickstart   File: NFJSLoaderTest.java   Source Code and License 6 votes vote down vote up
private void assertLeaderData(String name, String bio, String personalUrl, String twitterUsername) {
	Map<String, Object> externalLeaderData = jdbcTemplate.queryForObject("select leader, sourceId, source from ExternalLeader where source='NFJS' and sourceId=?", new ColumnMapRowMapper(), 38);
	Long leaderId = (Long) externalLeaderData.get("leader");
	assertEquals(Long.valueOf(15), leaderId);
	assertEquals(38L, externalLeaderData.get("sourceId"));
	assertEquals("NFJS", externalLeaderData.get("source"));
	
	Map<String, Object> leaderData = jdbcTemplate.queryForObject("select id, name, company, title, location, bio, personalUrl, companyUrl, twitterUsername, member from Leader where id=?", new ColumnMapRowMapper(), leaderId);
	assertEquals(leaderId, leaderData.get("id"));
	assertEquals(name, leaderData.get("name"));
	assertNull(leaderData.get("company"));
	assertNull(leaderData.get("title"));
	assertNull(leaderData.get("location"));
	assertEquals(bio, leaderData.get("bio").toString().trim());
	assertEquals(personalUrl, leaderData.get("personalUrl"));
	assertNull(leaderData.get("companyUrl"));
	assertEquals(twitterUsername, leaderData.get("twitterUsername"));
	assertNull(leaderData.get("member")); // TODO: Might want to figure out how to associate this with GH member table
}
 
Example 17
Project: lams   File: OracleCallMetaDataProvider.java   Source Code and 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 18
Project: lams   File: PostgresCallMetaDataProvider.java   Source Code and 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 19
Project: pub-service   File: LowerCaseJdbcTemplate.java   Source Code and License 5 votes vote down vote up
@Override
protected RowMapper getColumnMapRowMapper() {
	if("2".equals(EopSetting.DBTYPE)){
		return new OracleColumnMapRowMapper();
	}else if("1".equals(EopSetting.DBTYPE)){
		return new MySqlColumnMapRowMapper();
	}else{
		return new ColumnMapRowMapper();
	}
}
 
Example 20
Project: spring4-understanding   File: OracleCallMetaDataProvider.java   Source Code and 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 21
Project: spring4-understanding   File: PostgresCallMetaDataProvider.java   Source Code and 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
Project: spring-boot   File: JdbcTemplateUtils.java   Source Code and License 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 23
Project: Nicole   File: DaoHandler.java   Source Code and License 5 votes vote down vote up
private RowMapper<Map<String, Object>> getColumnMapRowMapper() {
    if (getKeyType().equalsIgnoreCase(LOWER_KEY)) {
        return new MiniColumnMapRowMapper();
    } else if (getKeyType().equalsIgnoreCase(UPPER_KEY)) {
        return new ColumnMapRowMapper();
    } else {
        return new MiniColumnOriginalMapRowMapper();
    }
}
 
Example 24
Project: maker   File: MiniDaoHandler.java   Source Code and License 5 votes vote down vote up
/**
 *根据参数设置map的key大小写
 **/
private RowMapper<Map<String,Object>> getColumnMapRowMapper() {
	if(getKeyType().equalsIgnoreCase(LOWER_KEY)){
		return new MiniColumnMapRowMapper();
	}else if(getKeyType().equalsIgnoreCase(UPPER_KEY)){
		return new ColumnMapRowMapper();
	}else{
		return new MiniColumnOriginalMapRowMapper();
	}
}
 
Example 25
Project: marklogic-spring-batch   File: AllTablesItemReader.java   Source Code and License 5 votes vote down vote up
/**
 * @param tableName
 * @param executionContext
 * @return a JdbcCursorItemReader for the given table name. Override this method to alert the SQL statement that's
 * used for a particular table.
 */
protected JdbcCursorItemReader<Map<String, Object>> buildTableReader(String tableName, ExecutionContext executionContext) {
    JdbcCursorItemReader<Map<String, Object>> reader = new JdbcCursorItemReader<>();
    reader.setDataSource(dataSource);
    reader.setRowMapper(new ColumnMapRowMapper());
    reader.setSql(getSqlQueryForTable(tableName));
    reader.open(executionContext);
    return reader;
}
 
Example 26
Project: tddl5   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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
Project: TDDL   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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 28
Project: tddl   File: ThreadLocalDataSourceIndexTest.java   Source Code and License 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 29
Project: class-guard   File: OracleCallMetaDataProvider.java   Source Code and 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 30
Project: class-guard   File: PostgresCallMetaDataProvider.java   Source Code and 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 31
Project: panelized   File: SelectCreatorDataProvider.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public Iterator<RowMap> iterator(long first, long count) {

    SelectCreator creator = selectCreator.clone();

    applyFilters(creator);
    applyQuickFilters(creator);

    if (getSort() != null) {
        creator.orderBy(getSort().getProperty(), getSort().isAscending());
    }

    if (getSecondarySort() != null) {
        creator.orderBy(getSecondarySort().getProperty(), getSecondarySort().isAscending());
    }

    creator.orderBy(uniqueColumn);

    log.debug("Executing query: " + creator);

    JdbcTemplate t = new JdbcTemplate(getDataSource());

    @SuppressWarnings("rawtypes")
    RowMapper rowMapper = new ColumnMapRowMapper() {
        @Override
        protected Map<String, Object> createColumnMap(int columnCount) {
            return new RowMap();
        }
        @Override
        public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
            Map<String, Object> row = super.mapRow(rs, rowNum);
            processRow((RowMap) row);
            return row;
        }
    };
    return t.query(creator.page(DIALECT, (int) count, (int) first), (RowMapper<RowMap>) rowMapper).iterator();

}
 
Example 32
Project: spring-greenhouse-clickstart   File: NFJSLoaderTest.java   Source Code and License 5 votes vote down vote up
private void assertVenueData(String name, String postalAddress, double latitude, double longitude, String locationHint, long createdBy) {
	Map<String, Object> eventVenueData = jdbcTemplate.queryForObject("select event, venue from EventVenue where event=?", new ColumnMapRowMapper(), 1);
	assertEquals(Long.valueOf(1), eventVenueData.get("event"));
	Long venueId = (Long) eventVenueData.get("venue");
	assertEquals(Long.valueOf(1), venueId);
	
	Map<String, Object> venueData = jdbcTemplate.queryForObject("select id, name, postalAddress, latitude, longitude, locationHint, createdBy from Venue where id=?", new ColumnMapRowMapper(), venueId);
	assertEquals(Long.valueOf(1), venueData.get("id"));
	assertEquals(name, venueData.get("name"));
	assertEquals(postalAddress, venueData.get("postalAddress"));
	assertEquals(latitude, venueData.get("latitude"));
	assertEquals(longitude, venueData.get("longitude"));
	assertEquals(locationHint, venueData.get("locationHint"));
	assertEquals(createdBy, venueData.get("createdBy"));
}
 
Example 33
Project: spring-greenhouse-clickstart   File: NFJSLoaderTest.java   Source Code and License 5 votes vote down vote up
private void assertEventTimeSlotData(long id, long eventId, String label, String startTime, String endTime) {
	Map<String, Object> externalEventTimeSlotData = jdbcTemplate.queryForObject("select timeSlot, sourceId, source from ExternalEventTimeSlot where timeSlot=?", new ColumnMapRowMapper(), id);
	assertEquals(id, externalEventTimeSlotData.get("timeSlot"));
	assertEquals(6311L, externalEventTimeSlotData.get("sourceId"));
	assertEquals("NFJS", externalEventTimeSlotData.get("source"));
	
	Map<String, Object> eventTimeSlotData = jdbcTemplate.queryForObject("select id, event, label, startTime, endTime from EventTimeSlot where id=?", new ColumnMapRowMapper(), 16);
	assertEquals(id, eventTimeSlotData.get("id"));
	assertEquals(eventId, eventTimeSlotData.get("event"));
	assertEquals(label, eventTimeSlotData.get("label"));
	assertEquals(startTime, eventTimeSlotData.get("startTime").toString());
	assertEquals(endTime, eventTimeSlotData.get("endTime").toString());
}
 
Example 34
Project: quickmon   File: JdbcSampler.java   Source Code and License 4 votes vote down vote up
@Override
public List<Map<String, Object>> sample() {
    JdbcTemplate temp = new JdbcTemplate();
    List<Map<String, Object>> result = temp.query(sql, new ColumnMapRowMapper());
    return result;
}
 
Example 35
Project: lams   File: NamedParameterJdbcTemplate.java   Source Code and License 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 36
Project: lams   File: NamedParameterJdbcTemplate.java   Source Code and License 4 votes vote down vote up
@Override
public Map<String, Object> queryForMap(String sql, Map<String, ?> paramMap) throws DataAccessException {
	return queryForObject(sql, paramMap, new ColumnMapRowMapper());
}
 
Example 37
Project: lams   File: NamedParameterJdbcTemplate.java   Source Code and License 4 votes vote down vote up
@Override
public List<Map<String, Object>> queryForList(String sql, SqlParameterSource paramSource)
		throws DataAccessException {

	return query(sql, paramSource, new ColumnMapRowMapper());
}
 
Example 38
Project: spring4-understanding   File: NamedParameterJdbcTemplate.java   Source Code and License 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 39
Project: spring4-understanding   File: NamedParameterJdbcTemplate.java   Source Code and License 4 votes vote down vote up
@Override
public Map<String, Object> queryForMap(String sql, Map<String, ?> paramMap) throws DataAccessException {
	return queryForObject(sql, paramMap, new ColumnMapRowMapper());
}
 
Example 40
Project: spring4-understanding   File: NamedParameterJdbcTemplate.java   Source Code and License 4 votes vote down vote up
@Override
public List<Map<String, Object>> queryForList(String sql, SqlParameterSource paramSource)
		throws DataAccessException {

	return query(sql, paramSource, new ColumnMapRowMapper());
}
 
Example 41
Project: compass   File: ShardJdbcTemplate.java   Source Code and License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
   public List<Map<String, Object>> query(String sql, Object[] args) {
       return this.query(sql, args, new ColumnMapRowMapper());
   }
 
Example 42
Project: perecoder   File: DataSourceDictionaryConverter.java   Source Code and License 4 votes vote down vote up
public DataSourceDictionaryConverter(String primaryMetaFieldName) {
    this.primaryMetaFieldName = primaryMetaFieldName;
    this.rowMapper = new ColumnMapRowMapper();
}
 
Example 43
Project: class-guard   File: NamedParameterJdbcTemplate.java   Source Code and License 4 votes vote down vote up
public Map<String, Object> queryForMap(String sql, SqlParameterSource paramSource) throws DataAccessException {
	return queryForObject(sql, paramSource, new ColumnMapRowMapper());
}
 
Example 44
Project: class-guard   File: NamedParameterJdbcTemplate.java   Source Code and License 4 votes vote down vote up
public Map<String, Object> queryForMap(String sql, Map<String, ?> paramMap) throws DataAccessException {
	return queryForObject(sql, paramMap, new ColumnMapRowMapper());
}
 
Example 45
Project: class-guard   File: NamedParameterJdbcTemplate.java   Source Code and License 4 votes vote down vote up
public List<Map<String, Object>> queryForList(String sql, SqlParameterSource paramSource)
		throws DataAccessException {

	return query(sql, paramSource, new ColumnMapRowMapper());
}
 
Example 46
Project: AGIA   File: MapJdbcLookupProcessor.java   Source Code and License 4 votes vote down vote up
public MapJdbcLookupProcessor() {
    jdbcCursorItemReader.setRowMapper(new ColumnMapRowMapper());
    jdbcCursorItemReader.setPreparedStatementSetter(preparedStatementSetter);
}
 
Example 47
Project: sqltemplate   File: SqlTemplate.java   Source Code and License 4 votes vote down vote up
public List<Map<String, Object>> forList(String fileName, Object... args) {
    String sql = getTemplate(fileName, args);
    return jdbcTemplate.query(sql, paramBuilder.byArgs(args), new ColumnMapRowMapper());
}
 
Example 48
Project: sqltemplate   File: SqlTemplate.java   Source Code and License 3 votes vote down vote up
/**
 * Executes a query,
 * passing the column maps to {@code handleStream} as a stream.
 *
 * <p>Example usage:</p>
 *
 * <pre>
 * int totalSalary = sqlTemplate.forStream("/path/to/query.sql",
 *         mapStream -&gt; mapStream.mapToInt(map -&gt; (Integer) map.get("salary")).sum());
 * </pre>
 *
 * @param fileName SQL specifier
 * @param handleStream the function which is applied to the stream
 * @param <U> the result type
 * @return the result of {@code handleStream}
 * @throws org.springframework.dao.DataAccessException if there is any problem
 */
public <U> U forStream(
        String fileName,
        Function<? super Stream<Map<String, Object>>, U> handleStream) {
    String sql = getTemplate(fileName, EMPTY_ARGS);
    PreparedStatementSetter pss = paramBuilder.byArgs(new Object[0]);
    RowMapper<Map<String, Object>> mapper = new ColumnMapRowMapper();
    return queryStreamWithOrdinalParams(sql, pss, mapper, handleStream);
}
 
Example 49
Project: sqltemplate   File: SqlTemplate.java   Source Code and License 3 votes vote down vote up
/**
 * Executes a query using {@code args} as the parameters,
 * passing the column maps to {@code handleStream} as a stream.
 *
 * <p>Example usage:</p>
 *
 * <pre>
 * int totalSalary = sqlTemplate.forStream("/path/to/query.sql",
 *         new Object[] { 30, "SALESMAN" },
 *         mapStream -&gt; mapStream.mapToInt(map -&gt; (Integer) map.get("salary")).sum());
 * </pre>
 *
 * @param fileName parameterized SQL specifier
 * @param args the parameters
 * @param handleStream  the function which is applied to the stream
 * @param <U> the result type
 * @return the result of {@code handleStream}
 * @throws org.springframework.dao.DataAccessException if there is any problem
 */
public <U> U forStream(
        String fileName,
        Object[] args,
        Function<? super Stream<Map<String, Object>>, U> handleStream) {
    String sql = getTemplate(fileName, args);
    PreparedStatementSetter pss = paramBuilder.byArgs(args);
    RowMapper<Map<String, Object>> mapper = new ColumnMapRowMapper();
    return queryStreamWithOrdinalParams(sql, pss, mapper, handleStream);
}
 
Example 50
Project: sqltemplate   File: SqlTemplate.java   Source Code and License 3 votes vote down vote up
/**
 * Executes a query using {@code params} as the named parameters,
 * passing the column maps to {@code handleStream} as a stream.
 *
 * <p>Example usage:</p>
 *
 * <pre>
 * Map&lt;String, Object&gt; params = new HashMap&gt;&lt;();
 * params.put("deptno", 30);
 * params.put("job", "SALESMAN");
 * int totalSalary = sqlTemplate.forStream("/path/to/query.sql", params,
 *         mapStream -&gt; mapStream.mapToInt(map -&gt; (Integer) map.get("salary")).sum());
 * </pre>
 *
 * @param fileName parameterized SQL specifier
 * @param params the named parameters
 * @param handleStream  the function which is applied to the stream
 * @param <U> the result type
 * @return the result of {@code handleStream}
 * @throws org.springframework.dao.DataAccessException if there is any problem
 */
public <U> U forStream(
        String fileName,
        Map<String, Object> params,
        Function<? super Stream<Map<String, Object>>, U> handleStream) {
    String sql = getTemplate(fileName, params);
    SqlParameterSource sps = paramBuilder.byMap(params);
    RowMapper<Map<String, Object>> mapper = new ColumnMapRowMapper();
    return queryStreamWithNamedParams(sql, sps, mapper, handleStream);
}
 
Example 51
Project: sqltemplate   File: SqlTemplate.java   Source Code and License 3 votes vote down vote up
/**
 * Executes a query, passing the column maps to {@code handleStream} as a stream.
 *
 * <p>{@code entity} is used as the single parameter if it is a simple value,
 * or as the container of the named parameters if it is a bean.</p>
 *
 * <p>Example usage with a simple value parameter:</p>
 *
 * <pre>
 * int totalSalary = sqlTemplate.forStream("/path/to/query.sql", "SALESMAN",
 *         mapStream -&gt; mapStream.mapToInt(map -&gt; (Integer) map.get("salary")).sum());
 * </pre>
 *
 * <p>Example usage with a bean parameter:</p>
 *
 * <pre>
 * emp.setDeptno(30);
 * emp.setJob("SALESMAN");
 * int totalSalary = sqlTemplate.forStream("/path/to/query.sql", emp,
 *         mapStream -&gt; mapStream.mapToInt(map -&gt; (Integer) map.get("salary")).sum());
 * </pre>
 *
 * @param fileName parameterized SQL specifier
 * @param entity the single parameter or the container of the named parameters
 * @param handleStream  the function which is applied to the stream
 * @param <U> the result type
 * @return the result of {@code handleStream}
 * @throws org.springframework.dao.DataAccessException if there is any problem
 */
public <U> U forStream(
        String fileName,
        Object entity,
        Function<? super Stream<Map<String, Object>>, U> handleStream) {
    String sql = getTemplate(fileName, entity);
    RowMapper<Map<String, Object>> mapper = new ColumnMapRowMapper();
    if (TypeUtils.isSimpleValueType(entity.getClass())) {
        PreparedStatementSetter pss = paramBuilder.byArgs(entity);
        return queryStreamWithOrdinalParams(sql, pss, mapper, handleStream);
    } else {
        SqlParameterSource sps = paramBuilder.byBean(entity);
        return queryStreamWithNamedParams(sql, sps, mapper, handleStream);
    }
}
 
Example 52
Project: spring-boot   File: JdbcTemplateUtils.java   Source Code and License 2 votes vote down vote up
/**
 * 同上,构造查询语句,不分页
 * 返回 map 包装类型 ,尤其是返回值没有对应的 bean 的时候,返回 map ,从而不必再构造一个 bean
 *
 * @param jdbcTemplate
 * @param queryNativeSql
 * @param queryArgs
 * @return
 */
public static List<Map<String, Object>> queryForListByMapMapperNativeSqlString(final JdbcTemplate jdbcTemplate, final String queryNativeSql, Object[] queryArgs) {
    return queryForListByNativeSqlString(jdbcTemplate, queryNativeSql, queryArgs, new ColumnMapRowMapper());
}
 
Example 53
Project: sqltemplate   File: SqlTemplate.java   Source Code and License 2 votes vote down vote up
/**
 * Executes a query, passing the column maps to {@code handleStream} as a stream.
 *
 * @param handleStream the function which is applied to the stream
 * @param <U> the result type
 * @return the result of {@code handleStream}
 * @throws org.springframework.dao.DataAccessException if there is any problem
 */
public <U> U forStream(
        Function<? super Stream<Map<String, Object>>, U> handleStream) {
    String sql = getTemplate(fileName, params);
    return queryStreamWithNamedParams(sql, paramBuilder.byMap(params), new ColumnMapRowMapper(), handleStream);
}