Java 类org.springframework.jdbc.core.SqlTypeValue 实例源码

项目:Rapture    文件:JDBCStructuredStore.java   
@Override
public String getCursorForJoin(List<String> tables, List<String> columnNames, String from,
                               String where, List<String> order, Boolean ascending, int limit) {
    List<? super Object> args = new ArrayList<>();
    where = convertToPreparedStatement(where, args);
    String sql = sqlGenerator.constructSelectJoin(tables, columnNames, from, where, order, ascending, limit);
    try {
        PreparedStatement pstmt = getPreparedStatementForCursor(sql);
        for (int i = 0; i < args.size(); i++) {
            StatementCreatorUtils.setParameterValue(pstmt, i + 1, SqlTypeValue.TYPE_UNKNOWN, args.get(i));
        }
        ResultSet rs = pstmt.executeQuery();
        String uuid = IDGenerator.getUUID();
        cache.putCursor(uuid, rs);
        return uuid;
    } catch (SQLException e) {
        throw RaptureExceptionFactory.create(String.format("Sql Exception executing cursor for joined query [%s]", e.getMessage()));
    }
}
项目:mtools    文件:DBUtil.java   
public static KeyHolder update(JdbcOperations dbop,final String sql,final Object[] args,final String[] retCols)
{
    KeyHolder kh=new GeneratedKeyHolder();
    dbop.update(new PreparedStatementCreator()
    {
            public PreparedStatement createPreparedStatement(Connection con) throws SQLException
            {
                int i=1;
                PreparedStatement ps;
                ps=con.prepareStatement(sql,retCols);
                for(Object o:args)
                {
                    StatementCreatorUtils.setParameterValue(ps, i++, SqlTypeValue.TYPE_UNKNOWN, o);
                }
                return ps;
            }           
    }, kh);
    return kh;
}
项目:lams    文件:AbstractJdbcInsert.java   
/**
 * 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);
        }
    }
}
项目:spring-data-jdbc-template    文件:SimpleJdbcUpdate.java   
private SqlParameterSource parameterSource(Map<String, Object> values) {
    Map<String, Integer> sqlTypes = sqlTypes();

    MapSqlParameterSource sqlParameterSource = new MapSqlParameterSource();
    for (Map.Entry<String, Object> entry : values.entrySet()) {
        String paramName = entry.getKey();
        int sqlType = sqlTypes.get(paramName) != null ? sqlTypes.get(paramName) : SqlTypeValue.TYPE_UNKNOWN;
        sqlParameterSource.addValue(paramName, entry.getValue(), sqlType);
    }
    return sqlParameterSource;
}
项目:spring4-understanding    文件:AbstractJdbcInsert.java   
/**
 * 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);
        }
    }
}
项目:nbone    文件:AbstractJdbcInsert.java   
/**
 * 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);
        }
    }
}
项目:rabbitframework    文件:DefaultParameterHandler.java   
@SuppressWarnings("unchecked")
public void setParameters(PreparedStatement ps) throws SQLException {
    try {
        List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
        if (parameterMappings != null) {
            int paramMappingSize = parameterMappings.size();
            for (int i = 0; i < paramMappingSize; i++) {
                ParameterMapping parameterMapping = parameterMappings.get(i);
                Object value;
                String propertyName = parameterMapping.getProperty();
                if (boundSql.hasAdditionalParameter(propertyName)) {
                    value = boundSql.getAdditionalParameter(propertyName);
                } else if (parameterObject == null) {
                    value = "";
                } else {
                    Class<?> type = parameterObject.getClass();
                    boolean isPrimitive = isColumnType(type);
                    if (isPrimitive) {
                        value = parameterObject;
                    } else {
                        MetaObject metaObject = configuration.newMetaObject(parameterObject);
                        value = metaObject.getValue(propertyName);
                    }
                }
                StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, value);
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new SQLException(e.getMessage(), e);
    }
}
项目:compass    文件:ShardJdbcTemplate.java   
@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();
    }
});
     }
项目:miabis-converter    文件:ArrayItemPreparedStatementSetter.java   
@Override
public void setValues(String[] item, PreparedStatement ps) throws SQLException {
    Assert.isInstanceOf(String[].class, item, "Input to map PreparedStatement parameters must be of type String[].");

    System.out.println(String.join(",", item));
    for(int i=0; i<item.length; i++ ){
        StatementCreatorUtils.setParameterValue(ps, i+1, SqlTypeValue.TYPE_UNKNOWN, item[i]);
    }
}
项目:SimpleFlatMapper    文件:SqlParameterSourceBuilder.java   
private static int getParameterType(PropertyMapping<?, ?, JdbcColumnKey, FieldMapperColumnDefinition<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;
}
项目:class-guard    文件:AbstractJdbcInsert.java   
/**
 * 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);
        }
    }
}
项目:AGIA    文件:ExpressionsPreparedStatementSetter.java   
@Override
public synchronized void setValues(PreparedStatement sPs) throws SQLException {
    try {
        String aResolvedValue;
        for(int i = 0; i < lookupFieldsExpressions.length; i++) {
            aResolvedValue = getExpressionResolver().evaluate(lookupFieldsExpressions[i], getEvaluationContext(), String.class);
            StatementCreatorUtils.setParameterValue(sPs, i + 1, SqlTypeValue.TYPE_UNKNOWN, aResolvedValue);
        }
    } catch (Exception e) {
        throw new SQLException(new PreparedStatementCreationException(e));
    }
}
项目:sqltemplate    文件:BatchArgsParameter.java   
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
    Object[] params = batchParams[i];

    int colIndex = 0;
    for (Object param : params) {
        colIndex++;
        StatementCreatorUtils.setParameterValue(ps, colIndex, SqlTypeValue.TYPE_UNKNOWN,
                Jsr310JdbcUtils.convertIfNecessary(param, zoneId));
    }
}
项目:sqltemplate    文件:SingleColumnBatchArgsParameter.java   
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
    Object param = batchParams[i];

    StatementCreatorUtils.setParameterValue(ps, 1, SqlTypeValue.TYPE_UNKNOWN,
            Jsr310JdbcUtils.convertIfNecessary(param, zoneId));
}
项目:sqltemplate    文件:Jsr310JdbcUtils.java   
public static int getSqlType(Class<?> type) {
    int sqlType = StatementCreatorUtils.javaTypeToSqlParameterType(type);
    if (sqlType != SqlTypeValue.TYPE_UNKNOWN) {
        return sqlType;
    }

    if (LocalDate.class.isAssignableFrom(type)) {
        return Types.DATE;
    }
    if (LocalDateTime.class.isAssignableFrom(type)) {
        return Types.TIMESTAMP;
    }
    if (LocalTime.class.isAssignableFrom(type)) {
        return Types.TIME;
    }
    if (ZonedDateTime.class.isAssignableFrom(type)) {
        return Types.TIMESTAMP;
    }
    if (OffsetDateTime.class.isAssignableFrom(type)) {
        return Types.TIMESTAMP;
    }
    if (OffsetTime.class.isAssignableFrom(type)) {
        return Types.TIME;
    }

    return SqlTypeValue.TYPE_UNKNOWN;

}
项目:spring-jdbc-oracle    文件:AbstractComparisonIntegrationTest.java   
@Override
protected boolean setValuesIfAvailable(PreparedStatement ps, int i) throws SQLException {
  if (i >= this.values.length) {
    return false;
  }

  StatementCreatorUtils.setParameterValue(ps, 1, SqlTypeValue.TYPE_UNKNOWN, "INSERT");
  StatementCreatorUtils.setParameterValue(ps, 2, SqlTypeValue.TYPE_UNKNOWN, this.values[i]);

  return true;
}
项目:spring-jdbc-oracle    文件:OracleNamedParameterJdbcTemplate.java   
private static void validateValue(Object value) {
  if (value instanceof SqlTypeValue) {
    // SqlTypeValue does not support binding by name
    throw new IllegalArgumentException("SqlTypeValue not supported");
  }
  if (value instanceof Collection) {
    // ojdbc does not support binding Collection
    throw new IllegalArgumentException("Collection not supported");
  }
}
项目:spring-jdbc-oracle    文件:TestInterruptiblePreparedStatementSetter.java   
@Override
protected boolean setValuesIfAvailable(PreparedStatement ps, int i) throws SQLException {
  if (i >= this.parameters.length) {
    return false;
  }

  StatementCreatorUtils.setParameterValue(ps, 1, SqlTypeValue.TYPE_UNKNOWN, Integer.MAX_VALUE);
  StatementCreatorUtils.setParameterValue(ps, 2, SqlTypeValue.TYPE_UNKNOWN, this.parameters[i]);

  return true;
}
项目:spring-jdbc-oracle    文件:AbstractComparisonIntegrationTest.java   
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
  StatementCreatorUtils.setParameterValue(ps, 1, SqlTypeValue.TYPE_UNKNOWN, "INSERT");
  StatementCreatorUtils.setParameterValue(ps, 2, SqlTypeValue.TYPE_UNKNOWN, this.values[i]);
}
项目:spring-jdbc-oracle    文件:AbstractComparisonIntegrationTest.java   
@Override
public void setValues(PreparedStatement ps, Object[] argument) throws SQLException {
  for (int i = 0; i < argument.length; i++) {
    StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, argument[i]);
  }
}
项目:spring-jdbc-oracle    文件:TestParameterizedPreparedStatementSetter.java   
@Override
public void setValues(PreparedStatement ps, int[] argument) throws SQLException {
  for (int i = 0; i < argument.length; i++) {
    StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, argument[i]);
  }
}
项目:spring-jdbc-oracle    文件:TestBatchPreparedStatementSetter.java   
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
  StatementCreatorUtils.setParameterValue(ps, 1, SqlTypeValue.TYPE_UNKNOWN, Integer.MAX_VALUE);
  StatementCreatorUtils.setParameterValue(ps, 2, SqlTypeValue.TYPE_UNKNOWN, this.parameters[i]);
}