Example usage for org.springframework.jdbc.core JdbcTemplate update

List of usage examples for org.springframework.jdbc.core JdbcTemplate update

Introduction

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

Prototype

@Override
    public int update(String sql, @Nullable Object... args) throws DataAccessException 

Source Link

Usage

From source file:com.osrdata.etltoolbox.fileloader.FileSpecification.java

/**
 * Inserts record for source file into the audit_file table.
 */// w w  w . j a  v  a  2s  . c o  m
private Integer insertAuditFile() throws SQLException {
    JdbcTemplate template = new JdbcTemplate(auditDs);
    StringBuilder sql = new StringBuilder();
    Integer fileId = null;
    int result = 0;
    String auditUrl = auditDs.getConnection().getMetaData().getURL();

    sql.append("insert into audit_file ");
    if (auditUrl.indexOf(":sqlserver:") != -1) {
        sql.append("values (next value for seq_audit, ?, ?, ?, ?, ?, ?)");
    } else if (auditUrl.indexOf(":oracle:") != -1) {
        sql.append("values (seq_audit.nextval, ?, ?, ?, ?, ?, ?)");
    } else if (auditUrl.indexOf(":postgresql:") != -1) {
        sql.append("values (nextval('seq_audit'), ?, ?, ?, ?, ?, ?)");
    } else {
        // If database type is unknown, attempt to insert record letting database set file_id with trigger or identity value.
        sql.append(
                "(source_id, file_name, table_name, etl_type, etl_date, processed_flag) values (?, ?, ?, ?, ?, ?)");
    }
    result = template.update(sql.toString(),
            new Object[] { sourceId, sourceFile.getName(), targetTable, etlType, etlDate, "N" });
    if (result > 0) {
        fileId = selectAuditFile();
    }

    log.debug("\tInsert into audit_file returned " + result + ", fileId " + fileId);
    return fileId;
}

From source file:de.uhh.l2g.dao.VideoDao.java

public void updateFileSize(Long fSize, int vId) {
    JdbcTemplate update = new JdbcTemplate(this.getDataSource());
    update.update("UPDATE video SET fileSize=? WHERE id=?", new Object[] { fSize, vId });
}

From source file:de.uhh.l2g.dao.VideoDao.java

/**
 * Sets the upload date./* w ww .j a v a2  s  .co m*/
 *
 * @param d the d
 * @param vId the v id
 */
public void updateUploadDate(Date d, int vId) {
    JdbcTemplate update = new JdbcTemplate(this.getDataSource());
    update.update("UPDATE video SET uploadDate=? WHERE id=?", new Object[] { d, vId });
}

From source file:de.uhh.l2g.dao.VideoDao.java

/**
 * Increment hits for video.// w  ww.  j av a2s  .c  om
 *
 * @param video the video
 */
public void incrementHitsForVideo(Video video) {
    JdbcTemplate update = new JdbcTemplate(this.getDataSource());
    update.update("UPDATE video SET hits=hits+1 WHERE id=?", new Object[] { video.getId() });
}

From source file:de.uhh.l2g.dao.VideoDao.java

/**
 * Activate openaccess./*w ww .  ja v  a 2  s.com*/
 *
 * @param id the id
 */
public void activateOpenaccess(int id) {

    JdbcTemplate update = new JdbcTemplate(this.getDataSource());
    update.update("UPDATE video SET openAccess=true, surl=null WHERE id=?", new Object[] { id });
}

From source file:de.uhh.l2g.dao.VideoDao.java

/**
 * Activate download.//w  w w. j av  a2s  .  co m
 *
 * @param id the id
 */
public void activateDownload(int id) {

    JdbcTemplate update = new JdbcTemplate(this.getDataSource());
    update.update("UPDATE video SET downloadLink=true WHERE id=?", new Object[] { id });
}

From source file:de.uhh.l2g.dao.VideoDao.java

/**
 * Deactivate download./* w w  w . j a va  2s  . co m*/
 *
 * @param id the id
 */
public void deactivateDownload(int id) {

    JdbcTemplate update = new JdbcTemplate(this.getDataSource());
    update.update("UPDATE video SET downloadLink=false WHERE id=?", new Object[] { id });
}

From source file:de.uhh.l2g.dao.VideoDao.java

/**
 * Delete by id.// www  .jav  a 2  s  .com
 *
 * @param id the id
 */
public void deleteById(int id) {

    JdbcTemplate delete = new JdbcTemplate(this.getDataSource());
    delete.update("DELETE from video where id=?", new Object[] { id });
    delete.update("DELETE from video_facility WHERE videoId=?", new Object[] { id });
}

From source file:de.uhh.l2g.dao.VideoDao.java

/**
 * Creates the one hit./*from w  w  w  . j a v a  2 s. c om*/
 *
 * @param id the id
 * @param hitsperday the hitsperday
 * @param hitsperweek the hitsperweek
 * @param hitspermonth the hitspermonth
 * @param hitsperyear the hitsperyear
 */
public void createOneHit(int id, int hitsperday, int hitsperweek, int hitspermonth, int hitsperyear) {
    JdbcTemplate insert = new JdbcTemplate(this.getDataSource());
    insert.update(
            "INSERT INTO videohitlist (id, hitsperday, hitsperweek, hitspermonth, hitsperyear ) VALUES(?,?,?,?,?)",
            new Object[] { id, hitsperday, hitsperweek, hitspermonth, hitsperyear });
}

From source file:de.uhh.l2g.dao.VideoDao.java

/**
 * Creates the./*from   ww w  .j av  a 2  s  .  c  om*/
 *
 * @param title the title
 * @param tags the tags
 * @param lectureseriesId the lectureseries id
 * @param ownerId the owner id
 * @param producerId the producer id
 * @param containerFormat the container format
 * @param filename the filename
 * @param resolution the resolution
 * @param duration the duration
 * @param hostId the host id
 * @param metadataId the metadata id
 * @param facilityId the facility id
 * @param citation2go the citation2go
 */
public void create(String title, String tags, int lectureseriesId, int ownerId, int producerId,
        String containerFormat, String filename, String resolution, String duration, int hostId, int metadataId,
        int facilityId, int citation2go) {

    JdbcTemplate insert = new JdbcTemplate(this.getDataSource());
    insert.update(
            "INSERT INTO video (title, tags, lectureseriesId, ownerId, producerId, containerFormat, filename, resolution, duration, hostId, metadataId, facilityId, citation2go) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)",
            new Object[] { title, tags, lectureseriesId, ownerId, producerId, containerFormat, filename,
                    resolution, duration, hostId, metadataId, facilityId, citation2go });
}