List of usage examples for java.sql PreparedStatement setBytes
void setBytes(int parameterIndex, byte x[]) throws SQLException;
From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java
/** * Delete dhcp lease./* ww w . j ava 2 s .c om*/ * * @param lease the lease */ protected void deleteDhcpLease(final DhcpLease lease) { getJdbcTemplate().update("delete from dhcplease" + " where ipaddress=?", new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, lease.getIpAddress().getAddress()); } }); }
From source file:org.pentaho.platform.repository.hibernate.usertypes.BlobUserType.java
public void nullSafeSet(final PreparedStatement arg0, final Object arg1, final int arg2) throws HibernateException, SQLException { if (BlobUserType.debug) { BlobUserType.log.debug(Messages.getInstance().getString("BLOBUTYPE.DEBUG_NULL_SAFE_SET")); //$NON-NLS-1$ }//from w w w . jav a 2s .c om if (arg1 != null) { try { arg0.setBytes(arg2, SerializationHelper.serialize((Serializable) arg1)); } catch (SerializationException ex) { BlobUserType.log.error(Messages.getInstance().getErrorString("BLOBUTYPE.ERROR_0001_SETTING_BLOB"), //$NON-NLS-1$ ex); throw new HibernateException( Messages.getInstance().getErrorString("BLOBUTYPE.ERROR_0001_SETTING_BLOB"), ex); //$NON-NLS-1$ } } else { arg0.setNull(arg2, sqlTypes()[0]); } }
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/*w w w. ja va2s . 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/* ww w . ja va 2 s . co 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 IaPrefixRowMapper()); }
From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java
/** * Update ia options.// w w w .j av a 2 s . co m */ protected void updateIaOptions(final InetAddress inetAddr, final Collection<DhcpOption> iaOptions) { getJdbcTemplate().update("update dhcplease" + " set ia_options=?" + " where ipaddress=?", new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, encodeOptions(iaOptions)); ps.setBytes(2, inetAddr.getAddress()); } }); }
From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java
/** * Update ipaddr options.//w w w . j a v a2s . c o m */ protected void updateIpAddrOptions(final InetAddress inetAddr, final Collection<DhcpOption> ipAddrOptions) { getJdbcTemplate().update("update dhcplease" + " set ipaddr_options=?" + " where ipaddress=?", new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, encodeOptions(ipAddrOptions)); ps.setBytes(2, inetAddr.getAddress()); } }); }
From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java
/** * Find dhcp leases for ia.//from w w w.j a v a2 s . c om * * @param duid the duid * @param iatype the iatype * @param iaid the iaid * @return the list */ protected List<DhcpLease> findDhcpLeasesForIA(final byte[] duid, final byte iatype, final long iaid) { return getJdbcTemplate().query("select * from dhcplease" + " where duid = ?" + " and iatype = ?" + " and iaid = ?" + " order by ipaddress", new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, duid); ps.setByte(2, iatype); ps.setLong(3, iaid); } }, new DhcpLeaseRowMapper()); }
From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java
/** * Find dhcp lease for InetAddr./* ww w. j a v a 2 s . co m*/ * * @param inetAddr the InetAddr * @return the DhcpLease */ protected DhcpLease findDhcpLeaseForInetAddr(final InetAddress inetAddr) { List<DhcpLease> leases = getJdbcTemplate().query("select * from dhcplease" + " where ipaddress = ?", new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, inetAddr.getAddress()); } }, new DhcpLeaseRowMapper()); if ((leases != null) && (leases.size() > 0)) { if (leases.size() == 1) { return leases.get(0); } else { //TODO: this really should be impossible because of the unique // constraint on the IP address log.error("Found more than one lease for IP=" + inetAddr.getHostAddress()); } } return null; }
From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java
/** * Insert dhcp lease./*from w w w.jav a 2 s . com*/ * * @param lease the lease */ protected void insertDhcpLease(final DhcpLease lease) { getJdbcTemplate().update("insert into dhcplease" + " (ipaddress, duid, iatype, iaid, prefixlen, state," + " starttime, preferredendtime, validendtime," + " ia_options, ipaddr_options)" + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new PreparedStatementSetter() { @Override public void setValues(PreparedStatement ps) throws SQLException { ps.setBytes(1, lease.getIpAddress().getAddress()); ps.setBytes(2, lease.getDuid()); ps.setByte(3, lease.getIatype()); ps.setLong(4, lease.getIaid()); ps.setShort(5, lease.getPrefixLength()); ps.setByte(6, lease.getState()); java.sql.Timestamp sts = new java.sql.Timestamp(lease.getStartTime().getTime()); ps.setTimestamp(7, sts, Util.GMT_CALENDAR); java.sql.Timestamp pts = new java.sql.Timestamp(lease.getPreferredEndTime().getTime()); ps.setTimestamp(8, pts, Util.GMT_CALENDAR); java.sql.Timestamp vts = new java.sql.Timestamp(lease.getValidEndTime().getTime()); ps.setTimestamp(9, vts, Util.GMT_CALENDAR); ps.setBytes(10, encodeOptions(lease.getIaDhcpOptions())); ps.setBytes(11, encodeOptions(lease.getIaAddrDhcpOptions())); } }); }
From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java
@Override public List<InetAddress> findExistingIPs(final InetAddress startAddr, final InetAddress endAddr) { return getJdbcTemplate().query("select ipaddress from dhcplease" + " where ipaddress >= ? and ipaddress <= ?" + " order by ipaddress", new PreparedStatementSetter() { @Override//w w w. ja v a2 s. c om 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; } }); }