Java Code Examples for org.springframework.jdbc.core.JdbcTemplate#setMaxRows()

The following examples show how to use org.springframework.jdbc.core.JdbcTemplate#setMaxRows() . 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: HibernatePersistentObjectDAO.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public List query(String sql, Object[] args, RowMapper rowMapper, Integer maxRows) throws PersistenceException {
	List list = new ArrayList();
	try {
		DataSource dataSource = (DataSource) Context.get().getBean("DataSource");

		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
		if (maxRows != null)
			jdbcTemplate.setMaxRows(maxRows);
		if (args != null)
			list = jdbcTemplate.query(insertTopClause(sql, maxRows), args, rowMapper);
		else
			list = jdbcTemplate.query(insertTopClause(sql, maxRows), rowMapper);
		return list;
	} catch (Throwable e) {
		throw new PersistenceException(e);
	}

}
 
Example 2
Source File: HibernatePersistentObjectDAO.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public List queryForList(String sql, Object[] args, Class elementType, Integer maxRows)
		throws PersistenceException {

	List list = new ArrayList();
	try {
		DataSource dataSource = (DataSource) Context.get().getBean("DataSource");
		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
		if (maxRows != null)
			jdbcTemplate.setMaxRows(maxRows);
		if (args != null)
			list = jdbcTemplate.queryForList(insertTopClause(sql, maxRows), args, elementType);
		else
			list = jdbcTemplate.queryForList(insertTopClause(sql, maxRows), elementType);
		return list;
	} catch (Throwable e) {
		log.error(e.getMessage(), e);
		throw new PersistenceException(e);
	}
}
 
Example 3
Source File: HibernatePersistentObjectDAO.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public SqlRowSet queryForRowSet(String sql, Object[] args, Integer maxRows) throws PersistenceException {
	SqlRowSet rs = null;
	try {
		DataSource dataSource = (DataSource) Context.get().getBean("DataSource");
		JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
		if (maxRows != null)
			jdbcTemplate.setMaxRows(maxRows);
		if (args != null)
			rs = jdbcTemplate.queryForRowSet(insertTopClause(sql, maxRows), args);
		else
			rs = jdbcTemplate.queryForRowSet(insertTopClause(sql, maxRows));
		return rs;
	} catch (Throwable e) {
		throw new PersistenceException(e);
	}
}
 
Example 4
Source File: V9__Compute_Word_Count.java    From mojito with Apache License 2.0 6 votes vote down vote up
private List<TmTextUnit> getTmTextUnits(JdbcTemplate jdbcTemplate) {
 
    jdbcTemplate.setMaxRows(MAX_ROW);
    
    List<TmTextUnit> tmTextUnits = jdbcTemplate.query(
            "select id, content from tm_text_unit tu where tu.word_count is null",
            new RowMapper<TmTextUnit>() {
                
        public TmTextUnit mapRow(ResultSet rs, int rowNum) throws SQLException {
            TmTextUnit tmTextUnit = new TmTextUnit();
            tmTextUnit.id = rs.getLong("id");
            tmTextUnit.content = rs.getString("content");
            return tmTextUnit;
        }
    });

    return tmTextUnits;
}
 
Example 5
Source File: ShardJdbcTemplate.java    From compass with Apache License 2.0 5 votes vote down vote up
/**
 * 创建一个JdbcTemplate,并且设置超时、maxRows参数
 * @param dataSource
 * @param config
 * @return
 */
private JdbcTemplate createJdbcTemplate(DataSource dataSource, ShardJdbcConfig config) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.setQueryTimeout(config.getQueryTimeout());
    jdbcTemplate.setMaxRows(config.getMaxRows());
    
    return jdbcTemplate;
}
 
Example 6
Source File: AuditReportlet.java    From syncope with Apache License 2.0 4 votes vote down vote up
private void doExtractConf(final ContentHandler handler, final AtomicReference<String> status) throws SAXException {
    status.set("Fetching " + conf.getSize() + " rows from the " + LoggerDAO.AUDIT_TABLE + " table");

    JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
    jdbcTemplate.setMaxRows(conf.getSize());
    List<Map<String, Object>> rows = jdbcTemplate.
            queryForList("SELECT * FROM " + LoggerDAO.AUDIT_TABLE + " ORDER BY EVENT_DATE DESC");

    handler.startElement("", "", "events", null);
    AttributesImpl atts = new AttributesImpl();
    for (Map<String, Object> row : rows) {
        AuditEntry auditEntry = POJOHelper.deserialize(row.get("MESSAGE").toString(), AuditEntry.class);

        atts.clear();
        if (StringUtils.isNotBlank(auditEntry.getWho())) {
            atts.addAttribute("", "", "who", ReportXMLConst.XSD_STRING, auditEntry.getWho());
        }
        handler.startElement("", "", "event", atts);

        atts.clear();
        if (StringUtils.isNotBlank(auditEntry.getLogger().getCategory())) {
            atts.addAttribute("", "", "category",
                    ReportXMLConst.XSD_STRING, auditEntry.getLogger().getCategory());
        }
        if (StringUtils.isNotBlank(auditEntry.getLogger().getSubcategory())) {
            atts.addAttribute("", "", "subcategory",
                    ReportXMLConst.XSD_STRING, auditEntry.getLogger().getSubcategory());
        }
        if (StringUtils.isNotBlank(auditEntry.getLogger().getEvent())) {
            atts.addAttribute("", "", "event",
                    ReportXMLConst.XSD_STRING, auditEntry.getLogger().getEvent());
        }
        if (auditEntry.getLogger().getResult() != null) {
            atts.addAttribute("", "", "result",
                    ReportXMLConst.XSD_STRING, auditEntry.getLogger().getResult().name());
        }
        handler.startElement("", "", "logger", atts);
        handler.endElement("", "", "logger");

        if (auditEntry.getBefore() != null) {
            char[] before = POJOHelper.serialize(auditEntry.getBefore()).toCharArray();
            handler.startElement("", "", "before", null);
            handler.characters(before, 0, before.length);
            handler.endElement("", "", "before");
        }

        if (!auditEntry.getInputs().isEmpty()) {
            handler.startElement("", "", "inputs", null);
            for (String input : auditEntry.getInputs()) {
                handler.startElement("", "", "input", null);
                handler.characters(input.toCharArray(), 0, input.length());
                handler.endElement("", "", "input");
            }
            handler.endElement("", "", "inputs");
        }

        if (auditEntry.getOutput() != null) {
            char[] output = POJOHelper.serialize(auditEntry.getOutput()).toCharArray();
            handler.startElement("", "", "output", null);
            handler.characters(output, 0, output.length);
            handler.endElement("", "", "output");
        }

        handler.startElement("", "", "throwable", null);
        char[] throwable = row.get("THROWABLE").toString().toCharArray();
        handler.characters(throwable, 0, throwable.length);
        handler.endElement("", "", "throwable");

        handler.endElement("", "", "event");
    }
    handler.endElement("", "", "events");

    status.set("Fetched " + conf.getSize() + " rows from the SYNCOPEAUDIT table");
}