1010
1111/******************************************************
1212 * Used by Explorer and one call in dotplot; it read proj_props, plus check for pairs
13- * CAS552 move ProjectPair class to here; removed lots of unused stuff; renamed from ProjectPool
13+ * dbProp contains everything in the proj_props DB table
14+ * Vector of pairs, Array of projects CAS570 renamed some stuff
1415 */
1516public class PropsDB {
16- private DatabaseProperties dbProp ;
17- private Vector <ProjectPair > projectPairs ;
18- private ProjectObj [] projects ;
17+ private DatabaseProperties dbProjProp ;
18+ private Vector <Pair > pairs ;
19+ private Project [] projects ;
1920 private DBconn2 dbc2 ;
2021
2122 public PropsDB (DBconn2 dbc2 ) { // DrawingPanel and Dotplot.Data
2223 this .dbc2 = dbc2 ;
23- projectPairs = new Vector <ProjectPair >();
24- dbProp = new DatabaseProperties ();
24+ pairs = new Vector <Pair >();
25+ dbProjProp = new DatabaseProperties ();
2526 load ();
2627 }
2728
2829 private void load () {
2930 try {
30- projectPairs .clear ();
31- dbProp .load (dbc2 );
31+ pairs .clear ();
32+
33+ // Projects
34+ dbProjProp .loadAllProps (dbc2 );
3235
33- Vector <ProjectObj > pvector = new Vector <ProjectObj >();
36+ Vector <Project > pvector = new Vector <Project >();
3437
3538 ResultSet rs = null ;
3639 int id , p1id , p2id ;
3740
3841 rs = dbc2 .executeQuery ("select idx,type,name from projects" );
3942 while (rs .next ()) {
4043 id = rs .getInt (1 );
41- pvector .add (new ProjectObj (id ,rs .getString (3 ),rs .getString (2 )));
44+ pvector .add (new Project (id ,rs .getString (3 ),rs .getString (2 )));
4245 }
4346 rs .close ();
4447
4548 if (!pvector .isEmpty ()) {
46- projects = new ProjectObj [pvector .size ()];
47- projects = (ProjectObj [])pvector .toArray (projects );
49+ projects = new Project [pvector .size ()];
50+ projects = (Project [])pvector .toArray (projects );
4851 }
49-
52+ // Pairs
5053 rs = dbc2 .executeQuery ("SELECT idx,proj1_idx,proj2_idx FROM pairs" );
5154 while (rs .next ()) {
5255 p1id = rs .getInt (2 );
5356 p2id = rs .getInt (3 );
54- projectPairs .add ( new ProjectPair (rs .getInt (1 ), p1id , p2id ) );
57+ pairs .add ( new Pair (rs .getInt (1 ), p1id , p2id ) );
5558 }
5659
57- for (ProjectPair pp : projectPairs ) {// CAS552 add for Sequence popup
60+ for (Pair pp : pairs ) {// for Sequence popup
5861 String x = dbc2 .executeString ("select value from pair_props where name='algo1' and pair_idx=" + pp .pid );
5962 pp .isAlgo1 = (x !=null ) ? x .equals ("1" ) : true ;
63+ x = dbc2 .executeString ("select value from pair_props where name='number_pseudo' and pair_idx=" + pp .pid );
64+ pp .hasPseudo = (x !=null ) ? x .equals ("1" ) : false ;
6065 }
6166 rs .close ();
6267 }
6368 catch (Exception e ) {ErrorReport .print (e , "Project pool reset" );}
6469 }
65-
70+
6671 public boolean isAlgo1 (int pp1 , int pp2 ) {
67- if (hasProjectPair (pp1 , pp2 )) return getProjectPair (pp1 , pp2 ).isAlgo1 ;
68- else return getProjectPair (pp2 , pp1 ).isAlgo1 ;
72+ if (hasPair (pp1 , pp2 )) return getPair (pp1 , pp2 ).isAlgo1 ;
73+ if (hasPair (pp2 , pp1 )) return getPair (pp2 , pp1 ).isAlgo1 ;
74+ return false ;
6975 }
76+
7077 public String getProperty (int projectID , String property ) { // Sequence
71- return dbProp .getProperty ((Object ) projectID ,property );
78+ return dbProjProp .getProperty ((Object ) projectID ,property );
7279 }
7380
7481 public String getName (int projectID ) { // Sequence
@@ -82,49 +89,54 @@ public String getDisplayName(int projectID) { // Sequence
8289 return getProperty (projectID ,"display_name" );
8390 }
8491
85- public boolean hasProjectPair (int p1 , int p2 ) { // MapperPool
86- for (ProjectPair pp : projectPairs ) {
92+ public boolean hasPair (int p1 , int p2 ) { // MapperPool
93+ for (Pair pp : pairs ) {
8794 if (pp .p1 == p1 && pp .p2 == p2 )
8895 return true ;
8996 }
9097 return false ;
9198 }
99+ public boolean hasPseudo (int pp1 , int pp2 ) { // MapperPool
100+ if (hasPair (pp1 , pp2 )) return getPair (pp1 , pp2 ).hasPseudo ;
101+ if (hasPair (pp2 , pp1 )) return getPair (pp2 , pp1 ).hasPseudo ;
102+ return false ;
103+ }
92104
93105 public boolean isSwapped (int pX , int pY ) { // Data
94- ProjectPair pair = getProjectPair (pX , pY );
106+ Pair pair = getPair (pX , pY );
95107 return (pair == null || pX == pair .getP1 ());
96108 }
97- private ProjectPair getProjectPair (int p1 , int p2 ) {
98- for (ProjectPair pp : projectPairs ) {
99- if ((pp .getP1 () == p1 && pp .getP2 () == p2 )
100- || (pp .getP1 () == p2 && pp .getP2 () == p1 ))
109+ private Pair getPair (int p1 , int p2 ) {
110+ for (Pair pp : pairs ) {
111+ if ((pp .getP1 () == p1 && pp .getP2 () == p2 ) || (pp .getP1 () == p2 && pp .getP2 () == p1 ))
101112 return pp ;
102113 }
103114 return null ;
104115 }
105116 /////////////////////////////////////////////////////////////////////
106- protected class ProjectObj {
117+ protected class Project {
107118 protected int id ;
108119 protected String name ;
109120 protected String type ;
110-
111- protected ProjectObj (int id , String name , String type ) {
121+
122+ protected Project (int id , String name , String type ) {
112123 this .id = id ;
113124 if (name == null ) this .name = "" ;
114125 else this .name = name ;
115126 this .type = type .intern ();
116127 }
117128
118129 public boolean equals (Object obj ) {
119- return obj instanceof ProjectObj && ((ProjectObj )obj ).id == id ;
130+ return obj instanceof Project && ((Project )obj ).id == id ;
120131 }
121132 }
122- private class ProjectPair {
133+ private class Pair {
123134 private int p1 , p2 ;
124135 private int pid ;
125136 private boolean isAlgo1 =false ;
137+ private boolean hasPseudo =false ; // CAS570 add for MapperPool to know if need to set annot_hits annot_idx to 0
126138
127- protected ProjectPair (int pid , int p1 , int p2 ) {
139+ protected Pair (int pid , int p1 , int p2 ) {
128140 this .pid = pid ;
129141 this .p1 = p1 ;
130142 this .p2 = p2 ;
@@ -138,16 +150,14 @@ protected ProjectPair(int pid, int p1, int p2) {
138150
139151 /**
140152 * Class DatabaseProperties can load properties from a database for quick access.
141- * @see Properties CAS534 moved from a separate file in util; this needs cleaning...
142153 */
143154 @ SuppressWarnings ("serial" ) // Prevent compiler warning for missing serialVersionUID
144- public class DatabaseProperties extends Properties {
155+ private class DatabaseProperties extends Properties {
145156 public static final String SEPARATOR = ":##:" ;
146157
147- private DatabaseProperties () {
148- super ();
149- }
150- private void load (DBconn2 dbc2 ) throws Exception {
158+ private DatabaseProperties () {super ();}
159+
160+ private void loadAllProps (DBconn2 dbc2 ) throws Exception {
151161 ResultSet rs = null ;
152162 try {
153163 rs = dbc2 .executeQuery ("SELECT proj_idx, name, value from proj_props" );
@@ -157,13 +167,11 @@ private void load(DBconn2 dbc2) throws Exception {
157167 }
158168 finally {
159169 if (rs != null ) {
160- try { rs .close ();
161- } catch (Exception e ) { }
170+ try { rs .close ();} catch (Exception e ) { }
162171 rs = null ;
163172 }
164173 }
165174 }
166-
167175 protected String getProperty (Object id , String name ) {
168176 return getProperty (getKey (id ,name ));
169177 }
0 commit comments