org.springframework.jdbc.core.SqlTypeValue Java Examples

The following examples show how to use org.springframework.jdbc.core.SqlTypeValue. 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: AbstractJdbcInsert.java    From spring-analysis-note with 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 File: AbstractJdbcInsert.java    From java-technology-stack with 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 File: AbstractJdbcInsert.java    From lams with 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 File: AbstractJdbcInsert.java    From spring4-understanding with 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 File: ShardJdbcTemplate.java    From compass with 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 File: SqlParameterSourceBuilder.java    From SimpleFlatMapper with 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 File: AbstractJdbcInsert.java    From effectivejava with 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);
		}
	}
}