Example usage for org.springframework.jdbc.core.namedparam SqlParameterSourceUtils createBatch

List of usage examples for org.springframework.jdbc.core.namedparam SqlParameterSourceUtils createBatch

Introduction

In this page you can find the example usage for org.springframework.jdbc.core.namedparam SqlParameterSourceUtils createBatch.

Prototype

public static SqlParameterSource[] createBatch(Map<String, ?>[] valueMaps) 

Source Link

Document

Create an array of MapSqlParameterSource objects populated with data from the values passed in.

Usage

From source file:org.jasig.schedassist.impl.relationship.advising.AdvisorListRelationshipDataSourceImpl.java

/**
 * This method deletes all existing rows from the isis_records table, then invokes
 * {@link #batchLoadData(Resource)} to refresh it.
 * /*from ww  w .j  ava 2  s  . c o  m*/
 * This method is marked with Spring's {@link Transactional} annotation, and if
 * the available application is running should only be executed when transactional 
 * support is available.
 * 
 * @see Transactional
 * @param resource
 * @throws IOException
 */
@Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRES_NEW)
public synchronized void reloadData() {
    final String propertyValue = System.getProperty("org.jasig.schedassist.runScheduledTasks", "true");
    if (Boolean.parseBoolean(propertyValue)) {
        String currentTerm = TermCalculator.getCurrentTerm();
        if (isResourceUpdated(advisorListResource)) {
            LOG.info("resource updated, reloading advisorList data");
            List<StudentAdvisorAssignment> records = readResource(advisorListResource, currentTerm);

            LOG.info("deleting all existing records from advisorlist table");
            StopWatch stopWatch = new StopWatch();
            stopWatch.start();
            this.getJdbcTemplate().execute("delete from advisorlist");
            long deleteTime = stopWatch.getTime();
            LOG.info("finished deleting existing (" + deleteTime + " msec), starting batch insert");
            stopWatch.reset();
            stopWatch.start();
            SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(records.toArray());
            this.getSimpleJdbcTemplate().batchUpdate(
                    "insert into advisorlist (advisor_emplid, advisor_relationship, student_emplid, term_description, term_number, advisor_type, committee_role) values (:advisorEmplid, :advisorRelationshipDescription, :studentEmplid, :termDescription, :termNumber, :advisorType, :committeeRole)",
                    batch);
            long insertTime = stopWatch.getTime();
            stopWatch.stop();
            LOG.info("batch insert complete (" + insertTime + " msec)");
            LOG.info("reloadData complete (total time: " + (insertTime + deleteTime) + " msec)");
            this.lastReloadTimestamp = new Date();
            try {
                this.resourceLastModified = advisorListResource.lastModified();
            } catch (IOException e) {
                LOG.debug("ignoring IOException from accessing Resource.lastModified()");
            }
        } else {
            LOG.info("resource not modified since last reload, skipping");
        }
    } else {
        LOG.debug("ignoring reloadData as 'org.jasig.schedassist.runScheduledTasks' set to false");
    }
}

From source file:org.jasig.schedassist.impl.owner.SpringJDBCPublicProfileDaoImpl.java

@Transactional
@Override/*from  w w  w. j av  a2 s  . c  om*/
public List<PublicProfileTag> setProfileTags(List<String> tags, PublicProfileId profileId) {
    int rows = this.simpleJdbcTemplate.update("delete from profile_tags where profile_key=?",
            profileId.getProfileKey());
    LOG.debug("deleted " + rows + " from profile_tags for profile " + profileId);

    List<PublicProfileTag> toStore = stringAsTags(tags, profileId);
    SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(toStore.toArray());
    this.simpleJdbcTemplate.batchUpdate(
            "insert into profile_tags (profile_key,tag,tag_display) values (:profileKey,:tag,:tagDisplay)",
            batch);
    LOG.debug("inserted " + tags.size() + " tags for " + profileId);
    return toStore;
}

From source file:org.jasig.schedassist.impl.owner.SpringJDBCAvailableScheduleDaoImpl.java

/**
 * Inserts all of the arguments into the schedules table using
 * {@link SimpleJdbcTemplate#batchUpdate(String, SqlParameterSource[])}.
 * //w w  w. j  av  a 2  s  .  com
 * @param blocks
 */
protected void internalStoreBlocks(final Set<PersistenceAvailableBlock> blocks) {
    SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch(blocks.toArray());
    this.simpleJdbcTemplate.batchUpdate(
            "insert into schedules (owner_id, start_time, end_time, visitor_limit, meeting_location) values (:ownerId, :startTime, :endTime, :visitorLimit, :meetingLocation)",
            batch);
}