Java Code Examples for org.springframework.jdbc.support.rowset.SqlRowSet

The following examples show how to use org.springframework.jdbc.support.rowset.SqlRowSet. 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: Lottery   Source File: CmsDataDaoImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
public List<CmsConstraints> listConstraints(String tablename) {
	String sql = "select constraint_name,table_name,column_name,referenced_table_name,referenced_column_name from information_schema.KEY_COLUMN_USAGE where constraint_schema='"
			+ db + "' and table_name='" + tablename + "'";
	List<CmsConstraints> constraints = new ArrayList<CmsConstraints>();
	SqlRowSet set = getJdbcTemplate().queryForRowSet(sql);
	while (set.next()) {
		CmsConstraints constraint = new CmsConstraints();
		constraint.setName(set.getString(1));
		constraint.setTableName(set.getString(2));
		constraint.setColumnName(set.getString(3));
		constraint.setReferencedTableName(set.getString(4));
		constraint.setReferencedColumnName(set.getString(5));
		constraints.add(constraint);
	}
	return constraints;
}
 
Example 2
/**
 * @see org.kuali.kfs.module.purap.dataaccess.StatusCodeAndDescriptionForPurapDocumentsDao#getLineItemReceivingDocumentStatuses()
 */
public Map<String, String> getLineItemReceivingDocumentStatuses() {
    LOG.debug("getLineItemReceivingDocumentStatuses() started");
    
    Map<String, String> lineItemReceivingStatuses = new HashMap<String, String>();
    
    try {
        SqlRowSet statusesRowSet = getJdbcTemplate().queryForRowSet("SELECT * FROM PUR_RCVNG_LN_STAT_T ORDER BY RCVNG_LN_STAT_CD"); 

        while (statusesRowSet.next()) {
            lineItemReceivingStatuses.put(statusesRowSet.getString("RCVNG_LN_STAT_CD"), statusesRowSet.getString("RCVNG_LN_STAT_DESC"));
        }
        
        LOG.debug("getLineItemReceivingDocumentStatuses() exited");
        
        return lineItemReceivingStatuses;
    } catch (DataAccessException dae) {
        return lineItemReceivingStatuses;
    }
}
 
Example 3
/**
 * @see org.kuali.kfs.module.purap.dataaccess.StatusCodeAndDescriptionForPurapDocumentsDao#getPaymentRequestDocumentStatuses()
 */
public Map<String, String> getPaymentRequestDocumentStatuses() {
    LOG.debug("getPaymentRequestDocumentStatuses() started");
    
    Map<String, String> paymentRequestStatuses = new HashMap<String, String>();
    
    try {
        SqlRowSet statusesRowSet = getJdbcTemplate().queryForRowSet("SELECT * FROM AP_PMT_RQST_STAT_T ORDER BY PMT_RQST_STAT_CD"); 

        while (statusesRowSet.next()) {
            paymentRequestStatuses.put(statusesRowSet.getString("PMT_RQST_STAT_CD"), statusesRowSet.getString("PMT_RQST_STAT_DESC"));
        }
        
        LOG.debug("getPaymentRequestDocumentStatuses() exited");
        
        return paymentRequestStatuses;
    } catch (DataAccessException dae) {
        return paymentRequestStatuses;
    }
}
 
Example 4
Source Project: Lottery   Source File: CmsDataBackDaoImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
public List<CmsField> listFields(String tablename) {
	String sql = " desc  " + tablename;
	List<CmsField> fields = new ArrayList<CmsField>();
	SqlRowSet set = getJdbcTemplate().queryForRowSet(sql);
	while (set.next()) {
		CmsField field = new CmsField();
		field.setName(set.getString(1));
		field.setFieldType(set.getString(2));
		field.setNullable(set.getString(3));
		field.setFieldProperty(set.getString(4));
		field.setFieldDefault(set.getString(5));
		field.setExtra(set.getString(6));
		fields.add(field);
	}
	return fields;
}
 
Example 5
Source Project: alchemy   Source File: HibernateTimeZoneIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Transactional
public void storeOffsetTimeWithUtcConfigShouldBeStoredOnGMTTimeZoneAccordingToHis1stJan1970Value() {
    dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);

    String request = generateSqlRequest("offset_time", dateTimeWrapper.getId());
    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
    String expectedValue = dateTimeWrapper
        .getOffsetTime()
        .toLocalTime()
        .atDate(LocalDate.of(1970, Month.JANUARY, 1))
        .atZone(ZoneId.systemDefault())
        .format(timeFormatter);

    assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(resultSet, expectedValue);
}
 
Example 6
Source Project: FoxBPM   Source File: SelectDeptActorConnectorTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 资源共享
 * <p>1.使用场景:将任务分配给某部门(部门可以多个)</p>
 * <p>2.预置条件:<p>
 *          1.发布一条带有任务分配(分配部门)的流程定义
 * <p>3.处理过程:首先,启动任务使流程进入分配任务节点上</p>
 * <p>4.测试用例:</p>
 * <p>		1.执行完成后,相应查看资源分配是否是所以人都能看得到</p>
 * <p>		2.执行完成后,相应查看foxbpm_run_taskidentitylink任务是否分配给部门</p>
 */
@Test
@Deployment(resources = { "org/foxbpm/connector/test/actorconnector/SelectDeptActorConnector/SelectDeptActorConnectorTest_1.bpmn" })
public void testSelectDeptActorConnector() {
	Authentication.setAuthenticatedUserId("admin");
	// 启动流程
	runtimeService.startProcessInstanceByKey("SelectDeptActorConnectorTest_1");
	Task task = taskService.createTaskQuery().processDefinitionKey("SelectDeptActorConnectorTest_1").taskNotEnd().singleResult();
	SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet("select * from foxbpm_run_taskidentitylink WHERE TASK_ID = '" + task.getId() + "'");
	List<String> userIds = new ArrayList<String>();
	while (sqlRowSet.next()) {
		userIds.add(sqlRowSet.getString("GROUP_ID"));
	}
	if (!userIds.contains("a") || !userIds.contains("b")) {
		throw new FoxBPMConnectorException("选择用户连接器出现异常");
	}
}
 
Example 7
@Test
@Transactional
public void storeOffsetTimeWithUtcConfigShouldBeStoredOnGMTTimeZoneAccordingToHis1stJan1970Value() {
    dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);

    String request = generateSqlRequest("offset_time", dateTimeWrapper.getId());
    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
    String expectedValue = dateTimeWrapper
        .getOffsetTime()
        .toLocalTime()
        .atDate(LocalDate.of(1970, Month.JANUARY, 1))
        .atZone(ZoneId.systemDefault())
        .format(timeFormatter);

    assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(resultSet, expectedValue);
}
 
Example 8
Source Project: ehcache3-samples   Source File: HibernateTimeZoneTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@Transactional
public void storeOffsetTimeWithUtcConfigShouldBeStoredOnGMTTimeZoneAccordingToHis1stJan1970Value() {
    dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);

    String request = generateSqlRequest("offset_time", dateTimeWrapper.getId());
    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
    String expectedValue = dateTimeWrapper
        .getOffsetTime()
        .toLocalTime()
        .atDate(LocalDate.of(1970, Month.JANUARY, 1))
        .atZone(ZoneId.systemDefault())
        .format(timeFormatter);

    assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(resultSet, expectedValue);
}
 
Example 9
Source Project: FoxBPM   Source File: SelectUserActorConnectorTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 任务分配给指定用户可以多个
 * <p>1.使用场景:需要将任务分配指定用户</p>
 * <p>2.预置条件:创建一个含有人工任务并且任务分配给指定用户的流程定义并发布<p>
 * <p>3.处理过程:首先,启动任务使流程进入分配任务节点上</p>
 * <p>4.测试用例:</p>
 * <p>		1.执行完成后,相应查看资源是否分配给指定用户</p>
 */
@Test
@Deployment(resources = { "org/foxbpm/connector/test/actorconnector/SelectUserActorConnector/SelectUserActorConnectorTest_1.bpmn" })
public void testSelectUserActorConnector() {
	Authentication.setAuthenticatedUserId("admin");
	// 启动流程
	runtimeService.startProcessInstanceByKey("SelectUserActorConnectorTest_1");
	Task task = taskService.createTaskQuery().processDefinitionKey("SelectUserActorConnectorTest_1").taskNotEnd().singleResult();
	SqlRowSet sqlRowSet = jdbcTemplate.queryForRowSet("select * from foxbpm_run_taskidentitylink WHERE TASK_ID = '" + task.getId() + "'");
	List<String> userIds = new ArrayList<String>();
	while (sqlRowSet.next()) {
		userIds.add(sqlRowSet.getString("USER_ID"));
	}
	if (!userIds.contains("a") || !userIds.contains("b")) {
		throw new FoxBPMConnectorException("选择用户连接器出现异常");
	}
}
 
Example 10
Source Project: appstatus   Source File: BatchDao.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Read batch object from result set.
 * 
 * @param srs
 * @return
 * @throws IOException
 * @throws SQLException
 */
private BdBatch mappinpBdbatch(SqlRowSet srs) throws SQLException,
		IOException {
	BdBatch bdBatch = new BdBatch();
	bdBatch.setUuid(srs.getString("UUID_BATCH"));
	bdBatch.setCurrentItem(srs.getString("ITEM"));
	bdBatch.setEndDate(srs.getDate("END_DATE"));
	bdBatch.setGroup(srs.getString("GROUP_BATCH"));
	bdBatch.setItemCount(srs.getLong("ITEMCOUNT"));
	bdBatch.setLastMessage(srs.getString("LAST_MSG"));
	bdBatch.setLastUpdate(srs.getDate("UPDATED"));
	bdBatch.setName(srs.getString("NAME_BATCH"));
	bdBatch.setProgress(srs.getFloat("PROGRESS"));
	bdBatch.setStartDate(srs.getDate("START_DATE"));
	bdBatch.setStatus(srs.getString("STATUS"));
	bdBatch.setSuccess(srs.getBoolean("SUCCESS"));

	// Clob
	Clob reject = (Clob) srs.getObject("REJECT");
	bdBatch.setReject(clobToString(reject));

	return bdBatch;
}
 
Example 11
Source Project: celerio   Source File: MySqlEnumExtractorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Ignore
public void film() {
    SqlRowSet queryForRowSet = jdbcTemplate().queryForRowSet("show columns from film where type like 'enum%'");
    while (queryForRowSet.next()) {
        String field = queryForRowSet.getString("Field");
        String type = queryForRowSet.getString("Type");
        MysqlEnumValuesExtractor mysqlEnumValuesExtractor = new MysqlEnumValuesExtractor();
        System.out.println("Extracting values from " + field + "." + type);
        for (String a : mysqlEnumValuesExtractor.extract(type)) {
            System.out.println(a);
        }
    }
}
 
Example 12
@Override
public Grid getEventClusters( EventQueryParams params, Grid grid, int maxLimit )
{
    String clusterField = params.getCoordinateField();
    String quotedClusterField = quoteAlias( clusterField );

    List<String> columns = Lists.newArrayList( "count(psi) as count", "ST_Extent(" + quotedClusterField + ") as extent" );

    columns.add( "case when count(psi) = 1 then ST_AsGeoJSON(array_to_string(array_agg(" + quotedClusterField + "), ','), 6) "
                +"else ST_AsGeoJSON(ST_Centroid(ST_Collect(" + quotedClusterField + ")), 6) end as center" );

    columns.add( params.isIncludeClusterPoints() ?
        "array_to_string(array_agg(psi), ',') as points" :
        "case when count(psi) = 1 then array_to_string(array_agg(psi), ',') end as points" );

    String sql = "select " + StringUtils.join( columns, "," ) + " ";

    sql += getFromClause( params );

    sql += getWhereClause( params );

    sql += "group by ST_SnapToGrid(ST_Transform(ST_SetSRID(ST_Centroid(" + quotedClusterField + "), 4326), 3785), " + params.getClusterSize() + ") ";

    log.debug( String.format( "Analytics event cluster SQL: %s", sql ) );

    SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );

    while ( rowSet.next() )
    {
        grid.addRow()
            .addValue( rowSet.getLong( "count" ) )
            .addValue( rowSet.getString( "center" ) )
            .addValue( rowSet.getString( "extent" ) )
            .addValue( rowSet.getString( "points" ) );
    }

    return grid;
}
 
Example 13
Source Project: Lottery   Source File: CmsDataBackDaoImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public List<Object[]> createTableData(String tablename) {
	int filedNum = getTableFieldNums(tablename);
	List<Object[]> results = new ArrayList<Object[]>();
	String sql = " select * from   " + tablename;
	SqlRowSet set = getJdbcTemplate().queryForRowSet(sql);
	while (set.next()) {
		Object[] oneResult = new Object[filedNum];
		for (int i = 1; i <= filedNum; i++) {
			oneResult[i - 1] = set.getObject(i);
		}
		results.add(oneResult);
	}
	return results;
}
 
Example 14
Source Project: spring-content   Source File: JpaLockingServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean isLockOwner(Object entityId, Principal principal) {
    if (principal == null) {
        throw new SecurityException("no principal");
    }

    String sql = "SELECT entity_id from locks where entity_id = ? and lock_owner = ?";
    SqlRowSet rs = template.queryForRowSet(sql, entityId.toString(), principal.getName());
    return rs.next();
}
 
Example 15
Source Project: alchemy   Source File: HibernateTimeZoneIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Transactional
public void storeInstantWithUtcConfigShouldBeStoredOnGMTTimeZone() {
    dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);

    String request = generateSqlRequest("instant", dateTimeWrapper.getId());
    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
    String expectedValue = dateTimeFormatter.format(dateTimeWrapper.getInstant());

    assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(resultSet, expectedValue);
}
 
Example 16
Source Project: dhis2-core   Source File: GridUtils.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Writes all rows in the SqlRowSet to the given Grid.
 */
public static void addRows( Grid grid, SqlRowSet rs )
{
    int cols = rs.getMetaData().getColumnCount();

    while ( rs.next() )
    {
        grid.addRow();

        for ( int i = 1; i <= cols; i++ )
        {
            grid.addValue( rs.getObject( i ) );
        }
    }
}
 
Example 17
Source Project: alchemy   Source File: HibernateTimeZoneIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Transactional
public void storeZoneDateTimeWithUtcConfigShouldBeStoredOnGMTTimeZone() {
    dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);

    String request = generateSqlRequest("zoned_date_time", dateTimeWrapper.getId());
    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
    String expectedValue = dateTimeWrapper
        .getZonedDateTime()
        .format(dateTimeFormatter);

    assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(resultSet, expectedValue);
}
 
Example 18
Source Project: alchemy   Source File: HibernateTimeZoneIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
@Transactional
public void storeLocalDateWithUtcConfigShouldBeStoredWithoutTransformation() {
    dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);

    String request = generateSqlRequest("local_date", dateTimeWrapper.getId());
    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
    String expectedValue = dateTimeWrapper
        .getLocalDate()
        .format(dateFormatter);

    assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(resultSet, expectedValue);
}
 
Example 19
Source Project: alchemy   Source File: HibernateTimeZoneIT.java    License: Apache License 2.0 5 votes vote down vote up
private void assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(SqlRowSet sqlRowSet, String expectedValue) {
    while (sqlRowSet.next()) {
        String dbValue = sqlRowSet.getString(1);

        assertThat(dbValue).isNotNull();
        assertThat(dbValue).isEqualTo(expectedValue);
    }
}
 
Example 20
@Test
@Transactional
public void storeInstantWithUtcConfigShouldBeStoredOnGMTTimeZone() {
    dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);

    String request = generateSqlRequest("instant", dateTimeWrapper.getId());
    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
    String expectedValue = dateTimeFormatter.format(dateTimeWrapper.getInstant());

    assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(resultSet, expectedValue);
}
 
Example 21
@Test
@Transactional
public void storeLocalDateTimeWithUtcConfigShouldBeStoredOnGMTTimeZone() {
    dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);

    String request = generateSqlRequest("local_date_time", dateTimeWrapper.getId());
    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
    String expectedValue = dateTimeWrapper
        .getLocalDateTime()
        .atZone(ZoneId.systemDefault())
        .format(dateTimeFormatter);

    assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(resultSet, expectedValue);
}
 
Example 22
@Test
@Transactional
public void storeOffsetDateTimeWithUtcConfigShouldBeStoredOnGMTTimeZone() {
    dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);

    String request = generateSqlRequest("offset_date_time", dateTimeWrapper.getId());
    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
    String expectedValue = dateTimeWrapper
        .getOffsetDateTime()
        .format(dateTimeFormatter);

    assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(resultSet, expectedValue);
}
 
Example 23
@Test
@Transactional
public void storeZoneDateTimeWithUtcConfigShouldBeStoredOnGMTTimeZone() {
    dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);

    String request = generateSqlRequest("zoned_date_time", dateTimeWrapper.getId());
    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
    String expectedValue = dateTimeWrapper
        .getZonedDateTime()
        .format(dateTimeFormatter);

    assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(resultSet, expectedValue);
}
 
Example 24
@Test
@Transactional
public void storeLocalDateWithUtcConfigShouldBeStoredWithoutTransformation() {
    dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);

    String request = generateSqlRequest("local_date", dateTimeWrapper.getId());
    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
    String expectedValue = dateTimeWrapper
        .getLocalDate()
        .format(dateFormatter);

    assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(resultSet, expectedValue);
}
 
Example 25
@Test
@Transactional
public void storeZoneDateTimeWithUtcConfigShouldBeStoredOnGMTTimeZone() {
    dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);

    String request = generateSqlRequest("zoned_date_time", dateTimeWrapper.getId());
    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
    String expectedValue = dateTimeWrapper
        .getZonedDateTime()
        .format(dateTimeFormatter);

    assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(resultSet, expectedValue);
}
 
Example 26
Source Project: Lottery   Source File: CmsDataBackDaoImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
private int getTableFieldNums(String tablename) {
	String sql = " desc  " + tablename;
	SqlRowSet set = getJdbcTemplate().queryForRowSet(sql);
	int rownum = 0;
	while (set.next()) {
		rownum++;
	}
	return rownum;
}
 
Example 27
Source Project: appstatus   Source File: BatchDao.java    License: Apache License 2.0 5 votes vote down vote up
@Transactional(readOnly = true)
private List<BdBatch> fetchBdBatch(final int max, String[] status) {
	SqlRowSet srs = this.jdbcTemplate.queryForRowSet(
			insertParametersFromList(getSql(BATCH_FETCH), status),
			new Object[] { max });
	return resultSet2Batches(srs);
}
 
Example 28
private void assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(SqlRowSet sqlRowSet, String expectedValue) {
    while (sqlRowSet.next()) {
        String dbValue = sqlRowSet.getString(1);

        assertThat(dbValue).isNotNull();
        assertThat(dbValue).isEqualTo(expectedValue);
    }
}
 
Example 29
Source Project: tutorials   Source File: HibernateTimeZoneIntegrationTest.java    License: MIT License 5 votes vote down vote up
@Test
@Transactional
public void storeLocalTimeWithUtcConfigShouldBeStoredOnGMTTimeZoneAccordingToHis1stJan1970Value() {
    dateTimeWrapperRepository.saveAndFlush(dateTimeWrapper);

    String request = generateSqlRequest("local_time", dateTimeWrapper.getId());
    SqlRowSet resultSet = jdbcTemplate.queryForRowSet(request);
    String expectedValue = dateTimeWrapper
        .getLocalTime()
        .atDate(LocalDate.of(1970, Month.JANUARY, 1))
        .atZone(ZoneId.systemDefault())
        .format(timeFormatter);

    assertThatDateStoredValueIsEqualToInsertDateValueOnGMTTimeZone(resultSet, expectedValue);
}
 
Example 30
Source Project: java-technology-stack   Source File: NamedParameterJdbcTemplate.java    License: MIT License 5 votes vote down vote up
@Override
public SqlRowSet queryForRowSet(String sql, SqlParameterSource paramSource) throws DataAccessException {
	SqlRowSet result = getJdbcOperations().query(
			getPreparedStatementCreator(sql, paramSource), new SqlRowSetResultSetExtractor());
	Assert.state(result != null, "No result");
	return result;
}