List of usage examples for org.springframework.jdbc.core.namedparam MapSqlParameterSource addValue
public MapSqlParameterSource addValue(String paramName, @Nullable Object value)
From source file:org.sakuli.services.forwarder.database.dao.impl.DaoTestSuiteImpl.java
private MapSqlParameterSource getCompleteParameters() { MapSqlParameterSource tcParameters = getInitialDataParameters(); tcParameters.addValues(getGuidParameter().getValues()); tcParameters.addValue("stop", testSuite.getStopDateAsUnixTimestamp()); int warningTime = testSuite.getWarningTime(); tcParameters.addValue("warning", (warningTime != 0) ? warningTime : null); int criticalTime = testSuite.getCriticalTime(); tcParameters.addValue("critical", (criticalTime != 0) ? criticalTime : null); tcParameters.addValue("duration", testSuite.getDuration()); //try to save the screenshot try {/*from ww w.j a va 2s. c o m*/ if (testSuite.getScreenShotPath() != null) { final InputStream blobIs = Files.newInputStream(testSuite.getScreenShotPath()); final int length = (int) testSuite.getScreenShotPath().toFile().length(); tcParameters.addValue("screenshot", new SqlLobValue(blobIs, length, lobHandler), Types.BLOB); } } catch (IOException e) { throw new RuntimeException(e); } tcParameters.addValue("msg", testSuite.getExceptionMessages()); return tcParameters; }
From source file:net.mindengine.oculus.frontend.db.jdbc.MySimpleJdbcDaoSupport.java
/** * Executes a sql query and converts the JDBC ResultSet to a list of java * bean objects./* w w w . j a va 2s .com*/ * * @param sql * The SQL command string * @param mapperClass * The end-point class of a java bean * @param args * An array of pairs of name and value for the * {@link MapSqlParameterSource} * @return A list of mapped java bean objects. * @throws Exception */ @SuppressWarnings("unchecked") public <T> List<T> query(String sql, Class<T> mapperClass, Object... args) throws Exception { logQuery(sql, args); if (args == null) return (List<T>) getSimpleJdbcTemplate().query(sql, beanMappingFactory.getBeanMapper(mapperClass)); MapSqlParameterSource map = new MapSqlParameterSource(); for (int i = 0; i < args.length; i += 2) { map.addValue((String) args[i], args[i + 1]); } return (List<T>) getSimpleJdbcTemplate().query(sql, beanMappingFactory.getBeanMapper(mapperClass), map); }
From source file:net.mindengine.oculus.frontend.db.jdbc.MySimpleJdbcDaoSupport.java
/** * Executes the SQL command for updating the entities in DB. * /* w w w.ja v a 2 s .com*/ * @param sql * SQL command string * @param args * An array of pairs of name and value for the * {@link MapSqlParameterSource} * @return * @throws Exception */ public int update(String sql, Object... args) throws Exception { logQuery(sql, args); if (args == null) return getSimpleJdbcTemplate().update(sql); MapSqlParameterSource map = new MapSqlParameterSource(); for (int i = 0; i < args.length; i += 2) { map.addValue((String) args[i], args[i + 1]); } return getSimpleJdbcTemplate().update(sql, map); }
From source file:com.perry.infrastructure.call.CallDaoServiceImpl.java
@Override public Call create(Call call) { String sql = "INSERT INTO calls(\r\n" + // " customer_first_name, customer_last_name, pick_up_location, \r\n" + // " drop_off_location, customer_vehicle_year, customer_vehicle_make, \r\n" + // " customer_vehicle_model, customer_vehicle_color, customer_vehicle_license_plate_number, \r\n" + ///* w ww .ja v a 2 s . c om*/ " customer_phone_number, customer_vehicle_key_location, customer_call_type, \r\n" + // " customer_payment_information, insert_by, update_by, truck_id, \r\n" + // " insert_time, update_time)\r\n" + // " VALUES (:customerFirstName, :customerLastName, :pickUpLocation, \r\n" + // " :dropOffLocation, :customerVehicleYear, :customerVehicleMake, \r\n" + // " :customerVehicleModel, :customerVehicleColor, :customerVehicleLiscensePlateNumber, \r\n" + // " :customerPhoneNumber, :customerVehicleKeyLocation, :customerCallType, \r\n" + // " :customerPaymentInformation , :insertBy, :updateBy, :truckId, \r\n" + // " :insertTime, :updateTime)"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("customerFirstName", call.getCustomer().getFirstName()); params.addValue("customerLastName", call.getCustomer().getLastName()); params.addValue("pickUpLocation", call.getPickUpLocation()); params.addValue("dropOffLocation", call.getDropOffLocation()); params.addValue("customerVehicleYear", call.getCustomer().getVehicle().getYear()); params.addValue("customerVehicleMake", call.getCustomer().getVehicle().getMake()); params.addValue("customerVehicleModel", call.getCustomer().getVehicle().getMake()); params.addValue("customerVehicleColor", call.getCustomer().getVehicle().getColor()); params.addValue("customerVehicleLiscensePlateNumber", call.getCustomer().getVehicle().getLicensePlateNumber()); params.addValue("customerPhoneNumber", call.getCustomer().getPhoneNumber()); params.addValue("customerVehicleKeyLocation", call.getCustomer().getVehicle().getKeyLocationType().getValue()); params.addValue("customerCallType", call.getCallType().getValue()); params.addValue("customerPaymentInformation", call.getCustomer().getVehicle().getMake()); params.addValue("insertBy", 1); params.addValue("updateBy", 1); params.addValue("truckId", 0); params.addValue("insertTime", Instant.now().getEpochSecond()); params.addValue("updateTime", Instant.now().getEpochSecond()); GeneratedKeyHolder keyHolder = new GeneratedKeyHolder(); namedParameterJdbcTemplate.update(sql, params, keyHolder); // update call with primary key returned from DB call.setId((Long) keyHolder.getKeys().get("call_id")); return call; }
From source file:com.perry.infrastructure.call.CallDaoServiceImpl.java
@Override public Call edit(Call call) { String sql = "UPDATE calls set customer_first_name = :customerFirstName, \r\n" + // " customer_last_name = :customerLastName, \r\n" + // " pick_up_location = :pickUpLocation, \r\n" + // " drop_off_location =:dropOffLocation, \r\n" + // " customer_vehicle_year=:customerVehicleYear, \r\n" + // " customer_vehicle_make=:customerVehicleMake, \r\n" + // " customer_vehicle_model= :customerVehicleModel, \r\n" + // " customer_vehicle_color=:customerVehicleColor, \r\n" + // " customer_vehicle_license_plate_number=:customerVehicleLiscensePlateNumber, \r\n" + // " customer_phone_number=:customerPhoneNumber, \r\n" + // " customer_vehicle_key_location=:customerVehicleKeyLocation, \r\n" + // " customer_call_type=:customerCallType, \r\n" + // " customer_payment_information=:customerPaymentInformation, \r\n" + // " insert_by=:insertBy, \r\n" + // " update_by=:updateBy, \r\n" + // " update_time=:updateTime WHERE call_id = :callId"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("customerFirstName", call.getCustomer().getFirstName()); params.addValue("customerLastName", call.getCustomer().getLastName()); params.addValue("pickUpLocation", call.getPickUpLocation()); params.addValue("dropOffLocation", call.getDropOffLocation()); params.addValue("customerVehicleYear", call.getCustomer().getVehicle().getYear()); params.addValue("customerVehicleMake", call.getCustomer().getVehicle().getMake()); params.addValue("customerVehicleModel", call.getCustomer().getVehicle().getMake()); params.addValue("customerVehicleColor", call.getCustomer().getVehicle().getColor()); params.addValue("customerVehicleLiscensePlateNumber", call.getCustomer().getVehicle().getLicensePlateNumber()); params.addValue("customerPhoneNumber", call.getCustomer().getPhoneNumber()); params.addValue("customerVehicleKeyLocation", call.getCustomer().getVehicle().getKeyLocationType().getValue()); params.addValue("customerCallType", call.getCallType().getValue()); params.addValue("customerPaymentInformation", call.getCustomer().getVehicle().getMake()); params.addValue("insertBy", 1); params.addValue("updateBy", 1); params.addValue("updateTime", Instant.now().getEpochSecond()); params.addValue("callId", call.getId()); GeneratedKeyHolder keyHolder = new GeneratedKeyHolder(); namedParameterJdbcTemplate.update(sql, params, keyHolder); // update call with primary key returned from DB call.setId((Long) keyHolder.getKeys().get("call_id")); return call;//from ww w .ja va 2 s . c o m }
From source file:com.google.enterprise.connector.sharepoint.dao.QueryProvider.java
/** * Creates a name-value map to that can be used to execute the query * * @param values/*from w w w .j a v a 2 s . c o m*/ * @return {@link MapSqlParameterSource} */ public SqlParameterSource createParameter(Object... values) { check(values); MapSqlParameterSource namedParam = new MapSqlParameterSource(); int i = 0; for (String placeholder : parameters) { namedParam.addValue(placeholder, values[i++]); } return namedParam; }
From source file:org.aksw.gerbil.database.ExperimentDAOImpl.java
@Override public List<ExperimentTaskResult> getAllRunningExperimentTasks() { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("unfinishedState", TASK_STARTED_BUT_NOT_FINISHED_YET); return this.template.query(GET_RUNNING_EXPERIMENT_TASKS, params, new ExperimentTaskResultRowMapper()); }
From source file:airport.database.services.users.UsersDaoOnlineImpl.java
@Override public void deleteSourUser(Date timeDifference, int secondsLimit) { MapSqlParameterSource parametrQuery = new MapSqlParameterSource(); parametrQuery.addValue("difference", new Timestamp(timeDifference.getTime())); parametrQuery.addValue("limit", secondsLimit); jdbcTemplate.update(SQL_QUERY_DELETE_SOUR_USER, parametrQuery); if (LOG.isInfoEnabled()) { LOG.info("delete user which not online. Date : " + timeDifference + ". SecondsLimit : " + secondsLimit); }/*from ww w . j a va 2s .c o m*/ }
From source file:org.string_db.jdbc.ProteinRepositoryJdbc.java
@Override public Map<Integer, Set<String>> loadProteinNames(Integer speciesId, Set<String> sources) { String filter = "species_id = :species_id "; MapSqlParameterSource params = new MapSqlParameterSource("species_id", speciesId); if (sources != null && !sources.isEmpty()) { filter += " AND \"source\" IN (:sources)"; params.addValue("sources", sources); }// w w w .j a v a 2 s. com return queryProcessor.selectTwoColumns("protein_id", "protein_name", "items.proteins_names", multiValSqlRowMapper, filter, params); }
From source file:org.aksw.gerbil.database.ExperimentDAOImpl.java
@Deprecated @Override/*from www . j a v a2s. c o m*/ protected List<String[]> getAnnotatorDatasetCombinations(String experimentType, String matching) { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("experimentType", experimentType); params.addValue("matching", matching); return this.template.query(GET_LATEST_EXPERIMENT_TASKS, params, new StringArrayRowMapper(new int[] { 1, 2 })); }