List of usage examples for org.springframework.jdbc.core PreparedStatementSetter PreparedStatementSetter
PreparedStatementSetter
From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java
public void updateIaAddr(final IaAddress iaAddr) { getJdbcTemplate().update("update dhcplease" + " set state = ?," + ((iaAddr instanceof IaPrefix) ? " prefixlen = ?," : "") + " starttime = ?," + " preferredendtime = ?," + " validendtime = ?" + " where ipaddress = ?", new PreparedStatementSetter() { @Override//from ww w. j ava2s . c o m public void setValues(PreparedStatement ps) throws SQLException { int i = 1; ps.setByte(i++, iaAddr.getState()); if (iaAddr instanceof IaPrefix) { ps.setShort(i++, ((IaPrefix) iaAddr).getPrefixLength()); } Date start = iaAddr.getStartTime(); if (start != null) { java.sql.Timestamp sts = new java.sql.Timestamp(start.getTime()); ps.setTimestamp(i++, sts, Util.GMT_CALENDAR); } else { ps.setNull(i++, java.sql.Types.TIMESTAMP); } Date preferred = iaAddr.getPreferredEndTime(); if (preferred != null) { java.sql.Timestamp pts = new java.sql.Timestamp(preferred.getTime()); ps.setTimestamp(i++, pts, Util.GMT_CALENDAR); } else { ps.setNull(i++, java.sql.Types.TIMESTAMP); } Date valid = iaAddr.getValidEndTime(); if (valid != null) { java.sql.Timestamp vts = new java.sql.Timestamp(valid.getTime()); ps.setTimestamp(i++, vts, Util.GMT_CALENDAR); } else { ps.setNull(i++, java.sql.Types.TIMESTAMP); } ps.setBytes(i++, iaAddr.getIpAddress().getAddress()); } }); }
From source file:com.jagornet.dhcp.db.JdbcIaAddressDAO.java
public List<IaAddress> findExpiredAddresses(final byte iatype) { return getJdbcTemplate().query("select * from iaaddress a" + " join identityassoc ia on ia.id=a.identityassoc_id" + " where ia.iatype = ?" + " and a.state != " + IaAddress.STATIC + " and a.validendtime < ? order by a.validendtime", new PreparedStatementSetter() { @Override// w w w . j a v a 2s .c o m public void setValues(PreparedStatement ps) throws SQLException { ps.setByte(1, iatype); java.sql.Timestamp ts = new java.sql.Timestamp(new Date().getTime()); ps.setTimestamp(2, ts, Util.GMT_CALENDAR); } }, new IaAddrRowMapper()); }
From source file:com.jagornet.dhcp.db.JdbcIaPrefixDAO.java
public List<IaPrefix> findAllOlderThan(Date date) { return getJdbcTemplate().query( "select * from iaprefix" + " join identityassoc ia on identityassoc_id=ia.id" + " where ia.iatype = ?" + " and validendtime < ? order by validendtime", new PreparedStatementSetter() { @Override//from ww w . j a v a 2 s .c om public void setValues(PreparedStatement ps) throws SQLException { ps.setByte(1, IdentityAssoc.PD_TYPE); java.sql.Timestamp ts = new java.sql.Timestamp(new Date().getTime()); ps.setTimestamp(2, ts, Util.GMT_CALENDAR); } }, new IaPrefixRowMapper()); }
From source file:com.skycloud.management.portal.admin.sysmanage.dao.impl.UserManageDaoImpl.java
@Override public int deleteUser(final Integer userId) throws SQLException { String sql = "delete from T_SCS_USER where ID=?;"; try {/*from ww w .j ava2 s . c o m*/ this.getJdbcTemplate().update(sql, new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setInt(1, userId); } }); } catch (Exception e) { throw new SQLException( "ID" + userId + ", " + e.getMessage()); } return 0; }
From source file:architecture.common.adaptor.connector.jdbc.AbstractJdbcConnector.java
protected Object deliver(final String queryString, final List<ParameterMapping> parameterMappings, final Map<String, Object> row) { // log.debug("delivering : 1"); return getJdbcTemplate().update(queryString, new PreparedStatementSetter() { public void setValues(PreparedStatement ps) throws SQLException { for (ParameterMapping mapping : parameterMappings) { JdbcType jdbcType = mapping.getJdbcType(); Object value = row.get(mapping.getProperty()); Object valueToUse = value; if (valueToUse == null && mapping.getJavaType() == Date.class) { valueToUse = new Date(); }/*from w w w . java 2 s . co m*/ if (valueToUse instanceof Date && jdbcType == JdbcType.VARCHAR) { valueToUse = DateFormatUtils.format((Date) valueToUse, mapping.getPattern()); } if (valueToUse instanceof String && jdbcType == JdbcType.VARCHAR) { String stringValue = (String) valueToUse; if (!StringUtils.isEmpty(mapping.getEncoding())) { if (!StringUtils.isEmpty(stringValue)) { String[] encoding = StringUtils.split(mapping.getEncoding(), ">"); try { if (encoding.length == 2) valueToUse = new String(stringValue.getBytes(encoding[0]), encoding[1]); else if (encoding.length == 1) valueToUse = new String(stringValue.getBytes(), encoding[0]); } catch (UnsupportedEncodingException e) { LOG.error(e); } } } } if (valueToUse == null) ps.setNull(mapping.getIndex(), jdbcType.TYPE_CODE); else ps.setObject(mapping.getIndex(), valueToUse, jdbcType.TYPE_CODE); } } }); }
From source file:com.jagornet.dhcp.db.JdbcIaAddressDAO.java
public List<IaAddress> findUnusedByRange(final InetAddress startAddr, final InetAddress endAddr) { final long offerExpiration = new Date().getTime() - 12000; // 2 min = 120 sec = 12000 ms return getJdbcTemplate().query( "select * from iaaddress" + " where ((state=" + IaAddress.ADVERTISED + " and starttime <= ?)" + " or (state=" + IaAddress.EXPIRED + " or state=" + IaAddress.RELEASED + "))" + " and ipaddress >= ? and ipaddress <= ?" + " order by state, validendtime, ipaddress", new PreparedStatementSetter() { @Override/* www .j a va2 s .c o m*/ public void setValues(PreparedStatement ps) throws SQLException { java.sql.Timestamp ts = new java.sql.Timestamp(offerExpiration); ps.setTimestamp(1, ts); ps.setBytes(2, startAddr.getAddress()); ps.setBytes(3, endAddr.getAddress()); } }, new IaAddrRowMapper()); }
From source file:com.jagornet.dhcp.db.JdbcIaPrefixDAO.java
public List<IaPrefix> findUnusedByRange(final InetAddress startAddr, final InetAddress endAddr) { final long offerExpiration = new Date().getTime() - 12000; // 2 min = 120 sec = 12000 ms return getJdbcTemplate().query("select * from iaprefix" + " where ((state=" + IaPrefix.ADVERTISED + " and starttime <= ?)" + " or (state=" + IaPrefix.EXPIRED + " or state=" + IaPrefix.RELEASED + "))" + " and prefixaddress >= ? and prefixaddress <= ?" + " order by state, validendtime, ipaddress", new PreparedStatementSetter() { @Override/*from w ww . ja va 2 s .com*/ public void setValues(PreparedStatement ps) throws SQLException { java.sql.Timestamp ts = new java.sql.Timestamp(offerExpiration); ps.setTimestamp(1, ts); ps.setBytes(2, startAddr.getAddress()); ps.setBytes(3, endAddr.getAddress()); } }, new IaPrefixRowMapper()); }
From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java
public void deleteIaAddr(final IaAddress iaAddr) { getJdbcTemplate().update("delete from dhcplease" + " where ipaddress = ?", new PreparedStatementSetter() { @Override//w ww. ja v a2 s . c o m public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, iaAddr.getIpAddress().getAddress()); } }); }
From source file:com.jagornet.dhcp.db.JdbcIaAddressDAO.java
public List<InetAddress> findExistingIPs(final InetAddress startAddr, final InetAddress endAddr) { return getJdbcTemplate().query("select ipaddress from iaaddress" + " where ipaddress >= ? and ipaddress <= ?" + " order by ipaddress", new PreparedStatementSetter() { @Override//from w w w . j a va 2 s. c o m public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, startAddr.getAddress()); ps.setBytes(2, endAddr.getAddress()); } }, new RowMapper<InetAddress>() { @Override public InetAddress mapRow(ResultSet rs, int rowNum) throws SQLException { InetAddress inetAddr = null; try { inetAddr = InetAddress.getByAddress(rs.getBytes("ipaddress")); } catch (UnknownHostException e) { // re-throw as SQLException throw new SQLException("Unable to map ipaddress", e); } return inetAddr; } }); }
From source file:com.jagornet.dhcp.db.JdbcIaPrefixDAO.java
public List<InetAddress> findExistingIPs(final InetAddress startAddr, final InetAddress endAddr) { return getJdbcTemplate().query("select prefixaddress from iaprefix" + " where prefixaddress >= ? and prefixaddress <= ?" + " order by prefixaddress", new PreparedStatementSetter() { @Override//from w w w .ja v a 2s . com public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, startAddr.getAddress()); ps.setBytes(2, endAddr.getAddress()); } }, new RowMapper<InetAddress>() { @Override public InetAddress mapRow(ResultSet rs, int rowNum) throws SQLException { InetAddress inetAddr = null; try { inetAddr = InetAddress.getByAddress(rs.getBytes("prefixaddress")); } catch (UnknownHostException e) { // re-throw as SQLException throw new SQLException("Unable to map prefixaddress", e); } return inetAddr; } }); }