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:de.uhh.l2g.dao.VideoDao.java

/**
 * Update by id.//ww  w.ja  v a  2s  . c o m
 *
 * @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 textId the text id
 * @param filesize the filesize
 * @param generationDate the generation date
 * @param openAccess the open access
 * @param downloadAllawed the download allawed
 * @param metadataId the metadata id
 * @param surl the surl
 * @param hits the hits
 * @param permittedToSegment the permitted to segment
 * @param facilityId the facility id
 * @param citation2go the citation2go
 * @param id the id
 */
public void updateById(String title, String tags, int lectureseriesId, int ownerId, int producerId,
        String containerFormat, String filename, String resolution, String duration, int hostId, int textId,
        Long filesize, String generationDate, boolean openAccess, boolean downloadAllawed, int metadataId,
        String surl, int hits, boolean permittedToSegment, int facilityId, int citation2go, int id) {
    JdbcTemplate update = new JdbcTemplate(this.getDataSource());
    update.update(
            "UPDATE video SET title=?, tags=?, lectureseriesId=?, ownerId=?, producerId=?, containerFormat=?, filename=?, resolution=?, duration=?, hostId=?, textId=?, filesize=?, generationDate=?, openAccess=?, downloadLink=?, metadataId=?, surl=?, hits=?, permittedToSegment=?, facilityId=?, citation2go=? WHERE id=?",
            new Object[] { title, tags, lectureseriesId, ownerId, producerId, containerFormat, filename,
                    resolution, duration, hostId, textId, filesize, generationDate, openAccess, downloadAllawed,
                    metadataId, surl, hits, permittedToSegment, facilityId, citation2go, id });
}

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

/**
 * Update facility id in table by id.//  w w  w.ja va  2 s  . c om
 *
 * @param id the id
 * @param facilityId the facility id
 * @return the int
 */
public int updateFacilityIdInTableById(int id, int facilityId) {
    JdbcTemplate update = new JdbcTemplate(this.getDataSource());
    int ret = update.update("UPDATE video SET facilityId=? WHERE id=?", new Object[] { facilityId, id });
    return ret;
}

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

/**
 * Delete video from video hit list by id.
 *
 * @param id the id//from w ww.  j  a v a2s  .  co  m
 */
public void deleteVideoFromVideoHitListById(int id) {
    JdbcTemplate delete = new JdbcTemplate(this.getDataSource());
    String sqlquery = "DELETE FROM videohitlist WHERE id=?";
    delete.update(sqlquery, new Object[] { id });
}

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

/**
 * Deactivate openaccess.//from w w w . j ava2 s .  c  om
 *
 * @param id the id
 */
public void deactivateOpenaccess(int id) {

    JdbcTemplate update = new JdbcTemplate(this.getDataSource());
    Video v = this.getById(id).iterator().next();
    String secureFileName = Security.createSecureFileName() + "." + v.getFilenameFormat();
    update.update("UPDATE video SET openAccess=false, surl='" + secureFileName + "' WHERE id=?",
            new Object[] { id });
}

From source file:db.migration.V055__UpdateECTS.java

private void handleOrganisaatiometadata(Map md, JdbcTemplate jdbcTemplate) {
    int id = (int) md.get("id");
    String hakutoimistoectsemail = (String) md.get("hakutoimistoectsemail");
    String hakutoimistoectsnimi = (String) md.get("hakutoimistoectsnimi");
    String hakutoimistoectspuhelin = (String) md.get("hakutoimistoectspuhelin");
    String hakutoimistoectstehtavanimike = (String) md.get("hakutoimistoectstehtavanimike");
    int email_mkt_id = 0;
    int nimi_mkt_id = 0;
    int puhelin_mkt_id = 0;
    int tehtavanimike_mkt_id = 0;

    if (hakutoimistoectsemail != null && hakutoimistoectsemail.length() > 0) {
        email_mkt_id = insertNewMkt(hakutoimistoectsemail, jdbcTemplate);
    }//from  www.  ja  v a 2 s .c  om
    if (hakutoimistoectsnimi != null && hakutoimistoectsnimi.length() > 0) {
        nimi_mkt_id = insertNewMkt(hakutoimistoectsnimi, jdbcTemplate);
    }
    if (hakutoimistoectspuhelin != null && hakutoimistoectspuhelin.length() > 0) {
        puhelin_mkt_id = insertNewMkt(hakutoimistoectspuhelin, jdbcTemplate);
    }
    if (hakutoimistoectstehtavanimike != null && hakutoimistoectstehtavanimike.length() > 0) {
        tehtavanimike_mkt_id = insertNewMkt(hakutoimistoectstehtavanimike, jdbcTemplate);
    }

    String update = "";

    if (email_mkt_id != 0) {
        update += "hakutoimistoectsemailmkt=" + email_mkt_id;
    }
    if (nimi_mkt_id != 0) {
        if (update.length() > 0) {
            update += ",";
        }
        update += "hakutoimistoectsnimimkt=" + nimi_mkt_id;
    }
    if (puhelin_mkt_id != 0) {
        if (update.length() > 0) {
            update += ",";
        }
        update += "hakutoimistoectspuhelinmkt=" + puhelin_mkt_id;
    }
    if (tehtavanimike_mkt_id != 0) {
        if (update.length() > 0) {
            update += ",";
        }
        update += "hakutoimistoectstehtavanimikemkt=" + tehtavanimike_mkt_id;
    }

    // Update the metadata
    int result = jdbcTemplate.update("UPDATE organisaatiometadata SET " + update + " WHERE id=?", id);
    if (result < 0 || result > 1) {
        LOG.error("Failed to UPDATE organisaatiometadata: {}.", update);
    } else {
        LOG.info("UPDATED organisaatiometadata for id {}: {}.", id, update);
    }
}

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

/**
 * Creates the and return generated id./* ww  w .  ja v  a2 s  .  c o  m*/
 *
 * @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
 * @return the int
 */
public int createAndReturnGeneratedId(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 jdbcTemplate = this.getJdbcTemplate();
    PreparedStatementCreator pscInsert = null;
    //initialize parameters
    try {
        String[] parameter = { title, tags, lectureseriesId + "", ownerId + "", producerId + "",
                containerFormat, filename, resolution, duration, hostId + "", metadataId + "", facilityId + "",
                citation2go + "" };
        pscInsert = new Video_INSERT_PreparedStatement(this.getJdbcTemplate(), parameter);
    } catch (SQLException e) {
    }

    KeyHolder keyHolder = new GeneratedKeyHolder();
    jdbcTemplate.update(pscInsert, keyHolder);

    Number n = keyHolder.getKey();
    int i = n.intValue();
    return i;
}

From source file:org.agnitas.dao.impl.MailingDaoImpl.java

public boolean deleteContentFromMailing(Mailing mailing, int contentID) {
    JdbcTemplate jdbcTemplate = AgnUtils.getJdbcTemplate(this.applicationContext);
    String deleteContentSQL = "DELETE from dyn_content_tbl " + "WHERE " + " dyn_content_id = ? AND"
            + " company_id = ?";

    Object[] params = new Object[] { new Integer(contentID), 1 };
    int affectedRows = 0;
    affectedRows = jdbcTemplate.update(deleteContentSQL, params);
    return affectedRows > 0;
}

From source file:org.agnitas.dao.impl.RecipientDaoImpl.java

/**
 * Delete complete Subscriber-Data from DB. customerID must be set first for this method.
 *///from w  ww  . j ava  2 s . c  om
@Override
public void deleteCustomerDataFromDb(int companyID, int customerID) {
    String sql = null;
    Object[] params = new Object[] { new Integer(customerID) };

    try {
        JdbcTemplate tmpl = new JdbcTemplate((DataSource) this.applicationContext.getBean("dataSource"));

        sql = "DELETE FROM customer_" + companyID + "_binding_tbl WHERE customer_id=?";
        tmpl.update(sql, params);

        sql = "DELETE FROM customer_" + companyID + "_tbl WHERE customer_id=?";
        tmpl.update(sql, params);
    } catch (Exception e) {
        logger.error("deleteCustomerDataFromDb: " + sql, e);
        AgnUtils.sendExceptionMail("sql:" + sql, e);
    }
}

From source file:org.agnitas.dao.impl.RecipientDaoImpl.java

public void deleteRecipientsBindings(int mailinglistID, int companyID, boolean activeOnly,
        boolean notAdminsAndTests) {
    JdbcTemplate jdbc = new JdbcTemplate((DataSource) applicationContext.getBean("dataSource"));

    String delete = "delete from customer_" + companyID + "_binding_tbl";
    String where = "where mailinglist_id = ?";
    StringBuffer sql = new StringBuffer(delete).append(" ").append(where);

    if (activeOnly) {
        sql.append(" ").append(String.format("and user_status = %d", BindingEntry.USER_STATUS_ACTIVE));
    }/*from w ww  .  j  a  v  a  2s . c  o  m*/
    if (notAdminsAndTests) {
        sql.append(" ")
                .append(String.format("and user_type <> '%s' and user_type <> '%s' and user_type <> '%s'",
                        BindingEntry.USER_TYPE_ADMIN, BindingEntry.USER_TYPE_TESTUSER,
                        BindingEntry.USER_TYPE_TESTVIP));
    }

    jdbc.update(sql.toString(), new Object[] { new Integer(mailinglistID) });
}

From source file:org.apache.syncope.core.logic.init.CamelRouteLoader.java

private void loadRoutes(final String domain, final DataSource dataSource, final Resource resource,
        final AnyTypeKind anyTypeKind) {

    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    boolean shouldLoadRoutes = jdbcTemplate.queryForList(
            String.format("SELECT * FROM %s WHERE ANYTYPEKIND = ?", CamelRoute.class.getSimpleName()),
            new Object[] { anyTypeKind.name() }).isEmpty();

    if (shouldLoadRoutes) {
        try {/*from w w  w .j a  va  2  s  .c  o  m*/
            TransformerFactory tf = null;
            DOMImplementationLS domImpl = null;
            NodeList routeNodes;
            if (IS_JBOSS) {
                tf = TransformerFactory.newInstance();
                tf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
                DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                dbFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
                DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
                Document doc = dBuilder.parse(resource.getInputStream());

                routeNodes = doc.getDocumentElement().getElementsByTagName("route");
            } else {
                DOMImplementationRegistry reg = DOMImplementationRegistry.newInstance();
                domImpl = (DOMImplementationLS) reg.getDOMImplementation("LS");
                LSInput lsinput = domImpl.createLSInput();
                lsinput.setByteStream(resource.getInputStream());

                LSParser parser = domImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);

                routeNodes = parser.parse(lsinput).getDocumentElement().getElementsByTagName("route");
            }

            for (int s = 0; s < routeNodes.getLength(); s++) {
                Node routeElement = routeNodes.item(s);
                String routeContent = IS_JBOSS ? nodeToString(routeNodes.item(s), tf)
                        : nodeToString(routeNodes.item(s), domImpl);
                String routeId = ((Element) routeElement).getAttribute("id");

                jdbcTemplate.update(
                        String.format("INSERT INTO %s(ID, ANYTYPEKIND, CONTENT) VALUES (?, ?, ?)",
                                CamelRoute.class.getSimpleName()),
                        new Object[] { routeId, anyTypeKind.name(), routeContent });
                LOG.info("[{}] Route successfully loaded: {}", domain, routeId);
            }
        } catch (Exception e) {
            LOG.error("[{}] Route load failed", domain, e);
        }
    }
}