List of usage examples for org.springframework.jdbc.core.simple SimpleJdbcInsert SimpleJdbcInsert
public SimpleJdbcInsert(JdbcTemplate jdbcTemplate)
From source file:au.org.ala.layers.dao.FieldDAOImpl.java
@Resource(name = "dataSource") public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new SimpleJdbcTemplate(dataSource); this.insertField = new SimpleJdbcInsert(dataSource).withTableName("fields").usingColumns("id", "name", "\"desc\"", "sname", "sdesc", "sid", "addtomap", "\"intersect\"", "defaultlayer", "enabled", "layerbranch", "analysis", "indb", "spid", "namesearch", "type", "last_update"); }
From source file:org.smigo.message.JdbcMessageDao.java
@Autowired public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); this.insert = new SimpleJdbcInsert(dataSource).withTableName("messages").usingGeneratedKeyColumns("id") .usingColumns("text", "submitter_user_id", "locale"); }
From source file:com.branded.holdings.qpc.repository.jdbc.JdbcVisitRepositoryImpl.java
@Autowired public JdbcVisitRepositoryImpl(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); this.insertVisit = new SimpleJdbcInsert(dataSource).withTableName("visits").usingGeneratedKeyColumns("id"); }
From source file:org.smigo.comment.JdbcCommentDao.java
@Autowired public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); this.insert = new SimpleJdbcInsert(dataSource).withTableName("COMMENTS").usingGeneratedKeyColumns("ID") .usingColumns("TEXT", "SUBMITTER_USER_ID", "RECEIVER_USER_ID", "YEAR", "UNREAD"); }
From source file:com.catt.mobile.repository.jdbc.JdbcAccountRepositoryImpl.java
@Autowired public JdbcAccountRepositoryImpl(DataSource dataSource, NamedParameterJdbcTemplate namedParameterJdbcTemplate) { this.dataSource = dataSource; this.insertAccount = new SimpleJdbcInsert(dataSource).withTableName("account") .usingGeneratedKeyColumns("id"); this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); }
From source file:com.jagornet.dhcp.db.JdbcDhcpOptionDAO.java
public void create(DhcpOption option) { SimpleJdbcInsert insertOption = new SimpleJdbcInsert(getDataSource()).withTableName("dhcpoption") .usingGeneratedKeyColumns("id"); Long iaId = option.getIdentityAssocId(); Long iaAddrId = option.getIaAddressId(); Long iaPrefixId = option.getIaPrefixId(); if ((iaId == null) && (iaAddrId == null) && (iaPrefixId == null)) { throw new IllegalStateException("DhcpOption must reference either an IdentityAssoc, an IaAddress"); }/*from w w w . jav a 2 s . co m*/ if ((iaId != null) && (iaAddrId != null)) { throw new IllegalStateException("DhcpOption cannot reference both an IdentityAssoc and an IaAddress"); } if ((iaId != null) && (iaPrefixId != null)) { throw new IllegalStateException("DhcpOption cannot reference both an IdentityAssoc and an IaPrefix"); } if ((iaAddrId != null) && (iaPrefixId != null)) { throw new IllegalStateException("DhcpOption cannot reference both an IaAddress and an IaPrefix"); } Map<String, Object> parameters = new HashMap<String, Object>(3); parameters.put("code", option.getCode()); parameters.put("value", option.getValue()); // TODO: verify that the option has only one foreign key if (iaId != null) { parameters.put("identityassoc_id", iaId); insertOption.usingColumns("code", "value", "identityassoc_id"); } else if (iaAddrId != null) { parameters.put("iaaddress_id", iaAddrId); insertOption.usingColumns("code", "value", "iaaddress_id"); } else if (iaPrefixId != null) { parameters.put("iaprefix_id", iaAddrId); insertOption.usingColumns("code", "value", "iaprefix_id"); } /** * Note: see https://issues.apache.org/jira/browse/DERBY-3609 * "Formally, Derby does not support getGeneratedKeys since * DatabaseMetaData.supportsGetGeneratedKeys() returns false. * However, Statement.getGeneratedKeys() is partially implemented, * ... since it will only return a meaningful result when an single * row insert is done with INSERT...VALUES" * * Spring has thus provided a workaround as described here: * http://jira.springframework.org/browse/SPR-5306 */ Number newId = insertOption.executeAndReturnKey(parameters); if (newId != null) { option.setId(newId.longValue()); } }
From source file:org.ala.spatial.services.dao.ApplicationDAOImpl.java
@Resource(name = "dataSource") public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new SimpleJdbcTemplate(dataSource); this.insertApplication = new SimpleJdbcInsert(dataSource).withTableName("applications") .usingGeneratedKeyColumns("id"); }
From source file:com.branded.holdings.qpc.repository.jdbc.JdbcTopicRepositoryImpl.java
@Autowired public JdbcTopicRepositoryImpl(DataSource dataSource) { this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); this.insertTopic = new SimpleJdbcInsert(dataSource).withTableName("topic").usingGeneratedKeyColumns("id"); }
From source file:io.github.huherto.springyRecords.BaseTable.java
public BaseTable(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); insertCommand = new SimpleJdbcInsert(dataSource); insertCommand.withTableName(tableName()); autoIncrementField = RecordUtils.autoIncrementField(recordClass()); if (autoIncrementField != null) { insertCommand.setGeneratedKeyName(autoIncrementField.getAnnotation(Column.class).name()); }//from w w w .ja v a2 s. c o m }
From source file:org.sakuli.services.receiver.database.dao.impl.DaoTestSuiteImpl.java
/** * {@inheritDoc}/*from www . j a v a 2 s.c o m*/ */ @Override public int insertInitialTestSuiteData() { logger.info("Build SQL query for new primary key in table 'sahi_suites'"); testSuite.refreshState(); MapSqlParameterSource tcParameters = getInitialDataParameters(); logger.info("write the following values to 'sahi_suites': " + tcParameters.getValues() + " ==> now execute ...."); SimpleJdbcInsert insertInitialSuiteData = new SimpleJdbcInsert(getDataSource()).withTableName("sahi_suites") .usingGeneratedKeyColumns("id"); int dbPrimaryKey = insertInitialSuiteData.executeAndReturnKey(tcParameters).intValue(); logger.info("test suite \"" + testSuite.getId() + "\" has been written to 'sahi_suites' with primaryKey=" + dbPrimaryKey); return dbPrimaryKey; }