Example usage for org.springframework.jdbc.core.namedparam EmptySqlParameterSource EmptySqlParameterSource

List of usage examples for org.springframework.jdbc.core.namedparam EmptySqlParameterSource EmptySqlParameterSource

Introduction

In this page you can find the example usage for org.springframework.jdbc.core.namedparam EmptySqlParameterSource EmptySqlParameterSource.

Prototype

EmptySqlParameterSource

Source Link

Usage

From source file:io.lavagna.service.ConfigurationRepositoryTest.java

@Before
public void prepare() {
    jdbc.update("DELETE FROM LA_CONF", new EmptySqlParameterSource());
}

From source file:io.lavagna.service.ProjectServiceTest.java

@Before
public void prepare() {
    jdbc.update("DELETE FROM LA_PROJECT_ROLE_PERMISSION", new EmptySqlParameterSource());
    jdbc.update("DELETE FROM LA_PROJECT_ROLE", new EmptySqlParameterSource());
    jdbc.update("DELETE FROM LA_CARD_LABEL_VALUE", new EmptySqlParameterSource());
    jdbc.update("DELETE FROM LA_CARD_LABEL_LIST_VALUE", new EmptySqlParameterSource());
    jdbc.update("DELETE FROM LA_CARD_LABEL", new EmptySqlParameterSource());
    jdbc.update("DELETE FROM LA_BOARD_COLUMN_DEFINITION", new EmptySqlParameterSource());
    jdbc.update("DELETE FROM LA_PROJECT", new EmptySqlParameterSource());
}

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 w w.  j a v a  2s  .c om*/

    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();
    }//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;
}

From source file:alfio.manager.system.DataMigrator.java

void fillReservationsLanguage() {
    transactionTemplate.execute(s -> {
        jdbc.queryForList("select id from tickets_reservation where user_language is null",
                new EmptySqlParameterSource(), String.class).forEach(id -> {
                    MapSqlParameterSource param = new MapSqlParameterSource("reservationId", id);
                    String language = optionally(() -> jdbc.queryForObject(
                            "select user_language from ticket where tickets_reservation_id = :reservationId limit 1",
                            param, String.class)).orElse("en");
                    jdbc.update(//from   w w w .j av a 2 s. c o  m
                            "update tickets_reservation set user_language = :userLanguage where id = :reservationId",
                            param.addValue("userLanguage", language));
                });
        return null;
    });
}

From source file:ch.digitalfondue.npjt.QueryType.java

private static SqlParameterSource extractParameters(Method m, Object[] args,
        Collection<ParameterConverter> parameterConverters) {

    Annotation[][] parameterAnnotations = m.getParameterAnnotations();
    if (parameterAnnotations == null || parameterAnnotations.length == 0) {
        return new EmptySqlParameterSource();
    }/*from  ww w  . j  a  v  a  2s . co  m*/

    MapSqlParameterSource ps = new MapSqlParameterSource();
    Class<?>[] parameterTypes = m.getParameterTypes();
    for (int i = 0; i < args.length; i++) {
        String name = parameterName(parameterAnnotations[i]);
        if (name != null) {
            Object arg = args[i];
            Class<?> parameterType = parameterTypes[i];

            boolean hasAccepted = false;
            for (ParameterConverter parameterConverter : parameterConverters) {
                if (parameterConverter.accept(parameterType)) {
                    hasAccepted = true;
                    parameterConverter.processParameter(name, arg, parameterType, ps);
                    break;
                }
            }

            if (!hasAccepted) {
                throw new IllegalStateException(
                        "Was not able to find a ParameterConverter able to process object: " + arg
                                + " with class " + parameterType);
            }
        }
    }

    return ps;
}