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:com.dojo.parkinglot.dao.VehicleDaoImpl.java

@Autowired
public void setDataSource(DataSource dataSource) {
    template = new JdbcTemplate(dataSource);
    insert_vehicle = new SimpleJdbcInsert(dataSource).withTableName(VEHICLES_TABLE)
            .usingColumns("licensePlate", "type").usingGeneratedKeyColumns("id");
}

From source file:com.manning.siia.batch.PaymentWriter.java

public PaymentWriter(DataSource dataSource) {
    paymentInsert = new SimpleJdbcInsert(dataSource).withTableName("PAYMENTS").usingColumns("RECIPIENT",
            "PAYEE", "AMOUNT", "PAY_DATE");
    accountUpdate = new JdbcTemplate(dataSource);
}

From source file:edu.northwestern.bioinformatics.studycalendar.dao.auditing.AuditEventDao.java

public void saveEvent(AuditEvent event) {
    SimpleJdbcInsert insert = new SimpleJdbcInsert(jdbcTemplate.getDataSource());
    insert.withTableName("audit_events");
    Map<String, Object> parameters = new HashMap<String, Object>();
    final DataAuditInfo info = event.getInfo();
    final DataReference reference = event.getReference();
    parameters.put("ip_address", info.getIp());
    parameters.put("user_name", info.getUsername());
    parameters.put("time", info.getTime());
    parameters.put("class_name", reference.getClassName());
    parameters.put("operation", event.getOperation().toString());
    parameters.put("url", info.getUrl());
    /*  Note: version is hardcoded to 0 otherwise SQLException is thrown for non-nullable column,
    if not included in SimpleJdbcInsert query's parameters.
     *///from   w  w w .  j  av  a2 s . c o m
    parameters.put("version", 0);
    parameters.put("object_id", reference.getId());
    parameters.put("user_action_id", event.getUserActionId());

    if (databaseType.contains("Oracle")) {
        int eventId = jdbcTemplate.queryForInt("SELECT SEQ_AUDIT_EVENTS_ID.nextval FROM dual");
        parameters.put("id", eventId);
        insert.execute(parameters);
        final String updateStatement = "insert into audit_event_values(id, audit_event_id, attribute_name , previous_value, new_value) values (?,?,?,?,?)";
        for (DataAuditEventValue value : event.getValues()) {
            int valueId = jdbcTemplate.queryForInt("SELECT SEQ_AUDIT_EVENT_VALUES_ID.nextval FROM dual");
            jdbcTemplate.update(updateStatement, new Object[] { valueId, eventId, value.getAttributeName(),
                    value.getPreviousValue(), value.getCurrentValue() });
        }
    } else {
        int eventId = insert.usingGeneratedKeyColumns("id").executeAndReturnKey(parameters).intValue();
        final String updateStatement = "insert into audit_event_values(audit_event_id, attribute_name , previous_value, new_value) values (?,?,?,?)";
        for (DataAuditEventValue value : event.getValues()) {
            jdbcTemplate.update(updateStatement, new Object[] { eventId, value.getAttributeName(),
                    value.getPreviousValue(), value.getCurrentValue() });
        }
    }
}

From source file:org.cbarrett.lcbo.db.LCBODatasetDAOImpl.java

public void setDataSource(DataSource dataSource) {
    this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
    this.insertDataset = new SimpleJdbcInsert(dataSource).withTableName("DATASET");
}

From source file:com.griddynamics.spring.batch.football.internal.JdbcGameDao.java

protected void initDao() throws Exception {
    super.initDao();
    insertGame = new SimpleJdbcInsert(getDataSource()).withTableName("games").usingColumns("player_id",
            "year_no", "team", "week", "opponent", " completes", "attempts", "passing_yards", "passing_td",
            "interceptions", "rushes", "rush_yards", "receptions", "receptions_yards", "total_td");
}

From source file:ru.org.linux.edithistory.EditHistoryDao.java

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

    editInsert = new SimpleJdbcInsert(dataSource).withTableName("edit_info").usingColumns("msgid", "editor",
            "oldmessage", "oldtitle", "oldtags", "oldlinktext", "oldurl", "object_type", "oldminor",
            "oldimage");

}

From source file:org.smigo.species.varieties.JdbcVarietyDao.java

@Autowired
public void setDataSource(DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    this.insert = new SimpleJdbcInsert(dataSource).withTableName("VARIETIES").usingGeneratedKeyColumns("ID")
            .usingColumns("NAME", "USER_ID", "SPECIES_ID");
}

From source file:com.github.akiraly.db4j.SimpleJdbcInsertBuilder.java

@Override
public final SimpleJdbcInsert get() {
    SimpleJdbcInsert result = new SimpleJdbcInsert(jdbcTemplate()).withTableName(tableName)
            .usingGeneratedKeyColumns(generatedKeyColumns);
    result.compile();//w  w  w .ja  v  a  2s. com
    return result;
}

From source file:ru.org.linux.user.MemoriesDao.java

@Autowired
public void setDataSource(DataSource ds) {
    jdbcTemplate = new JdbcTemplate(ds);
    insertTemplate = new SimpleJdbcInsert(ds).withTableName("memories").usingGeneratedKeyColumns("id")
            .usingColumns("userid", "topic", "watch");
}

From source file:com.nebhale.cyclinglibrary.repository.JdbcTaskRepository.java

@Autowired
JdbcTaskRepository(DataSource dataSource) {
    this.jdbcTemplate = new JdbcTemplate(dataSource);
    this.createStatement = new SimpleJdbcInsert(dataSource).withTableName("tasks")
            .usingGeneratedKeyColumns("id");
}