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

The following examples show how to use org.springframework.jdbc.core.SqlTypeValue. 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: spring-analysis-note   Source File: AbstractJdbcInsert.java    License: MIT License 5 votes vote down vote up
/**
 * Internal implementation for setting parameter values.
 * @param preparedStatement the PreparedStatement
 * @param values the values to be set
 */
private void setParameterValues(PreparedStatement preparedStatement, List<?> values, @Nullable int... columnTypes)
		throws SQLException {

	int colIndex = 0;
	for (Object value : values) {
		colIndex++;
		if (columnTypes == null || colIndex > columnTypes.length) {
			StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, SqlTypeValue.TYPE_UNKNOWN, value);
		}
		else {
			StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, columnTypes[colIndex - 1], value);
		}
	}
}
 
Example 2
Source Project: java-technology-stack   Source File: AbstractJdbcInsert.java    License: MIT License 5 votes vote down vote up
/**
 * Internal implementation for setting parameter values.
 * @param preparedStatement the PreparedStatement
 * @param values the values to be set
 */
private void setParameterValues(PreparedStatement preparedStatement, List<?> values, @Nullable int... columnTypes)
		throws SQLException {

	int colIndex = 0;
	for (Object value : values) {
		colIndex++;
		if (columnTypes == null || colIndex > columnTypes.length) {
			StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, SqlTypeValue.TYPE_UNKNOWN, value);
		}
		else {
			StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, columnTypes[colIndex - 1], value);
		}
	}
}
 
Example 3
Source Project: lams   Source File: AbstractJdbcInsert.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Internal implementation for setting parameter values
 * @param preparedStatement the PreparedStatement
 * @param values the values to be set
 */
private void setParameterValues(PreparedStatement preparedStatement, List<?> values, int... columnTypes)
		throws SQLException {

	int colIndex = 0;
	for (Object value : values) {
		colIndex++;
		if (columnTypes == null || colIndex > columnTypes.length) {
			StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, SqlTypeValue.TYPE_UNKNOWN, value);
		}
		else {
			StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, columnTypes[colIndex - 1], value);
		}
	}
}
 
Example 4
Source Project: spring4-understanding   Source File: AbstractJdbcInsert.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Internal implementation for setting parameter values
 * @param preparedStatement the PreparedStatement
 * @param values the values to be set
 */
private void setParameterValues(PreparedStatement preparedStatement, List<?> values, int... columnTypes)
		throws SQLException {

	int colIndex = 0;
	for (Object value : values) {
		colIndex++;
		if (columnTypes == null || colIndex > columnTypes.length) {
			StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, SqlTypeValue.TYPE_UNKNOWN, value);
		}
		else {
			StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, columnTypes[colIndex - 1], value);
		}
	}
}
 
Example 5
Source Project: compass   Source File: ShardJdbcTemplate.java    License: Apache License 2.0 5 votes vote down vote up
@Override
     public int[] call() throws Exception {
     	JdbcTemplate jdbcTemplate = createJdbcTemplate(shard.getTargetDataSource(), ShardJdbcTemplate.this);
         String interceptedSql = shardDataSource.getSqlInterceptor().intercept(sql, shard.getTableContext());
         
         return jdbcTemplate.batchUpdate(interceptedSql, new BatchPreparedStatementSetter() {
	
	@Override
	public void setValues(PreparedStatement ps, int statementIndex) throws SQLException {
		Object[] args = argsList.get(statementIndex);
		
		for (int i = 0; i < args.length; i++) {
			Object arg = args[i];
			if (arg instanceof SqlParameterValue) {
				SqlParameterValue paramValue = (SqlParameterValue) arg;
				StatementCreatorUtils.setParameterValue(ps, i + 1, paramValue, paramValue.getValue());
			}
			else {
				StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, arg);
			}
		}
	}
	
	@Override
	public int getBatchSize() {
		return argsList.size();
	}
});
     }
 
Example 6
Source Project: SimpleFlatMapper   Source File: SqlParameterSourceBuilder.java    License: MIT License 5 votes vote down vote up
private static int getParameterType(PropertyMapping<?, ?, JdbcColumnKey> pm) {
    Class<?> propertyType = TypeHelper.toClass(pm.getPropertyMeta().getPropertyType());
    
    if (pm.getColumnDefinition().has(SqlTypeColumnProperty.class)) {
        return pm.getColumnDefinition().lookFor(SqlTypeColumnProperty.class).getSqlType();
    }

    int t =  StatementCreatorUtils.javaTypeToSqlParameterType(propertyType);
    if (t == SqlTypeValue.TYPE_UNKNOWN) {
        //IFJAVA8_START
        if (propertyType.equals(ZonedDateTime.class) || propertyType.equals(OffsetDateTime.class)) {
            return Types.TIMESTAMP_WITH_TIMEZONE;
        }

        if (propertyType.equals(Instant.class) || propertyType.equals(LocalDateTime.class)) {
            return Types.TIMESTAMP;
        }

        if (propertyType.equals(LocalDate.class)) {
            return Types.DATE;
        }

        if (propertyType.equals(LocalTime.class)) {
            return Types.TIME;
        }

        //IFJAVA8_END
        return JdbcColumnKey.UNDEFINED_TYPE;
    }
    return t;
}
 
Example 7
Source Project: effectivejava   Source File: AbstractJdbcInsert.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Internal implementation for setting parameter values
 * @param preparedStatement the PreparedStatement
 * @param values the values to be set
 */
private void setParameterValues(PreparedStatement preparedStatement, List<Object> values, int[] columnTypes)
		throws SQLException {

	int colIndex = 0;
	for (Object value : values) {
		colIndex++;
		if (columnTypes == null || colIndex > columnTypes.length) {
			StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, SqlTypeValue.TYPE_UNKNOWN, value);
		}
		else {
			StatementCreatorUtils.setParameterValue(preparedStatement, colIndex, columnTypes[colIndex - 1], value);
		}
	}
}