List of usage examples for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate NamedParameterJdbcTemplate
public NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate)
From source file:org.aksw.gerbil.database.ExperimentDAOImpl.java
public ExperimentDAOImpl(DataSource dataSource, long resultDurability) { super(resultDurability); this.template = new NamedParameterJdbcTemplate(dataSource); }
From source file:org.tradex.validation.trade.TradeImportValidation.java
/** * {@inheritDoc}/*www . jav a 2 s.c o m*/ * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { jdbcTemplate = new NamedParameterJdbcTemplate(dataSource); }
From source file:com.lixiaocong.social.MyJdbcConnection.java
public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); }/*from w w w.jav a 2 s. com*/ StringBuilder providerUsersCriteriaSql = new StringBuilder(); MapSqlParameterSource parameters = new MapSqlParameterSource(); parameters.addValue("userId", userId); for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String providerId = entry.getKey(); providerUsersCriteriaSql.append("providerId = :providerId_").append(providerId) .append(" and providerUserId in (:providerUserIds_").append(providerId).append(")"); parameters.addValue("providerId_" + providerId, providerId); parameters.addValue("providerUserIds_" + providerId, entry.getValue()); if (it.hasNext()) { providerUsersCriteriaSql.append(" or "); } } List<Connection<?>> resultList = new NamedParameterJdbcTemplate(jdbcTemplate) .query(selectFromUserConnection() + " where userId = :userId and " + providerUsersCriteriaSql + " order by providerId, rank", parameters, connectionMapper); MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>(); for (Connection<?> connection : resultList) { String providerId = connection.getKey().getProviderId(); List<String> userIds = providerUsers.get(providerId); List<Connection<?>> connections = connectionsForUsers.get(providerId); if (connections == null) { connections = new ArrayList<Connection<?>>(userIds.size()); for (int i = 0; i < userIds.size(); i++) { connections.add(null); } connectionsForUsers.put(providerId, connections); } String providerUserId = connection.getKey().getProviderUserId(); int connectionIndex = userIds.indexOf(providerUserId); connections.set(connectionIndex, connection); } return connectionsForUsers; }
From source file:com.joliciel.jochre.boundaries.BoundaryDaoJdbc.java
@Override public void deleteSplit(Split split) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("split_id", split.getId()); String sql = null;/* w w w .ja va 2s .com*/ sql = "delete from ocr_split where split_id = :split_id"; LOG.debug(sql); logParameters(paramSource); jt.update(sql, paramSource); }
From source file:com.joliciel.jochre.graphics.GraphicsDaoJdbc.java
@Override public List<Shape> findShapesToSplit(Locale locale) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_SHAPE + ", count(split_id) as the_count FROM ocr_shape" + " LEFT JOIN ocr_split on shape_id = split_shape_id" + " LEFT JOIN ocr_group ON shape_group_id = group_id" + " LEFT JOIN ocr_row ON group_row_id = row_id" + " LEFT JOIN ocr_paragraph ON row_paragraph_id = paragraph_id" + " LEFT JOIN ocr_image ON paragraph_image_id = image_id" + " WHERE length(shape_letter)>1" + " AND shape_letter not like '%|'" + " AND shape_letter not like '|%'" + " AND shape_letter not in (:dual_character_letters)" + " AND image_imgstatus_id in (:image_imgstatus_id)" + " GROUP BY " + SELECT_SHAPE + " ORDER BY the_count, shape_letter, shape_id"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); Linguistics linguistics = Linguistics.getInstance(locale); paramSource.addValue("dual_character_letters", linguistics.getDualCharacterLetters()); List<Integer> imageStatusList = new ArrayList<Integer>(); imageStatusList.add(ImageStatus.TRAINING_VALIDATED.getId()); imageStatusList.add(ImageStatus.TRAINING_HELD_OUT.getId()); imageStatusList.add(ImageStatus.TRAINING_TEST.getId()); paramSource.addValue("image_imgstatus_id", imageStatusList); LOG.debug(sql);//from w w w. j ava 2 s. c o m logParameters(paramSource); @SuppressWarnings("unchecked") List<Shape> shapes = jt.query(sql, paramSource, new ShapeMapper(this.getGraphicsServiceInternal())); return shapes; }
From source file:com.joliciel.jochre.doc.DocumentDaoJdbc.java
@Override public void deleteJochrePage(JochrePage page) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("page_id", page.getId()); String sql = null;/*from w w w. jav a2 s.c o m*/ sql = "delete from ocr_page" + " WHERE page_id = :page_id"; LOG.info(sql); logParameters(paramSource); jt.update(sql, paramSource); }
From source file:com.yahoo.sql4d.sql4ddriver.sql.MysqlAccessor.java
/** * Suitable for CRUD operations where no result set is expected. * @param params/*ww w .jav a 2s. c o m*/ * @param query * @return */ public boolean execute(Map<String, String> params, String query) { final AtomicBoolean result = new AtomicBoolean(false); Tuple2<DataSource, Connection> conn = null; try { conn = getConnection(); NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(conn._1()); jdbcTemplate.execute(query, params, new PreparedStatementCallback<Void>() { @Override public Void doInPreparedStatement(PreparedStatement ps) { try { result.set(ps.execute()); } catch (SQLException e) { result.set(false); } return null; } }); } catch (Exception ex) { Logger.getLogger(MysqlAccessor.class.getName()).log(Level.SEVERE, null, ex); result.set(false); } finally { returnConnection(conn); } return result.get(); }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
public void saveCategory(CategoryInternal category) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("cat_code", category.getCode()); paramSource.addValue("cat_description", category.getDescription()); if (category.isNew()) { String sql = "SELECT nextval('ftb_category_cat_id_seq')"; LOG.info(sql);//ww w . j av a2s . com int categoryId = jt.queryForInt(sql, paramSource); paramSource.addValue("cat_id", categoryId); sql = "INSERT INTO ftb_category (cat_id, cat_code, cat_description) VALUES (:cat_id, :cat_code, :cat_description)"; LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); category.setId(categoryId); } else { String sql = "UPDATE ftb_category" + " SET cat_code = :cat_code" + ", cat_description = :cat_description" + " WHERE cat_id = :cat_id"; paramSource.addValue("cat_id", category.getId()); LOG.info(sql); TreebankDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); } }
From source file:org.cloudfoundry.identity.uaa.oauth.approval.JdbcApprovalStore.java
@Override public boolean revokeApprovals(String filter) { ProcessedFilter where = queryConverter.convert(filter, null, true); logger.debug(String.format("Filtering approvals with filter: [%s]", where)); String sql;/*from w w w . j a va 2s.c o m*/ Map<String, Object> sqlParams; if (handleRevocationsAsExpiry) { // just expire all approvals matching the filter sql = EXPIRE_AUTHZ_SQL + " where " + where.getSql(); sqlParams = where.getParams(); sqlParams.put("expiry", new Timestamp(new Date().getTime() - 1)); } else { // delete the records sql = DELETE_AUTHZ_SQL + " where " + where.getSql(); sqlParams = where.getParams(); } try { int revoked = new NamedParameterJdbcTemplate(jdbcTemplate).update(sql, sqlParams); logger.debug(String.format("revoked [%d] approvals matching sql: [%s]", revoked, where)); } catch (DataAccessException ex) { logger.error("Error expiring approvals, possible invalid filter: " + where, ex); throw new IllegalArgumentException("Error revoking approvals"); } return true; }
From source file:com.joliciel.jochre.doc.DocumentDaoJdbc.java
@Override public JochreDocument loadJochreDocument(int jochreDocumentId) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_DOCUMENT + " FROM ocr_document WHERE doc_id=:doc_id"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("doc_id", jochreDocumentId); LOG.info(sql);/*from w w w. ja v a2 s . c om*/ logParameters(paramSource); JochreDocument jochreDocument = null; try { jochreDocument = (JochreDocument) jt.queryForObject(sql, paramSource, new JochreDocumentMapper(this.getDocumentServiceInternal())); } catch (EmptyResultDataAccessException ex) { ex.hashCode(); } return jochreDocument; }