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.receiver.database.dao.impl.DaoTestCaseImpl.java

@Override
public void saveTestCaseResult(final TestCase testCase) {
    logger.info("Save results for test case \"" + testCase.getId() + "\"");

    //create a map for the sql parameters
    MapSqlParameterSource tcParameters = new MapSqlParameterSource();
    tcParameters.addValue("sahi_suites_id", testSuite.getDbPrimaryKey());
    tcParameters.addValue("caseID", testCase.getId());
    tcParameters.addValue("result", testCase.getState().getErrorCode());
    tcParameters.addValue("result_desc", testCase.getState());
    tcParameters.addValue("name", testCase.getName());
    tcParameters.addValue("guid", testSuite.getGuid());
    tcParameters.addValue("start", testCase.getStartDateAsUnixTimestamp());
    tcParameters.addValue("stop", testCase.getStopDateAsUnixTimestamp());
    tcParameters.addValue("warning", testCase.getWarningTime());
    tcParameters.addValue("critical", testCase.getCriticalTime());
    tcParameters.addValue("browser", testSuite.getBrowserInfo());
    tcParameters.addValue("lastpage", testCase.getLastURL());

    //try to save the screenshot
    try {//from   w  w  w.ja  va  2  s  .  c  om
        if (testCase.getScreenShotPath() != null) {
            final InputStream blobIs = Files.newInputStream(testCase.getScreenShotPath());
            final int length = (int) testCase.getScreenShotPath().toFile().length();
            tcParameters.addValue("screenshot", new SqlLobValue(blobIs, length, lobHandler), Types.BLOB);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    tcParameters.addValue("duration", testCase.getDuration());
    tcParameters.addValue("msg", testCase.getExceptionMessages());

    //generate the sql-statement
    SimpleJdbcInsert insertTCResults = new SimpleJdbcInsert(getDataSource()).withTableName("sahi_cases")
            .usingGeneratedKeyColumns("id");

    logger.info(
            "write the following values to 'sahi_cases': " + tcParameters.getValues() + " => now execute ....");

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

    logger.info("test case '" + testCase.getId() + "' has been written to 'sahi_cases' with  primaryKey="
            + dbPrimaryKey);
    testCase.setDbPrimaryKey(dbPrimaryKey);
}

From source file:at.ac.tuwien.qse.sepm.dao.impl.JDBCPhotoDAO.java

@Override
@Autowired/*from   ww  w  .ja v a2s . c  o  m*/
public void setDataSource(DataSource dataSource) {
    super.setDataSource(dataSource);
    this.insertPhoto = new SimpleJdbcInsert(dataSource).withTableName("Photo").usingGeneratedKeyColumns("id");
}

From source file:ru.org.linux.comment.CommentDaoImpl.java

@Autowired
public void setDataSource(DataSource dataSource) {
    jdbcTemplate = new JdbcTemplate(dataSource);

    insertMsgbase = new SimpleJdbcInsert(dataSource);
    insertMsgbase.setTableName("msgbase");
    insertMsgbase.usingColumns("id", "message", "bbcode");
}

From source file:at.ac.tuwien.qse.sepm.dao.impl.JDBCSlideDAO.java

@Override
@Autowired/*from  w  w w.  j a va 2s  . co m*/
public void setDataSource(DataSource dataSource) {
    super.setDataSource(dataSource);
    this.insertSlide = new SimpleJdbcInsert(dataSource).withTableName("Slide").usingGeneratedKeyColumns("id");
}

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

/**
 * Populate the issue_history table with the history data of the issue
 * //from   w w w  .ja va2  s  . c o  m
 * @param history
 * @param issueId
 * @param projectId
 */
private void addBugHistory(BugHistory history, long issueId, long projectId) {
    SimpleJdbcInsert insertPerson = new SimpleJdbcInsert(getDataSource()).withTableName("issue_history")
            .usingGeneratedKeyColumns("id");
    Map<String, Object> parameters = new HashMap<String, Object>(2);
    parameters.put("field", history.getField());
    parameters.put("changeDate", history.getWhen());
    parameters.put("oldValue", history.getOldValue());
    parameters.put("newValue", history.getNewValue());
    parameters.put("issueId", issueId);

    // get the person who changed the history
    long commentUser = PersonServiceClient.getPerson(null, history.getWho(), projectId,
            projectConfig.getPersonServiceURL());
    parameters.put("who", commentUser);
    insertPerson.executeAndReturnKey(parameters);
}

From source file:com.wandrell.pattern.repository.spring.SpringJdbcRepository.java

/**
 * Constructs a {@code SpringJDBCRepository} with the specified data and
 * queries.//from  ww  w  .  ja v  a2 s  .  co m
 * <p>
 * It will require templated queries for the update and delete operations.
 * The parameters for these queries will be acquired automatically from the
 * entity received for each of the operations.
 * <p>
 * The recommended delete query just requires knowing the ID of the entity,
 * so it can be similar to this:
 * <p>
 * {@code DELETE FROM employees WHERE id = :id"}
 * <p>
 * The update query requires all the columns which will be updated:
 * <p>
 * {@code UPDATE employees SET name = :name WHERE id = :id}
 * <p>
 * Any additional query which may be required, such as one for acquiring all
 * the entities, will be built from the received data.
 *
 * @param type
 *            the class of the objects to be returned
 * @param source
 *            source of the data
 * @param update
 *            query template for updating an entity on the database
 * @param delete
 *            query template for deleting an entity on the database
 * @param table
 *            table linked to the repository's entities
 * @param keys
 *            primary keys of the table
 */
public SpringJdbcRepository(final Class<V> type, final DataSource source, final String update,
        final String delete, final String table, final String... keys) {
    super();

    checkNotNull(type, "Received a null pointer as the class type");
    checkNotNull(source, "Received a null pointer as the data source");
    checkNotNull(update, "Received a null pointer as the update query");
    checkNotNull(delete, "Received a null pointer as the delete query");
    checkNotNull(table, "Received a null pointer as the table");
    checkNotNull(keys, "Received a null pointer as the key columns");

    classType = type;

    // Queries
    selectAllQuery = String.format("SELECT * FROM %s", table);
    updateQueryTemplate = update;
    deleteQueryTemplate = delete;

    insertHandler = new SimpleJdbcInsert(source).withTableName(table).usingGeneratedKeyColumns(keys);

    jdbcTemplate = new NamedParameterJdbcTemplate(source);
}

From source file:org.zenoss.zep.dao.impl.EventSummaryDaoImpl.java

public EventSummaryDaoImpl(DataSource dataSource) throws MetaDataAccessException {
    this.dataSource = dataSource;
    this.template = (SimpleJdbcOperations) Proxy.newProxyInstance(SimpleJdbcOperations.class.getClassLoader(),
            new Class<?>[] { SimpleJdbcOperations.class }, new SimpleJdbcTemplateProxy(dataSource));
    this.insert = new SimpleJdbcInsert(dataSource).withTableName(TABLE_EVENT_SUMMARY);
}

From source file:com.wandrell.pattern.repository.spring.SpringJdbcRepository.java

/**
 * Constructs a {@code SpringJDBCRepository} with the specified data and
 * queries./*from  www. j  a  va 2s.  c  o  m*/
 * <p>
 * It will require templated queries for the update and delete operations.
 * The parameters for these queries will be acquired automatically from the
 * entity received for each of the operations.
 * <p>
 * The recommended delete query just requires knowing the ID of the entity,
 * so it can be similar to this:
 * <p>
 * {@code DELETE FROM employees WHERE id = :id"}
 * <p>
 * The update query requires all the columns which will be updated:
 * <p>
 * {@code UPDATE employees SET name = :name WHERE id = :id}
 * <p>
 * Any additional query which may be required, such as one for acquiring all
 * the entities, will be built from the received data.
 *
 * @param type
 *            the class of the objects to be returned
 * @param template
 *            JDBC template with access to the data
 * @param update
 *            query template for updating an entity on the database
 * @param delete
 *            query template for deleting an entity on the database
 * @param table
 *            table linked to the repository's entities
 * @param keys
 *            primary keys of the table
 */
public SpringJdbcRepository(final Class<V> type, final JdbcTemplate template, final String update,
        final String delete, final String table, final String... keys) {
    super();

    checkNotNull(type, "Received a null pointer as the class type");
    checkNotNull(template, "Received a null pointer as the JDBC template");
    checkNotNull(update, "Received a null pointer as the update query");
    checkNotNull(delete, "Received a null pointer as the delete query");
    checkNotNull(table, "Received a null pointer as the table");
    checkNotNull(keys, "Received a null pointer as the key columns");

    classType = type;

    // Queries
    selectAllQuery = String.format("SELECT * FROM %s", table);
    updateQueryTemplate = update;
    deleteQueryTemplate = delete;

    insertHandler = new SimpleJdbcInsert(template).withTableName(table).usingGeneratedKeyColumns(keys);

    jdbcTemplate = new NamedParameterJdbcTemplate(template);
}

From source file:com.krawler.workflow.module.dao.DataObjectOperationDAOImpl.java

public boolean createDataObject(String objName, Map<String, Object> dataObject) {
    boolean result = true;

    try {//from   ww  w  .j a v  a  2 s  .c  o  m
        SimpleJdbcInsert insert = new SimpleJdbcInsert(getJdbcTemplate()).withTableName(getTableName(objName));
        insert.execute(dataObject);
    } catch (Exception e) {
        LOG.warn("Can not insert record", e);
        result = false;
    }

    return result;
}

From source file:org.ojbc.policyacknowledgement.dao.PolicyDAOImpl.java

@Autowired
public void setDataSource(DataSource dataSource) {
    this.insertUser = new SimpleJdbcInsert(dataSource).withTableName("ojbc_user")
            .usingGeneratedKeyColumns("id");
}