1 package fr.ifremer.quadrige2.core.dao.referential;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
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
102
103
104
105
106 @Autowired
107 public ReferentialJdbcDaoImpl(DataSource dataSource) {
108 super(dataSource);
109 this.connectionProperties = null;
110 }
111
112
113
114
115 public ReferentialJdbcDaoImpl() {
116 this((Properties) null);
117 }
118
119
120
121
122
123
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
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
150 checkAllQueriesExists();
151 }
152
153
154 @Override
155 public void afterPropertiesSet() throws Exception {
156
157 checkAllQueriesExists();
158 }
159
160
161 @Override
162 public List<MonitoringLocationVO> getMonitoringLocationsByIds(List<Integer> ids) {
163
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
178 @Override
179 public MonitoringLocationVO getMonitoringLocationById(int id) {
180
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
195 @Override
196 public List<TaxonNameVO> getTaxonNamesByReferenceTaxonIds(List<Integer> ids) {
197
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
212 @Override
213 public TaxonNameVO getTaxonNameByReferenceTaxonId(int id) {
214
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
229 @Override
230 public List<TaxonGroupVO> getTaxonGroupsByIds(List<Integer> ids) {
231
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
246 @Override
247 public TaxonGroupVO getTaxonGroupById(int id) {
248
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
263 @Override
264 public List<ParameterVO> getParametersByCodes(List<String> codes) {
265
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
280 @Override
281 public ParameterVO getParameterByCode(String code) {
282
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
297 @Override
298 public List<MatrixVO> getMatrixesByIds(List<Integer> ids) {
299
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
314 @Override
315 public MatrixVO getMatrixById(int id) {
316
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
331 @Override
332 public List<FractionVO> getFractionsByIds(List<Integer> ids) {
333
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
348 @Override
349 public FractionVO getFractionById(int id) {
350
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
365 @Override
366 public List<MethodVO> getMethodsByIds(List<Integer> ids) {
367
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
382 @Override
383 public MethodVO getMethodById(int id) {
384
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
399 @Override
400 public List<PmfmVO> getPmfmsByIds(List<Integer> ids) {
401
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
416 @Override
417 public PmfmVO getPmfmById(int id) {
418
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
433 @Override
434 public List<UnitVO> getUnitsByIds(List<Integer> ids) {
435
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
450 @Override
451 public UnitVO getUnitById(int id) {
452
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
467 @Override
468 public List<AnalysisInstrumentVO> getAnalysisInstrumentsByIds(List<Integer> ids) {
469
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
484 @Override
485 public AnalysisInstrumentVO getAnalysisInstrumentById(int id) {
486
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
501 @Override
502 public List<SamplingEquipmentVO> getSamplingEquipmentsByIds(List<Integer> ids) {
503
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
518 @Override
519 public SamplingEquipmentVO getSamplingEquipmentById(int id) {
520
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
535 @Override
536 public List<QualitativeValueVO> getQualitativeValueByIds(List<Integer> ids) {
537
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
552 @Override
553 public QualitativeValueVO getQualitativeValueById(int id) {
554
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
569 @Override
570 public List<?> getVOsByTableNameAndPks(String tableName, List<String> pks) {
571
572
573 if (tableName.equals(ReferentialSynchroTables.MONITORING_LOCATION.name())) {
574 return getMonitoringLocationsByIds(toIds(pks));
575 }
576
577
578 if (tableName.equals(ReferentialSynchroTables.REFERENCE_TAXON.name())) {
579 return getTaxonNamesByReferenceTaxonIds(toIds(pks));
580 }
581
582
583 if (tableName.equals(ReferentialSynchroTables.TAXON_GROUP.name())) {
584 return getTaxonGroupsByIds(toIds(pks));
585 }
586
587
588 if (tableName.equals(ReferentialSynchroTables.PARAMETER.name())) {
589 return getParametersByCodes(pks);
590 }
591
592
593 if (tableName.equals(ReferentialSynchroTables.MATRIX.name())) {
594 return getMatrixesByIds(toIds(pks));
595 }
596
597
598 if (tableName.equals(ReferentialSynchroTables.FRACTION.name())) {
599 return getFractionsByIds(toIds(pks));
600 }
601
602
603 if (tableName.equals(ReferentialSynchroTables.METHOD.name())) {
604 return getMethodsByIds(toIds(pks));
605 }
606
607
608 if (tableName.equals(ReferentialSynchroTables.PMFM.name())) {
609 return getPmfmsByIds(toIds(pks));
610 }
611
612
613 if (tableName.equals(ReferentialSynchroTables.UNIT.name())) {
614 return getUnitsByIds(toIds(pks));
615 }
616
617
618 if (tableName.equals(ReferentialSynchroTables.ANALYSIS_INSTRUMENT.name())) {
619 return getAnalysisInstrumentsByIds(toIds(pks));
620 }
621
622
623 if (tableName.equals(ReferentialSynchroTables.SAMPLING_EQUIPMENT.name())) {
624 return getSamplingEquipmentsByIds(toIds(pks));
625 }
626
627
628 if (tableName.equals(ReferentialSynchroTables.QUALITATIVE_VALUE.name())) {
629 return getQualitativeValueByIds(toIds(pks));
630 }
631
632
633 if (tableName.equals(ReferentialSynchroTables.QUSER.name())) {
634 return quserJdbcDao.getUsersByIds(toIds(pks));
635 }
636
637
638 if (tableName.equals(ReferentialSynchroTables.DEPARTMENT.name())) {
639 return departmentJdbcDao.getDepartmentsByIds(toIds(pks));
640 }
641
642
643 if (tableName.equals(ReferentialSynchroTables.PROGRAMME.name())) {
644 return programStrategyJdbcDao.getProgramsByCodes(pks);
645 }
646
647
648 if (tableName.equals(ReferentialSynchroTables.STRATEGY.name())) {
649 return programStrategyJdbcDao.getStrategiesByIds(toIds(pks));
650 }
651
652
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
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
672
673
674
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
695
696
697
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
707
708
709
710
711
712
713
714
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
729
730
731
732
733
734
735
736
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
750
751
752
753
754
755
756
757
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
771
772
773
774
775
776
777
778
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
792
793
794
795
796
797
798
799
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
813
814
815
816
817
818
819
820
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
834
835
836
837
838
839
840
841
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
855
856
857
858
859
860
861
862
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
871 ParameterVO parameter = new ParameterVO();
872 parameter.setCode(rs.getString(index++));
873 parameter.setName(rs.getString(index++));
874 target.setParameter(parameter);
875
876
877 MatrixVO matrix = new MatrixVO();
878 matrix.setId(rs.getInt(index++));
879 matrix.setName(rs.getString(index++));
880 target.setMatrix(matrix);
881
882
883 FractionVO fraction = new FractionVO();
884 fraction.setId(rs.getInt(index++));
885 fraction.setName(rs.getString(index++));
886 target.setFraction(fraction);
887
888
889 MethodVO method = new MethodVO();
890 method.setId(rs.getInt(index++));
891 method.setName(rs.getString(index++));
892 target.setMethod(method);
893
894
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
906
907
908
909
910
911
912
913
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
928
929
930
931
932
933
934
935
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
949
950
951
952
953
954
955
956
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
970
971
972
973
974
975
976
977
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
996
997
998
999
1000
1001
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 }