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