Salome HOME
Siman codebase is refactored. Spring beans are introduced in the context.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / admin / ImportedStudy.java
1 package org.splat.simer.admin;
2
3 import java.sql.Connection;
4 import java.sql.ResultSet;
5 import java.sql.SQLException;
6 import java.sql.Statement;
7 import java.util.ArrayList;
8 import java.util.List;
9
10 import org.hibernate.Session;
11 import org.hibernate.jdbc.Work;
12 import org.splat.dal.dao.som.Database;
13 import org.splat.dal.bo.som.Study;
14 import org.splat.service.SearchService;
15
16
17 public class ImportedStudy {
18
19     private SearchService _searchService;
20         private int     rid;
21     private String  sid;
22     private String  title;
23
24     protected class SelectStudies implements Work {
25 //  ----------------------------------------------------
26
27       private List<ImportedStudy> table = new ArrayList<ImportedStudy>();
28
29       protected SelectStudies(SearchService searchService) {
30       }
31       
32       public void execute (Connection connex) throws SQLException
33       {
34         Statement        request = connex.createStatement();
35         String           select  = "SELECT rid,sid,title FROM study";
36         ResultSet        result  = request.executeQuery(select);
37         Study.Properties sprop   = new Study.Properties();
38
39         while (result.next()) {
40           int    rid   = result.getInt("rid");
41           String sid   = result.getString("sid");
42           String title = result.getString("title");
43           try {
44             sprop.clear();
45             if (getSearchService().selectStudiesWhere(sprop.setReference(sid)).size() != 0) continue;
46           } catch (Exception error) {
47                 continue;
48           }
49           table.add( new ImportedStudy(rid, sid, title) );
50         }
51       }
52       
53       public List<ImportedStudy> getResult ()
54       {
55         return table;
56       }
57     }
58
59 //  ==============================================================================================================================
60 //  Constructor
61 //  ==============================================================================================================================
62
63     public ImportedStudy () {
64     }
65
66     public ImportedStudy (int rid, String sid, String title) {
67     //  --------------------------------------------------------
68           this.rid   = rid;
69           this.sid   = sid;
70           this.title = title;
71         }
72
73 //  ==============================================================================================================================
74 //  Public member functions
75 //  ==============================================================================================================================
76
77     public int getIndex () {
78 //  ----------------------
79       return rid;
80     }
81     public String getReference () {
82 //  -----------------------------
83       return sid;
84     }
85     public String getTitle () {
86 //  -------------------------
87       return title;
88     }
89
90 //  ==============================================================================================================================
91 //  Public services
92 //  ==============================================================================================================================
93
94     public List<ImportedStudy> selectAll () {
95 //  ----------------------------------------------
96       Session        session = Database.getSession();
97       SelectStudies  query   = new SelectStudies(getSearchService());
98       session.doWork(query);
99
100       return  query.getResult();
101     }
102
103         public org.splat.service.SearchService getSearchService() {
104                 return _searchService;
105         }
106
107         public void setSearchService(SearchService searchService) {
108                 _searchService = searchService;
109         }
110 }