List of usage examples for org.springframework.jdbc.core.namedparam MapSqlParameterSource addValue
public MapSqlParameterSource addValue(String paramName, @Nullable Object value)
From source file:com.exploringspatial.dao.impl.ConflictDaoImpl.java
private MapSqlParameterSource buildMapSqlParameterSource(Conflict instance) { final DateFormat df = new SimpleDateFormat("MM/dd/yyyy"); final MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource(); mapSqlParameterSource.addValue("gwno", instance.getGwno()); mapSqlParameterSource.addValue("event_id_cnty", instance.getEventIdCountry()); mapSqlParameterSource.addValue("eventId", instance.getEventPk()); mapSqlParameterSource.addValue("eventDate", df.format(instance.getEventDate())); mapSqlParameterSource.addValue("year", instance.getYear()); mapSqlParameterSource.addValue("timePrecision", instance.getTimePrecision()); mapSqlParameterSource.addValue("eventType", instance.getEventType()); mapSqlParameterSource.addValue("actor1", instance.getActor1()); mapSqlParameterSource.addValue("allyActor1", instance.getAllyActor1()); mapSqlParameterSource.addValue("inter1", instance.getInter1()); mapSqlParameterSource.addValue("actor2", instance.getActor2()); mapSqlParameterSource.addValue("allyActor2", instance.getAllyActor2()); mapSqlParameterSource.addValue("inter2", instance.getInter2()); mapSqlParameterSource.addValue("interaction", instance.getInteraction()); mapSqlParameterSource.addValue("country", instance.getCountry()); mapSqlParameterSource.addValue("admin1", instance.getAdmin1()); mapSqlParameterSource.addValue("admin2", instance.getAdmin2()); mapSqlParameterSource.addValue("admin3", instance.getAdmin3()); mapSqlParameterSource.addValue("location", instance.getLocation()); mapSqlParameterSource.addValue("latitude", instance.getLatitude()); mapSqlParameterSource.addValue("longitude", instance.getLongitude()); mapSqlParameterSource.addValue("geoPrecision", instance.getGwno()); mapSqlParameterSource.addValue("source", instance.getSource()); mapSqlParameterSource.addValue("notes", instance.getNotes()); mapSqlParameterSource.addValue("fatalities", instance.getFatalities()); return mapSqlParameterSource; }
From source file:org.jasig.schedassist.impl.statistics.SpringJDBCStatisticsDaoImpl.java
@Override public List<AppointmentEvent> getEvents(final IScheduleOwner owner, final String visitorUsername, final Date startTime, final Date endTime, final List<EventType> eventTypes) { MapSqlParameterSource parameterSource = new MapSqlParameterSource(); parameterSource.addValue("ownerId", owner.getId()); parameterSource.addValue("visitorId", visitorUsername); parameterSource.addValue("startTime", startTime); parameterSource.addValue("endTime", endTime); parameterSource.addValue("eventTypes", eventTypes); List<AppointmentEvent> results = this.simpleJdbcTemplate.query( "select event_id,owner_id,visitor_id,event_type,event_timestamp,event_start from event_statistics where owner_id = :ownerId and visitor_id = :visitorId and event_timestamp >= :startTime and event_timestamp <= :endTime and event_type in (:eventTypes)", new AppointmentEventRowMapper(ownerDao), parameterSource); return results; }
From source file:com.epam.catgenome.dao.DaoHelper.java
@Transactional(propagation = Propagation.MANDATORY) public Long createTempStringList(final Long listId, final Collection<String> list) { Assert.notNull(listId);/* ww w . j a v a 2 s . co m*/ Assert.isTrue(CollectionUtils.isNotEmpty(list)); // creates a new local temporary table if it doesn't exists to handle temporary lists getJdbcTemplate().update(createTemporaryStringListQuery); // fills in a temporary list by given values int i = 0; final Iterator<String> iterator = list.iterator(); final MapSqlParameterSource[] batchArgs = new MapSqlParameterSource[list.size()]; while (iterator.hasNext()) { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(HelperParameters.LIST_ID.name(), listId); params.addValue(HelperParameters.LIST_VALUE.name(), iterator.next()); batchArgs[i] = params; i++; } getNamedParameterJdbcTemplate().batchUpdate(insertTemporaryStringListItemQuery, batchArgs); return listId; }
From source file:com.epam.catgenome.dao.DaoHelper.java
@Transactional(propagation = Propagation.MANDATORY) public Long createTempList(final Long listId, final Collection<? extends BaseEntity> list) { Assert.notNull(listId);/*w w w . j a v a 2 s . c o m*/ Assert.isTrue(CollectionUtils.isNotEmpty(list)); // creates a new local temporary table if it doesn't exists to handle temporary lists getJdbcTemplate().update(createTemporaryListQuery); // fills in a temporary list by given values int i = 0; final Iterator<? extends BaseEntity> iterator = list.iterator(); final MapSqlParameterSource[] batchArgs = new MapSqlParameterSource[list.size()]; while (iterator.hasNext()) { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(HelperParameters.LIST_ID.name(), listId); params.addValue(HelperParameters.LIST_VALUE.name(), iterator.next().getId()); batchArgs[i] = params; i++; } getNamedParameterJdbcTemplate().batchUpdate(insertTemporaryListItemQuery, batchArgs); return listId; }
From source file:com.epam.catgenome.dao.DaoHelper.java
/** * Creates a new temporary list of {@code Long} values. The created temporary list is * identified by the given ID. If a list has been created successfully, it will be filled * in by {@code Collection} of provided {@code Long} values. * * @param listId {@code Long} represents unique ID that is used to identify a temporary list * @param list {@code Collection} specifies collection of {@code Long} values that should be * associated with a temporary list if this call is succeeded * @return {@code Long} represents unique ID of a temporary list that has been created after * this call//w ww . j a va2 s . co m * @throws IllegalArgumentException will be thrown if <tt>listId</tt> or <tt>list</tt> are * <tt>null</tt>, or the given <tt>list</tt> is empty */ @Transactional(propagation = Propagation.MANDATORY) public Long createTempLongList(final Long listId, final Collection<Long> list) { Assert.notNull(listId); Assert.isTrue(CollectionUtils.isNotEmpty(list)); // creates a new local temporary table if it doesn't exists to handle temporary lists getJdbcTemplate().update(createTemporaryListQuery); // fills in a temporary list by given values int i = 0; final Iterator<Long> iterator = list.iterator(); final MapSqlParameterSource[] batchArgs = new MapSqlParameterSource[list.size()]; while (iterator.hasNext()) { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(HelperParameters.LIST_ID.name(), listId); params.addValue(HelperParameters.LIST_VALUE.name(), iterator.next()); batchArgs[i] = params; i++; } getNamedParameterJdbcTemplate().batchUpdate(insertTemporaryListItemQuery, batchArgs); return listId; }
From source file:com.epam.catgenome.dao.DaoHelper.java
/** * Returns {@code List} which contains next values for sequence with the given name. * * @param sequenceName {@code String} specifies full-qualified name of sequence which * next values should be returned by a call * @param count int specifies the number of next values are should be retrieved * @return {@code List} list of next values for sequence; list.size() == count *//* w w w. j a va 2s.co m*/ @Transactional(propagation = Propagation.MANDATORY) public List<Long> createIds(final String sequenceName, final int count) { Assert.isTrue(StringUtils.isNotBlank(sequenceName)); if (count == 0) { return Collections.emptyList(); } // creates a new temporary list: list.size() == count final List<Long> rows = LongStream.range(0L, count).collect(LinkedList::new, LinkedList::add, LinkedList::addAll); final Long listId = createTempLongList(rows); // generates next values for sequence with the given name final MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(HelperParameters.LIST_ID.name(), listId); params.addValue(HelperParameters.SEQUENCE_NAME.name(), sequenceName.trim()); final List<Long> list = getNamedParameterJdbcTemplate().queryForList(createIdsQuery, params, Long.class); // clears a temporary list clearTempList(listId); return list; }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaLinkDao.java
/** * For the given list of new drops, find those that the link hash already * exists in the db and update the drop entry with the existing id. Also * remove the hash from the new link index for those that already exist. * /* w ww . j av a2 s . c o m*/ * @param newLinkIndex * @param drops */ private void updateNewLinkIndex(Map<String, List<int[]>> newLinkIndex, List<Drop> drops) { // First find and update existing drops with their ids. String sql = "SELECT id, hash FROM links WHERE hash IN (:hashes)"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("hashes", newLinkIndex.keySet()); List<Map<String, Object>> results = this.namedJdbcTemplate.queryForList(sql, params); // Update id for the drops that were found for (Map<String, Object> result : results) { String hash = (String) result.get("hash"); Long id = ((Number) result.get("id")).longValue(); List<int[]> indexes = newLinkIndex.get(hash); for (int[] index : indexes) { drops.get(index[0]).getLinks().get(index[1]).setId(id); } // Hash is not for a new drop so remove it newLinkIndex.remove(hash); } }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaTagDao.java
/** * For the given list of new drops, find those that the tag hash already * exists in the db and update the drop entry with the existing id. Also * remove the hash from the new tag index for those that already exist. * // www. jav a 2s. c o m * @param newTagIndex * @param drops */ private void updateNewTagIndex(Map<String, List<int[]>> newTagIndex, List<Drop> drops) { // First find and update existing drops with their ids. String sql = "SELECT id, hash FROM tags WHERE hash IN (:hashes)"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("hashes", newTagIndex.keySet()); List<Map<String, Object>> results = this.namedJdbcTemplate.queryForList(sql, params); // Update id for the drops that were found for (Map<String, Object> result : results) { String hash = (String) result.get("hash"); Long id = ((Number) result.get("id")).longValue(); List<int[]> indexes = newTagIndex.get(hash); for (int[] index : indexes) { drops.get(index[0]).getTags().get(index[1]).setId(id); } // Hash is not for a new drop so remove it newTagIndex.remove(hash); } }
From source file:org.inbio.modeling.core.dao.impl.LayerDAOImpl.java
@Override public Layer findById(Long id) { String sqlStatement = null;//from w ww.j a va2s .c o m MapSqlParameterSource args = null; Layer layer = null; sqlStatement = "SELECT * FROM " + this.table + " " + " WHERE id = :layer_id"; args = new MapSqlParameterSource(); args.addValue("layer_id", id); layer = getSimpleJdbcTemplate().queryForObject(sqlStatement, new LayerRowMapper(), args); return layer; }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaPlaceDao.java
/** * For the given list of new drops, find those that the place hash already * exists in the db and update the drop entry with the existing id. Also * remove the hash from the new place index for those that already exist. * /*from w w w . ja v a2 s.com*/ * @param newPlaceIndex * @param drops */ private void updateNewPlaceIndex(Map<String, List<int[]>> newPlaceIndex, List<Drop> drops) { // First find and update existing drops with their ids. String sql = "SELECT id, hash FROM places WHERE hash IN (:hashes)"; MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("hashes", newPlaceIndex.keySet()); List<Map<String, Object>> results = this.namedJdbcTemplate.queryForList(sql, params); // Update id for the drops that were found for (Map<String, Object> result : results) { String hash = (String) result.get("hash"); Long id = ((Number) result.get("id")).longValue(); List<int[]> indexes = newPlaceIndex.get(hash); for (int[] index : indexes) { drops.get(index[0]).getPlaces().get(index[1]).setId(id); } // Hash is not for a new drop so remove it newPlaceIndex.remove(hash); } }