List of usage examples for org.springframework.jdbc.core PreparedStatementCreator PreparedStatementCreator
PreparedStatementCreator
From source file:com.webapp.security.SecurityDataContext.java
/** * @param role/*from w w w . j av a2 s . co m*/ */ private boolean createRole(final Role role) { if (role != null) { final String insertRoleSql = "insert into SECURITY_ROLE (CONTEXT, ROLE, DESCRIPTION) values (?,?,?)"; final String insertRolePermSql = "insert into SECURITY_ROLE_PERMISSION (CONTEXT, ROLE, TARGET, PERMISSION) values (?,?,?,?)"; LOG.info("Inserting new role (" + role.getName() + "-" + role.getDescription() + ") into " + getName() + " context"); // If there is a value for the password... if (role.getName() != null && role.getName().trim().length() > 0) { try { jdbcTemplate.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(insertRoleSql.toString(), Statement.RETURN_GENERATED_KEYS); ps.setString(1, getName().toLowerCase()); //context ps.setString(2, role.getName().toLowerCase()); // name ps.setString(3, role.getDescription()); // description return ps; } }); } catch (DataAccessException e) { LOG.error("Could not create role: " + e.getMessage()); return false; } // now we have to insert any permissions in the role List<Permission> perms = role.getPermissions(); for (final Permission perm : perms) { try { jdbcTemplate.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(insertRolePermSql.toString(), Statement.RETURN_GENERATED_KEYS); ps.setString(1, getName().toLowerCase()); //context ps.setString(2, role.getName().toLowerCase()); // name ps.setString(3, perm.getTarget()); // target of the permission ps.setLong(4, perm.getAction()); return ps; } }); } catch (DataAccessException e) { LOG.error("Could not record permission target '" + perm.getTarget() + "' for role '" + role.getName() + "' : " + e.getMessage()); return false; } } return true; } else { LOG.error("Empty role name - role not added"); } } else { LOG.error("Null role cannot be added to context"); } return false; }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void insert(final Standplaats standplaats) throws DAOException { try {/*from ww w . j a v a 2 s . com*/ transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection .prepareStatement("insert into bag_standplaats (" + "bag_standplaats_id," + "aanduiding_record_inactief," + "aanduiding_record_correctie," + "officieel," + "standplaats_status," + "standplaats_geometrie," + "begindatum_tijdvak_geldigheid," + "einddatum_tijdvak_geldigheid," + "in_onderzoek," + "bron_documentdatum," + "bron_documentnummer," + "bag_nummeraanduiding_id" + ") values (?,?,?,?,?,?,?,?,?,?,?,?)"); ps.setLong(1, standplaats.getIdentificatie()); ps.setInt(2, standplaats.getAanduidingRecordInactief().ordinal()); ps.setLong(3, standplaats.getAanduidingRecordCorrectie()); ps.setInt(4, standplaats.getOfficieel().ordinal()); ps.setInt(5, standplaats.getStandplaatsStatus().ordinal()); ps.setString(6, standplaats.getStandplaatsGeometrie()); ps.setTimestamp(7, new Timestamp(standplaats.getBegindatumTijdvakGeldigheid().getTime())); if (standplaats.getEinddatumTijdvakGeldigheid() == null) ps.setNull(8, Types.TIMESTAMP); else ps.setTimestamp(8, new Timestamp(standplaats.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(9, standplaats.getInOnderzoek().ordinal()); ps.setDate(10, new Date(standplaats.getDocumentdatum().getTime())); ps.setString(11, standplaats.getDocumentnummer()); ps.setLong(12, standplaats.getHoofdAdres()); return ps; } }); insertNevenadressen(TypeAdresseerbaarObject.STANDPLAATS, standplaats); } }); } catch (DataAccessException e) { throw new DAOException("Error inserting standplaats: " + standplaats.getIdentificatie(), e); } }
From source file:com.skycloud.management.portal.admin.sysmanage.dao.impl.UserManageDaoImpl.java
@Override public int saveCompany(final TCompanyInfo tcompanyinfo) throws SQLException { KeyHolder keyHolder = new GeneratedKeyHolder(); final String sql = "insert into T_SCS_COMPANY_INFO (COMP_LEGAL_PERSON,COMP_CN_NAME," + "COMP_LEGAL_PERSON_ID," + " COMP_ADDRESS,POST_CODE," + " COMP_PHONE,RELA_MOBILE,COMP_FAX,COMP_EMAIL," + " COMP_ORG_CODE,BUS_LICENSE_NUM, " + " COMP_BANK_NAME,COMP_BANK_ACCOUNT,FIR_CHECK_COMMENT,CHECK_STATE,BLN_START_TIME,BLN_END_TIME) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,4,?,?);"; try {//from w ww.j a v a2s . co m this.getJdbcTemplate().update(new PreparedStatementCreator() { int i = 1; @Override public PreparedStatement createPreparedStatement(Connection con) throws SQLException { PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); ps.setString(i++, tcompanyinfo.getCompLegalPerson()); ps.setString(i++, tcompanyinfo.getCompCnName()); ps.setString(i++, tcompanyinfo.getCompLegalPersonId()); ps.setString(i++, tcompanyinfo.getCompAddress()); ps.setString(i++, tcompanyinfo.getPostCode()); ps.setString(i++, tcompanyinfo.getCompPhone()); ps.setString(i++, tcompanyinfo.getRelaMobile()); ps.setString(i++, tcompanyinfo.getCompFax()); ps.setString(i++, tcompanyinfo.getCompEmail()); ps.setString(i++, tcompanyinfo.getCompOrgCode()); ps.setString(i++, tcompanyinfo.getBusLicenseNum()); ps.setString(i++, tcompanyinfo.getCompBankName()); ps.setString(i++, tcompanyinfo.getCompBankAccount()); ps.setString(i++, tcompanyinfo.getFirCheckComment()); ps.setTimestamp(i++, new Timestamp(new Date(System.currentTimeMillis()).getTime())); ps.setTimestamp(i++, new Timestamp(new Date(System.currentTimeMillis()).getTime())); return ps; } }, keyHolder); } catch (Exception e) { e.printStackTrace(); throw new SQLException("?"); } return keyHolder.getKey().intValue(); }
From source file:info.raack.appliancelabeler.data.JDBCDatabase.java
public void storeUserOnOffLabels(final List<ApplianceStateTransition> detectedStateTransitions) { for (final ApplianceStateTransition transition : detectedStateTransitions) { KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement(insertApplianceStateTransition, new String[] { "id" }); ps.setInt(1, transition.getUserAppliance().getId()); if (transition.getDetectionAlgorithmId() > 0) { ps.setInt(2, transition.getDetectionAlgorithmId()); } else { ps.setNull(2, Types.INTEGER); }// w w w .ja v a 2 s . c o m ps.setLong(3, transition.getTime()); ps.setBoolean(4, transition.isOn()); return ps; } }, keyHolder); transition.setId(keyHolder.getKey().intValue()); } }
From source file:info.raack.appliancelabeler.data.JDBCDatabase.java
public void addUserAppliance(final EnergyMonitor energyMonitor, final UserAppliance userAppliance) { logger.debug("Inserting new user appliance " + userAppliance + " for energy monitor " + energyMonitor); // look for energy monitor id int id = energyMonitor.getId(); if (id <= 0) { id = getIdForEnergyMonitor(energyMonitor); energyMonitor.setId(id);// ww w.java 2 s .c o m } KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection .prepareStatement(userAppliance.getAlgorithmId() > 0 ? insertForNewUserApplianceForAlgorithm : insertForNewUserAppliance, new String[] { "id" }); ps.setInt(1, energyMonitor.getId()); ps.setLong(2, userAppliance.getAppliance().getId()); ps.setString(3, userAppliance.getName()); int next = 4; if (userAppliance.getAlgorithmId() > 0) { ps.setInt(next++, userAppliance.getAlgorithmId()); } ps.setBoolean(next++, userAppliance.isAlgorithmGenerated()); return ps; } }, keyHolder); userAppliance.setId(keyHolder.getKey().intValue()); }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void update(final Woonplaats woonplaats) throws DAOException { try {//from w ww . jav a 2 s . c om jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("update bag_woonplaats set" + " aanduiding_record_inactief = ?," + " woonplaats_naam = ?," + " woonplaats_geometrie = ?," + " officieel = ?," + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?," + " bron_documentdatum = ?," + " bron_documentnummer = ?," + " woonplaats_status = ?" + " where bag_woonplaats_id = ?" + " and aanduiding_record_correctie = ?" + " and begindatum_tijdvak_geldigheid = ?"); ps.setInt(1, woonplaats.getAanduidingRecordInactief().ordinal()); ps.setString(2, woonplaats.getWoonplaatsNaam()); ps.setString(3, woonplaats.getWoonplaatsGeometrie()); ps.setInt(4, woonplaats.getOfficieel().ordinal()); if (woonplaats.getEinddatumTijdvakGeldigheid() == null) ps.setNull(5, Types.TIMESTAMP); else ps.setTimestamp(5, new Timestamp(woonplaats.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(6, woonplaats.getInOnderzoek().ordinal()); ps.setDate(7, new Date(woonplaats.getDocumentdatum().getTime())); ps.setString(8, woonplaats.getDocumentnummer()); ps.setInt(9, woonplaats.getWoonplaatsStatus().ordinal()); ps.setLong(10, woonplaats.getIdentificatie()); ps.setLong(11, woonplaats.getAanduidingRecordCorrectie()); ps.setTimestamp(12, new Timestamp(woonplaats.getBegindatumTijdvakGeldigheid().getTime())); return ps; } }); } catch (DataAccessException e) { throw new DAOException("Error updating woonplaats: " + woonplaats.getIdentificatie(), e); } }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void update(final OpenbareRuimte openbareRuimte) throws DAOException { try {// www.j ava 2s . c om jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("update bag_openbare_ruimte set" + " aanduiding_record_inactief = ?," + " openbare_ruimte_naam = ?," + " officieel = ?," + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?," + " openbare_ruimte_type = ?," + " bron_documentdatum = ?," + " bron_documentnummer = ?," + " openbareruimte_status = ?," + " bag_woonplaats_id = ?," + " verkorte_openbare_ruimte_naam = ?" + " where bag_openbare_ruimte_id = ?" + " and aanduiding_record_correctie = ?" + " and begindatum_tijdvak_geldigheid = ?"); ps.setInt(1, openbareRuimte.getAanduidingRecordInactief().ordinal()); ps.setString(2, openbareRuimte.getOpenbareRuimteNaam()); ps.setInt(3, openbareRuimte.getOfficieel().ordinal()); if (openbareRuimte.getEinddatumTijdvakGeldigheid() == null) ps.setNull(4, Types.TIMESTAMP); else ps.setTimestamp(4, new Timestamp(openbareRuimte.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(5, openbareRuimte.getInOnderzoek().ordinal()); ps.setInt(6, openbareRuimte.getOpenbareRuimteType().ordinal()); ps.setDate(7, new Date(openbareRuimte.getDocumentdatum().getTime())); ps.setString(8, openbareRuimte.getDocumentnummer()); ps.setInt(9, openbareRuimte.getOpenbareruimteStatus().ordinal()); ps.setLong(10, openbareRuimte.getGerelateerdeWoonplaats()); ps.setString(11, openbareRuimte.getVerkorteOpenbareRuimteNaam()); ps.setLong(12, openbareRuimte.getIdentificatie()); ps.setLong(13, openbareRuimte.getAanduidingRecordCorrectie()); ps.setTimestamp(14, new Timestamp(openbareRuimte.getBegindatumTijdvakGeldigheid().getTime())); return ps; } }); } catch (DataAccessException e) { throw new DAOException("Error updating openbare ruimte: " + openbareRuimte.getIdentificatie(), e); } }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void update(final Nummeraanduiding nummeraanduiding) throws DAOException { try {/*from w w w .j a v a 2 s .c o m*/ jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("update bag_nummeraanduiding set" + " aanduiding_record_inactief = ?," + " huisnummer = ?," + " officieel = ?," + " huisletter = ?," + " huisnummertoevoeging = ?," + " postcode = ?," + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?," + " type_adresseerbaar_object = ?," + " bron_documentdatum = ?," + " bron_documentnummer = ?," + " nummeraanduiding_status = ?," + " bag_woonplaats_id = ?," + " bag_openbare_ruimte_id = ?" + " where bag_nummeraanduiding_id = ?" + " and aanduiding_record_correctie = ?" + " and begindatum_tijdvak_geldigheid = ?"); ps.setInt(1, nummeraanduiding.getAanduidingRecordInactief().ordinal()); ps.setInt(2, nummeraanduiding.getHuisnummer()); ps.setInt(3, nummeraanduiding.getOfficieel().ordinal()); if (nummeraanduiding.getHuisletter() == null) ps.setNull(4, Types.INTEGER); else ps.setString(4, nummeraanduiding.getHuisletter()); if (nummeraanduiding.getHuisnummertoevoeging() == null) ps.setNull(5, Types.VARCHAR); else ps.setString(5, nummeraanduiding.getHuisnummertoevoeging()); if (nummeraanduiding.getPostcode() == null) ps.setNull(6, Types.VARCHAR); else ps.setString(6, nummeraanduiding.getPostcode()); if (nummeraanduiding.getEinddatumTijdvakGeldigheid() == null) ps.setNull(7, Types.TIMESTAMP); else ps.setTimestamp(7, new Timestamp(nummeraanduiding.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(8, nummeraanduiding.getInOnderzoek().ordinal()); ps.setInt(9, nummeraanduiding.getTypeAdresseerbaarObject().ordinal()); ps.setDate(10, new Date(nummeraanduiding.getDocumentdatum().getTime())); ps.setString(11, nummeraanduiding.getDocumentnummer()); ps.setInt(12, nummeraanduiding.getNummeraanduidingStatus().ordinal()); if (nummeraanduiding.getGerelateerdeWoonplaats() == null) ps.setNull(13, Types.INTEGER); else ps.setLong(13, nummeraanduiding.getGerelateerdeWoonplaats()); ps.setLong(14, nummeraanduiding.getGerelateerdeOpenbareRuimte()); ps.setLong(15, nummeraanduiding.getIdentificatie()); ps.setLong(16, nummeraanduiding.getAanduidingRecordCorrectie()); ps.setTimestamp(17, new Timestamp(nummeraanduiding.getBegindatumTijdvakGeldigheid().getTime())); return ps; } }); } catch (DataAccessException e) { throw new DAOException("Error updating nummeraanduiding: " + nummeraanduiding.getIdentificatie(), e); } }
From source file:com.prosnav.oms.dao.CustDao.java
public int insertAndGetKey(final String sql, final Object[] o, String id) { KeyHolder keyHolder = new GeneratedKeyHolder(); jt.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { // String sql_sms = "insert into // sms(title,content,date_s,form,sffs,by1,by2,by3) values // (?,?,'"+dates+"',?,?,?,?,?)"; PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); for (int i = 0; i < o.length; i++) { ps.setObject(i + 1, o[i]); }/* w w w .j a v a 2 s .c om*/ return ps; } }, keyHolder); Map<String, Object> generatedId = keyHolder.getKeyList().get(0); Integer com_id = (Integer) generatedId.get(id); // Long generatedId = keyHolder.getKey().longValue(); // int a =Integer.parseInt(o_id); return com_id; }
From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java
@Override public void update(final Pand pand) throws DAOException { try {/*www. j a v a2s. co m*/ jdbcTemplate.update(new PreparedStatementCreator() { @Override public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { PreparedStatement ps = connection.prepareStatement("update bag_pand set" + " aanduiding_record_inactief = ?," + " officieel = ?," + " pand_geometrie = ?," + " bouwjaar = ?," + " pand_status = ?," + " einddatum_tijdvak_geldigheid = ?," + " in_onderzoek = ?," + " bron_documentdatum = ?," + " bron_documentnummer = ?" + " where bag_pand_id = ?" + " and aanduiding_record_correctie = ?" + " and begindatum_tijdvak_geldigheid = ?"); ps.setInt(1, pand.getAanduidingRecordInactief().ordinal()); ps.setInt(2, pand.getOfficieel().ordinal()); ps.setString(3, pand.getPandGeometrie()); ps.setInt(4, pand.getBouwjaar()); ps.setString(5, pand.getPandStatus()); if (pand.getEinddatumTijdvakGeldigheid() == null) ps.setNull(6, Types.TIMESTAMP); else ps.setTimestamp(6, new Timestamp(pand.getEinddatumTijdvakGeldigheid().getTime())); ps.setInt(7, pand.getInOnderzoek().ordinal()); ps.setDate(8, new Date(pand.getDocumentdatum().getTime())); ps.setString(9, pand.getDocumentnummer()); ps.setLong(10, pand.getIdentificatie()); ps.setLong(11, pand.getAanduidingRecordCorrectie()); ps.setTimestamp(12, new Timestamp(pand.getBegindatumTijdvakGeldigheid().getTime())); return ps; } }); } catch (DataAccessException e) { throw new DAOException("Error updating pand: " + pand.getIdentificatie(), e); } }