View Javadoc
1   package fr.ifremer.quadrige3.core.dao.referential;
2   
3   /*-
4    * #%L
5    * Quadrige3 Core :: Quadrige3 Client Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import com.google.common.base.Joiner;
27  import com.google.common.collect.ImmutableList;
28  import com.google.common.collect.Maps;
29  import fr.ifremer.quadrige3.core.dao.administration.program.ProgramStrategyJdbcDao;
30  import fr.ifremer.quadrige3.core.dao.administration.program.ProgramStrategyJdbcDaoImpl;
31  import fr.ifremer.quadrige3.core.dao.administration.user.DepartmentJdbcDao;
32  import fr.ifremer.quadrige3.core.dao.administration.user.DepartmentJdbcDaoImpl;
33  import fr.ifremer.quadrige3.core.dao.administration.user.QuserJdbcDao;
34  import fr.ifremer.quadrige3.core.dao.administration.user.QuserJdbcDaoImpl;
35  import fr.ifremer.quadrige3.core.dao.system.rule.RuleListJdbcDao;
36  import fr.ifremer.quadrige3.core.dao.system.rule.RuleListJdbcDaoImpl;
37  import fr.ifremer.quadrige3.core.dao.technical.Assert;
38  import fr.ifremer.quadrige3.core.dao.technical.jdbc.OptionalDataSourceJdbcDaoSupport;
39  import fr.ifremer.quadrige3.core.exception.QuadrigeTechnicalException;
40  import fr.ifremer.quadrige3.core.vo.referential.AnalysisInstrumentVO;
41  import fr.ifremer.quadrige3.core.vo.referential.SamplingEquipmentVO;
42  import fr.ifremer.quadrige3.core.vo.referential.monitoringLocation.MonitoringLocationVO;
43  import fr.ifremer.quadrige3.core.vo.referential.pmfm.*;
44  import fr.ifremer.quadrige3.core.vo.referential.taxon.TaxonGroupVO;
45  import fr.ifremer.quadrige3.core.vo.referential.taxon.TaxonNameVO;
46  import fr.ifremer.quadrige3.synchro.meta.referential.ReferentialSynchroTables;
47  import fr.ifremer.quadrige3.synchro.meta.system.RuleSynchroTables;
48  import org.apache.commons.collections4.CollectionUtils;
49  import org.apache.commons.io.IOUtils;
50  import org.apache.commons.lang3.StringUtils;
51  import org.springframework.beans.factory.InitializingBean;
52  import org.springframework.beans.factory.annotation.Autowired;
53  import org.springframework.context.annotation.Lazy;
54  import org.springframework.stereotype.Repository;
55  
56  import javax.annotation.Resource;
57  import javax.sql.DataSource;
58  import java.io.IOException;
59  import java.io.InputStream;
60  import java.sql.ResultSet;
61  import java.sql.SQLException;
62  import java.util.List;
63  import java.util.Map;
64  import java.util.Properties;
65  import java.util.stream.Collectors;
66  
67  /**
68   * Created by blavenie on 31/08/15.
69   */
70  @Repository("referentialJdbcDao")
71  @Lazy
72  public class ReferentialJdbcDaoImpl
73  		extends OptionalDataSourceJdbcDaoSupport
74  		implements ReferentialJdbcDao, InitializingBean {
75  
76  	private final static String QUERIES_FILE_PATH = "queries.jdbc.xml";
77  
78  	@Resource(name = "queriesJdbcProperties")
79  	private Properties queriesJdbcProperties;
80  
81  	@Resource(name = "quserJdbcDao")
82  	private QuserJdbcDao quserJdbcDao;
83  
84  	@Resource(name = "departmentJdbcDao")
85  	private DepartmentJdbcDao departmentJdbcDao;
86  
87  	@Resource(name = "programStrategyJdbcDao")
88  	private ProgramStrategyJdbcDao programStrategyJdbcDao;
89  
90  	@Resource(name = "ruleListJdbcDao")
91  	private RuleListJdbcDao ruleListJdbcDao;
92  
93  	protected final Properties connectionProperties;
94  
95  	/**
96  	 * Constructor used by Spring
97  	 * 
98  	 * @param dataSource
99  	 *            a {@link javax.sql.DataSource} object.
100 	 */
101 	@Autowired
102 	public ReferentialJdbcDaoImpl(DataSource dataSource) {
103 		super(dataSource);
104 		this.connectionProperties = null;
105 	}
106 
107 	/**
108 	 * Constructor without Spring (e.g. for synchro), using the default connection properties (from configuration)
109 	 */
110 	public ReferentialJdbcDaoImpl() {
111 		this((Properties) null);
112 	}
113 
114 	/**
115 	 * Constructor without Spring (e.g. for synchro), using the given connection properties
116 	 * 
117 	 * @param connectionProperties
118 	 *            a {@link java.util.Properties} object.
119 	 */
120 	public ReferentialJdbcDaoImpl(Properties connectionProperties) {
121 		super();
122 		this.connectionProperties = connectionProperties;
123 		this.quserJdbcDao = new QuserJdbcDaoImpl(connectionProperties);
124 		this.departmentJdbcDao = new DepartmentJdbcDaoImpl(connectionProperties);
125 		this.programStrategyJdbcDao = new ProgramStrategyJdbcDaoImpl(connectionProperties);
126 		this.ruleListJdbcDao = new RuleListJdbcDaoImpl(connectionProperties);
127 
128 		// Load properties
129 		Properties properties = new Properties();
130 		InputStream is = null;
131 		try {
132 			is = getClass().getClassLoader().getResourceAsStream(QUERIES_FILE_PATH);
133 			properties.loadFromXML(is);
134 
135 			this.queriesJdbcProperties = properties;
136 		} catch (IOException e) {
137 			throw new QuadrigeTechnicalException(
138 					String.format("Unable to read file [%s] from classpath", QUERIES_FILE_PATH),
139 					e);
140 		} finally {
141 			IOUtils.closeQuietly(is);
142 		}
143 
144 		// Check all queries
145 		checkAllQueriesExists();
146 	}
147 
148 	/** {@inheritDoc} */
149 	@Override
150 	public void afterPropertiesSet() {
151 		// Check queries exists on queries file
152 		checkAllQueriesExists();
153 	}
154 
155 	/** {@inheritDoc} */
156 	@Override
157 	public List<MonitoringLocationVO> getMonitoringLocationsByIds(List<Integer> ids) {
158 		// Find the user, by id
159 		String sql = queriesJdbcProperties.getProperty("monitoringLocationsByIds");
160 
161 		sql = sql.replace(":ids", Joiner.on(",").skipNulls().join(ids));
162 
163 		Map<String, Object> paramMap = Maps.newHashMap();
164 		return query(connectionProperties, sql, paramMap, (rs, rowNum) -> toMonitoringLocationVO(rs));
165 	}
166 
167 	/** {@inheritDoc} */
168 	@Override
169 	public MonitoringLocationVO getMonitoringLocationById(int id) {
170 		// Find the user, by id
171 		String sql = queriesJdbcProperties.getProperty("monitoringLocationsByIds");
172 
173 		Map<String, Object> paramMap = Maps.newHashMap();
174 		paramMap.put("ids", id);
175 
176 		return query(connectionProperties, sql, paramMap, this::toMonitoringLocationVO);
177 	}
178 
179 	/** {@inheritDoc} */
180 	@Override
181 	public List<TaxonNameVO> getTaxonNamesByReferenceTaxonIds(List<Integer> ids) {
182 		// Find the user, by id
183 		String sql = queriesJdbcProperties.getProperty("taxonNamesByReferenceTaxonIds");
184 
185 		sql = sql.replace(":referenceTaxonIds", Joiner.on(",").skipNulls().join(ids));
186 
187 		Map<String, Object> paramMap = Maps.newHashMap();
188 		return query(connectionProperties, sql, paramMap, (rs, rowNum) -> toTaxonVO(rs));
189 	}
190 
191 	/** {@inheritDoc} */
192 	@Override
193 	public TaxonNameVO getTaxonNameByReferenceTaxonId(int id) {
194 		// Find the user, by id
195 		String sql = queriesJdbcProperties.getProperty("taxonNamesByReferenceTaxonIds");
196 
197 		Map<String, Object> paramMap = Maps.newHashMap();
198 		paramMap.put("ids", id);
199 
200 		return query(connectionProperties, sql, paramMap, this::toTaxonVO);
201 	}
202 
203 	/** {@inheritDoc} */
204 	@Override
205 	public List<TaxonGroupVO> getTaxonGroupsByIds(List<Integer> ids) {
206 		// Find the user, by id
207 		String sql = queriesJdbcProperties.getProperty("taxonGroupsByIds");
208 
209 		sql = sql.replace(":ids", Joiner.on(",").skipNulls().join(ids));
210 
211 		Map<String, Object> paramMap = Maps.newHashMap();
212 		return query(connectionProperties, sql, paramMap, (rs, rowNum) -> toTaxonGroupVO(rs));
213 	}
214 
215 	/** {@inheritDoc} */
216 	@Override
217 	public TaxonGroupVO getTaxonGroupById(int id) {
218 		// Find the user, by id
219 		String sql = queriesJdbcProperties.getProperty("taxonGroupsByIds");
220 
221 		Map<String, Object> paramMap = Maps.newHashMap();
222 		paramMap.put("ids", id);
223 
224 		return query(connectionProperties, sql, paramMap, this::toTaxonGroupVO);
225 	}
226 
227 	/** {@inheritDoc} */
228 	@Override
229 	public List<ParameterVO> getParametersByCodes(List<String> codes) {
230 		// Find the user, by id
231 		String sql = queriesJdbcProperties.getProperty("parametersByCodes");
232 
233 		sql = sql.replace(":codes", "'" + Joiner.on("','").skipNulls().join(codes) + "'");
234 
235 		Map<String, Object> paramMap = Maps.newHashMap();
236 		return query(connectionProperties, sql, paramMap, (rs, rowNum) -> toParameterVO(rs));
237 	}
238 
239 	/** {@inheritDoc} */
240 	@Override
241 	public ParameterVO getParameterByCode(String code) {
242 		// Find the user, by id
243 		String sql = queriesJdbcProperties.getProperty("parametersByCodes");
244 
245 		Map<String, Object> paramMap = Maps.newHashMap();
246 		paramMap.put("codes", code);
247 
248 		return query(connectionProperties, sql, paramMap, this::toParameterVO);
249 	}
250 
251 	/** {@inheritDoc} */
252 	@Override
253 	public List<MatrixVO> getMatrixesByIds(List<Integer> ids) {
254 		// Find the user, by id
255 		String sql = queriesJdbcProperties.getProperty("matrixesByIds");
256 
257 		sql = sql.replace(":ids", Joiner.on(",").skipNulls().join(ids));
258 
259 		Map<String, Object> paramMap = Maps.newHashMap();
260 		return query(connectionProperties, sql, paramMap, (rs, rowNum) -> toMatrixVO(rs));
261 	}
262 
263 	/** {@inheritDoc} */
264 	@Override
265 	public MatrixVO getMatrixById(int id) {
266 		// Find the user, by id
267 		String sql = queriesJdbcProperties.getProperty("matrixesByIds");
268 
269 		Map<String, Object> paramMap = Maps.newHashMap();
270 		paramMap.put("ids", id);
271 
272 		return query(connectionProperties, sql, paramMap, this::toMatrixVO);
273 	}
274 
275 	/** {@inheritDoc} */
276 	@Override
277 	public List<FractionVO> getFractionsByIds(List<Integer> ids) {
278 		// Find the user, by id
279 		String sql = queriesJdbcProperties.getProperty("fractionsByIds");
280 
281 		sql = sql.replace(":ids", Joiner.on(",").skipNulls().join(ids));
282 
283 		Map<String, Object> paramMap = Maps.newHashMap();
284 		return query(connectionProperties, sql, paramMap, (rs, rowNum) -> toFractionVO(rs));
285 	}
286 
287 	/** {@inheritDoc} */
288 	@Override
289 	public FractionVO getFractionById(int id) {
290 		// Find the user, by id
291 		String sql = queriesJdbcProperties.getProperty("fractionsByIds");
292 
293 		Map<String, Object> paramMap = Maps.newHashMap();
294 		paramMap.put("ids", id);
295 
296 		return query(connectionProperties, sql, paramMap, this::toFractionVO);
297 	}
298 
299 	/** {@inheritDoc} */
300 	@Override
301 	public List<MethodVO> getMethodsByIds(List<Integer> ids) {
302 		// Find the user, by id
303 		String sql = queriesJdbcProperties.getProperty("methodsByIds");
304 
305 		sql = sql.replace(":ids", Joiner.on(",").skipNulls().join(ids));
306 
307 		Map<String, Object> paramMap = Maps.newHashMap();
308 		return query(connectionProperties, sql, paramMap, (rs, rowNum) -> toMethodVO(rs));
309 	}
310 
311 	/** {@inheritDoc} */
312 	@Override
313 	public MethodVO getMethodById(int id) {
314 		// Find the user, by id
315 		String sql = queriesJdbcProperties.getProperty("methodsByIds");
316 
317 		Map<String, Object> paramMap = Maps.newHashMap();
318 		paramMap.put("ids", id);
319 
320 		return query(connectionProperties, sql, paramMap, this::toMethodVO);
321 	}
322 
323 	/** {@inheritDoc} */
324 	@Override
325 	public List<PmfmVO> getPmfmsByIds(List<Integer> ids) {
326 		// Find the user, by id
327 		String sql = queriesJdbcProperties.getProperty("pmfmsByIds");
328 
329 		sql = sql.replace(":ids", Joiner.on(",").skipNulls().join(ids));
330 
331 		Map<String, Object> paramMap = Maps.newHashMap();
332 		return query(connectionProperties, sql, paramMap, (rs, rowNum) -> toPmfmVO(rs));
333 	}
334 
335 	/** {@inheritDoc} */
336 	@Override
337 	public PmfmVO getPmfmById(int id) {
338 		// Find the user, by id
339 		String sql = queriesJdbcProperties.getProperty("pmfmsByIds");
340 
341 		Map<String, Object> paramMap = Maps.newHashMap();
342 		paramMap.put("ids", id);
343 
344 		return query(connectionProperties, sql, paramMap, this::toPmfmVO);
345 	}
346 
347 	/** {@inheritDoc} */
348 	@Override
349 	public List<UnitVO> getUnitsByIds(List<Integer> ids) {
350 		// Find the user, by id
351 		String sql = queriesJdbcProperties.getProperty("unitsByIds");
352 
353 		sql = sql.replace(":ids", Joiner.on(",").skipNulls().join(ids));
354 
355 		Map<String, Object> paramMap = Maps.newHashMap();
356 		return query(connectionProperties, sql, paramMap, (rs, rowNum) -> toUnitVO(rs));
357 	}
358 
359 	/** {@inheritDoc} */
360 	@Override
361 	public UnitVO getUnitById(int id) {
362 		// Find the user, by id
363 		String sql = queriesJdbcProperties.getProperty("unitsByIds");
364 
365 		Map<String, Object> paramMap = Maps.newHashMap();
366 		paramMap.put("ids", id);
367 
368 		return query(connectionProperties, sql, paramMap, this::toUnitVO);
369 	}
370 
371 	/** {@inheritDoc} */
372 	@Override
373 	public List<AnalysisInstrumentVO> getAnalysisInstrumentsByIds(List<Integer> ids) {
374 		// Find the user, by id
375 		String sql = queriesJdbcProperties.getProperty("analysisInstrumentsByIds");
376 
377 		sql = sql.replace(":ids", Joiner.on(",").skipNulls().join(ids));
378 
379 		Map<String, Object> paramMap = Maps.newHashMap();
380 		return query(connectionProperties, sql, paramMap, (rs, rowNum) -> toAnalysisInstrumentVO(rs));
381 	}
382 
383 	/** {@inheritDoc} */
384 	@Override
385 	public AnalysisInstrumentVO getAnalysisInstrumentById(int id) {
386 		// Find the user, by id
387 		String sql = queriesJdbcProperties.getProperty("analysisInstrumentsByIds");
388 
389 		Map<String, Object> paramMap = Maps.newHashMap();
390 		paramMap.put("ids", id);
391 
392 		return query(connectionProperties, sql, paramMap, this::toAnalysisInstrumentVO);
393 	}
394 
395 	/** {@inheritDoc} */
396 	@Override
397 	public List<SamplingEquipmentVO> getSamplingEquipmentsByIds(List<Integer> ids) {
398 		// Find the user, by id
399 		String sql = queriesJdbcProperties.getProperty("samplingEquipmentsByIds");
400 
401 		sql = sql.replace(":ids", Joiner.on(",").skipNulls().join(ids));
402 
403 		Map<String, Object> paramMap = Maps.newHashMap();
404 		return query(connectionProperties, sql, paramMap, (rs, rowNum) -> toSamplingEquipmentVO(rs));
405 	}
406 
407 	/** {@inheritDoc} */
408 	@Override
409 	public SamplingEquipmentVO getSamplingEquipmentById(int id) {
410 		// Find the user, by id
411 		String sql = queriesJdbcProperties.getProperty("samplingEquipmentsByIds");
412 
413 		Map<String, Object> paramMap = Maps.newHashMap();
414 		paramMap.put("ids", id);
415 
416 		return query(connectionProperties, sql, paramMap, this::toSamplingEquipmentVO);
417 	}
418 
419 	/** {@inheritDoc} */
420 	@Override
421 	public List<QualitativeValueVO> getQualitativeValueByIds(List<Integer> ids) {
422 		// Find the user, by id
423 		String sql = queriesJdbcProperties.getProperty("qualitativeValueByIds");
424 
425 		sql = sql.replace(":ids", Joiner.on(",").skipNulls().join(ids));
426 
427 		Map<String, Object> paramMap = Maps.newHashMap();
428 		return query(connectionProperties, sql, paramMap, (rs, rowNum) -> toQualitativeValueVO(rs));
429 	}
430 
431 	/** {@inheritDoc} */
432 	@Override
433 	public QualitativeValueVO getQualitativeValueById(int id) {
434 		// Find the user, by id
435 		String sql = queriesJdbcProperties.getProperty("qualitativeValueByIds");
436 
437 		Map<String, Object> paramMap = Maps.newHashMap();
438 		paramMap.put("ids", id);
439 
440 		return query(connectionProperties, sql, paramMap, this::toQualitativeValueVO);
441 	}
442 
443 	/** {@inheritDoc} */
444 	@Override
445 	public List<?> getVOsByTableNameAndPks(String tableName, List<String> pks) {
446 
447 		// monitoring location
448 		if (tableName.equals(ReferentialSynchroTables.MONITORING_LOCATION.name())) {
449 			return getMonitoringLocationsByIds(toIds(pks));
450 		}
451 
452 		// taxon
453 		if (tableName.equals(ReferentialSynchroTables.REFERENCE_TAXON.name())) {
454 			return getTaxonNamesByReferenceTaxonIds(toIds(pks));
455 		}
456 
457 		// Groupe de taxon
458 		if (tableName.equals(ReferentialSynchroTables.TAXON_GROUP.name())) {
459 			return getTaxonGroupsByIds(toIds(pks));
460 		}
461 
462 		// parameter
463 		if (tableName.equals(ReferentialSynchroTables.PARAMETER.name())) {
464 			return getParametersByCodes(pks);
465 		}
466 
467 		// matrix
468 		if (tableName.equals(ReferentialSynchroTables.MATRIX.name())) {
469 			return getMatrixesByIds(toIds(pks));
470 		}
471 
472 		// fraction
473 		if (tableName.equals(ReferentialSynchroTables.FRACTION.name())) {
474 			return getFractionsByIds(toIds(pks));
475 		}
476 
477 		// method
478 		if (tableName.equals(ReferentialSynchroTables.METHOD.name())) {
479 			return getMethodsByIds(toIds(pks));
480 		}
481 
482 		// pmfm
483 		if (tableName.equals(ReferentialSynchroTables.PMFM.name())) {
484 			return getPmfmsByIds(toIds(pks));
485 		}
486 
487 		// unit
488 		if (tableName.equals(ReferentialSynchroTables.UNIT.name())) {
489 			return getUnitsByIds(toIds(pks));
490 		}
491 
492 		// analysis instrument
493 		if (tableName.equals(ReferentialSynchroTables.ANALYSIS_INSTRUMENT.name())) {
494 			return getAnalysisInstrumentsByIds(toIds(pks));
495 		}
496 
497 		// sampling equipment
498 		if (tableName.equals(ReferentialSynchroTables.SAMPLING_EQUIPMENT.name())) {
499 			return getSamplingEquipmentsByIds(toIds(pks));
500 		}
501 
502 		// qualitative value
503 		if (tableName.equals(ReferentialSynchroTables.QUALITATIVE_VALUE.name())) {
504 			return getQualitativeValueByIds(toIds(pks));
505 		}
506 
507 		// quser
508 		if (tableName.equals(ReferentialSynchroTables.QUSER.name())) {
509 			return quserJdbcDao.getUsersByIds(toIds(pks));
510 		}
511 
512 		// department
513 		if (tableName.equals(ReferentialSynchroTables.DEPARTMENT.name())) {
514 			return departmentJdbcDao.getDepartmentsByIds(toIds(pks));
515 		}
516 
517 		// program
518 		if (tableName.equals(ReferentialSynchroTables.PROGRAMME.name())) {
519 			return programStrategyJdbcDao.getProgramsByCodes(pks);
520 		}
521 
522 		// strategy
523 		if (tableName.equals(ReferentialSynchroTables.STRATEGY.name())) {
524 			return programStrategyJdbcDao.getStrategiesByIds(toIds(pks));
525 		}
526 
527 		// rule list
528 		if (tableName.equals(RuleSynchroTables.RULE_LIST.name())) {
529 			return ruleListJdbcDao.getRuleListsByCodes(pks);
530 		}
531 
532 		throw new QuadrigeTechnicalException(String.format("Unable to find DAO method for table [%s]", tableName));
533 	}
534 
535 	/** {@inheritDoc} */
536 	@Override
537 	public Object getVOByTableNameAndPk(String tableName, String pk) {
538 
539 		List<?> result = getVOsByTableNameAndPks(tableName, ImmutableList.of(pk));
540 		if (CollectionUtils.isEmpty(result)) {
541 			return null;
542 		}
543 		return result.get(0);
544 	}
545 
546 	/* -- Internal methods -- */
547 
548 	/**
549 	 * Check queries exists on queries file
550 	 */
551 	protected void checkAllQueriesExists() {
552 		Assert.notNull(queriesJdbcProperties);
553 
554 		checkQueryExists("monitoringLocationsByIds");
555 		checkQueryExists("taxonNamesByReferenceTaxonIds");
556 		checkQueryExists("taxonGroupsByIds");
557 		checkQueryExists("parametersByCodes");
558 		checkQueryExists("matrixesByIds");
559 		checkQueryExists("fractionsByIds");
560 		checkQueryExists("methodsByIds");
561 		checkQueryExists("pmfmsByIds");
562 		checkQueryExists("unitsByIds");
563 		checkQueryExists("analysisInstrumentsByIds");
564 		checkQueryExists("samplingEquipmentsByIds");
565 		checkQueryExists("qualitativeValueByIds");
566 	}
567 
568 	/**
569 	 * Check if a query exists on the queries properties file
570 	 * 
571 	 * @param queryName
572 	 *            a {@link java.lang.String} object.
573 	 */
574 	protected void checkQueryExists(String queryName) {
575 		if (StringUtils.isBlank(queriesJdbcProperties.getProperty(queryName))) {
576 			throw new QuadrigeTechnicalException(String.format("Property with name [%s] not exists on JDBC queries file", queryName));
577 		}
578 	}
579 
580 	/**
581 	 * <p>
582 	 * toMonitoringLocationVO.
583 	 * </p>
584 	 * 
585 	 * @param rs
586 	 *            a {@link java.sql.ResultSet} object.
587 	 * @return a {@link fr.ifremer.quadrige3.core.vo.referential.monitoringLocation.MonitoringLocationVO} object.
588 	 * @throws java.sql.SQLException
589 	 *             if any.
590 	 */
591 	protected MonitoringLocationVO toMonitoringLocationVO(ResultSet rs) throws SQLException {
592 		MonitoringLocationVO target = new MonitoringLocationVO();
593 
594 		int index = 0;
595 		target.setId(rs.getInt(++index));
596 		target.setLabel(rs.getString(++index));
597 		target.setName(rs.getString(++index));
598 
599 		return target;
600 	}
601 
602 	/**
603 	 * <p>
604 	 * toTaxonVO.
605 	 * </p>
606 	 * 
607 	 * @param rs
608 	 *            a {@link java.sql.ResultSet} object.
609 	 * @return a {@link fr.ifremer.quadrige3.core.vo.referential.taxon.TaxonNameVO} object.
610 	 * @throws java.sql.SQLException
611 	 *             if any.
612 	 */
613 	protected TaxonNameVO toTaxonVO(ResultSet rs) throws SQLException {
614 		TaxonNameVO target = new TaxonNameVO();
615 
616 		int index = 0;
617 		target.setId(rs.getInt(++index));
618 		target.setName(rs.getString(++index));
619 
620 		return target;
621 	}
622 
623 	/**
624 	 * <p>
625 	 * toTaxonGroupVO.
626 	 * </p>
627 	 * 
628 	 * @param rs
629 	 *            a {@link java.sql.ResultSet} object.
630 	 * @return a {@link fr.ifremer.quadrige3.core.vo.referential.taxon.TaxonGroupVO} object.
631 	 * @throws java.sql.SQLException
632 	 *             if any.
633 	 */
634 	protected TaxonGroupVO toTaxonGroupVO(ResultSet rs) throws SQLException {
635 		TaxonGroupVO target = new TaxonGroupVO();
636 
637 		int index = 0;
638 		target.setId(rs.getInt(++index));
639 		target.setName(rs.getString(++index));
640 
641 		return target;
642 	}
643 
644 	/**
645 	 * <p>
646 	 * toParameterVO.
647 	 * </p>
648 	 * 
649 	 * @param rs
650 	 *            a {@link java.sql.ResultSet} object.
651 	 * @return a {@link fr.ifremer.quadrige3.core.vo.referential.pmfm.ParameterVO} object.
652 	 * @throws java.sql.SQLException
653 	 *             if any.
654 	 */
655 	protected ParameterVO toParameterVO(ResultSet rs) throws SQLException {
656 		ParameterVO target = new ParameterVO();
657 
658 		int index = 0;
659 		target.setCode(rs.getString(++index));
660 		target.setName(rs.getString(++index));
661 
662 		return target;
663 	}
664 
665 	/**
666 	 * <p>
667 	 * toMatrixVO.
668 	 * </p>
669 	 * 
670 	 * @param rs
671 	 *            a {@link java.sql.ResultSet} object.
672 	 * @return a {@link fr.ifremer.quadrige3.core.vo.referential.pmfm.MatrixVO} object.
673 	 * @throws java.sql.SQLException
674 	 *             if any.
675 	 */
676 	protected MatrixVO toMatrixVO(ResultSet rs) throws SQLException {
677 		MatrixVO target = new MatrixVO();
678 
679 		int index = 0;
680 		target.setId(rs.getInt(++index));
681 		target.setName(rs.getString(++index));
682 
683 		return target;
684 	}
685 
686 	/**
687 	 * <p>
688 	 * toFractionVO.
689 	 * </p>
690 	 * 
691 	 * @param rs
692 	 *            a {@link java.sql.ResultSet} object.
693 	 * @return a {@link fr.ifremer.quadrige3.core.vo.referential.pmfm.FractionVO} object.
694 	 * @throws java.sql.SQLException
695 	 *             if any.
696 	 */
697 	protected FractionVO toFractionVO(ResultSet rs) throws SQLException {
698 		FractionVO target = new FractionVO();
699 
700 		int index = 0;
701 		target.setId(rs.getInt(++index));
702 		target.setName(rs.getString(++index));
703 
704 		return target;
705 	}
706 
707 	/**
708 	 * <p>
709 	 * toMethodVO.
710 	 * </p>
711 	 * 
712 	 * @param rs
713 	 *            a {@link java.sql.ResultSet} object.
714 	 * @return a {@link fr.ifremer.quadrige3.core.vo.referential.pmfm.MethodVO} object.
715 	 * @throws java.sql.SQLException
716 	 *             if any.
717 	 */
718 	protected MethodVO toMethodVO(ResultSet rs) throws SQLException {
719 		MethodVO target = new MethodVO();
720 
721 		int index = 0;
722 		target.setId(rs.getInt(++index));
723 		target.setName(rs.getString(++index));
724 
725 		return target;
726 	}
727 
728 	/**
729 	 * <p>
730 	 * toPmfmVO.
731 	 * </p>
732 	 * 
733 	 * @param rs
734 	 *            a {@link java.sql.ResultSet} object.
735 	 * @return a {@link fr.ifremer.quadrige3.core.vo.referential.pmfm.PmfmVO} object.
736 	 * @throws java.sql.SQLException
737 	 *             if any.
738 	 */
739 	protected PmfmVO toPmfmVO(ResultSet rs) throws SQLException {
740 		PmfmVO target = new PmfmVO();
741 
742 		int index = 0;
743 		target.setId(rs.getInt(++index));
744 
745 		// Parameter
746 		ParameterVO parameter = new ParameterVO();
747 		parameter.setCode(rs.getString(++index));
748 		parameter.setName(rs.getString(++index));
749 		target.setParameter(parameter);
750 
751 		// Matrix
752 		MatrixVO matrix = new MatrixVO();
753 		matrix.setId(rs.getInt(++index));
754 		matrix.setName(rs.getString(++index));
755 		target.setMatrix(matrix);
756 
757 		// Fraction
758 		FractionVO fraction = new FractionVO();
759 		fraction.setId(rs.getInt(++index));
760 		fraction.setName(rs.getString(++index));
761 		target.setFraction(fraction);
762 
763 		// Method
764 		MethodVO method = new MethodVO();
765 		method.setId(rs.getInt(++index));
766 		method.setName(rs.getString(++index));
767 		target.setMethod(method);
768 
769 		// Unit
770 		UnitVO unit = new UnitVO();
771 		unit.setId(rs.getInt(++index));
772 		unit.setName(rs.getString(++index));
773 		unit.setSymbol(rs.getString(++index));
774 		target.setUnit(unit);
775 
776 		return target;
777 	}
778 
779 	/**
780 	 * <p>
781 	 * toUnitVO.
782 	 * </p>
783 	 * 
784 	 * @param rs
785 	 *            a {@link java.sql.ResultSet} object.
786 	 * @return a {@link fr.ifremer.quadrige3.core.vo.referential.pmfm.UnitVO} object.
787 	 * @throws java.sql.SQLException
788 	 *             if any.
789 	 */
790 	protected UnitVO toUnitVO(ResultSet rs) throws SQLException {
791 		UnitVO target = new UnitVO();
792 
793 		int index = 0;
794 		target.setId(rs.getInt(++index));
795 		target.setName(rs.getString(++index));
796 		target.setSymbol(rs.getString(++index));
797 
798 		return target;
799 	}
800 
801 	/**
802 	 * <p>
803 	 * toAnalysisInstrumentVO.
804 	 * </p>
805 	 * 
806 	 * @param rs
807 	 *            a {@link java.sql.ResultSet} object.
808 	 * @return a {@link fr.ifremer.quadrige3.core.vo.referential.AnalysisInstrumentVO} object.
809 	 * @throws java.sql.SQLException
810 	 *             if any.
811 	 */
812 	protected AnalysisInstrumentVO toAnalysisInstrumentVO(ResultSet rs) throws SQLException {
813 		AnalysisInstrumentVO target = new AnalysisInstrumentVO();
814 
815 		int index = 0;
816 		target.setId(rs.getInt(++index));
817 		target.setName(rs.getString(++index));
818 
819 		return target;
820 	}
821 
822 	/**
823 	 * <p>
824 	 * toSamplingEquipmentVO.
825 	 * </p>
826 	 * 
827 	 * @param rs
828 	 *            a {@link java.sql.ResultSet} object.
829 	 * @return a {@link fr.ifremer.quadrige3.core.vo.referential.SamplingEquipmentVO} object.
830 	 * @throws java.sql.SQLException
831 	 *             if any.
832 	 */
833 	protected SamplingEquipmentVO toSamplingEquipmentVO(ResultSet rs) throws SQLException {
834 		SamplingEquipmentVO target = new SamplingEquipmentVO();
835 
836 		int index = 0;
837 		target.setId(rs.getInt(++index));
838 		target.setName(rs.getString(++index));
839 
840 		return target;
841 	}
842 
843 	/**
844 	 * <p>
845 	 * toQualitativeValueVO.
846 	 * </p>
847 	 * 
848 	 * @param rs
849 	 *            a {@link java.sql.ResultSet} object.
850 	 * @return a {@link fr.ifremer.quadrige3.core.vo.referential.pmfm.QualitativeValueVO} object.
851 	 * @throws java.sql.SQLException
852 	 *             if any.
853 	 */
854 	protected QualitativeValueVO toQualitativeValueVO(ResultSet rs) throws SQLException {
855 		QualitativeValueVO target = new QualitativeValueVO();
856 
857 		int index = 0;
858 		target.setId(rs.getInt(++index));
859 		target.setName(rs.getString(++index));
860 
861 		ParameterVO parameter = new ParameterVO();
862 		parameter.setCode(rs.getString(++index));
863 		parameter.setName(rs.getString(++index));
864 		target.setParameter(parameter);
865 
866 		return target;
867 	}
868 
869 	/**
870 	 * <p>
871 	 * toIds.
872 	 * </p>
873 	 * 
874 	 * @param pkStr
875 	 *            a {@link java.util.List} object.
876 	 * @return a {@link java.util.List} object.
877 	 */
878 	protected List<Integer> toIds(List<String> pkStr) {
879 		return pkStr.stream().map(s -> s == null ? null : Integer.parseInt(s.trim())).collect(Collectors.toList());
880 	}
881 }