Example usage for org.springframework.jdbc.core.simple SimpleJdbcInsert SimpleJdbcInsert

List of usage examples for org.springframework.jdbc.core.simple SimpleJdbcInsert SimpleJdbcInsert

Introduction

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

Prototype

public SimpleJdbcInsert(JdbcTemplate jdbcTemplate) 

Source Link

Document

Alternative Constructor that takes one parameter with the JdbcTemplate to be used.

Usage

From source file:org.sakuli.services.forwarder.database.dao.impl.DaoTestSuiteImpl.java

/**
 * {@inheritDoc}/*w  ww.  j  av  a  2s.  com*/
 */
@Override
public int insertInitialTestSuiteData() {
    LOGGER.debug("Build SQL query for new primary key in table 'sakuli_suites'");

    testSuite.refreshState();
    MapSqlParameterSource tcParameters = getInitialDataParameters();
    LOGGER.debug("write the following values to 'sakuli_suites': " + tcParameters.getValues()
            + " ==>  now execute ....");
    SimpleJdbcInsert insertInitialSuiteData = new SimpleJdbcInsert(getDataSource())
            .withTableName("sakuli_suites").usingGeneratedKeyColumns("id");

    int dbPrimaryKey = insertInitialSuiteData.executeAndReturnKey(tcParameters).intValue();

    LOGGER.info("test suite \"" + testSuite.getId() + "\" has been written to 'sakuli_suites' with  primaryKey="
            + dbPrimaryKey);
    return dbPrimaryKey;
}

From source file:main.java.net.bornil.db.service.jdbc.JdbcUserDao.java

@Override
public int createUser(User user) {
    SimpleJdbcInsert insertUser = new SimpleJdbcInsert(this.jdbcTemplate);
    insertUser.withTableName("USERS");
    insertUser.usingColumns("USERNAME", "PASSWORD", "ENABLED");

    Map<String, Object> args = new HashMap<String, Object>(2);
    args.put("USERNAME", user.getUserId());
    args.put("PASSWORD", user.getUserPass());
    args.put("ENABLED", true);

    insertUser.execute(args);//from www  . j a va  2  s .  c  o  m

    return 0;
}

From source file:org.smigo.species.JdbcSpeciesDao.java

@Autowired
public void setDataSource(DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    this.insertSpecies = new SimpleJdbcInsert(dataSource).withTableName("species")
            .usingGeneratedKeyColumns("id").usingColumns("creator");
}

From source file:org.ala.spatial.services.dao.ActionDAOImpl.java

@Resource(name = "dataSource")
public void setDataSource(DataSource dataSource) {
    this.jdbcTemplate = new SimpleJdbcTemplate(dataSource);
    this.insertAction = new SimpleJdbcInsert(dataSource).withTableName("actions")
            .usingGeneratedKeyColumns("id");
    this.insertService = new SimpleJdbcInsert(dataSource).withTableName("services")
            .usingGeneratedKeyColumns("id");
}

From source file:com.rambird.miles.repository.jdbc.JdbcCatgRepositoryImpl.java

@Autowired
public JdbcCatgRepositoryImpl(DataSource dataSource, NamedParameterJdbcTemplate namedParameterJdbcTemplate) {

    this.insertMileCatg = new SimpleJdbcInsert(dataSource).withTableName("category")
            .usingGeneratedKeyColumns("catgid");

    this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}

From source file:de.siemens.quantarch.bugs.dao.IssueTrackerDaoImpl.java

@Override
public long addIssue(Issue issue, long projectId, List<BugHistory> bugHistoryList) {

    // Step 4: Add the users
    // a> Created By
    long createdBy = PersonServiceClient.getPerson(issue.getReporterName(), issue.getReporter(), projectId,
            projectConfig.getPersonServiceURL());
    long assignee = PersonServiceClient.getPerson(issue.getAssigneeName(), issue.getAssignee(), projectId,
            projectConfig.getPersonServiceURL());

    // Step 5: Add the issue
    // now add the issue record
    SimpleJdbcInsert insertPerson = new SimpleJdbcInsert(getDataSource()).withTableName("issue")
            .usingGeneratedKeyColumns("id");
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("bugId", issue.getId());
    parameters.put("creationDate", issue.getCreationTimestamp());
    parameters.put("modifiedDate", issue.getDeltaTimestamp());
    parameters.put("url", null);
    parameters.put("isRegression", 0);
    parameters.put("status", issue.getStatus());
    parameters.put("resolution", issue.getResolution());
    parameters.put("severity", issue.getSeverity());
    parameters.put("priority", issue.getPriority());
    parameters.put("createdBy", createdBy);
    parameters.put("assignedTo", assignee);
    parameters.put("projectId", projectId);

    if (projectConfig.isProductAsProject()) {
        // when product is parsed as a project
        // component becomes subComponent and subSubComponent is null
        parameters.put("subComponent", issue.getComponent());
    } else {/*  w  ww .jav  a  2 s  .com*/
        parameters.put("subComponent", issue.getProduct());
        parameters.put("subSubComponent", issue.getComponent());
    }

    parameters.put("version", issue.getVersion());

    Number newId = insertPerson.executeAndReturnKey(parameters);
    long issueId = newId.longValue();

    // Step 6: Populate cc list of the issue
    Iterator<String> iter = issue.getCcIterator();
    while (iter.hasNext()) {
        String cc = iter.next();
        long ccUser = PersonServiceClient.getPerson(null, cc, projectId, projectConfig.getPersonServiceURL());
        getJdbcTemplate().update("INSERT INTO cc_list (issueId,who) VALUES(?,?)", issueId, ccUser);
    }

    // Step 7: Populate issue communication / comments
    Iterator<LongDescription> longDescIter = issue.getLongDescriptionIterator();
    while (longDescIter.hasNext()) {
        LongDescription desc = longDescIter.next();
        Date date = desc.getWhen();
        String who = desc.getWho();
        long commentUser = PersonServiceClient.getPerson(desc.getAuthorName(), who, projectId,
                projectConfig.getPersonServiceURL());
        getJdbcTemplate().update("INSERT INTO issue_comment (who,fk_issueId,commentDate) VALUES(?,?,?)",
                commentUser, issueId, date);
    }

    // Step 8: add the bug history
    for (BugHistory record : bugHistoryList) {
        addBugHistory(record, issueId, projectId);
    }

    return issueId;
}

From source file:com.daugherty.e2c.persistence.data.jdbc.JdbcSupplierDao.java

@Override
protected void createSimpleJdbcInserts(DataSource dataSource) {
    super.createSimpleJdbcInserts(dataSource);
    partyAuditInsert = new SimpleJdbcInsert(dataSource).withTableName("party_audit")
            .usingGeneratedKeyColumns(PARTY_AUDIT_ID_COLUMN_NAME).usingColumns(PARTY_TYPE_COLUMN_NAME,
                    ENGLISH_NAME_COLUMN_NAME, DESCRIPTION_COLUMN_NAME, EMPLOYEES_COLUMN_NAME,
                    WEBSITE_COLUMN_NAME, YEAR_ESTABLISHED_COLUMN_NAME, ANNUAL_SALES_COLUMN_NAME,
                    FIRST_NAME_COLUMN_NAME, LAST_NAME_COLUMN_NAME, SKYPE_COLUMN_NAME, MSN_COLUMN_NAME,
                    ICQ_COLUMN_NAME, EMAIL_COLUMN_NAME, COUNTRY_COLUMN_NAME, LICENSE_LINK_COLUMN_NAME,
                    LOGO_LINK_COLUMN_NAME, GENDER_COLUMN_NAME, VIDEO_LINK_COLUMN_NAME,
                    BUSINESS_PHONE_COLUMN_NAME, LAST_MODIFIED_BY_COLUMN_NAME, LAST_MODIFIED_DATE_COLUMN_NAME);
}

From source file:au.org.ala.layers.dao.LayerDAOImpl.java

@Resource(name = "dataSource")
public void setDataSource(DataSource dataSource) {
    logger.info("setting data source in layers-store.layersDao");
    if (dataSource != null) {
        logger.info("dataSource is NOT null");
        logger.info(dataSource.toString());
    } else {//from w w  w.j a va 2s.  c  o  m
        logger.info("dataSource is null");
    }
    this.dataSource = dataSource;
    this.jdbcTemplate = new SimpleJdbcTemplate(dataSource);
    this.insertLayer = new SimpleJdbcInsert(dataSource).withTableName("layers").usingGeneratedKeyColumns("id");
}

From source file:com.fns.grivet.repo.JdbcEntityRepository.java

@Override
public Long newId(Integer cid, LocalDateTime createdTime) {
    return Long.valueOf(String.valueOf(new SimpleJdbcInsert(jdbcTemplate).withTableName("entity")
            .usingGeneratedKeyColumns("eid").usingColumns("cid", "created_time")
            .executeAndReturnKey(ImmutableMap.of("cid", cid, "created_time", Timestamp.valueOf(createdTime)))));
}

From source file:com.branded.holdings.qpc.repository.jdbc.JdbcOwnerRepositoryImpl.java

@Autowired
public JdbcOwnerRepositoryImpl(DataSource dataSource, NamedParameterJdbcTemplate namedParameterJdbcTemplate,
        VisitRepository visitRepository) {

    this.insertOwner = new SimpleJdbcInsert(dataSource).withTableName("owners").usingGeneratedKeyColumns("id");

    this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);

    this.visitRepository = visitRepository;
}