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

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

Introduction

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

Prototype

public MapSqlParameterSource(String paramName, @Nullable Object value) 

Source Link

Document

Create a new MapSqlParameterSource, with one value comprised of the supplied arguments.

Usage

From source file:com.exploringspatial.dao.impl.CodeDefinitionDaoImpl.java

@Override
public int delete(final Long codeDefinitionPk) {
    final String sql = "DELETE FROM CODE_DEFINITION WHERE CODE_DEFINITION_PK = :codeDefinitionPk";
    final MapSqlParameterSource params = new MapSqlParameterSource("codeDefinitionPk", codeDefinitionPk);
    return jdbcTemplate.update(sql, params);
}

From source file:tomekkup.helenos.dao.AccountDao.java

public void delete(String username) {
    if (username.toLowerCase().equals("admin")) {
        throw new IllegalArgumentException("admin account can not be removed");
    }// ww w  . j a  v a2s .  c  o m
    jdbcTemplate.update(queriesProperties.getProperty("user.delete"),
            new MapSqlParameterSource("username", username));
}

From source file:org.string_db.jdbc.ProteinRepositoryJdbc.java

@Override
public Integer count(Integer speciesId) {
    return namedParameterJdbcTemplate.queryForObject(
            "select count(protein_id) from items.proteins where species_id = :species_id",
            new MapSqlParameterSource("species_id", speciesId), Integer.class);
}

From source file:com.daugherty.e2c.persistence.data.jdbc.JdbcSupplierDao.java

@Override
public List<Supplier> loadApprovedBySupplierIds(List<Long> ids, Locale locale) {
    List<Supplier> suppliers = Lists.newArrayList();
    HashSet<Long> uniqueIds = Sets.newHashSet(ids);
    LOGGER.debug("Getting Supplier from the database by supplier ids " + uniqueIds);
    for (List<Long> partitionedIds : Lists.partition(Lists.newArrayList(uniqueIds), 1000)) {
        String sql = getSql("/supplier/getApprovedBySupplierIds.sql");
        SqlParameterSource parameterSource = new MapSqlParameterSource("supplierIds", partitionedIds)
                .addValue("language", locale.getLanguage());
        suppliers.addAll(jdbcTemplate.query(sql, parameterSource, new SupplierResultSetExtractor()));
    }//www.  ja  v a  2s .  c o  m

    return suppliers;
}

From source file:tds.assessment.repositories.impl.AssessmentWindowQueryRepositoryIntegrationTests.java

@Test
public void shouldFindAssessmentFormWindowsWithNoSegments() {
    DateTime startTime = new DateTime(2016, 8, 10, 19, 2, 11, DateTimeZone.UTC);
    DateTime endTime = new DateTime(2017, 8, 10, 19, 2, 11, DateTimeZone.UTC);

    SqlParameterSource parameters = new MapSqlParameterSource("startTime",
            mapJodaInstantToTimestamp(startTime.toInstant())).addValue("endTime",
                    mapJodaInstantToTimestamp(endTime.toInstant()));

    String testWindowInsert = "INSERT INTO configs.client_testwindow VALUES ('SBAC_PT', 'SBAC-Mathematics-3', 1, 3, :startTime, :endTime, NULL, NULL, 'ANNUAL', UNHEX('F12479625F2C11E6B2C80243FCF25EAB'), -1, 1);";
    String testModeInsert = "INSERT INTO configs.client_testmode VALUES ('SBAC_PT', 'SBAC-Mathematics-3', 'online', 'fixedform', 0, 0, 50, 0, 0, 1, 0, '(SBAC_PT)SBAC-MATH-3-Spring-2013-2015', UNHEX('F12140D05F2C11E6B2C80243FCF25EAB'));";
    String testFormPropertiesInsert = "INSERT INTO configs.client_testformproperties VALUES ('SBAC_PT', '187-507', NULL, NULL, 'ENU', 'PracTest::MG3::S1::SP14', 'SBAC-Mathematics-3', '(SBAC_PT)SBAC-MATH-3-Spring-2013-2015', NULL, NULL);";

    jdbcTemplate.update(testWindowInsert, parameters);
    jdbcTemplate.update(testModeInsert, new MapSqlParameterSource());
    jdbcTemplate.update(testFormPropertiesInsert, new MapSqlParameterSource());

    List<AssessmentWindow> assessmentWindows = repository.findCurrentAssessmentFormWindows("SBAC_PT",
            "SBAC-Mathematics-3", 0, 0, 0, 0);
    assertThat(assessmentWindows).hasSize(1);
    AssessmentWindow window = assessmentWindows.get(0);

    assertThat(window.getWindowMaxAttempts()).isEqualTo(3);
    assertThat(window.getModeSessionType()).isEqualTo(0);
    assertThat(window.getMode()).isEqualTo("online");
    assertThat(window.getStartTime()).isEqualByComparingTo(startTime.toInstant());
    assertThat(window.getEndTime()).isEqualByComparingTo(endTime.toInstant());
    assertThat(window.getFormKey()).isEqualTo("187-507");
    assertThat(window.getWindowId()).isEqualTo("ANNUAL");
}

From source file:alfio.manager.UploadedResourceManager.java

public void outputResource(int organizationId, int eventId, String name, OutputStream out) {
    SqlParameterSource param = new MapSqlParameterSource("name", name)
            .addValue("organizationId", organizationId).addValue("eventId", eventId);
    jdbc.query(uploadedResourceRepository.fileContentTemplate(organizationId, eventId, name), param, rs -> {
        try (InputStream is = rs.getBinaryStream("content")) {
            StreamUtils.copy(is, out);/*www .  j ava 2 s  .  co  m*/
        } catch (IOException e) {
            throw new IllegalStateException("Error while copying data", e);
        }
    });
}

From source file:tds.assessment.repositories.impl.AccommodationsQueryRepositoryImplIntegrationTests.java

@Before
public void setUp() {

    Instant now = Instant.now();

    String testModeInsertSQL = "INSERT INTO configs.client_testmode VALUES ('SBAC_PT','SBAC-Mathematics-11','online','virtual',0,1,50,0,0,1,0,'(SBAC_PT)SBAC-Mathematics-11-Spring-2013-2015',X'0431F6515F2D11E6B2C80243FCF25EAB');";
    String segmentTestToolTypeInsertSQL = "INSERT INTO configs.client_testtooltype (clientname, toolname, allowchange, rtsfieldname, isrequired, isselectable, dateentered, contexttype, context, testmode) VALUES ('SBAC_PT', 'toolTypeSegmented', 0, 'rts', 1, 0, :dateentered, 'SEGMENT', 'SBAC-SEG1-MATH-11', 'ALL');";
    String segmentTestToolInsertSQL = "INSERT INTO configs.client_testtool (clientname, type, code, value, isdefault, allowcombine, context, contexttype, testmode) VALUES ('SBAC_PT', 'toolTypeSegmented', 'toolTypeSegmented', 'segmentValue', 1, 0, 'SBAC-SEG1-MATH-11', 'SEGMENT', 'ALL');";
    String segmentPropertiesInsertSQL = "INSERT INTO configs.client_segmentproperties (ispermeable, clientname, entryapproval, exitapproval, segmentid, segmentposition, parenttest, modekey) VALUES (1, 'SBAC_PT', 1, 1, 'SBAC-SEG1-MATH-11', 99, 'SBAC-Mathematics-11', '(SBAC_PT)SBAC-Mathematics-11-Spring-2013-2015');";
    String defaultToolTypeInsertSQL = "INSERT INTO configs.client_testtooltype (clientname, toolname, allowchange, rtsfieldname, isrequired, isselectable, dateentered, contexttype, context, testmode) VALUES ('SBAC_PT', 'toolTypeDefault', 0, 'rts', 1, 0, :dateentered, 'TEST', '*', 'ALL')  ";
    String defaultTestToolInsertSQL = "INSERT INTO configs.client_testtool (clientname, type, code, value, isdefault, allowcombine, context, contexttype, testmode) VALUES ('SBAC_PT', 'toolTypeDefault', 'toolTypeDefault', 'defaultTool', 1, 0, '*', 'TEST', 'ALL');";

    String nonSegmentTestToolTypeInsertSQL = "INSERT INTO configs.client_testtooltype (clientname, context, contexttype, toolname, allowchange, rtsfieldname, isrequired, isselectable, dateentered, testmode) "
            + "VALUES ('SBAC_PT', 'SBAC-Mathematics-11', 'TEST', 'Language', 0, 'rts', 1, 0, :dateentered, 'ALL');";
    String noSegmentTestToolInsertEnglishSQL = "INSERT INTO configs.client_testtool (clientname, context, contexttype, type, code, value, isdefault, allowcombine, testmode) "
            + "VALUES ('SBAC_PT', 'SBAC-Mathematics-11', 'TEST', 'Language', 'ENU', 'ENU', 1, 0, 'ALL');";
    String noSegmentTestToolInsertFrenchSQL = "INSERT INTO configs.client_testtool (clientname, context, contexttype, type, code, value, isdefault, allowcombine, testmode) "
            + "VALUES ('SBAC_PT', 'SBAC-Mathematics-11', 'TEST', 'Language', 'FRN', 'FRN', 1, 0, 'ALL');";

    String toolDependencies = "INSERT INTO configs.client_tooldependencies (context, contexttype, iftype, ifvalue, isdefault, thentype, thenvalue, clientname, _key, testmode) "
            + "VALUES ('SBAC-Mathematics-11','TEST','Language','ENU',0,'Streamlined Mode','TDS_SLM1','SBAC_PT',X'16DE7974D75943C4BE266DE4835608C4','ALL'), \n"
            + "('SBAC-Mathematics-11','TEST','Language','ENU-Braille',1,'Emboss Request Type','TDS_ERT_OR','SBAC_PT',X'17F829A06A434DC0945A62CA53ADA0C6','ALL')";

    SqlParameterSource parameters = new MapSqlParameterSource("dateentered",
            ResultSetMapperUtility.mapJodaInstantToTimestamp(now));

    jdbcTemplate.update(testModeInsertSQL, parameters);
    jdbcTemplate.update(segmentTestToolTypeInsertSQL, parameters);
    jdbcTemplate.update(segmentTestToolInsertSQL, parameters);
    jdbcTemplate.update(segmentPropertiesInsertSQL, parameters);
    jdbcTemplate.update(defaultToolTypeInsertSQL, parameters);
    jdbcTemplate.update(defaultTestToolInsertSQL, parameters);
    jdbcTemplate.update(nonSegmentTestToolTypeInsertSQL, parameters);
    jdbcTemplate.update(toolDependencies, parameters);
    jdbcTemplate.update(noSegmentTestToolInsertEnglishSQL, parameters);
    jdbcTemplate.update(noSegmentTestToolInsertFrenchSQL, parameters);
}

From source file:org.string_db.DbFacade.java

/**
 * Seems like items.species_names has lots of not really useful names,
 * so let's just pick short, one-word ones, that start with lower case,
 * e.g. human for 9606, mouse&mice for 10090, yeast for 4932, etc.
 *
 * @param speciesId/*ww  w. j a v a  2  s  .  c om*/
 * @return
 */
public Collection<String> loadSpeciesNames(Integer speciesId) {
    final Map<String, Set<String>> all = queryProcessor.selectTwoColumns("official_name", "species_name",
            "items.species_names", TwoColumnRowMapper.<String, String>multiValMapper(),
            "species_id = :species_id and species_name not like '% %';",
            new MapSqlParameterSource("species_id", speciesId));
    List<String> names = new ArrayList<>();
    final Iterator<String> iterator = all.keySet().iterator();
    if (!iterator.hasNext()) {
        //some species don't have synonyms so need to get the official one:
        names.add(loadSpeciesName(speciesId));
        return names;
    }
    final String official = iterator.next();
    names.add(official);
    for (String name : all.get(official)) {
        if (Character.isLowerCase(name.charAt(0))) {
            names.add(name);
        }
    }
    return names;

}

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

public Map<String, Integer> findUsersId(List<String> users) {

    List<String[]> usersToFind = new ArrayList<>(users.size());
    for (String user : users) {
        String[] splittedString = StringUtils.split(user, ':');
        if (splittedString.length > 1) {
            String provider = splittedString[0];
            String username = StringUtils.join(ArrayUtils.subarray(splittedString, 1, splittedString.length),
                    ':');
            usersToFind.add(new String[] { provider, username });
        }//from  ww  w  .ja va  2 s .co m
    }

    if (usersToFind.isEmpty()) {
        return Collections.emptyMap();
    }

    final Map<String, Integer> res = new HashMap<>();
    MapSqlParameterSource param = new MapSqlParameterSource("users", usersToFind);

    jdbc.query(queries.findUsersId(), param, new RowCallbackHandler() {
        @Override
        public void processRow(ResultSet rs) throws SQLException {
            res.put(rs.getString("PROVIDER_USER"), rs.getInt("USER_ID"));
        }
    });

    return res;
}

From source file:org.mulima.internal.freedb.FreeDbJdbcDaoImpl.java

/**
 * Gets the disc specified by the id.//  w ww .ja v a  2s.  c o  m
 * @param id the id of the disc
 * @return the disc
 */
private Disc getDisc(int id) {
    final String sql = "SELECT * FROM `discs` WHERE `id`=:id";
    SqlParameterSource parms = new MapSqlParameterSource("id", id);
    List<Disc> result = this.getNamedParameterJdbcTemplate().query(sql, parms, new DiscRowMapper());
    Disc disc = result.get(0);
    disc.getTracks().addAll(getTracksForDisc(id));

    for (String cddbId : getCddbIdsForDisc(id)) {
        disc.add(GenericTag.CDDB_ID, cddbId);
    }
    return disc;
}