List of usage examples for org.springframework.jdbc.core.namedparam NamedParameterJdbcTemplate NamedParameterJdbcTemplate
public NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate)
From source file:com.joliciel.jochre.security.SecurityDaoJdbc.java
@Override public void saveUserInternal(UserInternal user) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("user_username", user.getUsername()); paramSource.addValue("user_password", user.getPassword()); paramSource.addValue("user_first_name", user.getFirstName()); paramSource.addValue("user_last_name", user.getLastName()); paramSource.addValue("user_role", user.getRole().getId()); paramSource.addValue("user_failed_logins", user.getFailedLoginCount()); paramSource.addValue("user_logins", user.getLoginCount()); String sql = null;//from w w w.j av a2s.com if (user.isNew()) { sql = "SELECT nextval('ocr_user_id_seq')"; LOG.info(sql); int userId = jt.queryForInt(sql, paramSource); paramSource.addValue("user_id", userId); sql = "INSERT INTO ocr_user (user_id, user_username, user_password" + ", user_first_name, user_last_name, user_role, user_failed_logins, user_logins) " + "VALUES (:user_id, :user_username, :user_password" + ", :user_first_name, :user_last_name, :user_role, :user_failed_logins, :user_logins)"; LOG.info(sql); logParameters(paramSource); jt.update(sql, paramSource); user.setId(userId); } else { paramSource.addValue("user_id", user.getId()); sql = "UPDATE ocr_user" + " SET user_username = :user_username" + ", user_password = :user_password" + ", user_first_name = :user_first_name" + ", user_last_name = :user_last_name" + ", user_role = :user_role" + ", user_failed_logins = :user_failed_logins" + ", user_logins = :user_logins" + " WHERE user_id = :user_id"; LOG.info(sql); logParameters(paramSource); jt.update(sql, paramSource); } }
From source file:org.tradex.jdbc.JDBCHelper.java
/** * Issues a query for an Object/*from w ww . j a v a2 s .c o m*/ * @param <T> The expected return type * @param sql The SQL * @param clazz The expected return type * @param binds The bind values * @return an Object */ public <T> T templateQueryForObject(CharSequence sql, Class<T> clazz, Object... binds) { NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(ds); return template.queryForObject(sql.toString(), getBinds(sql.toString().trim().toUpperCase(), binds), clazz); }
From source file:edu.wisc.jmeter.dao.JdbcMonitorDao.java
public JdbcMonitorDao(JdbcTemplate jdbcTemplate, PlatformTransactionManager transactionManager, int purgeOldFailures, int purgeOldStatus) { this.jdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); this.transactionTemplate = new TransactionTemplate(transactionManager); this.purgeOldFailure = TimeUnit.MILLISECONDS.convert(purgeOldFailures, TimeUnit.MINUTES); this.purgeOldStatus = TimeUnit.MILLISECONDS.convert(purgeOldStatus, TimeUnit.MINUTES); }
From source file:com.joliciel.jochre.graphics.GraphicsDaoJdbc.java
@Override public List<Shape> findShapes(RowOfShapes row) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_SHAPE + " FROM ocr_shape" + " INNER JOIN ocr_group ON shape_group_id = group_id" + " WHERE group_row_id = :group_row_id" + " ORDER BY group_index, shape_index"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("group_row_id", row.getId()); LOG.debug(sql);//from w ww. j a v a 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.yahoo.sql4d.sql4ddriver.sql.MysqlAccessor.java
public List<Map<String, Object>> query(Map<String, String> params, String query) { List<Map<String, Object>> result = null; Tuple2<DataSource, Connection> conn = null; try {/*from www .j av a 2s . c o m*/ conn = getConnection(); NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(conn._1()); result = jdbcTemplate.queryForList(query, params); } catch (Exception ex) { Logger.getLogger(MysqlAccessor.class.getName()).log(Level.SEVERE, null, ex); } finally { returnConnection(conn); } return result; }
From source file:org.aksw.gerbil.database.ExperimentDAOImpl.java
public ExperimentDAOImpl(DataSource dataSource) { this.template = new NamedParameterJdbcTemplate(dataSource); }
From source file:com.eftech.wood.phone.iphone.IphoneJDBCTemplate.java
public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; this.jdbcTemplateObject = new NamedParameterJdbcTemplate(dataSource); }
From source file:com.joliciel.frenchTreebank.TreebankDaoImpl.java
public Category loadCategory(String categoryCode) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_CATEGORY + " FROM ftb_category WHERE cat_code=:cat_code"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("cat_code", categoryCode); LOG.info(sql);//ww w. java2 s. com TreebankDaoImpl.LogParameters(paramSource); Category category = null; try { category = (Category) jt.queryForObject(sql, paramSource, new CategoryMapper()); } catch (EmptyResultDataAccessException ex) { ex.hashCode(); } return category; }
From source file:org.tradex.jdbc.JDBCHelper.java
/** * Issues a named parameter query using numerical binds, starting at 0. * @param sql The SQL/*from w w w .j av a 2 s . com*/ * @param binds The bind values * @return an Object array of the results */ public Object[][] templateQuery(CharSequence sql, Object... binds) { NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(ds); final List<Object[]> results = template.query(sql.toString(), getBinds(sql.toString().trim().toUpperCase(), binds), new RowMapper<Object[]>() { int columnCount = -1; @Override public Object[] mapRow(ResultSet rs, int rowNum) throws SQLException { if (columnCount == -1) columnCount = rs.getMetaData().getColumnCount(); Object[] row = new Object[columnCount]; for (int i = 0; i < columnCount; i++) { row[i] = rs.getObject(i + 1); } return row; } }); Object[][] ret = new Object[results.size()][]; int cnt = 0; for (Object[] arr : results) { ret[cnt] = arr; cnt++; } return ret; }
From source file:com.joliciel.lefff.LefffDaoImpl.java
public void saveAttribute(AttributeInternal attribute) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("attribute_code", attribute.getCode()); paramSource.addValue("attribute_value", attribute.getValue()); paramSource.addValue("attribute_morph", attribute.isMorphological()); if (attribute.isNew()) { String sql = "SELECT nextval('seq_attribute_id')"; LOG.info(sql);// w w w . jav a 2 s .com int attributeId = jt.queryForInt(sql, paramSource); paramSource.addValue("attribute_id", attributeId); sql = "INSERT INTO lef_attribute (attribute_id, attribute_code, attribute_value, attribute_morph)" + " VALUES (:attribute_id, :attribute_code, :attribute_value, :attribute_morph)"; LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); attribute.setId(attributeId); } else { String sql = "UPDATE lef_attribute" + " SET attribute_code = :attribute_code" + ", attribute_value = :attribute_value" + ", attribute_morph = :attribute_morph" + " WHERE attribute_id = :attribute_id"; paramSource.addValue("attribute_id", attribute.getId()); LOG.info(sql); LefffDaoImpl.LogParameters(paramSource); jt.update(sql, paramSource); } }