Search in sources :

Example 56 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project SSM by Intel-bigdata.

the class FileInfoDao method getFidPaths.

public Map<Long, String> getFidPaths(Collection<Long> ids) throws SQLException {
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
    Map<Long, String> idToPath = new HashMap<>();
    String sql = "SELECT * FROM file WHERE fid IN (:ids)";
    MapSqlParameterSource parameterSource = new MapSqlParameterSource();
    parameterSource.addValue("ids", ids);
    List<FileInfo> files = namedParameterJdbcTemplate.query(sql, parameterSource, new FileInfoRowMapper());
    for (FileInfo file : files) {
        idToPath.put(file.getFileId(), file.getPath());
    }
    return idToPath;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) FileInfo(org.smartdata.model.FileInfo) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) HashMap(java.util.HashMap)

Example 57 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project SSM by Intel-bigdata.

the class FileInfoDao method getPathFids.

public Map<String, Long> getPathFids(Collection<String> paths) throws SQLException {
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
    Map<String, Long> pathToId = new HashMap<>();
    String sql = "SELECT * FROM file WHERE path IN (:paths)";
    MapSqlParameterSource parameterSource = new MapSqlParameterSource();
    parameterSource.addValue("paths", paths);
    List<FileInfo> files = namedParameterJdbcTemplate.query(sql, parameterSource, new FileInfoRowMapper());
    for (FileInfo file : files) {
        pathToId.put(file.getPath(), file.getFileId());
    }
    return pathToId;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) FileInfo(org.smartdata.model.FileInfo) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) HashMap(java.util.HashMap)

Example 58 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project SSM by Intel-bigdata.

the class FileInfoDao method getFilesByPaths.

public List<FileInfo> getFilesByPaths(Collection<String> paths) {
    NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
    String sql = "SELECT * FROM file WHERE path IN (:paths)";
    MapSqlParameterSource parameterSource = new MapSqlParameterSource();
    parameterSource.addValue("paths", paths);
    return namedParameterJdbcTemplate.query(sql, parameterSource, new FileInfoRowMapper());
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 59 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project ontrack by nemerosa.

the class SVNRevisionJdbcDao method addRevision.

@Override
public void addRevision(int repositoryId, long revision, String author, LocalDateTime dateTime, String message, String branch) {
    NamedParameterJdbcTemplate t = getNamedParameterJdbcTemplate();
    // Getting rid of the revision
    MapSqlParameterSource params = params("revision", revision).addValue("repositoryId", repositoryId);
    t.update("DELETE FROM EXT_SVN_REVISION WHERE REPOSITORY =:repositoryId AND REVISION = :revision", params);
    // Creates the revision record
    t.update("INSERT INTO EXT_SVN_REVISION (REPOSITORY, REVISION, AUTHOR, CREATION, MESSAGE, BRANCH) " + "VALUES (:repositoryId, :revision, :author, :creation, :message, :branch)", params.addValue("author", author).addValue("creation", dateTimeForDB(dateTime)).addValue("message", Objects.toString(StringUtils.abbreviate(message, MESSAGE_LENGTH), "")).addValue("branch", branch));
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Example 60 with NamedParameterJdbcTemplate

use of org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate in project alf.io by alfio-event.

the class DataSourceConfiguration method getDataSource.

@Bean
@Profile({ "!" + Initializer.PROFILE_INTEGRATION_TEST, "travis" })
public DataSource getDataSource(Environment env, PlatformProvider platform) {
    if (platform == PlatformProvider.CLOUD_FOUNDRY) {
        return new FakeCFDataSource();
    } else {
        HikariDataSource dataSource = new HikariDataSource();
        dataSource.setJdbcUrl(platform.getUrl(env));
        dataSource.setUsername(platform.getUsername(env));
        dataSource.setPassword(platform.getPassword(env));
        dataSource.setDriverClassName("org.postgresql.Driver");
        dataSource.setMaximumPoolSize(platform.getMaxActive(env));
        dataSource.setMinimumIdle(platform.getMinIdle(env));
        dataSource.setConnectionTimeout(1000L);
        log.debug("Connection pool properties: max active {}, initial size {}", dataSource.getMaximumPoolSize(), dataSource.getMinimumIdle());
        // check
        boolean isSuperAdmin = Boolean.TRUE.equals(new NamedParameterJdbcTemplate(dataSource).queryForObject("select usesuper from pg_user where usename = CURRENT_USER", EmptySqlParameterSource.INSTANCE, Boolean.class));
        if (isSuperAdmin) {
            log.warn("You're accessing the database using a superuser. This is highly discouraged since it will disable the row security policy checks.");
        }
        // 
        return dataSource;
    }
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)

Aggregations

NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)119 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)66 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)42 HashMap (java.util.HashMap)30 ResultSet (java.sql.ResultSet)16 SQLException (java.sql.SQLException)16 DbXref (org.nextprot.api.core.domain.DbXref)8 NextProtException (org.nextprot.api.commons.exception.NextProtException)7 PublicationDbXref (org.nextprot.api.core.domain.PublicationDbXref)7 ArrayList (java.util.ArrayList)5 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)5 List (java.util.List)4 Map (java.util.Map)4 CvTerm (org.nextprot.api.core.domain.CvTerm)4 GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)3 NotSupportException (com.kyj.fx.voeditor.visual.exceptions.NotSupportException)3 DataSource (javax.sql.DataSource)3 UserProteinList (org.nextprot.api.user.domain.UserProteinList)3 ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)2 Date (java.util.Date)2