Example usage for org.springframework.jdbc.core StatementCreatorUtils javaTypeToSqlParameterType

List of usage examples for org.springframework.jdbc.core StatementCreatorUtils javaTypeToSqlParameterType

Introduction

In this page you can find the example usage for org.springframework.jdbc.core StatementCreatorUtils javaTypeToSqlParameterType.

Prototype

public static int javaTypeToSqlParameterType(@Nullable Class<?> javaType) 

Source Link

Document

Derive a default SQL type from the given Java type.

Usage

From source file:io.lavagna.common.QueryType.java

private static SqlParameterSource extractParameters(Method m, Object[] args) {

    Class<?>[] parameterTypes = m.getParameterTypes();
    Annotation[][] parameterAnnotations = m.getParameterAnnotations();
    if (parameterAnnotations == null || parameterAnnotations.length == 0) {
        return new EmptySqlParameterSource();
    }/*from   w  ww .j av  a 2s .  c o m*/

    MapSqlParameterSource ps = new MapSqlParameterSource();
    for (int i = 0; i < args.length; i++) {
        String name = parameterName(parameterAnnotations[i]);
        if (name != null) {
            ps.addValue(name, args[i], StatementCreatorUtils.javaTypeToSqlParameterType(parameterTypes[i]));
        }
    }

    return ps;
}

From source file:alfio.datamapper.QueryType.java

private static SqlParameterSource extractParameters(Method m, Object[] args) {

    Annotation[][] parameterAnnotations = m.getParameterAnnotations();
    if (parameterAnnotations == null || parameterAnnotations.length == 0) {
        return new EmptySqlParameterSource();
    }/*from w  w w .ja v  a2 s .  c  om*/

    MapSqlParameterSource ps = new MapSqlParameterSource();
    Class<?>[] parameterTypes = m.getParameterTypes();
    for (int i = 0; i < args.length; i++) {
        String name = parameterName(parameterAnnotations[i]);
        if (name != null) {
            if (args[i] != null && ZonedDateTime.class.isAssignableFrom(parameterTypes[i])) {
                ZonedDateTime dateTime = ZonedDateTime.class.cast(args[i]);
                final ZonedDateTime utc = dateTime.withZoneSameInstant(ZoneId.of("UTC"));
                Calendar c = Calendar.getInstance();
                c.setTimeZone(TimeZone.getTimeZone("UTC"));
                c.setTimeInMillis(utc.toInstant().toEpochMilli());
                ps.addValue(name, c, Types.TIMESTAMP);
            } else {
                ps.addValue(name, args[i], StatementCreatorUtils.javaTypeToSqlParameterType(parameterTypes[i]));
            }
        }
    }

    return ps;
}