Example usage for org.springframework.jdbc.core PreparedStatementSetter PreparedStatementSetter

List of usage examples for org.springframework.jdbc.core PreparedStatementSetter PreparedStatementSetter

Introduction

In this page you can find the example usage for org.springframework.jdbc.core PreparedStatementSetter PreparedStatementSetter.

Prototype

PreparedStatementSetter

Source Link

Usage

From source file:org.obiba.onyx.jade.instrument.holologic.APEXScanDataExtractor.java

/**
 * Called by extractData(). Query the Apex PatScan db for the scan ID, raw data file name, scan mode and scan type
 * based on the patient key and scan type. Scan type is provided by child classes (eg., AP Spine = 1).
 *///from   w  ww  .  j  a  v  a 2 s .c o  m
private Map<String, Data> extractScanAnalysisData() {
    log.info("extractscananalysisdata: " + getParticipantKey() + ", " + Long.toString(getScanType()));
    return patScanDb.query(
            "SELECT SCANID, SCAN_MODE, SCAN_DATE FROM ScanAnalysis WHERE PATIENT_KEY = ? AND SCAN_TYPE = ?",
            new PreparedStatementSetter() {
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setString(1, getParticipantKey());
                    ps.setString(2, Long.toString(getScanType()));
                }
            }, new ScanAnalysisResultSetExtractor());
}

From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java

/**
 * Update ipaddr options./* w w  w.ja va 2 s.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   ww w  .  ja  v  a2 s  .co  m
 *
 * @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.JdbcIaAddressDAO.java

public List<IaAddress> findAllByIdentityAssocId(final long identityAssocId) {
    return getJdbcTemplate().query("select * from iaaddress where identityassoc_id = ? order by ipaddress",
            new PreparedStatementSetter() {
                @Override//  w  w  w.  ja v a 2s . c  o  m
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setLong(1, identityAssocId);
                }
            }, new IaAddrRowMapper());
}

From source file:com.jagornet.dhcp.db.JdbcIaPrefixDAO.java

public List<IaPrefix> findAllByIdentityAssocId(final long identityAssocId) {
    return getJdbcTemplate().query("select * from iaprefix where identityassoc_id = ? order by prefixaddress",
            new PreparedStatementSetter() {
                @Override/* ww  w . j  av  a2 s.c  o m*/
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setLong(1, identityAssocId);
                }
            }, new IaPrefixRowMapper());
}

From source file:com.skycloud.management.portal.admin.sysmanage.dao.impl.UserManageDaoImpl.java

@Override
public int udpateUser(final TUserBO user) throws SQLException {
    StringBuilder sql = new StringBuilder("update T_SCS_USER set NAME=?,DEPT_ID=?,ROLE_ID=?,");
    sql.append(" EMAIL=?,PHONE=?,MOBILE=?,FAX=?,");
    sql.append(" LASTUPDATE_DT=?,STATE=?,CHECK_CODE=?");
    if (StringUtils.isNotEmpty(user.getPwd())) {
        sql.append(" ,PWD=?");
    }//  ww  w.ja va2 s.  c  o m
    sql.append(" where ID=?");
    int result = 0;
    try {
        result = this.getJdbcTemplate().update(sql.toString(), new PreparedStatementSetter() {
            int i = 1;

            public void setValues(PreparedStatement ps) throws SQLException {
                ps.setString(i++, user.getName());
                ps.setInt(i++, user.getDeptId());
                ps.setInt(i++, user.getRoleId());
                ps.setString(i++, user.getEmail());
                ps.setString(i++, user.getPhone());
                ps.setString(i++, user.getMobile());
                ps.setString(i++, user.getFax());
                ps.setTimestamp(i++, new Timestamp(user.getLastupdateDt().getTime()));
                ps.setInt(i++, user.getState());
                ps.setString(i++, user.getCheckCode());//fix buf 3040 
                if (StringUtils.isNotEmpty(user.getPwd())) {
                    ps.setString(i++, DegistUtil.md5(user.getPwd()));
                }
                ps.setInt(i++, user.getId());
            }
        });
    } catch (Exception e) {
        throw new SQLException(" " + user.getLastupdateDt()
                + "  " + e.getMessage());
    }
    return result;
}

From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java

/**
 * Find dhcp lease for InetAddr./*  w w  w. ja  va2  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.JdbcIaAddressDAO.java

public List<IaAddress> findAllByRange(final InetAddress startAddr, final InetAddress endAddr) {
    return getJdbcTemplate().query(
            "select * from iaaddress where ipaddress >= ? and ipaddress <= ? order by ipaddress",
            new PreparedStatementSetter() {
                @Override/* w ww.j  a  v  a2  s  .c o m*/
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setBytes(1, startAddr.getAddress());
                    ps.setBytes(2, endAddr.getAddress());
                }
            }, new IaAddrRowMapper());
}

From source file:com.jagornet.dhcp.db.JdbcIaPrefixDAO.java

public List<IaPrefix> findAllByRange(final InetAddress startAddr, final InetAddress endAddr) {
    return getJdbcTemplate().query("select * from iaprefix" + " where prefixaddress >= ? and prefixaddress <= ?"
            + " order by prefixaddress", new PreparedStatementSetter() {
                @Override/*from w ww .j av a2 s  .  c o m*/
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setBytes(1, startAddr.getAddress());
                    ps.setBytes(2, endAddr.getAddress());
                }
            }, new IaPrefixRowMapper());
}

From source file:org.bremersee.common.security.acls.jdbc.BasicLookupStrategy.java

/**
 * Locates the primary key IDs specified in "findNow", adding AclImpl instances with
 * StubAclParents to the "acls" Map./*from  ww w .  j av  a2 s  . com*/
 *
 * @param acls the AclImpls (with StubAclParents)
 * @param findNow Long-based primary keys to retrieve
 * @param sids the sids
 */
private void lookupPrimaryKeys(final Map<Serializable, Acl> acls, final Set<Long> findNow,
        final List<Sid> sids) {
    Assert.notNull(acls, "ACLs are required");
    Assert.notEmpty(findNow, "Items to find now required");

    String sql = computeRepeatingSql(lookupPrimaryKeysWhereClause, findNow.size());

    Set<Long> parentsToLookup = jdbcTemplate.query(sql, new PreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps) throws SQLException {
            int i = 0;

            for (Long toFind : findNow) {
                i++;
                ps.setLong(i, toFind);
            }
        }
    }, new ProcessResultSet(acls, sids));

    // Lookup the parents, now that our JdbcTemplate has released the database
    // connection (SEC-547)
    if (!parentsToLookup.isEmpty()) {
        lookupPrimaryKeys(acls, parentsToLookup, sids);
    }
}