List of usage examples for org.springframework.jdbc.core.namedparam MapSqlParameterSource MapSqlParameterSource
public MapSqlParameterSource()
From source file:com.joliciel.jochre.doc.DocumentDaoJdbc.java
@Override public void saveJochrePage(JochrePage jochrePage) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); MapSqlParameterSource paramSource = new MapSqlParameterSource(); JochrePageInternal iJochrePage = (JochrePageInternal) jochrePage; paramSource.addValue("page_doc_id", jochrePage.getDocumentId()); paramSource.addValue("page_index", jochrePage.getIndex()); String sql = null;/*ww w.j a va 2s . co m*/ if (jochrePage.isNew()) { sql = "SELECT nextval('ocr_page_id_seq')"; LOG.info(sql); int jochrePageId = jt.queryForInt(sql, paramSource); paramSource.addValue("page_id", jochrePageId); sql = "INSERT INTO ocr_page (page_id, page_doc_id, page_index) " + "VALUES (:page_id, :page_doc_id, :page_index)"; LOG.info(sql); logParameters(paramSource); jt.update(sql, paramSource); iJochrePage.setId(jochrePageId); } else { paramSource.addValue("page_id", jochrePage.getId()); sql = "UPDATE ocr_page" + " SET page_doc_id = :page_doc_id" + ", page_index = :page_index" + " WHERE page_id = :page_id"; LOG.info(sql); logParameters(paramSource); jt.update(sql, paramSource); } }
From source file:com.joliciel.jochre.graphics.GraphicsDaoJdbc.java
@Override public List<Shape> findShapes(GroupOfShapes group) { NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(this.getDataSource()); String sql = "SELECT " + SELECT_SHAPE + " FROM ocr_shape WHERE shape_group_id=:shape_group_id" + " ORDER BY shape_index"; MapSqlParameterSource paramSource = new MapSqlParameterSource(); paramSource.addValue("shape_group_id", group.getId()); LOG.debug(sql);/* ww w. ja v a2 s. c om*/ logParameters(paramSource); @SuppressWarnings("unchecked") List<Shape> shapes = jt.query(sql, paramSource, new ShapeMapper(this.getGraphicsServiceInternal())); return shapes; }
From source file:fi.luontola.cqrshotel.framework.PsqlEventStore.java
@Override public long getCurrentPosition() { List<Long> position = jdbcTemplate.queryForList( "SELECT position FROM event_sequence ORDER BY position DESC LIMIT 1", new MapSqlParameterSource(), Long.class); return position.isEmpty() ? BEGINNING : position.get(0); }
From source file:com.epam.catgenome.dao.BiologicalDataItemDao.java
/** * Persists a BiologicalDataItem instance into the database * @param item BiologicalDataItem to persist *//* w w w . j a v a2 s. c o m*/ @Transactional(propagation = Propagation.MANDATORY) public void createBiologicalDataItem(BiologicalDataItem item) { if (!item.getFormat().isIndex() || (item.getFormat().isIndex() && !StringUtils.isEmpty(item.getName()))) { Assert.isTrue(!StringUtils.isEmpty(item.getName()), "File name is required for registration."); List<BiologicalDataItem> items = loadFilesByNameStrict(item.getName()); Assert.isTrue(items.isEmpty(), MessageHelper.getMessage(MessagesConstants.ERROR_FILE_NAME_EXISTS, item.getName())); item.setId(daoHelper.createId(biologicalDataItemSequenceName)); } else { item.setId(daoHelper.createId(biologicalDataItemSequenceName)); item.setName("INDEX " + item.getId()); } final MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue(BiologicalDataItemParameters.BIO_DATA_ITEM_ID.name(), item.getId()); params.addValue(BiologicalDataItemParameters.NAME.name(), item.getName()); params.addValue(BiologicalDataItemParameters.TYPE.name(), item.getType().getId()); params.addValue(BiologicalDataItemParameters.PATH.name(), item.getPath()); params.addValue(BiologicalDataItemParameters.FORMAT.name(), item.getFormat().getId()); params.addValue(BiologicalDataItemParameters.CREATED_DATE.name(), item.getCreatedDate()); params.addValue(BiologicalDataItemParameters.CREATED_BY.name(), item.getCreatedBy()); params.addValue(BiologicalDataItemParameters.BUCKET_ID.name(), item.getBucketId()); params.addValue(BiologicalDataItemParameters.PRETTY_NAME.name(), item.getPrettyName()); getNamedParameterJdbcTemplate().update(insertBiologicalDataItemQuery, params); }
From source file:com.xinferin.dao.DAOCustomerRegistrationImpl.java
private void bindRegistrationAndLicence(int registration_id, int licence_id) { String sql = "INSERT INTO licence_registration (registration_id, licence_id)" + " VALUES (:registration_id, :licence_id)"; MapSqlParameterSource args = new MapSqlParameterSource(); args.addValue("registration_id", registration_id); args.addValue("licence_id", licence_id); jdbcTemplate.update(sql, args);/*from w w w . j av a 2 s .c o m*/ }
From source file:net.mindengine.oculus.frontend.db.jdbc.MySimpleJdbcDaoSupport.java
/** * Executes the SQL command for updating the entities in DB. * //w w w.j a v a 2 s . co m * @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: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 w w w . j a va 2 s . c om*/ }
From source file:com.lixiaocong.social.MyJdbcConnection.java
public MultiValueMap<String, Connection<?>> findConnectionsToUsers( MultiValueMap<String, String> providerUsers) { if (providerUsers == null || providerUsers.isEmpty()) { throw new IllegalArgumentException("Unable to execute find: no providerUsers provided"); }//from w w w .ja v a2 s.co m StringBuilder providerUsersCriteriaSql = new StringBuilder(); MapSqlParameterSource parameters = new MapSqlParameterSource(); parameters.addValue("userId", userId); for (Iterator<Entry<String, List<String>>> it = providerUsers.entrySet().iterator(); it.hasNext();) { Entry<String, List<String>> entry = it.next(); String providerId = entry.getKey(); providerUsersCriteriaSql.append("providerId = :providerId_").append(providerId) .append(" and providerUserId in (:providerUserIds_").append(providerId).append(")"); parameters.addValue("providerId_" + providerId, providerId); parameters.addValue("providerUserIds_" + providerId, entry.getValue()); if (it.hasNext()) { providerUsersCriteriaSql.append(" or "); } } List<Connection<?>> resultList = new NamedParameterJdbcTemplate(jdbcTemplate) .query(selectFromUserConnection() + " where userId = :userId and " + providerUsersCriteriaSql + " order by providerId, rank", parameters, connectionMapper); MultiValueMap<String, Connection<?>> connectionsForUsers = new LinkedMultiValueMap<String, Connection<?>>(); for (Connection<?> connection : resultList) { String providerId = connection.getKey().getProviderId(); List<String> userIds = providerUsers.get(providerId); List<Connection<?>> connections = connectionsForUsers.get(providerId); if (connections == null) { connections = new ArrayList<Connection<?>>(userIds.size()); for (int i = 0; i < userIds.size(); i++) { connections.add(null); } connectionsForUsers.put(providerId, connections); } String providerUserId = connection.getKey().getProviderUserId(); int connectionIndex = userIds.indexOf(providerUserId); connections.set(connectionIndex, connection); } return connectionsForUsers; }
From source file:org.smart.migrate.dao.impl.DefaultImportDao.java
@Override public void saveTargetData(TableSetting tableSetting, List<Map<String, Object>> targetDataList) { String sql = "INSERT INTO " + tableSetting.getTargetTable() + " (" + SettingUtils.getTargetFields(tableSetting) + ")"; sql += " VALUES (" + SettingUtils.getTargetPreparedFields(tableSetting) + ")"; NamedParameterJdbcTemplate namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(targetJdbcTemplate); List<MapSqlParameterSource> parameterSources = new ArrayList<MapSqlParameterSource>(); for (Map<String, Object> targetData : targetDataList) { MapSqlParameterSource psource = new MapSqlParameterSource(); psource.addValues(targetData);/* w w w . j a v a 2 s. c o m*/ parameterSources.add(psource); } namedParameterJdbcTemplate.batchUpdate(sql, parameterSources.toArray(new MapSqlParameterSource[0])); }
From source file:org.sakuli.services.forwarder.database.dao.impl.DaoTestSuiteImpl.java
private MapSqlParameterSource getGuidParameter() { return new MapSqlParameterSource().addValue("guid", testSuite.getGuid()); }