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