Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
814 mhunt 1
package com.erggroup.buildtool.ripple;
2
 
3
import java.sql.CallableStatement;
4
import java.sql.Connection;
5
 
6
import java.sql.DriverManager;
7
 
8
import java.sql.PreparedStatement;
9
import java.sql.ResultSet;
10
import java.sql.SQLException;
11
 
12
import java.sql.Timestamp;
13
 
14
import java.sql.Types;
15
 
16
import java.util.Calendar;
17
import java.util.Date;
18
import java.util.GregorianCalendar;
19
import java.util.Iterator;
20
import java.util.ListIterator;
21
import java.util.Vector;
22
 
23
import oracle.jdbc.driver.OracleDriver;
24
 
25
import org.apache.log4j.Logger;
26
 
27
/**Release Manager schema abstraction
28
 */
29
public class ReleaseManager
30
{
31
  /**Unit test hook.
32
   * Prevents Oracle interaction when false.
33
   * @attribute
34
   */
35
  public static boolean mUseDatabase = true;
36
 
37
  /**Unit test hook
38
   * Container of persisted run levels for unit test usage
39
   * Must be managed by the unit test code
40
   * @attribute
41
   */
42
  public static Vector mPersistedRunLevelCollection = new Vector();
43
 
44
  /**database represented enumerated value
45
   * @attribute
46
   */
47
  public static final int DB_CANNOT_CONTINUE = 1;
48
 
49
  /**database represented enumerated value
50
   * @attribute
51
   */
52
  public static final int DB_PAUSED = 2;
53
 
54
  /**database represented enumerated value
55
   * @attribute
56
   */
57
  public static final int DB_ACTIVE = 3;
58
 
59
  /**database represented enumerated value
60
   * @attribute
61
   */
62
  public static final int DB_IDLE = 4;
63
 
64
  /**database represented enumerated value
65
   * @attribute
66
   */
67
  public static final int DB_WAITING = 5;
68
 
69
  /**package object of no consequence
70
   * @attribute
71
   */
72
  static final Package NULL_PACKAGE = new Package();
73
 
74
  /**registered status
75
   * @attribute
76
   */
77
  static boolean mRegistered = false;
78
 
79
  /**Logger
80
   * @attribute
81
   */
82
  private static final Logger mLogger = Logger.getLogger(ReleaseManager.class);
83
 
84
  /**database session handle
85
   * @attribute
86
   */
87
  private Connection mConnection = null;
88
 
89
  /**index to current ReleaseConfig item
90
   * @attribute
91
   */
92
  private int mReleaseConfigIndex = -1;
93
 
94
  /**index to current RunLevel item
95
   * @attribute
96
   */
97
  private int mRunLevelIndex = -1;
98
 
99
  /**collection of ReleaseConfig objects
100
   * @attribute
101
   */
102
  private Vector mReleaseConfigCollection = new Vector();
103
 
104
  /**database connection string
105
   * @attribute
106
   */
107
  private static String mConnectionString = new String();
108
 
109
  /**database username
110
   * @attribute
111
   */
112
  private static String mUsername = new String();
113
 
114
  /**database password
115
   * @attribute
116
   */
117
  private static String mPassword = new String();
118
 
119
  /**collection of RunLevel objects
120
   * @attribute
121
   */
122
  private Vector mRunLevelCollection = new Vector();
123
 
124
  /**in daemon mode
125
   *   select gm.gbe_value from release_config rc, gbe_machtype gm
126
   *   where rc.rtag_id=<baseline> and gm.gbe_id=rc.gbe_id;
127
   * in escrow mode
128
   *   select gm.gbe_value from boms b, release_manager.release_config rc,
129
   *   release_manager.gbe_machtype gm
130
   *   where b.bom_id=<baseline> and rc.rtag_id=b.rtag_id_fk and gm.gbe_id=rc.gbe_id;
131
   * populates the machtypeCollection with the resultset
132
   */
133
  void queryMachtypes(Vector machtypeCollection, boolean daemonMode, int baseline) throws SQLException, Exception
134
  {
135
    mLogger.debug("queryMachtypes " + daemonMode);
136
    if ( !mUseDatabase )
137
    {
138
      mLogger.info("queryMachtypes !mUseDatabase");
139
      // a highly unlikely set of machtypes
140
      String machtype = new String("linux_i386");
141
      machtypeCollection.add(machtype);
142
      machtype = new String("sparc");
143
      machtypeCollection.add(machtype);
144
      machtype = new String("solaris10_x86");
145
      machtypeCollection.add(machtype);
146
    }
147
    else
148
    {
149
      String sql = new String("");
150
 
151
      if ( daemonMode )
152
      {
153
        sql = "select gm.gbe_value from release_manager.release_config rc, release_manager.gbe_machtype gm where rc.rtag_id=" + baseline + " and gm.gbe_id=rc.gbe_id";
154
      }
155
      else
156
      {
157
        sql = 
158
        "select gm.gbe_value from boms b, release_manager.release_config rc, release_manager.gbe_machtype gm where b.bom_id=" + 
159
        baseline + " and rc.rtag_id=b.rtag_id_fk and gm.gbe_id=rc.gbe_id";
160
      }
161
 
162
      try
163
      {
164
        CallableStatement stmt = mConnection.prepareCall(sql);
165
        ResultSet rset = stmt.executeQuery();
166
 
167
        while( rset.next() )
168
        {
169
          String machtype = rset.getString("gbe_value");
170
 
171
          if ( machtype != null )
172
          {
173
            machtypeCollection.add(machtype);
174
          }
175
        }
830 mhunt 176
 
177
        rset.close();
178
        stmt.close();
814 mhunt 179
      }
180
      catch ( SQLException e )
181
      {
182
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
183
        {
184
          mLogger.error("queryMachtypes database access error only");
185
          throw new SQLException();
186
        }
187
        else
188
        {
189
          mLogger.fatal("queryMachtypes show stopper");
190
          throw new Exception();
191
        }
192
      }
193
    }
194
  }
195
 
196
  /**in daemon mode
197
   *   select p.proj_name, rt.rtag_name from projects p, release_tags rt
198
   *   where rt.rtag_id=<baseline> and p.proj_id=rt.proj_id;
199
   * returns a concatenation of the proj_name and rtag_name
200
   * in escrow mode
201
   *   select dp.proj_name, br.branch_name, b.bom_version, b.bom_lifecycle
202
   *   from dm_projects dp, branches br, boms b
203
   *   where b.bom_id=<baseline> and br.branch_id=b.branch_id and dp.proj_id=br.proj_id;
204
   * returns a concatenation of the proj_name, branch_name, bom_version and bom_lifecycle
205
   */
206
  String queryBaselineName(boolean daemonMode, int baseline) throws SQLException, Exception
207
  {
208
    mLogger.debug("queryBaselineName " + daemonMode);
209
    String retVal = new String();
210
 
211
    if ( !mUseDatabase )
212
    {
213
      mLogger.info("queryBaselineName !mUseDatabase");
214
      // a highly unlikely baseline name
215
      if (daemonMode)
216
      {
217
        retVal = "TIMBUKTU (TIM) > R7";
218
      }
219
      else
220
      {
221
        retVal = "TIMBUKTU (TIM) > R7 7.9";
222
      }
223
    }
224
    else
225
    {
226
      String sql = new String("");
227
 
228
      if ( daemonMode )
229
      {
230
        sql = "select p.proj_name, rt.rtag_name from release_manager.projects p, release_manager.release_tags rt where rt.rtag_id=" + baseline + " and p.proj_id=rt.proj_id";
231
      }
232
      else
233
      {
234
        sql = 
235
        "select dp.proj_name, br.branch_name, b.bom_version, b.bom_lifecycle from dm_projects dp, branches br, boms b where b.bom_id=" + 
236
        baseline + " and br.branch_id=b.branch_id and dp.proj_id=br.proj_id";
237
      }
238
 
239
      try
240
      {
241
        CallableStatement stmt = mConnection.prepareCall(sql);
242
        ResultSet rset = stmt.executeQuery();
243
 
244
        while( rset.next() )
245
        {
246
          String proj_name = rset.getString("proj_name");
247
 
248
          if ( proj_name != null )
249
          {
250
            retVal += proj_name;
251
          }
252
 
253
          if ( daemonMode )
254
          {
255
            String rtag_name = rset.getString("rtag_name");
256
 
257
            if ( rtag_name != null )
258
            {
259
              retVal += " > " + rtag_name;
260
            }
261
          }
262
          else
263
          {
264
            String branch_name = rset.getString("branch_name");
265
 
266
            if ( branch_name != null )
267
            {
268
              retVal += " > " + branch_name;
269
            }
270
 
271
            String bom_version = rset.getString("bom_version");
272
 
273
            if ( bom_version != null )
274
            {
275
              retVal += " " + bom_version;
276
            }
277
 
278
            String bom_lifecycle = rset.getString("bom_lifecycle");
279
 
280
            if ( bom_lifecycle != null )
281
            {
282
              retVal += "." + bom_lifecycle;
283
            }
284
          }
285
        }
830 mhunt 286
 
287
        rset.close();
288
        stmt.close();
814 mhunt 289
      }
290
      catch ( SQLException e )
291
      {
292
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
293
        {
294
          mLogger.error("queryBaselineName database access error only");
295
          throw new SQLException();
296
        }
297
        else
298
        {
299
          mLogger.fatal("queryBaselineName show stopper");
300
          throw new Exception();
301
        }
302
      }
303
    }
304
    mLogger.info("queryBaselineName returned " + retVal);
305
    return retVal;
306
  }
307
 
308
  /**in daemon mode
309
   *  1 get planned package info
310
   *     select pl.pv_id, p.pkg_id, p.pkg_name, pv.v_ext, pv.pkg_label, pv.src_path, pv.change_type
311
   *     from planned pl, package_versions pv, packages p
312
   *     where pl.rtag_id=<mBaseline> and pv.build_type='A' and pv.dlocked='A'
313
   *     and pv.pv_id=pl.pv_id and p.pkg_id=pv.pkg_id
314
   *     order by pl.pv_id;
315
   *  2 get planned package dependency info
316
   *     select pl.pv_id, p.pkg_name, dpv.v_ext
317
   *     from planned pl, package_versions pv, package_dependencies pd, package_versions dpv, packages p
318
   *     where pl.rtag_id=<mBaseline> and pv.build_type='A' and pv.dlocked='A'
319
   *     and pv.pv_id = pl.pv_id and pd.pv_id=pl.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id
320
   *     order by pl.pv_id;
321
   *  3 get planned package build info
322
   *     select pl.pv_id, bm.bm_name, bsa.bsa_name
323
   *     from planned pl, package_versions pv, package_build_info pbi, build_machines bm, build_standards_addendum bsa
324
   *     where pl.rtag_id=<mBaseline> and pv.build_type='A' and pv.dlocked='A'
325
   *     and pv.pv_id = pl.pv_id and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id
326
   *     order by pl.pv_id;
327
   *  4 get planned package unit test info
328
   *     select pl.pv_id, tt.test_type_name
329
   *     from planned pl, package_versions pv, unit_tests ut, test_types tt
330
   *     where pl.rtag_id=<mBaseline> and pv.build_type='A' and pv.dlocked='A'
331
   *     and pv.pv_id = pl.pv_id and ut.pv_id=pv.pv_id and tt.test_type_id=ut.test_types_fk
332
   *     order by pl.pv_id;
333
   *  5 get planned package build failure info
334
   *     select pl.pv_id, u.user_email
335
   *     from planned pl, release_tags rt, package_versions pv, autobuild_failure af, members_group mg, users u
336
   *     where pl.rtag_id=<mBaseline> and rt.rtag_id=pl.rtag_id and pv.build_type='A' and pv.dlocked='A'
337
   *     and pv.pv_id = pl.pv_id and af.view_id=pl.view_id and mg.group_email_id=af.group_email_id and u.user_id=mg.user_id and af.proj_id=rt.proj_id
338
   *     order by pl.pv_id;
339
   *  6 get planned package do not ripple info
340
   *     select pl.pv_id
341
   *     from planned pl, package_versions pv, do_not_ripple dnr
342
   *     where pl.rtag_id=<mBaseline> and pv.build_type='A' and pv.dlocked='A'
343
   *     and pv.pv_id = pl.pv_id and dnr.rtag_id=pl.rtag_id and dnr.pv_id=pl.pv_id
344
   *     order by pl.pv_id;
345
   *  7 get planned package advisory ripple info
346
   *     select pl.pv_id
347
   *     from planned pl, package_versions pv, advisory_ripple ar
348
   *     where pl.rtag_id=<mBaseline> and pv.build_type='A' and pv.dlocked='A'
349
   *     and pv.pv_id = pl.pv_id and ar.rtag_id=pl.rtag_id and ar.pv_id=pl.pv_id
350
   *     order by pl.pv_id;
351
   *  8 get released package info
352
   *     select rc.pv_id, p.pkg_id, p.pkg_name, pv.pkg_version, pv.v_ext, pv.pkg_label, pv.src_path, pv.ripple_field
353
   *     from release_content rc, package_versions pv, packages p
354
   *     where rc.rtag_id=<mBaseline>
355
   *     and pv.pv_id = rc.pv_id and p.pkg_id = pv.pkg_id
356
   *     order by rc.pv_id;
357
   *  9 get released package dependency info
358
   *     select rc.pv_id, dpv.pv_id, p.pkg_name, dpv.v_ext
359
   *     from release_content rc, package_versions pv, package_dependencies pd, package_versions dpv, packages p
360
   *     where rc.rtag_id=<mBaseline>
361
   *     and pv.pv_id = rc.pv_id and pd.pv_id=pv.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id
362
   *     order by rc.pv_id;
363
   * 10 get released package build info
364
   *     select rc.pv_id, bm.bm_name, bsa.bsa_name
365
   *     from release_content rc, package_versions pv, package_build_info pbi, build_machines bm, build_standards_addendum bsa
366
   *     where rc.rtag_id=<mBaseline>
367
   *     and pv.pv_id = rc.pv_id and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id
368
   *     order by rc.pv_id;
369
   * 11 get released package unit test info
370
   *     select rc.pv_id, tt.test_type_name
371
   *     from release_content rc, package_versions pv, unit_tests ut, test_types tt
372
   *     where rc.rtag_id=<mBaseline>
373
   *     and pv.pv_id = rc.pv_id and ut.pv_id=pv.pv_id and tt.test_type_id=ut.test_types_fk
374
   *     order by rc.pv_id;
375
   * 12 get released package build failure email info
376
   *     select rc.pv_id, u.user_email
377
   *     from release_content rc, release_tags rt, package_versions pv, autobuild_failure af, members_group mg, users u
378
   *     where rc.rtag_id=<mBaseline> and rt.rtag_id=rc.rtag_id
379
   *     and pv.pv_id = rc.pv_id and af.view_id=rc.base_view_id and mg.group_email_id=af.group_email_id and u.user_id=mg.user_id and af.proj_id=rt.proj_id
380
   *     order by rc.pv_id;
381
   * 13 get released package do not ripple info
382
   *     select rc.pv_id
383
   *     from release_content rc, package_versions pv, do_not_ripple dnr
384
   *     where rc.rtag_id=3741
385
   *     and pv.pv_id = rc.pv_id and dnr.rtag_id=rc.rtag_id and dnr.pv_id=rc.pv_id
386
   *     order by rc.pv_id;
387
   * 14 get released advisory ripple info
388
   *     select rc.pv_id
389
   *     from release_content rc, package_versions pv, advisory_ripple ar
390
   *     where rc.rtag_id=<mBaseline>
391
   *     and pv.pv_id = rc.pv_id and ar.rtag_id=rc.rtag_id and ar.pv_id=rc.pv_id
392
   *     order by rc.pv_id;
393
   * in escrow mode
394
   *  1 get released product info
395
   *     select oc.prod_id, p.pkg_name, pv.pkg_version, pv.v_ext, pv.pkg_label, pv.src_path
396
   *     from bom_contents bc, operating_systems os, os_contents oc, release_manager.package_versions pv, release_manager.packages p
397
   *     where bc.bom_id=<mBaseline> and os.node_id=bc.node_id and oc.os_id=os.os_id and pv.pv_id=oc.prod_id and p.pkg_id=pv.pkg_id
398
   *     order by oc.prod_id;
399
   *    this will generate a list of pv_ids associtaed with products
400
   *    many in the list will reference cots products outside the scope of a escrow build
401
   *  2 for each <pv_id>, call traverseDependencies( packageCollection, pv_id, false ) to traverse its set of dependencies
402
   *  3 for each Package, call queryBuildInfo to get released package build info
403
   *  
404
   * Supports
405
   *    test_type_name="Autobuild UTF"
406
   *    bm_name="Generic"|"Linux"|"Solaris"|"Win32"
407
   *    bsa_name="Debug"|"Production"|"Production and Debug"|"Java 1.4"|"Java 1.5"|"Java 1.6"
408
   */
409
  void queryPackageVersions(RippleEngine rippleEngine, 
410
                            Vector packageCollection, boolean daemonMode, int baseline) throws SQLException, Exception
411
  {
412
    mLogger.debug("queryPackageVersions " + daemonMode);
413
 
414
    if ( !mUseDatabase )
415
    {
416
      mLogger.info("queryPackageVersions !mUseDatabase");
417
 
418
      if (daemonMode)
419
      {
420
        /* a highly unlikely set of packages
421
         * planned info
422
         * pv_id pkg_id pkg_name                     v_ext pkg_label src_path                          change_type
423
         * 0     76     UncommonDependency           .tim  0.TIM.WIP \vob\UncommonDependency           P
424
         * 1     1011   DependencyMissingFromRelease .tim  1.TIM.WIP \vob\DependencyMissingFromRelease M
425
         * 2     34     CommonDependency             .tim  2.TIM.WIP \vob\CommonDependency             M
426
         * 3     908    SolarisCentricProduct        .tim  3.TIM.WIP \vob\SolarisCentricProduct        N
427
         * 4     6      GenericProduct               .tim  4.TIM.WIP \vob\GenericProduct               P
428
         * 5     11     Product                      .tim  5.TIM.WIP \vob\Product                      M
429
         * 6     113    UnfinishedProduct            .tim  6.TIM.WIP \vob\UnfinishedProduct            M
430
         */
431
         if ( mConnectionString.compareTo("iteration1") == 0 )
432
         {
433
           Package p = new Package(0, "UncommonDependency", ".tim", "UncommonDependency.tim", "0.TIM.WIP", "\\vob\\UncommonDependency", 'P');
434
           p.mPid = 76;
435
           p.mDirectlyPlanned = true;
436
           packageCollection.add(p);
437
         }
438
 
439
         Package p = new Package(1, "DependencyMissingFromRelease", ".tim", "DependencyMissingFromRelease.tim", "1.TIM.WIP", "\\vob\\DependencyMissingFromRelease", 'M');
440
         p.mPid = 1011;
441
         p.mDirectlyPlanned = true;
442
         packageCollection.add(p);
443
 
444
         if ( mConnectionString.compareTo("iteration1") == 0 || mConnectionString.compareTo("iteration2") == 0 )
445
         {
446
           p = new Package(2, "CommonDependency", ".tim", "CommonDependency.tim", "2.TIM.WIP", "\\vob\\CommonDependency", 'M');
447
           p.mPid = 34;
448
           p.mDirectlyPlanned = true;
449
           packageCollection.add(p);
450
         }
451
 
452
         if ( mConnectionString.compareTo("iteration1") == 0 
453
           || mConnectionString.compareTo("iteration2") == 0
454
           || mConnectionString.compareTo("iteration3") == 0 )
455
         {
456
           p = new Package(3, "SolarisCentricProduct", ".tim", "SolarisCentricProduct.tim", "3.TIM.WIP", "\\vob\\SolarisCentricProduct", 'N');
457
           p.mPid = 908;
458
           p.mDirectlyPlanned = true;
459
           packageCollection.add(p);
460
         }
461
 
462
         if ( mConnectionString.compareTo("iteration1") == 0 
463
           || mConnectionString.compareTo("iteration2") == 0
464
           || mConnectionString.compareTo("iteration3") == 0
465
           || mConnectionString.compareTo("iteration4") == 0 )
466
         {
467
           p = new Package(4, "GenericProduct", ".tim", "GenericProduct.tim", "4.TIM.WIP", "\\vob\\GenericProduct", 'P');
468
           p.mPid = 6;
469
           p.mDirectlyPlanned = true;
470
           packageCollection.add(p);
471
         }
472
 
473
         if ( mConnectionString.compareTo("iteration1") == 0 
474
           || mConnectionString.compareTo("iteration2") == 0
475
           || mConnectionString.compareTo("iteration3") == 0
476
           || mConnectionString.compareTo("iteration4") == 0
477
           || mConnectionString.compareTo("iteration5") == 0 )
478
         {
479
           p = new Package(5, "Product", ".tim", "Product.tim", "5.TIM.WIP", "\\vob\\Product", 'M');
480
           p.mPid = 11;
481
           p.mDirectlyPlanned = true;
482
           packageCollection.add(p);
483
         }
484
 
485
         p = new Package(6, "UnfinishedProduct", ".tim", "UnfinishedProduct.tim", "6.TIM.WIP", "\\vob\\UnfinishedProduct", 'M');
486
         p.mPid = 113;
487
         p.mDirectlyPlanned = true;
488
         packageCollection.add(p);
489
 
490
        /* planned dependencies
491
         * pv_id pkg_name                     v_ext
492
         * 1     NotInTheRelease              .cots
493
         * 2     CotsWithFunnyVersion         .cots
494
         * 2     UncommonDependency           .tim
495
         * 3     CommonDependency             .tim
496
         * 4     CommonDependency             .tim
497
         * 5     UncommonDependency           .tim
498
         */
499
         p = findPackage(1, packageCollection);
500
         p.mDependencyCollection.add("NotInTheRelease.cots");
501
         p.mDependencyIDCollection.add(-1);
502
 
503
         if ( mConnectionString.compareTo("iteration1") == 0 || mConnectionString.compareTo("iteration2") == 0 )
504
         {
505
           p = findPackage(2, packageCollection);
506
           p.mDependencyCollection.add("CotsWithFunnyVersion.cots");
507
           p.mDependencyIDCollection.add(-1);
508
           p.mDependencyCollection.add("UncommonDependency.tim");
509
           p.mDependencyIDCollection.add(-1);
510
         }
511
 
512
         if ( mConnectionString.compareTo("iteration1") == 0 
513
           || mConnectionString.compareTo("iteration2") == 0
514
           || mConnectionString.compareTo("iteration3") == 0 )
515
         {
516
           p = findPackage(3, packageCollection);
517
           p.mDependencyCollection.add("CommonDependency.tim");
518
           p.mDependencyIDCollection.add(-1);
519
         }
520
 
521
         if ( mConnectionString.compareTo("iteration1") == 0 
522
           || mConnectionString.compareTo("iteration2") == 0
523
           || mConnectionString.compareTo("iteration3") == 0
524
           || mConnectionString.compareTo("iteration4") == 0 )
525
         {
526
           p = findPackage(4, packageCollection);
527
           p.mDependencyCollection.add("CommonDependency.tim");
528
           p.mDependencyIDCollection.add(-1);
529
         }
530
 
531
         if ( mConnectionString.compareTo("iteration1") == 0 
532
           || mConnectionString.compareTo("iteration2") == 0
533
           || mConnectionString.compareTo("iteration3") == 0
534
           || mConnectionString.compareTo("iteration4") == 0
535
           || mConnectionString.compareTo("iteration5") == 0 )
536
         {
537
           p = findPackage(5, packageCollection);
538
           p.mDependencyCollection.add("UncommonDependency.tim");
539
           p.mDependencyIDCollection.add(-1);
540
         }
541
 
542
        /* planned build info
543
         * pv_id bm_name bsa_name
544
         * 0     Linux   Java 1.6
545
         * 1     Linux   Debug
546
         * 2     Linux   Debug
547
         * 2     Solaris Production
548
         * 2     Win32   Production and Debug
549
         * 3     Solaris Java 1.4
550
         * 4     Generic Java 1.5
551
         * 5     Linux   Java 1.6
552
         * 5     Win32   Java 1.6
553
         */
554
         if ( mConnectionString.compareTo("iteration1") == 0 )
555
         {
556
           p = findPackage(0, packageCollection);
557
           BuildStandard bs = new BuildStandard(rippleEngine);
558
           bs.setLinux();
559
           bs.set1_6();
560
           p.mBuildStandardCollection.add(bs);
561
         }
562
 
563
         p = findPackage(1, packageCollection);
564
         BuildStandard bs = new BuildStandard(rippleEngine);
565
         bs.setLinux();
566
         bs.setDebug();
567
         p.mBuildStandardCollection.add(bs);
568
 
569
         if ( mConnectionString.compareTo("iteration1") == 0 || mConnectionString.compareTo("iteration2") == 0 )
570
         {
571
           p = findPackage(2, packageCollection);
572
           bs = new BuildStandard(rippleEngine);
573
           bs.setLinux();
574
           bs.setDebug();
575
           p.mBuildStandardCollection.add(bs);
576
           bs = new BuildStandard(rippleEngine);
577
           bs.setSolaris();
578
           bs.setProduction();
579
           p.mBuildStandardCollection.add(bs);
580
           bs = new BuildStandard(rippleEngine);
581
           bs.setWin32();
582
           bs.setAll();
583
           p.mBuildStandardCollection.add(bs);
584
         }
585
 
586
         if ( mConnectionString.compareTo("iteration1") == 0 
587
           || mConnectionString.compareTo("iteration2") == 0
588
           || mConnectionString.compareTo("iteration3") == 0 )
589
         {
590
           p = findPackage(3, packageCollection);
591
           bs = new BuildStandard(rippleEngine);
592
           bs.setSolaris();
593
           bs.set1_4();
594
           p.mBuildStandardCollection.add(bs);
595
         }
596
 
597
         if ( mConnectionString.compareTo("iteration1") == 0 
598
           || mConnectionString.compareTo("iteration2") == 0
599
           || mConnectionString.compareTo("iteration3") == 0
600
           || mConnectionString.compareTo("iteration4") == 0 )
601
         {
602
           p = findPackage(4, packageCollection);
603
           bs = new BuildStandard(rippleEngine);
604
           bs.setGeneric();
605
           bs.set1_5();
606
           p.mBuildStandardCollection.add(bs);
607
         }
608
 
609
         if ( mConnectionString.compareTo("iteration1") == 0 
610
           || mConnectionString.compareTo("iteration2") == 0
611
           || mConnectionString.compareTo("iteration3") == 0
612
           || mConnectionString.compareTo("iteration4") == 0
613
           || mConnectionString.compareTo("iteration5") == 0 )
614
         {
615
           p = findPackage(5, packageCollection);
616
           bs = new BuildStandard(rippleEngine);
617
           bs.setLinux();
618
           bs.set1_6();
619
           p.mBuildStandardCollection.add(bs);
620
           bs = new BuildStandard(rippleEngine);
621
           bs.setWin32();
622
           bs.set1_6();
623
           p.mBuildStandardCollection.add(bs);
624
         }
625
 
626
        /* planned unit test info
627
         * pv_id test_type_name
628
         * 2     Manual Test
629
         * 2     Interactive Test
630
         * 2     Integration Test
631
         * 5     Autobuild UTF
632
         */
633
         if ( mConnectionString.compareTo("iteration1") == 0 
634
           || mConnectionString.compareTo("iteration2") == 0
635
           || mConnectionString.compareTo("iteration3") == 0
636
           || mConnectionString.compareTo("iteration4") == 0
637
           || mConnectionString.compareTo("iteration5") == 0 )
638
         {
639
           p = findPackage(5, packageCollection);
640
           p.mHasAutomatedUnitTests = true;
641
         }
642
 
643
        /* planned build failure info
644
         * pv_id user_email
645
         * 3     jimmyfishcake@erggroup.com
646
         * 3     rayhaddock@erggroup.com
647
         * 5     timbutdim@erggroup.com
648
         */
649
         if ( mConnectionString.compareTo("iteration1") == 0 
650
           || mConnectionString.compareTo("iteration2") == 0
651
           || mConnectionString.compareTo("iteration3") == 0 )
652
         {
653
           p = findPackage(3, packageCollection);
654
           p.mBuildFailureEmailCollection.add("jimmyfishcake@erggroup.com");
655
           p.mBuildFailureEmailCollection.add("rayhaddock@erggroup.com");
656
         }
657
 
658
         if ( mConnectionString.compareTo("iteration1") == 0 
659
           || mConnectionString.compareTo("iteration2") == 0
660
           || mConnectionString.compareTo("iteration3") == 0
661
           || mConnectionString.compareTo("iteration4") == 0
662
           || mConnectionString.compareTo("iteration5") == 0 )
663
         {
664
           p = findPackage(5, packageCollection);
665
           p.mBuildFailureEmailCollection.add("timbutdim@erggroup.com");
666
         }
667
 
668
        /* planned do not ripple info
669
         * pv_id
670
         * 6
671
         */
672
         p = findPackage(6, packageCollection);
673
         p.mDoNotRipple = true;
674
 
675
        /* planned advisory ripple info
676
         * pv_id
677
         * 0
678
         */
679
         if ( mConnectionString.compareTo("iteration1") == 0 )
680
         {
681
           p = findPackage(0, packageCollection);
682
           p.mAdvisoryRipple = true;
683
         }
684
 
685
        /* released info
686
         * pv_id pkg_id pkg_name                     pkg_version      v_ext pkg_label                           src_path                   ripple_field
687
         * 7     8      CotsWithFunnyVersion         hoopla2_x.cots   .cots CotsWithFunnyVersion_hoopla2_x.cots \vob\CotsWithFunnyVersion
688
         * 8     17     NotInAnyWayReproducible      1.0.0.tim        .tim  NA                                  NA
689
         * 9     34     CommonDependency             1.0.0000.tim     .tim  CommonDependency_1.0.0000.tim       \vob\CommonDependency
690
         * 10    908    SolarisCentricProduct        1.0.0000.tim     .tim  SolarisCentricProduct_1.0.0000.tim  \vob\SolarisCentricProduct m
691
         * 11    16     LinuxCentricProduct          1.0.0000.tim     .tim  LinuxCentricProduct_1.0.0000.tim    \vob\LinuxCentricProduct
692
         * 12    312    Win32CentricProduct          1.0.0000.tim     .tim  Win32CentricProduct_1.0.0000.tim    \vob\Win32CentricProduct
693
         * 13    6      GenericProduct               1.0.0000.tim     .tim  GenericProduct_1.0.0000.tim         \vob\ToBeMovedFromHere     M
694
         * 14    81     AdvisoryDependency           1.0.0000.tim     .tim  AdvisoryDependency_1.0.0000.tim     \vob\AdvisoryDependency
695
         * 15    1      MergedProduct                1.0.0000.tim     .tim  MergedProduct_1.0.0000.tim          \vob\MergedProduct         m
696
         */
697
         if ( mConnectionString.compareTo("iteration1") != 0 )
698
         {
699
           p = new Package(0, "UncommonDependency", "0.0.1000.tim", ".tim", "UncommonDependency.tim", "UncommonDependency_0.0.1000.tim", "\\vob\\UncommonDependency", 'x');
700
           p.mPid = 76;
701
           Integer pv_id = new Integer(0);
702
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
703
           Package plannedPackage = findPackage(p.mAlias, packageCollection);
704
 
705
           if ( plannedPackage == NULL_PACKAGE )
706
           {
707
             packageCollection.add(p);
708
           }
709
           else
710
           {
711
             plannedPackage.mVersion = "0.0.1000";
712
           }
713
         }
714
 
715
         if ( mConnectionString.compareTo("iteration1") != 0 && mConnectionString.compareTo("iteration2") != 0 )
716
         {
717
           p = new Package(2, "CommonDependency", "2.0.0000.tim", ".tim", "CommonDependency.tim", "CommonDependency_2.0.0000.tim", "\\vob\\CommonDependency", 'x');
718
           p.mPid = 34;
719
           Integer pv_id = new Integer(2);
720
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
721
           Package plannedPackage = findPackage(p.mAlias, packageCollection);
722
 
723
           if ( plannedPackage == NULL_PACKAGE )
724
           {
725
             packageCollection.add(p);
726
           }
727
           else
728
           {
729
             plannedPackage.mVersion = "2.0.0000";
730
           }
731
         }
732
 
733
         if ( mConnectionString.compareTo("iteration1") != 0 
734
           && mConnectionString.compareTo("iteration2") != 0
735
           && mConnectionString.compareTo("iteration3") != 0 )
736
         {
737
           p = new Package(3, "SolarisCentricProduct", "1.1.0000.tim", ".tim", "SolarisCentricProduct.tim", "SolarisCentricProduct_1.1.0000.tim", "\\vob\\SolarisCentricProduct", 'm');
738
           p.mPid = 908;
739
           Integer pv_id = new Integer(3);
740
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
741
           Package plannedPackage = findPackage(p.mAlias, packageCollection);
742
 
743
           if ( plannedPackage == NULL_PACKAGE )
744
           {
745
             packageCollection.add(p);
746
           }
747
           else
748
           {
749
             plannedPackage.mVersion = "1.1.0000";
750
           }
751
         }
752
 
753
         if ( mConnectionString.compareTo("iteration1") != 0 
754
           && mConnectionString.compareTo("iteration2") != 0
755
           && mConnectionString.compareTo("iteration3") != 0
756
           && mConnectionString.compareTo("iteration4") != 0 )
757
         {
758
           p = new Package(4, "GenericProduct", "1.0.1000.tim", ".tim", "GenericProduct.tim", "GenericProduct_1.0.1000.tim", "\\vob\\GenericProduct", 'M');
759
           p.mPid = 6;
760
           Integer pv_id = new Integer(4);
761
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
762
           Package plannedPackage = findPackage(p.mAlias, packageCollection);
763
 
764
           if ( plannedPackage == NULL_PACKAGE )
765
           {
766
             packageCollection.add(p);
767
           }
768
           else
769
           {
770
             plannedPackage.mVersion = "1.0.1000";
771
           }
772
         }
773
 
774
         if ( mConnectionString.compareTo("iteration1") != 0 
775
           && mConnectionString.compareTo("iteration2") != 0
776
           && mConnectionString.compareTo("iteration3") != 0
777
           && mConnectionString.compareTo("iteration4") != 0
778
           && mConnectionString.compareTo("iteration5") != 0 )
779
         {
780
           p = new Package(5, "Product", "1.0.0000.tim", ".tim", "Product.tim", "Product_1.0.0000.tim", "\\vob\\Product", 'M');
781
           p.mPid = 11;
782
           Integer pv_id = new Integer(5);
783
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
784
           Package plannedPackage = findPackage(p.mAlias, packageCollection);
785
 
786
           if ( plannedPackage == NULL_PACKAGE )
787
           {
788
             packageCollection.add(p);
789
           }
790
           else
791
           {
792
             plannedPackage.mVersion = "1.0.0000";
793
           }
794
         }
795
 
796
         p = new Package(7, "CotsWithFunnyVersion", "hoopla2_x.cots", ".cots", "CotsWithFunnyVersion.cots", "CotsWithFunnyVersion_hoopla2_x", "\\vob\\CotsWithFunnyVersion", 'x');
797
         p.mPid = 8;
798
         Integer pv_id = new Integer(7);
799
         rippleEngine.mReleasedPvIDCollection.add(pv_id);
800
         Package plannedPackage = findPackage(p.mAlias, packageCollection);
801
 
802
         if ( plannedPackage == NULL_PACKAGE )
803
         {
804
           packageCollection.add(p);
805
         }
806
         else
807
         {
808
           plannedPackage.mVersion = "hoopla2_x";
809
         }
810
 
811
         p = new Package(8, "NotInAnyWayReproducible", "1.0.0.tim", ".tim", "NotInAnyWayReproducible.tim", "NA", "NA", 'x');
812
         p.mPid = 17;
813
         pv_id = new Integer(8);
814
         rippleEngine.mReleasedPvIDCollection.add(pv_id);
815
         plannedPackage = findPackage(p.mAlias, packageCollection);
816
 
817
         if ( plannedPackage == NULL_PACKAGE )
818
         {
819
           packageCollection.add(p);
820
         }
821
         else
822
         {
823
           plannedPackage.mVersion = "1.0.0";
824
         }
825
 
826
         if ( mConnectionString.compareTo("iteration1") == 0 || mConnectionString.compareTo("iteration2") == 0 )
827
         {
828
           p = new Package(9, "CommonDependency", "1.0.0000.tim", ".tim", "CommonDependency.tim", "CommonDependency_1.0.0000.tim", "\\vob\\CommonDependency", 'x');
829
           p.mPid = 34;
830
           pv_id = new Integer(9);
831
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
832
           plannedPackage = findPackage(p.mAlias, packageCollection);
833
 
834
           if ( plannedPackage == NULL_PACKAGE )
835
           {
836
             packageCollection.add(p);
837
           }
838
           else
839
           {
840
             plannedPackage.mVersion = "1.0.0000";
841
           }
842
         }
843
 
844
         if ( mConnectionString.compareTo("iteration1") == 0 
845
           || mConnectionString.compareTo("iteration2") == 0
846
           || mConnectionString.compareTo("iteration3") == 0 )
847
         {
848
           p = new Package(10, "SolarisCentricProduct", "1.0.0000.tim", ".tim", "SolarisCentricProduct.tim", "SolarisCentricProduct_1.0.0000.tim", "\\vob\\SolarisCentricProduct", 'm');
849
           p.mPid = 908;
850
           pv_id = new Integer(10);
851
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
852
           plannedPackage = findPackage(p.mAlias, packageCollection);
853
 
854
           if ( plannedPackage == NULL_PACKAGE )
855
           {
856
             packageCollection.add(p);
857
           }
858
           else
859
           {
860
             plannedPackage.mVersion = "1.0.0000";
861
           }
862
         }
863
 
864
         p = new Package(11, "LinuxCentricProduct", "1.0.0000.tim", ".tim", "LinuxCentricProduct.tim", "LinuxCentricProduct_1.0.0000.tim", "\\vob\\LinuxCentricProduct", 'x');
865
         p.mPid = 16;
866
         pv_id = new Integer(11);
867
         rippleEngine.mReleasedPvIDCollection.add(pv_id);
868
         plannedPackage = findPackage(p.mAlias, packageCollection);
869
 
870
         if ( plannedPackage == NULL_PACKAGE )
871
         {
872
           packageCollection.add(p);
873
         }
874
         else
875
         {
876
           plannedPackage.mVersion = "1.0.0000";
877
         }
878
 
879
         p = new Package(12, "Win32CentricProduct", "1.0.0000.tim", ".tim", "Win32CentricProduct.tim", "Win32CentricProduct_1.0.0000.tim", "\\vob\\Win32CentricProduct", 'x');
880
         p.mPid = 312;
881
         pv_id = new Integer(12);
882
         rippleEngine.mReleasedPvIDCollection.add(pv_id);
883
         plannedPackage = findPackage(p.mAlias, packageCollection);
884
 
885
         if ( plannedPackage == NULL_PACKAGE )
886
         {
887
           packageCollection.add(p);
888
         }
889
         else
890
         {
891
           plannedPackage.mVersion = "1.0.0000";
892
         }
893
 
894
         if ( mConnectionString.compareTo("iteration1") == 0 
895
           || mConnectionString.compareTo("iteration2") == 0
896
           || mConnectionString.compareTo("iteration3") == 0
897
           || mConnectionString.compareTo("iteration4") == 0 )
898
         {
899
           p = new Package(13, "GenericProduct", "1.0.0000.tim", ".tim", "GenericProduct.tim", "GenericProduct_1.0.0000.tim", "\\vob\\ToBeMovedFromHere", 'M');
900
           p.mPid = 6;
901
           pv_id = new Integer(13);
902
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
903
           plannedPackage = findPackage(p.mAlias, packageCollection);
904
         }
905
 
906
         if ( plannedPackage == NULL_PACKAGE )
907
         {
908
           packageCollection.add(p);
909
         }
910
         else
911
         {
912
           plannedPackage.mVersion = "1.0.0000";
913
         }
914
 
915
         p = new Package(14, "AdvisoryDependency", "1.0.0000.tim", ".tim", "AdvisoryDependency.tim", "AdvisoryDependency_1.0.0000.tim", "\\vob\\AdvisoryDependency", 'x');
916
         p.mPid = 81;
917
         pv_id = new Integer(14);
918
         rippleEngine.mReleasedPvIDCollection.add(pv_id);
919
         plannedPackage = findPackage(p.mAlias, packageCollection);
920
 
921
         if ( plannedPackage == NULL_PACKAGE )
922
         {
923
           packageCollection.add(p);
924
         }
925
         else
926
         {
927
           plannedPackage.mVersion = "1.0.0000";
928
         }
929
 
930
         if ( mConnectionString.compareTo("iteration1") == 0 
931
           || mConnectionString.compareTo("iteration2") == 0
932
           || mConnectionString.compareTo("iteration3") == 0
933
           || mConnectionString.compareTo("iteration4") == 0
934
           || mConnectionString.compareTo("iteration5") == 0
935
           || mConnectionString.compareTo("iteration6") == 0 )
936
         {
937
           p = new Package(15, "MergedProduct", "1.0.0000.tim", ".tim", "MergedProduct.tim", "MergedProduct_1.0.0000.tim", "\\vob\\MergedProduct", 'm');
938
           p.mPid = 1;
939
           pv_id = new Integer(15);
940
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
941
           plannedPackage = findPackage(p.mAlias, packageCollection);
942
         }
943
         else
944
         {
945
           p = new Package(16, "MergedProduct", "1.0.0000.tim", ".tim", "MergedProduct.tim", "MergedProduct_1.0.0000.tim", "\\vob\\MergedProduct", 'm');
946
           p.mPid = 1;
947
           pv_id = new Integer(16);
948
           rippleEngine.mReleasedPvIDCollection.add(pv_id);
949
           plannedPackage = findPackage(p.mAlias, packageCollection);
950
         }
951
 
952
         if ( plannedPackage == NULL_PACKAGE )
953
         {
954
           packageCollection.add(p);
955
         }
956
         else
957
         {
958
           plannedPackage.mVersion = "1.0.0000";
959
         }
960
 
961
        /* released dependencies
962
         * pv_id dpv_id pkg_name                     v_ext
963
         * 8     9      CommonDependency             .tim
964
         * 9     7      CotsWithFunnyVersion         .cots
965
         * 10    9      CommonDependency             .tim
966
         * 11    44     AdvisoryDependency           .tim
967
         * 13    9      CommonDependency             .tim
968
         * 15    99     CommonDependency             .tim
969
         */
970
         if ( mConnectionString.compareTo("iteration1") != 0 && mConnectionString.compareTo("iteration2") != 0 )
971
         {
972
           p = findPackage(2, packageCollection);
973
           p.mDependencyCollection.add("CotsWithFunnyVersion.cots");
974
           p.mDependencyIDCollection.add(7);
975
           p.mDependencyCollection.add("UncommonDependency.tim");
976
           p.mDependencyIDCollection.add(0);
977
         }
978
 
979
         if ( mConnectionString.compareTo("iteration1") != 0 
980
           && mConnectionString.compareTo("iteration2") != 0
981
           && mConnectionString.compareTo("iteration3") != 0 )
982
         {
983
           p = findPackage(3, packageCollection);
984
           p.mDependencyCollection.add("CommonDependency.tim");
985
           p.mDependencyIDCollection.add(2);
986
         }
987
 
988
         if ( mConnectionString.compareTo("iteration1") != 0 
989
           && mConnectionString.compareTo("iteration2") != 0
990
           && mConnectionString.compareTo("iteration3") != 0
991
           && mConnectionString.compareTo("iteration4") != 0 )
992
         {
993
           p = findPackage(4, packageCollection);
994
           p.mDependencyCollection.add("CommonDependency.tim");
995
           p.mDependencyIDCollection.add(2);
996
         }
997
 
998
         if ( mConnectionString.compareTo("iteration1") != 0 
999
           && mConnectionString.compareTo("iteration2") != 0
1000
           && mConnectionString.compareTo("iteration3") != 0
1001
           && mConnectionString.compareTo("iteration4") != 0
1002
           && mConnectionString.compareTo("iteration5") != 0 )
1003
         {
1004
           p = findPackage(5, packageCollection);
1005
           p.mDependencyCollection.add("UncommonDependency.tim");
1006
           p.mDependencyIDCollection.add(0);
1007
         }
1008
 
1009
         p = findPackage(8, packageCollection);
1010
         p.mDependencyCollection.add("CommonDependency.tim");
1011
         p.mDependencyIDCollection.add(9);
1012
 
1013
         if ( mConnectionString.compareTo("iteration1") == 0 || mConnectionString.compareTo("iteration2") == 0 )
1014
         {
1015
           p = findPackage(9, packageCollection);
1016
           p.mDependencyCollection.add("CotsWithFunnyVersion.cots");
1017
           p.mDependencyIDCollection.add(7);
1018
         }
1019
 
1020
         if ( mConnectionString.compareTo("iteration1") == 0 
1021
           || mConnectionString.compareTo("iteration2") == 0
1022
           || mConnectionString.compareTo("iteration3") == 0 )
1023
         {
1024
           p = findPackage(10, packageCollection);
1025
           p.mDependencyCollection.add("CommonDependency.tim");
1026
           p.mDependencyIDCollection.add(9);
1027
         }
1028
 
1029
         p = findPackage(11, packageCollection);
1030
         p.mDependencyCollection.add("AdvisoryDependency.tim");
1031
         p.mDependencyIDCollection.add(44);
1032
 
1033
         if ( mConnectionString.compareTo("iteration1") == 0 
1034
           || mConnectionString.compareTo("iteration2") == 0
1035
           || mConnectionString.compareTo("iteration3") == 0
1036
           || mConnectionString.compareTo("iteration4") == 0 )
1037
         {
1038
           p = findPackage(13, packageCollection);
1039
           p.mDependencyCollection.add("CommonDependency.tim");
1040
           p.mDependencyIDCollection.add(9);
1041
         }
1042
 
1043
         if ( mConnectionString.compareTo("iteration1") == 0 
1044
           || mConnectionString.compareTo("iteration2") == 0
1045
           || mConnectionString.compareTo("iteration3") == 0
1046
           || mConnectionString.compareTo("iteration4") == 0
1047
           || mConnectionString.compareTo("iteration5") == 0
1048
           || mConnectionString.compareTo("iteration6") == 0 )
1049
         {
1050
           p = findPackage(15, packageCollection);
1051
           p.mDependencyCollection.add("CommonDependency.tim");
1052
           p.mDependencyIDCollection.add(99);
1053
         }
1054
         else
1055
         {
1056
           p = findPackage(16, packageCollection);
1057
           p.mDependencyCollection.add("CommonDependency.tim");
1058
           p.mDependencyIDCollection.add(2);
1059
         }
1060
 
1061
        /* released build info
1062
         * pv_id bm_name bsa_name
1063
         * 7     Solaris Debug
1064
         * 9     Linux   Debug
1065
         * 9     Solaris Debug
1066
         * 9     Win32   Production
1067
         * 10    Solaris Java 1.4
1068
         * 11    Linux   Production and Debug
1069
         * 12    Win32   Java 1.6
1070
         * 13    Generic Java 1.4
1071
         * 14    Linux   Debug
1072
         * 15    Linux   Debug
1073
         */
1074
         if ( mConnectionString.compareTo("iteration1") != 0 )
1075
         {
1076
           p = findPackage(0, packageCollection);
1077
           bs = new BuildStandard(rippleEngine);
1078
           bs.setLinux();
1079
           bs.set1_6();
1080
           p.mBuildStandardCollection.add(bs);
1081
         }
1082
 
1083
         if ( mConnectionString.compareTo("iteration1") != 0 && mConnectionString.compareTo("iteration2") != 0 )
1084
         {
1085
           p = findPackage(2, packageCollection);
1086
           bs = new BuildStandard(rippleEngine);
1087
           bs.setLinux();
1088
           bs.setDebug();
1089
           p.mBuildStandardCollection.add(bs);
1090
           bs = new BuildStandard(rippleEngine);
1091
           bs.setSolaris();
1092
           bs.setProduction();
1093
           p.mBuildStandardCollection.add(bs);
1094
           bs = new BuildStandard(rippleEngine);
1095
           bs.setWin32();
1096
           bs.setAll();
1097
           p.mBuildStandardCollection.add(bs);
1098
         }
1099
 
1100
         if ( mConnectionString.compareTo("iteration1") != 0 
1101
           && mConnectionString.compareTo("iteration2") != 0
1102
           && mConnectionString.compareTo("iteration3") != 0 )
1103
         {
1104
           p = findPackage(3, packageCollection);
1105
           bs = new BuildStandard(rippleEngine);
1106
           bs.setSolaris();
1107
           bs.set1_4();
1108
           p.mBuildStandardCollection.add(bs);
1109
         }
1110
 
1111
         if ( mConnectionString.compareTo("iteration1") != 0 
1112
           && mConnectionString.compareTo("iteration2") != 0
1113
           && mConnectionString.compareTo("iteration3") != 0
1114
           && mConnectionString.compareTo("iteration4") != 0 )
1115
         {
1116
           p = findPackage(4, packageCollection);
1117
           bs = new BuildStandard(rippleEngine);
1118
           bs.setGeneric();
1119
           bs.set1_5();
1120
           p.mBuildStandardCollection.add(bs);
1121
         }
1122
 
1123
         if ( mConnectionString.compareTo("iteration1") != 0 
1124
           && mConnectionString.compareTo("iteration2") != 0
1125
           && mConnectionString.compareTo("iteration3") != 0
1126
           && mConnectionString.compareTo("iteration4") != 0
1127
           && mConnectionString.compareTo("iteration5") != 0 )
1128
         {
1129
           p = findPackage(5, packageCollection);
1130
           bs = new BuildStandard(rippleEngine);
1131
           bs.setLinux();
1132
           bs.set1_6();
1133
           p.mBuildStandardCollection.add(bs);
1134
           bs = new BuildStandard(rippleEngine);
1135
           bs.setWin32();
1136
           bs.set1_6();
1137
           p.mBuildStandardCollection.add(bs);
1138
         }
1139
 
1140
         p = findPackage(7, packageCollection);
1141
         bs = new BuildStandard(rippleEngine);
1142
         bs.setSolaris();
1143
         bs.setDebug();
1144
         p.mBuildStandardCollection.add(bs);
1145
 
1146
         if ( mConnectionString.compareTo("iteration1") == 0 || mConnectionString.compareTo("iteration2") == 0 )
1147
         {
1148
           p = findPackage(9, packageCollection);
1149
           bs = new BuildStandard(rippleEngine);
1150
           bs.setLinux();
1151
           bs.setDebug();
1152
           p.mBuildStandardCollection.add(bs);
1153
           bs = new BuildStandard(rippleEngine);
1154
           bs.setSolaris();
1155
           bs.setDebug();
1156
           p.mBuildStandardCollection.add(bs);
1157
           bs = new BuildStandard(rippleEngine);
1158
           bs.setWin32();
1159
           bs.setProduction();
1160
           p.mBuildStandardCollection.add(bs);
1161
         }
1162
 
1163
         if ( mConnectionString.compareTo("iteration1") == 0 
1164
           || mConnectionString.compareTo("iteration2") == 0
1165
           || mConnectionString.compareTo("iteration3") == 0 )
1166
         {
1167
           p = findPackage(10, packageCollection);
1168
           bs = new BuildStandard(rippleEngine);
1169
           bs.setSolaris();
1170
           bs.set1_4();
1171
           p.mBuildStandardCollection.add(bs);
1172
         }
1173
 
1174
         p = findPackage(11, packageCollection);
1175
         bs = new BuildStandard(rippleEngine);
1176
         bs.setLinux();
1177
         bs.setAll();
1178
         p.mBuildStandardCollection.add(bs);
1179
 
1180
         p = findPackage(12, packageCollection);
1181
         bs = new BuildStandard(rippleEngine);
1182
         bs.setWin32();
1183
         bs.set1_6();
1184
         p.mBuildStandardCollection.add(bs);
1185
 
1186
         if ( mConnectionString.compareTo("iteration1") == 0 
1187
           || mConnectionString.compareTo("iteration2") == 0
1188
           || mConnectionString.compareTo("iteration3") == 0
1189
           || mConnectionString.compareTo("iteration4") == 0 )
1190
         {
1191
           p = findPackage(13, packageCollection);
1192
           bs = new BuildStandard(rippleEngine);
1193
           bs.setGeneric();
1194
           bs.set1_4();
1195
           p.mBuildStandardCollection.add(bs);
1196
         }
1197
 
1198
         p = findPackage(14, packageCollection);
1199
         bs = new BuildStandard(rippleEngine);
1200
         bs.setLinux();
1201
         bs.setDebug();
1202
         p.mBuildStandardCollection.add(bs);
1203
 
1204
         if ( mConnectionString.compareTo("iteration1") == 0 
1205
           || mConnectionString.compareTo("iteration2") == 0
1206
           || mConnectionString.compareTo("iteration3") == 0
1207
           || mConnectionString.compareTo("iteration4") == 0
1208
           || mConnectionString.compareTo("iteration5") == 0
1209
           || mConnectionString.compareTo("iteration6") == 0 )
1210
         {
1211
           p = findPackage(15, packageCollection);
1212
           bs = new BuildStandard(rippleEngine);
1213
           bs.setLinux();
1214
           bs.setDebug();
1215
           p.mBuildStandardCollection.add(bs);
1216
         }
1217
         else
1218
         {
1219
           p = findPackage(16, packageCollection);
1220
           bs = new BuildStandard(rippleEngine);
1221
           bs.setLinux();
1222
           bs.setDebug();
1223
           p.mBuildStandardCollection.add(bs);
1224
         }
1225
 
1226
        /* released package unit test info
1227
         * pv_id tt.test_type_name
1228
         * 9     Manual Test
1229
         * 9     Interactive Test
1230
         * 9     Integration Test
1231
         * 11    Autobuild UTF
1232
         */
1233
         if ( mConnectionString.compareTo("iteration1") != 0 
1234
           && mConnectionString.compareTo("iteration2") != 0
1235
           && mConnectionString.compareTo("iteration3") != 0
1236
           && mConnectionString.compareTo("iteration4") != 0
1237
           && mConnectionString.compareTo("iteration5") != 0 )
1238
         {
1239
           p = findPackage(5, packageCollection);
1240
           p.mHasAutomatedUnitTests = true;
1241
         }
1242
 
1243
         p = findPackage(11, packageCollection);
1244
         p.mHasAutomatedUnitTests = true;
1245
 
1246
        /* released build failure email info
1247
         * pv_id user_email
1248
         * 10    jimmyfishcake@erggroup.com
1249
         */
1250
         if ( mConnectionString.compareTo("iteration1") != 0 
1251
           && mConnectionString.compareTo("iteration2") != 0
1252
           && mConnectionString.compareTo("iteration3") != 0 )
1253
         {
1254
           p = findPackage(3, packageCollection);
1255
           p.mBuildFailureEmailCollection.add("jimmyfishcake@erggroup.com");
1256
           p.mBuildFailureEmailCollection.add("rayhaddock@erggroup.com");
1257
         }
1258
 
1259
         if ( mConnectionString.compareTo("iteration1") != 0 
1260
           && mConnectionString.compareTo("iteration2") != 0
1261
           && mConnectionString.compareTo("iteration3") != 0
1262
           && mConnectionString.compareTo("iteration4") != 0
1263
           && mConnectionString.compareTo("iteration5") != 0 )
1264
         {
1265
           p = findPackage(5, packageCollection);
1266
           p.mBuildFailureEmailCollection.add("timbutdim@erggroup.com");
1267
         }
1268
 
1269
         if ( mConnectionString.compareTo("iteration1") == 0 
1270
           || mConnectionString.compareTo("iteration2") == 0
1271
           || mConnectionString.compareTo("iteration3") == 0 )
1272
         {
1273
           p = findPackage(10, packageCollection);
1274
           p.mBuildFailureEmailCollection.add("jimmyfishcake@erggroup.com");
1275
         }
1276
 
1277
        /* released do not ripple info
1278
         * pv_id
1279
         * 11
1280
         */
1281
         p = findPackage(11, packageCollection);
1282
         p.mDoNotRipple = true;
1283
 
1284
        /* released advisory ripple info
1285
         * pv_id
1286
         * 14
1287
         */
1288
         if ( mConnectionString.compareTo("iteration1") != 0 )
1289
         {
1290
           p = findPackage(0, packageCollection);
1291
           p.mAdvisoryRipple = true;
1292
         }
1293
 
1294
         p = findPackage(14, packageCollection);
1295
         p.mAdvisoryRipple = true;
1296
      }
1297
      else
1298
      {
1299
        /* prod_id pkg_name                pkg_version  v_ext pkg_label                           src_path
1300
         * 8       NotInAnyWayReproducible 1.0.0.tim    .tim  NA                                  NA
1301
         * 10      SolarisCentricProduct   1.0.0000.tim .tim  SolarisCentricProduct_1.0.0000.tim  \vob\SolarisCentricProduct
1302
         * 11      LinuxCentricProduct     1.0.0000.tim .tim  LinuxCentricProduct_1.0.0000.tim    \vob\LinuxCentricProduct
1303
         * 12      Win32CentricProduct     1.0.0000.tim .tim  Win32CentricProduct_1.0.0000.tim    \vob\Win32CentricProduct
1304
         * 13      GenericProduct          1.0.0000.tim .tim  GenericProduct_1.0.0000.tim         \vob\ToBeMovedFromHere
1305
         */
1306
         Package p = new Package(8, "NotInAnyWayReproducible", "1.0.0.tim", ".tim", "NotInAnyWayReproducible.1.0.0.tim", "NA", "NA", 'x');
1307
         packageCollection.add(p);
1308
         p = new Package(10, "SolarisCentricProduct", "1.0.0000.tim", ".tim", "SolarisCentricProduct.1.0.0000.tim", "SolarisCentricProduct_1.0.0000.tim", "\\vob\\SolarisCentricProduct", 'x');
1309
         packageCollection.add(p);
1310
         p = new Package(11, "LinuxCentricProduct", "1.0.0000.tim", ".tim", "LinuxCentricProduct.1.0.0000.tim", "LinuxCentricProduct_1.0.0000.tim", "\\vob\\LinuxCentricProduct", 'x');
1311
         packageCollection.add(p);
1312
         p = new Package(12, "Win32CentricProduct", "1.0.0000.tim", ".tim", "Win32CentricProduct.1.0.0000.tim", "Win32CentricProduct_1.0.0000.tim", "\\vob\\Win32CentricProduct", 'x');
1313
         packageCollection.add(p);
1314
         p = new Package(13, "GenericProduct", "1.0.0000.tim", ".tim", "GenericProduct.1.0.0000.tim", "GenericProduct_1.0.0000.tim", "\\vob\\ToBeMovedFromHere", 'x');
1315
         packageCollection.add(p);
1316
 
1317
        /* the above products have the following dependencies which will be discovered in traverseDependencies
1318
         * pv_id   pkg_name, dpv.pkg_version, dpv.v_ext, dpv.pkg_label, dpv.src_path
1319
         * 7     CotsWithFunnyVersion         hoopla2_x.cots   .cots CotsWithFunnyVersion_hoopla2_x.cots \vob\CotsWithFunnyVersion
1320
         * 9     CommonDependency             1.0.0000.tim     .tim  CommonDependency_1.0.0000.tim       \vob\CommonDependency
1321
         * 14    AdvisoryDependency           1.0.0000.tim     .tim  AdvisoryDependency_1.0.0000.tim     \vob\AdvisoryDependency
1322
         * the above packages have the following build info
1323
         * pv_id bm_name bsa_name
1324
         * 7     Solaris Debug
1325
         * 9     Linux   Debug
1326
         * 9     Solaris Debug
1327
         * 9     Win32   Production
1328
         * 10    Solaris Java 1.4
1329
         * 11    Linux   Production and Debug
1330
         * 12    Win32   Java 1.6
1331
         * 13    Generic Java 1.4
1332
         * 14    Linux   Debug
1333
         */
1334
      }
1335
    }
1336
    else
1337
    {
1338
      try
1339
      {
1340
        if (daemonMode)
1341
        {
1342
          // get planned package info
1343
          CallableStatement stmt1 = mConnection.prepareCall(
1344
          "select pl.pv_id, p.pkg_id, p.pkg_name, pv.v_ext, pv.pkg_label, pv.src_path, pv.change_type " +
1345
          "from release_manager.planned pl, release_manager.package_versions pv, release_manager.packages p " +
1346
          "where pl.rtag_id=" + baseline + " and pv.build_type='A' and pv.dlocked='A' " +
1347
          "and pv.pv_id=pl.pv_id and p.pkg_id=pv.pkg_id " +
1348
          "order by pl.pv_id"
1349
          );
1350
          ResultSet rset1 = stmt1.executeQuery();
1351
 
1352
          while( rset1.next() )
1353
          {
1354
            int pv_id = rset1.getInt("pv_id");
1355
 
1356
            if ( rset1.wasNull() )
1357
            {
1358
              mLogger.fatal("queryPackageVersions rset1 null pv_id");
1359
              // show stopper
1360
              throw new Exception();
1361
            }
1362
 
1363
            int pkg_id = rset1.getInt("pkg_id");
1364
 
1365
            if ( rset1.wasNull() )
1366
            {
1367
              mLogger.fatal("queryPackageVersions rset1 null pkg_id " + pv_id);
1368
              // show stopper
1369
              throw new Exception();
1370
            }
1371
 
1372
            String pkg_name = rset1.getString("pkg_name");
1373
 
1374
            if ( pkg_name == null )
1375
            {
1376
              mLogger.fatal("queryPackageVersions rset1 null pkg_name " + pv_id);
1377
              // show stopper
1378
              throw new Exception();
1379
            }
1380
 
1381
            String v_ext = rset1.getString("v_ext");
1382
 
1383
            if ( v_ext == null )
1384
            {
1385
              v_ext = "";
1386
            }
1387
 
1388
            String pkg_label = rset1.getString("pkg_label");
1389
 
1390
            if ( pkg_label == null )
1391
            {
1392
              pkg_label = "NA";
1393
            }
1394
 
1395
            String src_path = rset1.getString("src_path");
1396
 
1397
            if ( src_path == null )
1398
            {
1399
              src_path = "NA";
1400
            }
1401
 
1402
            String change_type = rset1.getString("change_type");
1403
 
1404
            if ( change_type == null )
1405
            {
1406
              change_type = "P";
1407
            }
1408
 
1409
            char ct = 'x';
1410
 
1411
            if ( change_type.compareTo("M") == 0 )
1412
            {
1413
              ct = 'M';
1414
            }
1415
            else if ( change_type.compareTo("N") == 0 )
1416
            {
1417
              ct = 'N';
1418
            }
1419
            else if ( change_type.compareTo("P") == 0 )
1420
            {
1421
              ct = 'P';
1422
            }
1423
 
1424
            if ( ct != 'x' )
1425
            {
1426
              Package p = new Package(pv_id, pkg_name, v_ext, pkg_name + v_ext, pkg_label, src_path, ct);
1427
              p.mPid = pkg_id;
1428
              p.mDirectlyPlanned = true;
1429
              packageCollection.add(p);
1430
            }
1431
          }
830 mhunt 1432
 
1433
          rset1.close();
1434
          stmt1.close();
814 mhunt 1435
 
1436
          // get planned package dependency info
1437
          CallableStatement stmt2 = mConnection.prepareCall(
1438
          "select pl.pv_id, p.pkg_name, dpv.v_ext " +
1439
          "from release_manager.planned pl, release_manager.package_versions pv, release_manager.package_dependencies pd, release_manager.package_versions dpv, release_manager.packages p " +
1440
          "where pl.rtag_id=" + baseline + " and pv.build_type='A' and pv.dlocked='A' " +
1441
          "and pv.pv_id = pl.pv_id and pd.pv_id=pl.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id " +
1442
          "order by pl.pv_id"
1443
          );
1444
          ResultSet rset2 = stmt2.executeQuery();
1445
 
1446
          while( rset2.next() )
1447
          {
1448
            boolean ignore = false;
1449
 
1450
            int pv_id = rset2.getInt("pv_id");
1451
 
1452
            if ( rset2.wasNull() )
1453
            {
1454
              mLogger.fatal("queryPackageVersions rset2 null pv_id");
1455
              // show stopper
1456
              throw new Exception();
1457
            }
1458
 
1459
            Package p = findPackage(pv_id, packageCollection);
1460
 
1461
            if ( p == NULL_PACKAGE )
1462
            {
1463
              mLogger.info("queryPackageVersions rset2 highly unlikely " + pv_id);
1464
              // highly unlikely but package may have been added in between queries
1465
              ignore = true;
1466
            }
1467
 
1468
            String pkg_name = rset2.getString("pkg_name");
1469
 
1470
            if ( pkg_name == null )
1471
            {
1472
              mLogger.fatal("queryPackageVersions rset2 null pkg_name " + pv_id);
1473
              // show stopper
1474
              throw new Exception();
1475
            }
1476
 
1477
            String v_ext = rset2.getString("v_ext");
1478
 
1479
            if ( v_ext == null )
1480
            {
1481
              v_ext = "";
1482
            }
1483
 
1484
            if ( !ignore )
1485
            {
1486
              p.mDependencyCollection.add(pkg_name + v_ext);
1487
              p.mDependencyIDCollection.add(-1);
1488
            }
1489
          }
1490
 
830 mhunt 1491
          rset2.close();
1492
          stmt2.close();
1493
 
814 mhunt 1494
          // get planned package build info
1495
          CallableStatement stmt3 = mConnection.prepareCall(
1496
          "select pl.pv_id, bm.bm_name, bsa.bsa_name " +
1497
          "from release_manager.planned pl, release_manager.package_versions pv, release_manager.package_build_info pbi, release_manager.build_machines bm, release_manager.build_standards_addendum bsa " +
1498
          "where pl.rtag_id=" + baseline + " and pv.build_type='A' and pv.dlocked='A' " +
1499
          "and pv.pv_id = pl.pv_id and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id " +
1500
          "order by pl.pv_id"
1501
          );
1502
          ResultSet rset3 = stmt3.executeQuery();
1503
 
1504
          while( rset3.next() )
1505
          {
1506
            boolean ignore = false;
1507
            int pv_id = rset3.getInt("pv_id");
1508
 
1509
            if ( rset3.wasNull() )
1510
            {
1511
              mLogger.fatal("queryPackageVersions rset3 null pv_id");
1512
              // show stopper
1513
              throw new Exception();
1514
            }
1515
 
1516
            Package p = findPackage(pv_id, packageCollection);
1517
 
1518
            if ( p == NULL_PACKAGE )
1519
            {
1520
              mLogger.info("queryPackageVersions rset3 highly unlikely " + pv_id);
1521
              // highly unlikely but package may have been added in between queries
1522
              ignore = true;
1523
            }
1524
 
1525
            String bm_name = rset3.getString("bm_name");
1526
 
1527
            if ( bm_name == null )
1528
            {
1529
              mLogger.fatal("queryPackageVersions rset3 null bm_name " + pv_id);
1530
              // show stopper
1531
              throw new Exception();
1532
            }
1533
 
1534
            String bsa_name = rset3.getString("bsa_name");
1535
 
1536
            if ( bsa_name == null )
1537
            {
1538
              mLogger.fatal("queryPackageVersions rset3 null bsa_name " + pv_id);
1539
              // show stopper
1540
              throw new Exception();
1541
            }
1542
 
1543
            if ( !ignore )
1544
            {
1545
              boolean supportedBuildStandard = true;
1546
              BuildStandard bs = new BuildStandard(rippleEngine);
1547
 
1548
              if ( bm_name.compareTo("Solaris") == 0 )
1549
              {
1550
                bs.setSolaris();
1551
              }
1552
              else if ( bm_name.compareTo("Win32") == 0 )
1553
              {
1554
                bs.setWin32();
1555
              }
1556
              else if ( bm_name.compareTo("Linux") == 0 )
1557
              {
1558
                bs.setLinux();
1559
              }
1560
              else if ( bm_name.compareTo("Generic") == 0 )
1561
              {
1562
                bs.setGeneric();
1563
              }
1564
              else
1565
              {
1566
                supportedBuildStandard = false;
1567
              }
1568
 
1569
              if ( bsa_name.compareTo("Production") == 0 )
1570
              {
1571
                bs.setProduction();
1572
              }
1573
              else if ( bsa_name.compareTo("Debug") == 0 )
1574
              {
1575
                bs.setDebug();
1576
              }
1577
              else if ( bsa_name.compareTo("Production and Debug") == 0 )
1578
              {
1579
                bs.setAll();
1580
              }
1581
              else if ( bsa_name.compareTo("Java 1.4") == 0 )
1582
              {
1583
                bs.set1_4();
1584
              }
1585
              else if ( bsa_name.compareTo("Java 1.5") == 0 )
1586
              {
1587
                bs.set1_5();
1588
              }
1589
              else if ( bsa_name.compareTo("Java 1.6") == 0 )
1590
              {
1591
                bs.set1_6();
1592
              }
1593
              else
1594
              {
1595
                supportedBuildStandard = false;
1596
              }
1597
 
1598
              if ( supportedBuildStandard )
1599
              {
1600
                p.mBuildStandardCollection.add(bs);
1601
              }
1602
            }
1603
          }
830 mhunt 1604
 
1605
          rset3.close();
1606
          stmt3.close();
814 mhunt 1607
 
1608
          // get planned package unit test info
1609
          CallableStatement stmt4 = mConnection.prepareCall(
1610
          "select pl.pv_id, tt.test_type_name " +
1611
          "from release_manager.planned pl, release_manager.package_versions pv, release_manager.unit_tests ut, release_manager.test_types tt " +
1612
          "where pl.rtag_id=" + baseline + " and pv.build_type='A' and pv.dlocked='A' " +
1613
          "and pv.pv_id = pl.pv_id and ut.pv_id=pv.pv_id and tt.test_type_id=ut.test_types_fk " +
1614
          "order by pl.pv_id"
1615
          );
1616
          ResultSet rset4 = stmt4.executeQuery();
1617
 
1618
          while( rset4.next() )
1619
          {
1620
            boolean ignore = false;
1621
 
1622
            int pv_id = rset4.getInt("pv_id");
1623
 
1624
            if ( rset4.wasNull() )
1625
            {
1626
              mLogger.fatal("queryPackageVersions rset4 null pv_id");
1627
              // show stopper
1628
              throw new Exception();
1629
            }
1630
 
1631
            Package p = findPackage(pv_id, packageCollection);
1632
 
1633
            if ( p == NULL_PACKAGE )
1634
            {
1635
              mLogger.info("queryPackageVersions rset4 highly unlikely " + pv_id);
1636
              // highly unlikely but package may have been added in between queries
1637
              ignore = true;
1638
            }
1639
 
1640
            String test_type_name = rset4.getString("test_type_name");
1641
 
1642
            if ( test_type_name == null )
1643
            {
1644
              mLogger.fatal("queryPackageVersions rset4 null test_type_name " + pv_id);
1645
              // show stopper
1646
              throw new Exception();
1647
            }
1648
 
1649
            if ( !ignore )
1650
            {
1651
              if ( test_type_name.compareTo("Autobuild UTF") == 0 )
1652
              {
1653
                p.mHasAutomatedUnitTests = true;
1654
              }
1655
            }
1656
          }
830 mhunt 1657
 
1658
          rset4.close();
1659
          stmt4.close();
814 mhunt 1660
 
1661
          // get planned package build failure info
1662
          CallableStatement stmt5 = mConnection.prepareCall(
1663
          "select pl.pv_id, u.user_email " +
1664
          "from release_manager.planned pl, release_manager.release_tags rt, release_manager.package_versions pv, release_manager.autobuild_failure af, release_manager.members_group mg, release_manager.users u " +
1665
          "where pl.rtag_id=" + baseline + " and rt.rtag_id=pl.rtag_id and pv.build_type='A' and pv.dlocked='A' " +
1666
          "and pv.pv_id = pl.pv_id and af.view_id=pl.view_id and mg.group_email_id=af.group_email_id and u.user_id=mg.user_id and af.proj_id=rt.proj_id " +
1667
          "order by pl.pv_id"
1668
          );
1669
          ResultSet rset5 = stmt5.executeQuery();
1670
 
1671
          while( rset5.next() )
1672
          {
1673
            boolean ignore = false;
1674
 
1675
            int pv_id = rset5.getInt("pv_id");
1676
 
1677
            if ( rset5.wasNull() )
1678
            {
1679
              mLogger.fatal("queryPackageVersions rset5 null pv_id");
1680
              // show stopper
1681
              throw new Exception();
1682
            }
1683
 
1684
            Package p = findPackage(pv_id, packageCollection);
1685
 
1686
            if ( p == NULL_PACKAGE )
1687
            {
1688
              mLogger.info("queryPackageVersions rset5 highly unlikely " + pv_id);
1689
              // highly unlikely but package may have been added in between queries
1690
              ignore = true;
1691
            }
1692
 
1693
            String user_email = rset5.getString("user_email");
1694
 
1695
            if ( user_email == null )
1696
            {
1697
              // this can be null!
1698
              ignore = true;
1699
            }
1700
 
1701
            if ( !ignore )
1702
            {
1703
              p.mBuildFailureEmailCollection.add(user_email);
1704
            }
1705
          }
830 mhunt 1706
 
1707
          rset5.close();
1708
          stmt5.close();
814 mhunt 1709
 
1710
          // get planned package do not ripple info
1711
          CallableStatement stmt6 = mConnection.prepareCall(
1712
          "select pl.pv_id " +
1713
          "from release_manager.planned pl, release_manager.package_versions pv, release_manager.do_not_ripple dnr " +
1714
          "where pl.rtag_id=" + baseline + " and pv.build_type='A' and pv.dlocked='A' " +
1715
          "and pv.pv_id = pl.pv_id and dnr.rtag_id=pl.rtag_id and dnr.pv_id=pl.pv_id " +
1716
          "order by pl.pv_id"
1717
          );
1718
          ResultSet rset6 = stmt6.executeQuery();
1719
 
1720
          while( rset6.next() )
1721
          {
1722
            boolean ignore = false;
1723
 
1724
            int pv_id = rset6.getInt("pv_id");
1725
 
1726
            if ( rset6.wasNull() )
1727
            {
1728
              mLogger.fatal("queryPackageVersions rset6 null pv_id");
1729
              // show stopper
1730
              throw new Exception();
1731
            }
1732
 
1733
            Package p = findPackage(pv_id, packageCollection);
1734
 
1735
            if ( p == NULL_PACKAGE )
1736
            {
1737
              mLogger.info("queryPackageVersions rset6 highly unlikely " + pv_id);
1738
              // highly unlikely but package may have been added in between queries
1739
              ignore = true;
1740
            }
1741
 
1742
            if ( !ignore )
1743
            {
1744
              p.mDoNotRipple = true;
1745
            }
1746
          }
830 mhunt 1747
 
1748
          rset6.close();
1749
          stmt6.close();
814 mhunt 1750
 
1751
          // get planned package advisory ripple info
1752
          CallableStatement stmt7 = mConnection.prepareCall(
1753
          "select pl.pv_id " +
1754
          "from release_manager.planned pl, release_manager.package_versions pv, release_manager.advisory_ripple ar " +
1755
          "where pl.rtag_id=" + baseline + " and pv.build_type='A' and pv.dlocked='A' " +
1756
          "and pv.pv_id = pl.pv_id and ar.rtag_id=pl.rtag_id and ar.pv_id=pl.pv_id " +
1757
          "order by pl.pv_id"
1758
          );
1759
          ResultSet rset7 = stmt7.executeQuery();
1760
 
1761
          while( rset7.next() )
1762
          {
1763
            boolean ignore = false;
1764
 
1765
            int pv_id = rset7.getInt("pv_id");
1766
 
1767
            if ( rset7.wasNull() )
1768
            {
1769
              mLogger.fatal("queryPackageVersions rset7 null pv_id");
1770
              // show stopper
1771
              throw new Exception();
1772
            }
1773
 
1774
            Package p = findPackage(pv_id, packageCollection);
1775
 
1776
            if ( p == NULL_PACKAGE )
1777
            {
1778
              mLogger.info("queryPackageVersions rset7 highly unlikely " + pv_id);
1779
              // highly unlikely but package may have been added in between queries
1780
              ignore = true;
1781
            }
1782
 
1783
            if ( !ignore )
1784
            {
1785
              p.mAdvisoryRipple = true;
1786
            }
1787
          }
1788
 
830 mhunt 1789
          rset7.close();
1790
          stmt7.close();
1791
 
814 mhunt 1792
          // get released package info
1793
          CallableStatement stmt8 = mConnection.prepareCall(
1794
          "select rc.pv_id, p.pkg_id, p.pkg_name, pv.pkg_version, pv.v_ext, pv.pkg_label, pv.src_path, pv.ripple_field " +
1795
          "from release_manager.release_content rc, release_manager.package_versions pv, release_manager.packages p " +
1796
          "where rc.rtag_id=" + baseline +
1797
          " and pv.pv_id = rc.pv_id and p.pkg_id = pv.pkg_id " +
1798
          "order by rc.pv_id"
1799
          );
1800
          ResultSet rset8 = stmt8.executeQuery();
1801
 
1802
          while( rset8.next() )
1803
          {
1804
            int pv_id = rset8.getInt("pv_id");
1805
 
1806
            if ( rset8.wasNull() )
1807
            {
1808
              mLogger.fatal("queryPackageVersions rset8 null pv_id");
1809
              // show stopper
1810
              throw new Exception();
1811
            }
1812
 
1813
            int pkg_id = rset8.getInt("pkg_id");
1814
 
1815
            if ( rset8.wasNull() )
1816
            {
1817
              mLogger.fatal("queryPackageVersions rset8 null pkg_id " + pv_id);
1818
              // show stopper
1819
              throw new Exception();
1820
            }
1821
 
1822
            String pkg_name = rset8.getString("pkg_name");
1823
 
1824
            if ( pkg_name == null )
1825
            {
1826
              mLogger.fatal("queryPackageVersions rset8 null pkg_name " + pv_id);
1827
              // show stopper
1828
              throw new Exception();
1829
            }
1830
 
1831
            String pkg_version = rset8.getString("pkg_version");
1832
 
1833
            if ( pkg_version == null )
1834
            {
1835
              mLogger.fatal("queryPackageVersions rset8 null pkg_version " + pv_id);
1836
              // show stopper
1837
              throw new Exception();
1838
            }
1839
 
1840
            String v_ext = rset8.getString("v_ext");
1841
 
1842
            if ( v_ext == null )
1843
            {
1844
              v_ext = "";
1845
            }
1846
 
1847
            String pkg_label = rset8.getString("pkg_label");
1848
 
1849
            if ( pkg_label == null )
1850
            {
1851
              pkg_label = "NA";
1852
            }
1853
 
1854
            String src_path = rset8.getString("src_path");
1855
 
1856
            if ( src_path == null )
1857
            {
1858
              src_path = "NA";
1859
            }
1860
 
1861
            String ripple_field = rset8.getString("ripple_field");
1862
 
1863
            if ( ripple_field == null )
1864
            {
1865
              ripple_field = "x";
1866
            }
1867
            else if ( ripple_field.length() == 0 )
1868
            {
1869
              ripple_field = "x";
1870
            }
1871
 
1872
            Package p = new Package(pv_id, pkg_name, pkg_version, v_ext, pkg_name + v_ext, pkg_label, src_path, ripple_field.charAt(0));
1873
            p.mPid = pkg_id;
1874
            Integer ipv_id = new Integer(pv_id);
1875
            rippleEngine.mReleasedPvIDCollection.add(ipv_id);
1876
            Package plannedPackage = findPackage(p.mAlias, packageCollection);
1877
 
1878
            if ( plannedPackage == NULL_PACKAGE )
1879
            {
1880
              mLogger.info("queryPackageVersions rset8 no planned package " + pv_id);
1881
              packageCollection.add(p);
1882
            }
1883
            else
1884
            {
1885
              int endindex = pkg_version.length() - v_ext.length();
1886
 
1887
              if ( endindex > 0 )
1888
              {
1889
                pkg_version = pkg_version.substring(0, endindex);
1890
              }
1891
 
1892
              plannedPackage.mVersion = pkg_version;
1893
            }
1894
          }
830 mhunt 1895
 
1896
          rset8.close();
1897
          stmt8.close();
814 mhunt 1898
 
1899
          // get released package dependency info
1900
          CallableStatement stmt9 = mConnection.prepareCall(
1901
          "select rc.pv_id, dpv.pv_id, p.pkg_name, dpv.v_ext " +
1902
          "from release_manager.release_content rc, release_manager.package_versions pv, release_manager.package_dependencies pd, release_manager.package_versions dpv, release_manager.packages p " +
1903
          "where rc.rtag_id=" + baseline +
1904
          " and pv.pv_id = rc.pv_id and pd.pv_id=pv.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id " +
1905
          "order by rc.pv_id"
1906
          );
1907
          ResultSet rset9 = stmt9.executeQuery();
1908
 
1909
          while( rset9.next() )
1910
          {
1911
            boolean ignore = false;
1912
 
1913
            int pv_id = rset9.getInt(1);
1914
 
1915
            if ( rset9.wasNull() )
1916
            {
1917
              mLogger.fatal("queryPackageVersions rset9 null pv_id");
1918
              // show stopper
1919
              throw new Exception();
1920
            }
1921
 
1922
            int dpv_id = rset9.getInt(2);
1923
 
1924
            if ( rset9.wasNull() )
1925
            {
1926
              mLogger.fatal("queryPackageVersions rset9 null dpv_id " + pv_id);
1927
              // show stopper
1928
              throw new Exception();
1929
            }
1930
 
1931
            Package p = findPackage(pv_id, packageCollection);
1932
 
1933
            if ( p == NULL_PACKAGE )
1934
            {
1935
              mLogger.info("queryPackageVersions rset9 package may have been superceded by planned " + pv_id);
1936
              ignore = true;
1937
            }
1938
 
1939
            String pkg_name = rset9.getString("pkg_name");
1940
 
1941
            if ( pkg_name == null )
1942
            {
1943
              mLogger.fatal("queryPackageVersions rset9 null pkg_name " + pv_id);
1944
              // show stopper
1945
              throw new Exception();
1946
            }
1947
 
1948
            String v_ext = rset9.getString("v_ext");
1949
 
1950
            if ( v_ext == null )
1951
            {
1952
              v_ext = "";
1953
            }
1954
 
1955
            if ( !ignore )
1956
            {
1957
              p.mDependencyCollection.add(pkg_name + v_ext);
1958
              p.mDependencyIDCollection.add(dpv_id);
1959
            }
1960
          }
830 mhunt 1961
 
1962
          rset9.close();
1963
          stmt9.close();
814 mhunt 1964
 
1965
          // get released package build info
1966
          CallableStatement stmt10 = mConnection.prepareCall(
1967
          "select rc.pv_id, bm.bm_name, bsa.bsa_name " +
1968
          "from release_manager.release_content rc, release_manager.package_versions pv, release_manager.package_build_info pbi, release_manager.build_machines bm, release_manager.build_standards_addendum bsa " +
1969
          "where rc.rtag_id=" + baseline +
1970
          " and pv.pv_id = rc.pv_id and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id " +
1971
          "order by rc.pv_id"
1972
          );
1973
          ResultSet rset10 = stmt10.executeQuery();
1974
 
1975
          while( rset10.next() )
1976
          {
1977
            boolean ignore = false;
1978
            int pv_id = rset10.getInt("pv_id");
1979
 
1980
            if ( rset10.wasNull() )
1981
            {
1982
              mLogger.fatal("queryPackageVersions rset10 null pv_id");
1983
              // show stopper
1984
              throw new Exception();
1985
            }
1986
 
1987
            Package p = findPackage(pv_id, packageCollection);
1988
 
1989
            if ( p == NULL_PACKAGE )
1990
            {
1991
              mLogger.info("queryPackageVersions rset10 package may have been superceded by planned " + pv_id);
1992
              ignore = true;
1993
            }
1994
 
1995
            String bm_name = rset10.getString("bm_name");
1996
 
1997
            if ( bm_name == null )
1998
            {
1999
              mLogger.fatal("queryPackageVersions rset10 null bm_name " + pv_id);
2000
              // show stopper
2001
              throw new Exception();
2002
            }
2003
 
2004
            String bsa_name = rset10.getString("bsa_name");
2005
 
2006
            if ( bsa_name == null )
2007
            {
2008
              mLogger.fatal("queryPackageVersions rset10 null bsa_name " + pv_id);
2009
              // show stopper
2010
              throw new Exception();
2011
            }
2012
 
2013
            if ( !ignore )
2014
            {
2015
              boolean supportedBuildStandard = true;
2016
              BuildStandard bs = new BuildStandard(rippleEngine);
2017
 
2018
              if ( bm_name.compareTo("Solaris") == 0 )
2019
              {
2020
                bs.setSolaris();
2021
              }
2022
              else if ( bm_name.compareTo("Win32") == 0 )
2023
              {
2024
                bs.setWin32();
2025
              }
2026
              else if ( bm_name.compareTo("Linux") == 0 )
2027
              {
2028
                bs.setLinux();
2029
              }
2030
              else if ( bm_name.compareTo("Generic") == 0 )
2031
              {
2032
                bs.setGeneric();
2033
              }
2034
              else
2035
              {
2036
                supportedBuildStandard = false;
2037
              }
2038
 
2039
              if ( bsa_name.compareTo("Production") == 0 )
2040
              {
2041
                bs.setProduction();
2042
              }
2043
              else if ( bsa_name.compareTo("Debug") == 0 )
2044
              {
2045
                bs.setDebug();
2046
              }
2047
              else if ( bsa_name.compareTo("Production and Debug") == 0 )
2048
              {
2049
                bs.setAll();
2050
              }
2051
              else if ( bsa_name.compareTo("Java 1.4") == 0 )
2052
              {
2053
                bs.set1_4();
2054
              }
2055
              else if ( bsa_name.compareTo("Java 1.5") == 0 )
2056
              {
2057
                bs.set1_5();
2058
              }
2059
              else if ( bsa_name.compareTo("Java 1.6") == 0 )
2060
              {
2061
                bs.set1_6();
2062
              }
2063
              else
2064
              {
2065
                supportedBuildStandard = false;
2066
              }
2067
 
2068
              if ( supportedBuildStandard )
2069
              {
2070
                p.mBuildStandardCollection.add(bs);
2071
              }
2072
            }
2073
          }
830 mhunt 2074
 
2075
          rset10.close();
2076
          stmt10.close();
814 mhunt 2077
 
2078
          // get released package unit test info
2079
          CallableStatement stmt11 = mConnection.prepareCall(
2080
          "select rc.pv_id, tt.test_type_name " +
2081
          "from release_manager.release_content rc, release_manager.package_versions pv, release_manager.unit_tests ut, release_manager.test_types tt " +
2082
          "where rc.rtag_id=" + baseline +
2083
          " and pv.pv_id = rc.pv_id and ut.pv_id=pv.pv_id and tt.test_type_id=ut.test_types_fk " +
2084
          "order by rc.pv_id"
2085
          );
2086
          ResultSet rset11 = stmt11.executeQuery();
2087
 
2088
          while( rset11.next() )
2089
          {
2090
            boolean ignore = false;
2091
 
2092
            int pv_id = rset11.getInt("pv_id");
2093
 
2094
            if ( rset11.wasNull() )
2095
            {
2096
              mLogger.fatal("queryPackageVersions rset11 null pv_id");
2097
              // show stopper
2098
              throw new Exception();
2099
            }
2100
 
2101
            Package p = findPackage(pv_id, packageCollection);
2102
 
2103
            if ( p == NULL_PACKAGE )
2104
            {
2105
              mLogger.info("queryPackageVersions rset11 package may have been superceded by planned " + pv_id);
2106
              ignore = true;
2107
            }
2108
 
2109
            String test_type_name = rset11.getString("test_type_name");
2110
 
2111
            if ( test_type_name == null )
2112
            {
2113
              mLogger.fatal("queryPackageVersions rset11 null test_type_name " + pv_id);
2114
              // show stopper
2115
              throw new Exception();
2116
            }
2117
 
2118
            if ( !ignore )
2119
            {
2120
              if ( test_type_name.compareTo("Autobuild UTF") == 0 )
2121
              {
2122
                p.mHasAutomatedUnitTests = true;
2123
              }
2124
            }
2125
          }
830 mhunt 2126
 
2127
          rset11.close();
2128
          stmt11.close();
814 mhunt 2129
 
2130
          // get released package build failure email info
2131
          CallableStatement stmt12 = mConnection.prepareCall(
2132
          "select rc.pv_id, u.user_email " +
2133
          "from release_manager.release_content rc, release_manager.release_tags rt, release_manager.package_versions pv, release_manager.autobuild_failure af, release_manager.members_group mg, release_manager.users u " +
2134
          "where rc.rtag_id=" + baseline + " and rt.rtag_id=rc.rtag_id " +
2135
          "and pv.pv_id = rc.pv_id and af.view_id=rc.base_view_id and mg.group_email_id=af.group_email_id and u.user_id=mg.user_id and af.proj_id=rt.proj_id " +
2136
          "order by rc.pv_id"
2137
          );
2138
          ResultSet rset12 = stmt12.executeQuery();
2139
 
2140
          while( rset12.next() )
2141
          {
2142
            boolean ignore = false;
2143
 
2144
            int pv_id = rset12.getInt("pv_id");
2145
 
2146
            if ( rset12.wasNull() )
2147
            {
2148
              mLogger.fatal("queryPackageVersions rset12 null pv_id");
2149
              // show stopper
2150
              throw new Exception();
2151
            }
2152
 
2153
            Package p = findPackage(pv_id, packageCollection);
2154
 
2155
            if ( p == NULL_PACKAGE )
2156
            {
2157
              mLogger.info("queryPackageVersions rset12 package may have been superceded by planned " + pv_id);
2158
              ignore = true;
2159
            }
2160
 
2161
            String user_email = rset12.getString("user_email");
2162
 
2163
            if ( user_email == null )
2164
            {
2165
              // this can be null
2166
              ignore = true;
2167
            }
2168
 
2169
            if ( !ignore )
2170
            {
2171
              p.mBuildFailureEmailCollection.add(user_email);
2172
            }
2173
          }
830 mhunt 2174
 
2175
          rset12.close();
2176
          stmt12.close();
814 mhunt 2177
 
2178
          // get released package do not ripple info
2179
          CallableStatement stmt13 = mConnection.prepareCall(
2180
          "select rc.pv_id " +
2181
          "from release_manager.release_content rc, release_manager.package_versions pv, release_manager.do_not_ripple dnr " +
2182
          "where rc.rtag_id=" + baseline +
2183
          " and pv.pv_id = rc.pv_id and dnr.rtag_id=rc.rtag_id and dnr.pv_id=rc.pv_id " +
2184
          "order by rc.pv_id"
2185
          );
2186
          ResultSet rset13 = stmt13.executeQuery();
2187
 
2188
          while( rset13.next() )
2189
          {
2190
            boolean ignore = false;
2191
 
2192
            int pv_id = rset13.getInt("pv_id");
2193
 
2194
            if ( rset13.wasNull() )
2195
            {
2196
              mLogger.fatal("queryPackageVersions rset13 null pv_id");
2197
              // show stopper
2198
              throw new Exception();
2199
            }
2200
 
2201
            Package p = findPackage(pv_id, packageCollection);
2202
 
2203
            if ( p == NULL_PACKAGE )
2204
            {
2205
              mLogger.info("queryPackageVersions rset13 package may have been superceded by planned " + pv_id);
2206
              ignore = true;
2207
            }
2208
 
2209
            if ( !ignore )
2210
            {
2211
              p.mDoNotRipple = true;
2212
            }
2213
          }
830 mhunt 2214
 
2215
          rset13.close();
2216
          stmt13.close();
814 mhunt 2217
 
2218
          // get released advisory ripple info
2219
          CallableStatement stmt14 = mConnection.prepareCall(
2220
          "select rc.pv_id " +
2221
          "from release_manager.release_content rc, release_manager.package_versions pv, release_manager.advisory_ripple ar " +
2222
          "where rc.rtag_id=" + baseline +
2223
          " and pv.pv_id = rc.pv_id and ar.rtag_id=rc.rtag_id and ar.pv_id=rc.pv_id " +
2224
          "order by rc.pv_id"
2225
          );
2226
          ResultSet rset14 = stmt14.executeQuery();
2227
 
2228
          while( rset14.next() )
2229
          {
2230
            boolean ignore = false;
2231
 
2232
            int pv_id = rset14.getInt("pv_id");
2233
 
2234
            if ( rset14.wasNull() )
2235
            {
2236
              mLogger.fatal("queryPackageVersions rset14 null pv_id");
2237
              // show stopper
2238
              throw new Exception();
2239
            }
2240
 
2241
            Package p = findPackage(pv_id, packageCollection);
2242
 
2243
            if ( p == NULL_PACKAGE )
2244
            {
2245
              mLogger.info("queryPackageVersions rset14 package may have been superceded by planned " + pv_id);
2246
              ignore = true;
2247
            }
2248
 
2249
            if ( !ignore )
2250
            {
2251
              p.mAdvisoryRipple = true;
2252
            }
2253
          }
830 mhunt 2254
 
2255
          rset14.close();
2256
          stmt14.close();
814 mhunt 2257
        }
2258
        else
2259
        {
2260
          // get released product info
2261
          CallableStatement stmt = mConnection.prepareCall(
2262
          "select oc.prod_id, p.pkg_name, pv.pkg_version, pv.v_ext, pv.pkg_label, pv.src_path " +
2263
          "from bom_contents bc, operating_systems os, os_contents oc, release_manager.package_versions pv, release_manager.packages p " +
2264
          "where bc.bom_id=" + baseline + " and os.node_id=bc.node_id and oc.os_id=os.os_id and pv.pv_id=oc.prod_id and p.pkg_id=pv.pkg_id " +
2265
          "order by oc.prod_id"
2266
          );
2267
          ResultSet rset = stmt.executeQuery();
2268
 
2269
          while( rset.next() )
2270
          {
2271
            int pv_id = rset.getInt("prod_id");
2272
 
2273
            if ( rset.wasNull() )
2274
            {
2275
              mLogger.fatal("queryPackageVersions rset null prod_id");
2276
              // show stopper
2277
              throw new Exception();
2278
            }
2279
 
2280
            String pkg_name = rset.getString("pkg_name");
2281
 
2282
            if ( pkg_name == null )
2283
            {
2284
              mLogger.fatal("queryPackageVersions rset null pkg_name " + pv_id);
2285
              // show stopper
2286
              throw new Exception();
2287
            }
2288
 
2289
            String pkg_version = rset.getString("pkg_version");
2290
 
2291
            if ( pkg_version == null )
2292
            {
2293
              mLogger.fatal("queryPackageVersions rset null pkg_version " + pv_id);
2294
              // show stopper
2295
              throw new Exception();
2296
            }
2297
 
2298
            String v_ext = rset.getString("v_ext");
2299
 
2300
            if ( v_ext == null )
2301
            {
2302
              v_ext = "";
2303
            }
2304
 
2305
            String pkg_label = rset.getString("pkg_label");
2306
 
2307
            if ( pkg_label == null )
2308
            {
2309
              pkg_label = "NA";
2310
            }
2311
 
2312
            String src_path = rset.getString("src_path");
2313
 
2314
            if ( src_path == null )
2315
            {
2316
              src_path = "NA";
2317
            }
2318
 
2319
            Package p = new Package(pv_id, pkg_name, pkg_version, v_ext, pkg_name + "." + pkg_version, pkg_label, src_path, 'x');
2320
            packageCollection.add(p);
2321
          }
830 mhunt 2322
 
2323
          rset.close();
2324
          stmt.close();
814 mhunt 2325
        }
2326
      }
2327
      catch ( SQLException e )
2328
      {
2329
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2330
        {
2331
          mLogger.error("queryPackageVersions database access error only");
2332
          throw new SQLException();
2333
        }
2334
        else
2335
        {
2336
          mLogger.fatal("queryPackageVersions show stopper");
2337
          throw new Exception();
2338
        }
2339
      }
2340
    }
2341
 
2342
    if (!daemonMode)
2343
    {
2344
      // use a ListIterator as it allows traverseDependencies to modify the packageCollection
2345
      for (ListIterator it = packageCollection.listIterator(); it.hasNext(); )
2346
      {
2347
        Package p = (Package) it.next();
2348
        traverseDependencies(packageCollection, p, false, it);
2349
      }
2350
 
2351
      for (Iterator it = packageCollection.iterator(); it.hasNext(); )
2352
      {
2353
        Package p = (Package) it.next();
2354
        queryBuildInfo(rippleEngine, p);
2355
      }
2356
    }
2357
 
2358
  }
2359
 
2360
  /**only used in daemon mode
2361
   *   select config from build_service_config where service='MAIL SERVER';
2362
   * returns the configured service
2363
   */
2364
  String queryMailServer() throws SQLException, Exception
2365
  {
2366
    mLogger.debug("queryMailServer");
2367
    String retVal = new String();
2368
 
2369
    if ( !mUseDatabase )
2370
    {
2371
      mLogger.info("queryMailServer !mUseDatabase");
2372
      // a highly likely mail server
2373
      retVal = "aupera03.aupera.erggroup.com";
2374
    }
2375
    else
2376
    {
2377
      try
2378
      {
2379
        CallableStatement stmt = mConnection.prepareCall("select config from release_manager.build_service_config where service='MAIL SERVER'");
2380
        ResultSet rset = stmt.executeQuery();
2381
 
2382
        while( rset.next() )
2383
        {
2384
          String config = rset.getString("config");
2385
 
2386
          if ( config != null )
2387
          {
2388
            retVal += config;
2389
          }
2390
        }
830 mhunt 2391
 
2392
        rset.close();
2393
        stmt.close();
814 mhunt 2394
      }
2395
      catch ( SQLException e )
2396
      {
2397
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2398
        {
2399
          mLogger.error("queryMailServer database access error only");
2400
          throw new SQLException();
2401
        }
2402
        else
2403
        {
2404
          mLogger.fatal("queryMailServer show stopper");
2405
          throw new Exception();
2406
        }
2407
      }
2408
    }
2409
 
2410
    mLogger.info("queryMailServer returned " + retVal);
2411
    return retVal;
2412
  }
2413
 
2414
  /**only used in daemon mode
2415
   *   select config from build_service_config where service='BUILD FAILURE MAIL SENDER';
2416
   * returns the configured service
2417
   */
2418
  String queryMailSender() throws SQLException, Exception
2419
  {
2420
    mLogger.debug("queryMailSender");
2421
    String retVal = new String();
2422
 
2423
    if ( !mUseDatabase )
2424
    {
2425
      mLogger.info("queryMailSender !mUseDatabase");
2426
      // a highly likely mail sender
2427
      retVal = "buildadm@erggroup.com";
2428
    }
2429
    else
2430
    {
2431
      try
2432
      {
2433
        CallableStatement stmt = mConnection.prepareCall("select config from release_manager.build_service_config where service='BUILD FAILURE MAIL SENDER'");
2434
        ResultSet rset = stmt.executeQuery();
2435
 
2436
        while( rset.next() )
2437
        {
2438
          String config = rset.getString("config");
2439
 
2440
          if ( config != null )
2441
          {
2442
            retVal += config;
2443
          }
2444
        }
830 mhunt 2445
 
2446
        rset.close();
2447
        stmt.close();
814 mhunt 2448
      }
2449
      catch ( SQLException e )
2450
      {
2451
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2452
        {
2453
          mLogger.error("queryMailSender database access error only");
2454
          throw new SQLException();
2455
        }
2456
        else
2457
        {
2458
          mLogger.fatal("queryMailSender show stopper");
2459
          throw new Exception();
2460
        }
2461
      }
2462
    }
2463
 
2464
    mLogger.debug("queryMailSender returned " + retVal);
2465
    return retVal;
2466
  }
2467
 
2468
  /**called only in escrow mode
2469
   * if checkCollection is true, checks the pv_id is in the packageCollection
2470
   * if checkCollection is false, or the pv_id is not in the collection
2471
   * 1 traverses the pv_id package dependencies
2472
   *   select dpv.pv_id, p.pkg_name, dpv.pkg_version, dpv.v_ext, dpv.pkg_label, dpv.src_path
2473
   *   from release_manager.package_versions pv, release_manager.package_dependencies pd, release_manager.package_versions dpv, release_manager.packages p
2474
   *   where pv.pv_id = <pv_id> and pd.pv_id=pv.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id
2475
   *   order by pv.pv_id;
2476
   * 2 for each dpv.pv_id in the resultset
2477
   *     call traverseDependencies( packageCollection, dpv.pv_id, true )
2478
   *     if the pv_id is not in the collection, add it
2479
   *   
2480
   */
2481
  private void traverseDependencies(Vector packageCollection, Package pkg, 
2482
                                     boolean checkCollection, 
2483
                                     ListIterator listIterator) throws SQLException, Exception
2484
  {
2485
    mLogger.debug("traverseDependencies " + checkCollection);
2486
    boolean pvIdInCollection = false;
2487
 
2488
    if ( checkCollection )
2489
    {
2490
      for (Iterator it = packageCollection.iterator(); it.hasNext(); )
2491
      {
2492
        Package p = (Package) it.next();
2493
 
2494
        if ( p.mId == pkg.mId )
2495
        {
2496
          pvIdInCollection = true;
2497
          break;
2498
        }
2499
      }
2500
    }
2501
 
2502
    if ( !pvIdInCollection )
2503
    {
2504
      Vector resultset = new Vector();
2505
 
2506
      if ( !mUseDatabase )
2507
      {
2508
        mLogger.info("traverseDependencies !mUseDatabase");
2509
 
2510
        if ( pkg.mId == 8 || pkg.mId == 10 || pkg.mId == 13 )
2511
        {
2512
          Package p = new Package(9, "CommonDependency", "1.0.0000.tim", ".tim", "CommonDependency.1.0.0000.tim", "CommonDependency_1.0.0000.tim", "\\vob\\CommonDependency", 'x');
2513
          resultset.add(p);
2514
          pkg.mDependencyCollection.add(p.mAlias);
2515
        }
2516
        else if ( pkg.mId == 9 )
2517
        {
2518
          Package p = new Package(7, "CotsWithFunnyVersion", "hoopla2_x.cots", ".cots", "CotsWithFunnyVersion.hoopla2_x.cots", "CotsWithFunnyVersion_hoopla2_x.cots", "\\vob\\CotsWithFunnyVersion", 'x');
2519
          resultset.add(p);
2520
          pkg.mDependencyCollection.add(p.mAlias);
2521
        }
2522
        else if ( pkg.mId == 11 )
2523
        {
2524
          Package p = new Package(14, "AdvisoryDependency", "1.0.0000.tim", ".tim", "AdvisoryDependency.1.0.0000.tim", "AdvisoryDependency_1.0.0000.tim", "\\vob\\AdvisoryDependency", 'x');
2525
          resultset.add(p);
2526
          pkg.mDependencyCollection.add(p.mAlias);
2527
        }
2528
      }
2529
      else
2530
      {
2531
        try
2532
        {
2533
          CallableStatement stmt = mConnection.prepareCall(
2534
          "select dpv.pv_id, p.pkg_name, dpv.pkg_version, dpv.v_ext, dpv.pkg_label, dpv.src_path " +
2535
          "from release_manager.package_versions pv, release_manager.package_dependencies pd, release_manager.package_versions dpv, release_manager.packages p " +
2536
          "where pv.pv_id=" + pkg.mId + " and pd.pv_id=pv.pv_id and dpv.pv_id=pd.dpv_id and p.pkg_id=dpv.pkg_id " +
2537
          "order by pv.pv_id"
2538
          );
2539
          ResultSet rset = stmt.executeQuery();
2540
 
2541
          while( rset.next() )
2542
          {
2543
            int pv_id = rset.getInt("pv_id");
2544
 
2545
            if ( rset.wasNull() )
2546
            {
2547
              mLogger.fatal("traverseDependencies null pv_id");
2548
              // show stopper
2549
              throw new Exception();
2550
            }
2551
 
2552
            String pkg_name = rset.getString("pkg_name");
2553
 
2554
            if ( pkg_name == null )
2555
            {
2556
              mLogger.fatal("traverseDependencies null pkg_name " + pv_id);
2557
              // show stopper
2558
              throw new Exception();
2559
            }
2560
 
2561
            String pkg_version = rset.getString("pkg_version");
2562
 
2563
            if ( pkg_version == null )
2564
            {
2565
              mLogger.fatal("traverseDependencies null pkg_version " + pv_id);
2566
              // show stopper
2567
              throw new Exception();
2568
            }
2569
 
2570
            String v_ext = rset.getString("v_ext");
2571
 
2572
            if ( v_ext == null )
2573
            {
2574
              v_ext = "";
2575
            }
2576
 
2577
            String pkg_label = rset.getString("pkg_label");
2578
 
2579
            if ( pkg_label == null )
2580
            {
2581
              pkg_label = "NA";
2582
            }
2583
 
2584
            String src_path = rset.getString("src_path");
2585
 
2586
            if ( src_path == null )
2587
            {
2588
              src_path = "NA";
2589
            }
2590
 
2591
            Package p = new Package(pv_id, pkg_name, pkg_version, v_ext, pkg_name + "." + pkg_version, pkg_label, src_path, 'x');
2592
            resultset.add(p);
2593
            pkg.mDependencyCollection.add(p.mAlias);
2594
          }
830 mhunt 2595
 
2596
          rset.close();
2597
          stmt.close();
814 mhunt 2598
        }
2599
        catch ( SQLException e )
2600
        {
2601
          if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2602
          {
2603
            mLogger.fatal("traverseDependencies database access error only");
2604
            throw new SQLException();
2605
          }
2606
          else
2607
          {
2608
            mLogger.fatal("traverseDependencies show stopper");
2609
            throw new Exception();
2610
          }
2611
        }
2612
      }
2613
 
2614
      for (Iterator it = resultset.iterator(); it.hasNext(); )
2615
      {
2616
        Package r = (Package) it.next();
2617
        traverseDependencies(packageCollection, r, true, listIterator);
2618
 
2619
        pvIdInCollection = false;
2620
 
2621
        for (Iterator it2 = packageCollection.iterator(); it2.hasNext(); )
2622
        {
2623
          Package p = (Package) it2.next();
2624
 
2625
          if ( p.mId == r.mId )
2626
          {
2627
            pvIdInCollection = true;
2628
            break;
2629
          }
2630
        }
2631
 
2632
        if (!pvIdInCollection)
2633
        {
2634
          // insert the Package immediately before the next Package returned by next
2635
          // this does not change the next Package (if any) to be returned by next
2636
          listIterator.add(r);
2637
        }
2638
 
2639
      }
2640
    }
2641
  }
2642
 
2643
  /**returns the Package with the matching mID or NULL_PACKAGE if no package has the mID
2644
   */
2645
  private Package findPackage(int id, Vector packageCollection)
2646
  {
2647
    mLogger.debug("findPackage 1 id " + id);
2648
    Package retVal = NULL_PACKAGE;
2649
 
2650
    for (Iterator it = packageCollection.iterator(); it.hasNext(); )
2651
    {
2652
      Package p = (Package) it.next();
2653
 
2654
      if ( p.mId == id )
2655
      {
2656
        retVal = p;
2657
        break;
2658
      }
2659
    }
2660
 
2661
    mLogger.debug("findPackage 1 returned " + retVal.mName);
2662
    return retVal;
2663
  }
2664
 
2665
  /**called only in escrow mode to add build info to the Package
2666
   * select bm.bm_name, bsa.bsa_name
2667
   * from release_manager.package_versions pv, release_manager.package_build_info pbi, release_manager.build_machines bm, release_manager.build_standards_addendum bsa
2668
   * where pv.pv_id = <p.pv_id> and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id
2669
   * order by pv.pv_id;
2670
   */
2671
  private void queryBuildInfo(RippleEngine rippleEngine, Package p) throws SQLException, Exception
2672
  {
2673
    mLogger.debug("queryBuildInfo");
2674
    if ( !mUseDatabase )
2675
    {
2676
      mLogger.info("queryBuildInfo !mUseDatabase");
2677
 
2678
      if (p.mId == 7)
2679
      {
2680
        BuildStandard bs = new BuildStandard(rippleEngine);
2681
        bs.setSolaris();
2682
        bs.setDebug();
2683
        p.mBuildStandardCollection.add(bs);
2684
      }
2685
      else if (p.mId == 9)
2686
      {
2687
        BuildStandard bs = new BuildStandard(rippleEngine);
2688
        bs.setLinux();
2689
        bs.setDebug();
2690
        p.mBuildStandardCollection.add(bs);
2691
        bs = new BuildStandard(rippleEngine);
2692
        bs.setSolaris();
2693
        bs.setDebug();
2694
        p.mBuildStandardCollection.add(bs);
2695
        bs = new BuildStandard(rippleEngine);
2696
        bs.setWin32();
2697
        bs.setProduction();
2698
        p.mBuildStandardCollection.add(bs);
2699
      }
2700
      else if (p.mId == 10)
2701
      {
2702
        BuildStandard bs = new BuildStandard(rippleEngine);
2703
        bs.setSolaris();
2704
        bs.set1_4();
2705
        p.mBuildStandardCollection.add(bs);
2706
      }
2707
      else if (p.mId == 11)
2708
      {
2709
        BuildStandard bs = new BuildStandard(rippleEngine);
2710
        bs.setLinux();
2711
        bs.setAll();
2712
        p.mBuildStandardCollection.add(bs);
2713
      }
2714
      else if (p.mId == 12)
2715
      {
2716
        BuildStandard bs = new BuildStandard(rippleEngine);
2717
        bs.setWin32();
2718
        bs.set1_6();
2719
        p.mBuildStandardCollection.add(bs);
2720
      }
2721
      else if (p.mId == 13)
2722
      {
2723
        BuildStandard bs = new BuildStandard(rippleEngine);
2724
        bs.setGeneric();
2725
        bs.set1_4();
2726
        p.mBuildStandardCollection.add(bs);
2727
      }
2728
      else if (p.mId == 14)
2729
      {
2730
        BuildStandard bs = new BuildStandard(rippleEngine);
2731
        bs.setLinux();
2732
        bs.setDebug();
2733
        p.mBuildStandardCollection.add(bs);
2734
      }
2735
 
2736
    }
2737
    else
2738
    {
2739
      try
2740
      {
2741
        CallableStatement stmt = mConnection.prepareCall(
2742
        "select bm.bm_name, bsa.bsa_name " +
2743
        "from release_manager.package_versions pv, release_manager.package_build_info pbi, release_manager.build_machines bm, release_manager.build_standards_addendum bsa " +
2744
        "where pv.pv_id=" + p.mId + " and pbi.pv_id=pv.pv_id and bm.bm_id=pbi.bm_id and bsa.bsa_id=pbi.bsa_id " +
2745
        "order by pv.pv_id"
2746
        );
2747
        ResultSet rset = stmt.executeQuery();
2748
 
2749
        while( rset.next() )
2750
        {
2751
          boolean supportedBuildStandard = true;
2752
          BuildStandard bs = new BuildStandard(rippleEngine);
2753
          String bm_name = rset.getString("bm_name");
2754
 
2755
          if ( bm_name == null )
2756
          {
2757
            mLogger.fatal("queryBuildInfo null bm_name " + p.mId);
2758
            // show stopper
2759
            throw new Exception();
2760
          }
2761
          else if ( bm_name.compareTo("Solaris") == 0 )
2762
          {
2763
            bs.setSolaris();
2764
          }
2765
          else if ( bm_name.compareTo("Win32") == 0 )
2766
          {
2767
            bs.setWin32();
2768
          }
2769
          else if ( bm_name.compareTo("Linux") == 0 )
2770
          {
2771
            bs.setLinux();
2772
          }
2773
          else if ( bm_name.compareTo("Generic") == 0 )
2774
          {
2775
            bs.setGeneric();
2776
          }
2777
          else
2778
          {
2779
            supportedBuildStandard = false;
2780
          }
2781
 
2782
          String bsa_name = rset.getString("bsa_name");
2783
 
2784
          if ( bsa_name == null )
2785
          {
2786
            mLogger.fatal("queryBuildInfo null bsa_name " + p.mId);
2787
            // show stopper
2788
            throw new Exception();
2789
          }
2790
          else if ( bsa_name.compareTo("Production") == 0 )
2791
          {
2792
            bs.setProduction();
2793
          }
2794
          else if ( bsa_name.compareTo("Debug") == 0 )
2795
          {
2796
            bs.setDebug();
2797
          }
2798
          else if ( bsa_name.compareTo("Production and Debug") == 0 )
2799
          {
2800
            bs.setAll();
2801
          }
2802
          else if ( bsa_name.compareTo("Java 1.4") == 0 )
2803
          {
2804
            bs.set1_4();
2805
          }
2806
          else if ( bsa_name.compareTo("Java 1.5") == 0 )
2807
          {
2808
            bs.set1_5();
2809
          }
2810
          else if ( bsa_name.compareTo("Java 1.6") == 0 )
2811
          {
2812
            bs.set1_6();
2813
          }
2814
          else
2815
          {
2816
            supportedBuildStandard = false;
2817
          }
2818
 
2819
          if ( supportedBuildStandard )
2820
          {
2821
            p.mBuildStandardCollection.add(bs);
2822
          }
2823
        }
830 mhunt 2824
 
2825
        rset.close();
2826
        stmt.close();
814 mhunt 2827
      }
2828
      catch ( SQLException e )
2829
      {
2830
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2831
        {
2832
          mLogger.error("queryBuildInfo database access error only");
2833
          throw new SQLException();
2834
        }
2835
        else
2836
        {
2837
          mLogger.fatal("queryBuildInfo show stopper");
2838
          throw new Exception();
2839
        }
2840
      }
2841
    }
2842
  }
2843
 
2844
  /**returns the Package with the matching mAlias or NULL_PACKAGE if no package has the mAlias
2845
   */
2846
  private Package findPackage(String alias, Vector packageCollection)
2847
  {
2848
    mLogger.debug("findPackage 2 alias " + alias);
2849
    Package retVal = NULL_PACKAGE;
2850
 
2851
    for (Iterator it = packageCollection.iterator(); it.hasNext(); )
2852
    {
2853
      Package p = (Package) it.next();
2854
 
2855
      if ( p.mAlias.compareTo( alias ) == 0 )
2856
      {
2857
        retVal = p;
2858
        break;
2859
      }
2860
    }
2861
 
2862
    mLogger.info("findPackage 2 returned " + retVal.mName);
2863
    return retVal;
2864
  }
2865
 
2866
  /**essentially locks the row in the BUILD_SERVICE_CONFIG table with a service of MUTEX
2867
   * for the duration of the connection
2868
   * this prevents other MasterThreads from generating build files in parallel
2869
   * and hence prevents planned version numbering contention
2870
   * select CONFIG from BUILD_SERVICE_CONFIG WHERE SERVICE='MUTEX' FOR UPDATE
2871
   */
2872
  public void claimMutex() throws SQLException, Exception
2873
  {
2874
    mLogger.debug("claimMutex");
2875
    if ( mUseDatabase )
2876
    {
2877
      try
2878
      {
2879
        CallableStatement stmt = mConnection.prepareCall("select CONFIG from release_manager.BUILD_SERVICE_CONFIG WHERE SERVICE='MUTEX' FOR UPDATE");
2880
        stmt.executeUpdate();
2881
      }
2882
      catch ( SQLException e )
2883
      {
2884
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2885
        {
2886
          mLogger.error("claimMutex database access error only");
2887
          throw new SQLException();
2888
        }
2889
        else
2890
        {
2891
          mLogger.fatal("claimMutex show stopper");
2892
          throw new Exception();
2893
        }
2894
      }
2895
    }
2896
  }
2897
 
2898
  /**sets CURRENT_BUILD_FILES to NULL for the rcon_id
2899
   * update run_level set current_build_files=null where rcon_id=<rcon_id>
2900
   * returns true if successful
2901
   */
2902
  public boolean clearBuildFile(int rcon_id) throws SQLException, Exception
2903
  {
2904
    mLogger.debug("clearBuildFile");
2905
    boolean retVal = false;
2906
 
2907
    try
2908
    {
2909
      connect();
2910
      CallableStatement stmt = mConnection.prepareCall("update release_manager.run_level set current_build_files=null where rcon_id=" + rcon_id);
2911
      stmt.executeUpdate();
2912
      mConnection.commit();
2913
      disconnect();
2914
      retVal = true;
2915
    }
2916
    catch ( SQLException e )
2917
    {
2918
      if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2919
      {
2920
        mLogger.error("clearBuildFile database access error only");
2921
        throw new SQLException();
2922
      }
2923
      else
2924
      {
2925
        mLogger.fatal("clearBuildFile show stopper");
2926
        throw new Exception();
2927
      }
2928
    }
2929
 
2930
    mLogger.info("clearBuildFile returned " + retVal);
2931
    return retVal;
2932
  }
2933
 
2934
  /**updates the CURRENT_BUILD_FILES for the rtag_id
2935
   * update (
2936
   * select current_build_files from run_level rl, release_config rc
2937
   * where rc.rtag_id=<rtag_id> and rl.rcon_id=rc.rcon_id
2938
   * ) set current_build_files=<buildFile>
2939
   * returns true if successful
2940
   */
2941
  public boolean publishBuildFile(int rtag_id, String buildFile) throws SQLException, Exception
2942
  {
2943
    mLogger.debug("publishBuildFile publishing a build file of length " + buildFile.length());
2944
    boolean retVal = false;
2945
 
2946
    try
2947
    {
2948
      connect();
2949
 
2950
      PreparedStatement stmt = mConnection.prepareStatement(
2951
      "update (" +
2952
      "select current_build_files from release_manager.run_level rl, release_manager.release_config rc " +
2953
      "where rc.rtag_id=? and rl.rcon_id=rc.rcon_id" +
2954
      ") set current_build_files=?");
2955
      stmt.setInt(1, rtag_id);
2956
      stmt.setString(2, buildFile);
2957
      stmt.executeUpdate();
2958
      mConnection.commit();
2959
      disconnect();
2960
      retVal = true;
2961
    }
2962
    catch ( SQLException e )
2963
    {
2964
      if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
2965
      {
2966
        mLogger.error("publishBuildFile database access error only");
2967
        throw new SQLException();
2968
      }
2969
      else
2970
      {
2971
        mLogger.fatal("publishBuildFile show stopper");
2972
        throw new Exception();
2973
      }
2974
    }
2975
    catch ( Exception e )
2976
    {
2977
      // this catch and rethrow is historical
2978
      // problems were found using CallableStatement when updating a CLOB column with data > 4000 bytes
2979
      mLogger.fatal("publishBuildFile caught Exception " + e.getMessage());
2980
      throw new Exception();
2981
    }
2982
    mLogger.info("publishBuildFile returned " + retVal);
2983
    return retVal;
2984
  }
2985
 
2986
  /**ensures a run_level_schedule row with a non null indefinite_pause column exists
2987
   * this is aimed at stopping all daemons dead
2988
   * it is raised when handling an unsupported exception case in either the main or slave daemons
2989
   * typically an SQLException other than a database connection related one
2990
   */
2991
  public void indefinitePause() throws SQLException, Exception
2992
  {
2993
    mLogger.debug("indefinitePause");
2994
    if ( mUseDatabase )
2995
    {
2996
      connect();
2997
      CallableStatement stmt = mConnection.prepareCall( "begin ? := PK_BUILDAPI.SET_INFINITE_PAUSE(); end;" );
2998
      stmt.executeUpdate();
2999
      mConnection.commit();
3000
      disconnect();
3001
    }
3002
  }
3003
 
3004
  /**only used in daemon mode to determine version existence in the database
3005
   *  1 select pkg_id from package_versions where pkg_id=<pkg_id> and pkg_version=<pkg_version>;
3006
   *  2 select pkg_id from planned_versions where pkg_id=<pkg_id> and pkg_version=<pkg_version>;
3007
   * returns true if either resultset contains one record to indicate it already exists
3008
   */
3009
  boolean queryPackageVersions(int pkg_id, String pkg_version) throws SQLException, Exception
3010
  {
3011
    mLogger.debug("queryPackageVersions");
3012
    boolean retVal = false;
3013
 
3014
    if ( mUseDatabase )
3015
    {
3016
      try
3017
      {
3018
        mLogger.info("queryPackageVersions release_manager.package_versions");
3019
        CallableStatement stmt1 = mConnection.prepareCall("select pkg_id from release_manager.package_versions where pkg_id=" + pkg_id + " and pkg_version='" + pkg_version + "'");
3020
        ResultSet rset1 = stmt1.executeQuery();
3021
        int rsetSize = 0;
3022
 
3023
        while( rset1.next() )
3024
        {
3025
          rsetSize++;
3026
        }
830 mhunt 3027
 
3028
        rset1.close();
3029
        stmt1.close();
814 mhunt 3030
 
3031
        if ( rsetSize > 1 )
3032
        {
3033
          mLogger.fatal("queryPackageVersions rsetSize > 1 " + pkg_id + " " + pkg_version);
3034
          // show stopper
3035
          throw new Exception();
3036
        }
3037
 
3038
        if ( rsetSize == 1 )
3039
        {
3040
          retVal = true;
3041
        }
3042
        else
3043
        {
3044
          mLogger.info("queryPackageVersions release_manager.planned_versions");
3045
          CallableStatement stmt2 = mConnection.prepareCall("select pkg_id from release_manager.planned_versions where pkg_id=" + pkg_id + " and pkg_version='" + pkg_version + "'");
3046
          ResultSet rset2 = stmt2.executeQuery();
3047
          rsetSize = 0;
3048
 
3049
          while( rset2.next() )
3050
          {
3051
            rsetSize++;
3052
          }
830 mhunt 3053
 
3054
          rset2.close();
3055
          stmt2.close();
814 mhunt 3056
 
3057
          if ( rsetSize > 1 )
3058
          {
3059
            mLogger.fatal("queryPackageVersions rsetSize > 1 " + pkg_id + " " + pkg_version);
3060
            // show stopper
3061
            throw new Exception();
3062
          }
3063
 
3064
          if ( rsetSize == 1 )
3065
          {
3066
            retVal = true;
3067
          }
3068
          else
3069
          {
3070
            mLogger.info("queryPackageVersions archive_manager.package_versions");
3071
            CallableStatement stmt3 = mConnection.prepareCall("select pkg_id from archive_manager.package_versions where pkg_id=" + pkg_id + " and pkg_version='" + pkg_version + "'");
3072
            ResultSet rset3 = stmt3.executeQuery();
3073
            rsetSize = 0;
3074
 
3075
            while( rset3.next() )
3076
            {
3077
              rsetSize++;
3078
            }
830 mhunt 3079
 
3080
            rset3.close();
3081
            stmt3.close();
814 mhunt 3082
 
3083
            if ( rsetSize > 1 )
3084
            {
3085
              mLogger.fatal("queryPackageVersions rsetSize > 1 " + pkg_id + " " + pkg_version);
3086
              // show stopper
3087
              throw new Exception();
3088
            }
3089
 
3090
            if ( rsetSize == 1 )
3091
            {
3092
              retVal = true;
3093
            }
3094
          }
3095
        }
3096
      }
3097
      catch ( SQLException e )
3098
      {
3099
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3100
        {
3101
          mLogger.error("queryPackageVersions database access error only");
3102
          throw new SQLException();
3103
        }
3104
        else
3105
        {
3106
          mLogger.fatal("queryPackageVersions show stopper");
3107
          throw new Exception();
3108
        }
3109
      }
3110
    }
3111
 
3112
    mLogger.info("queryPackageVersions returned " + retVal);
3113
    return retVal;
3114
  }
3115
 
3116
  /**only used in daemon mode
3117
   *  insert into planned_versions (pkg_id, pkg_version) values (<pkg_id>, <pkg_version>);
3118
   *  update
3119
   *  (
3120
   *  select current_pkg_id_being_built from run_level rl, release_config rc
3121
   *  where rc.rtag_id=<rtag_id> and rl.rcon_id=rc.rcon_id
3122
   *  )
3123
   *  set current_pkg_id_being_built=<pkg_id>
3124
   */
3125
  void claimVersion(int pkg_id, String pkg_version, int rtag_id) throws SQLException, Exception
3126
  {
3127
    mLogger.debug("claimVersion " + pkg_id + " " + pkg_version);
3128
    if ( mUseDatabase )
3129
    {
3130
      try
3131
      {
3132
        CallableStatement stmt3 = mConnection.prepareCall("insert into release_manager.planned_versions (pkg_id, pkg_version) values (" + pkg_id + ", '" + pkg_version + "')");
3133
        stmt3.executeUpdate();
3134
        CallableStatement stmt4 = mConnection.prepareCall(
3135
        "update " +
3136
        "(" +
3137
        "select current_pkg_id_being_built from release_manager.run_level rl, release_manager.release_config rc " +
3138
        "where rc.rtag_id=" + rtag_id + " and rl.rcon_id=rc.rcon_id" +
3139
        ")" +
3140
        "set current_pkg_id_being_built=" + pkg_id);
3141
        stmt4.executeUpdate();
3142
        mConnection.commit();
3143
      }
3144
      catch ( SQLException e )
3145
      {
3146
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3147
        {
3148
          mLogger.error("claimVersion database access error only");
3149
          throw new SQLException();
3150
        }
3151
        else
3152
        {
3153
          mLogger.fatal("claimVersion show stopper");
3154
          throw new Exception();
3155
        }
3156
      }
3157
    }
3158
  }
3159
 
818 mhunt 3160
  /**only used in daemon mode
3161
   *  update
3162
   *  (
3163
   *  select current_pkg_id_being_built from run_level
3164
   *  where rcon_id=<rcon_id>
3165
   *  )
3166
   *  set current_pkg_id_being_built=null
3167
   */
3168
  public void clearCurrentPackageBeingBuilt(int rcon_id) throws SQLException, Exception
3169
  {
3170
    mLogger.debug("clearCurrentPackageBeingBuilt " + rcon_id);
3171
    if ( mUseDatabase )
3172
    {
3173
      try
3174
      {
820 mhunt 3175
        connect();
818 mhunt 3176
        CallableStatement stmt4 = mConnection.prepareCall(
3177
        "update " +
3178
        "(" +
3179
        "select current_pkg_id_being_built from run_level " +
3180
        "where rcon_id=" + rcon_id +
3181
        ")" +
3182
        "set current_pkg_id_being_built=null" );
3183
        stmt4.executeUpdate();
3184
        mConnection.commit();
820 mhunt 3185
        disconnect();
818 mhunt 3186
      }
3187
      catch ( SQLException e )
3188
      {
3189
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3190
        {
3191
          mLogger.error("clearCurrentPackageBeingBuilt database access error only");
3192
          throw new SQLException();
3193
        }
3194
        else
3195
        {
3196
          mLogger.fatal("clearCurrentPackageBeingBuilt show stopper");
3197
          throw new Exception();
3198
        }
3199
      }
3200
    }
3201
  }
3202
 
814 mhunt 3203
  /**handles database connection/disconnection
3204
   * executes the AutoMakeRelease stored procedure with the passed parameters
3205
   */
3206
  public void autoMakeRelease(String rtagId, String packageName, 
3207
                              String packageExtension, 
3208
                              String packageVersion, String packageLabel, 
3209
                              String packageDepends, String isRipple) throws SQLException, Exception
3210
  {
3211
    mLogger.debug("autoMakeRelease " + packageName);
3212
    if ( mUseDatabase )
3213
    {
3214
      try
3215
      {
3216
        connect();
3217
        CallableStatement stmt = mConnection.prepareCall( "begin ? := PK_RMAPI.AUTO_MAKE_RELEASE(?,?,?,?,?,?,?,?); end;" );
3218
        stmt.registerOutParameter( 1, Types.INTEGER);
3219
        stmt.setString( 2, rtagId );
3220
        stmt.setString( 3, packageName );
3221
        stmt.setString( 4, packageExtension );
3222
        stmt.setString( 5, packageVersion );
3223
        stmt.setString( 6, packageLabel );
3224
        stmt.setString( 7, packageDepends );
3225
        stmt.setString( 8, isRipple );
3226
        stmt.setString( 9, "buildadm" );
3227
        stmt.executeUpdate();
3228
        int result = stmt.getInt( 1 );
3229
 
3230
        if ( result <= 0 && result != -2 )
3231
        {
3232
          // -2 if already released
3233
          // flag build failure
3234
          mLogger.fatal("autoMakeRelease show stopper PK_RMAPI.AUTO_MAKE_RELEASE failed, returned" + result);
3235
          throw new Exception();
3236
        }
3237
        mConnection.commit();
3238
        disconnect();
3239
      }
3240
      catch( SQLException e )
3241
      {
3242
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3243
        {
3244
          mLogger.error("autoMakeRelease database access error only");
3245
          throw new SQLException();
3246
        }
3247
        else
3248
        {
3249
          mLogger.fatal("autoMakeRelease show stopper");
3250
          throw new Exception();
3251
        }
3252
      }
3253
    }
3254
  }
3255
 
3256
  /**handles database connection/disconnection
3257
   * executes the ExcludeFromBuild stored procedure with the passed parameters
3258
   */
3259
  public void excludeFromBuild(String packageVersionId, 
3260
                               String packageVersion, String rtagId) throws SQLException, Exception
3261
  {
3262
    mLogger.debug("excludeFromBuild " + packageVersionId);
3263
    if ( mUseDatabase )
3264
    {
3265
      try
3266
      {
3267
        connect();
3268
        CallableStatement stmt = mConnection.prepareCall( "begin ? := PK_RMAPI.EXCLUDE_FROM_BUILD(?,?,?,?); end;" );
3269
        stmt.registerOutParameter( 1, Types.INTEGER);
3270
        stmt.setString( 2, packageVersionId );
3271
        stmt.setString( 3, packageVersion );
3272
        stmt.setString( 4, rtagId );
3273
        stmt.setString( 5, "buildadm" );
3274
        stmt.executeUpdate();
3275
        int result = stmt.getInt( 1 );
3276
 
3277
        if ( result != 0 )
3278
        {
3279
          // flag build failure
3280
          mLogger.fatal( "excludeFromBuild show stopper PK_RMAPI.EXCLUDE_FROM_BUILD failed, returned " + result );
3281
          throw new Exception();
3282
        }
3283
        mConnection.commit();
3284
        disconnect();
3285
      }
3286
      catch( SQLException e )
3287
      {
3288
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3289
        {
3290
          mLogger.error("excludeFromBuild database access error only");
3291
          throw new SQLException();
3292
        }
3293
        else
3294
        {
3295
          mLogger.fatal("excludeFromBuild show stopper");
3296
          throw new Exception();
3297
        }
3298
      }
3299
    }
3300
  }
3301
 
3302
  /**Representation of a row in the RELEASE_CONFIG table
3303
   */
3304
  private class ReleaseConfig
3305
  {
3306
    /**rtag_id column value
3307
     * @attribute
3308
     */
3309
    private int mRtag_id;
3310
 
3311
    /**rcon_id column value
3312
     * @attribute
3313
     */
3314
    private int mRcon_id;
3315
 
3316
    /**daemon_mode column value
3317
     * @attribute
3318
     */
3319
    private char mDaemon_mode;
3320
 
3321
    /**gbebuildfilter column value
3322
     * @attribute
3323
     */
3324
    private String mGbebuildfilter;
3325
 
3326
    /**constructor
3327
     */
3328
    ReleaseConfig(int rtag_id, int rcon_id, char daemon_mode, 
3329
                  String gbebuildfilter)
3330
    {
3331
      mLogger.debug("ReleaseConfig rtag_id " + rtag_id + " rcon_id " + rcon_id + " daemon_mode " + daemon_mode + " gbebuildfilter " + gbebuildfilter );
3332
      mRtag_id = rtag_id;
3333
      mRcon_id = rcon_id;
3334
      mDaemon_mode = daemon_mode;
3335
      mGbebuildfilter = gbebuildfilter;
3336
    }
3337
 
3338
    /**accessor method
3339
     */
3340
    int get_rtag_id()
3341
    {
3342
      mLogger.debug("get_rtag_id");
3343
      mLogger.info("get_rtag_id returned " + mRtag_id);
3344
      return mRtag_id;
3345
    }
3346
 
3347
    /**accessor method
3348
     */
3349
    int get_rcon_id()
3350
    {
3351
      mLogger.debug("get_rcon_id");
3352
      mLogger.info("get_rcon_id returned " + mRcon_id);
3353
      return mRcon_id;
3354
    }
3355
 
3356
    /**accessor method
3357
     */
3358
    char get_daemon_mode()
3359
    {
3360
      mLogger.debug("get_daemon_mode");
3361
      mLogger.info("get_daemon_mode returned " + mDaemon_mode);
3362
      return mDaemon_mode;
3363
    }
3364
 
3365
    /**accessor method
3366
     */
3367
    String get_gbebuildfilter()
3368
    {
3369
      mLogger.debug("get_gbebuildfilter");
3370
      mLogger.info("get_gbebuildfilter returned " + mGbebuildfilter);
3371
      return mGbebuildfilter;
3372
    }
3373
  }
3374
 
3375
  /**Representation of a row in the RUN_LEVEL table
3376
   */
3377
  private class RunLevel
3378
  {
3379
    /**rcon_id column value
3380
     * @attribute
3381
     */
3382
    private int mRcon_id;
3383
 
3384
    /**current_build_files column value
3385
     * @attribute
3386
     */
3387
    private String mCurrent_build_file;
3388
 
3389
    /**current_run_level column value
3390
     * @attribute
3391
     */
3392
    private int mCurrent_run_level;
3393
 
3394
    /**pause column value
3395
     * @attribute
3396
     */
3397
    private boolean mPause;
3398
 
3399
    /**constructor
3400
     */
3401
    RunLevel(int rcon_id, String current_build_file, int current_run_level, 
3402
             boolean pause)
3403
    {
3404
      mLogger.debug("RunLevel");
3405
      mRcon_id = rcon_id;
3406
      mCurrent_build_file = current_build_file;
3407
      mCurrent_run_level = current_run_level;
3408
      mPause = pause;
3409
    }
3410
 
3411
    /**accessor method
3412
     */
3413
    int get_rcon_id()
3414
    {
3415
      mLogger.debug("get_rcon_id");
3416
      mLogger.info("get_rcon_id returned " + mRcon_id);
3417
      return mRcon_id;
3418
    }
3419
 
3420
    /**accessor method
3421
     */
3422
    String get_current_build_file()
3423
    {
3424
      mLogger.debug("get_current_build_file");
3425
      mLogger.info("get_current_build_file returned " + mCurrent_build_file);
3426
      return mCurrent_build_file;
3427
    }
3428
 
3429
    /**accessor method
3430
     */
3431
    int get_current_run_level()
3432
    {
3433
      mLogger.debug("get_current_run_level");
3434
      mLogger.info("get_current_run_level returned " + mCurrent_run_level);
3435
      return mCurrent_run_level;
3436
    }
3437
 
3438
    /**accessor method
3439
     */
3440
    boolean get_pause()
3441
    {
3442
      mLogger.debug("get_pause");
3443
      mLogger.debug("get_pause returned " + mPause);      
3444
      return mPause;
3445
    }
3446
 
3447
  }
3448
 
3449
  /**constructor
3450
   */
3451
  public ReleaseManager(final String connectionString, final String username, 
3452
                        final String password)
3453
  {
3454
    mLogger.debug("ReleaseManager " + connectionString);
3455
    mConnectionString = connectionString;
3456
    mUsername = username;
3457
    mPassword = password;
3458
  }
3459
 
3460
  /**constructor used when schema information is unknown eg location, username, password
3461
   */
3462
  public ReleaseManager()
3463
  {
3464
    // inherit mConnectionString, mUsername, mPassword
3465
     mLogger.debug("ReleaseManager");
3466
  }
3467
 
3468
  /**connect to oracle
3469
   */
3470
  public void connect() throws SQLException, Exception
3471
  {
3472
    mLogger.debug("connect");
3473
 
3474
    if ( !mUseDatabase )
3475
    {
3476
      mLogger.info("connect !mUseDatabase");
3477
    }
3478
    else
3479
    {
3480
      if ( !mRegistered )
3481
      {
3482
        try
3483
        {
3484
          // the JDBC driver is registered only once per database that needs to be accessed
3485
          mLogger.debug("connect registering driver");
3486
          DriverManager.registerDriver( new OracleDriver() );
3487
          mRegistered = true;
3488
        }
3489
        catch(SQLException e)
3490
        {
3491
          mLogger.fatal("connect failed to register the oracle jdbc driver with the driver manager");
3492
          throw new Exception();
3493
        }
3494
      }
3495
 
3496
      // let connect throw SQLException to indicate a database access error
3497
      try
3498
      {
3499
        mConnection = DriverManager.getConnection(mConnectionString, mUsername, mPassword);
3500
      }
3501
      catch(SQLException e)
3502
      {
3503
        mLogger.error("connect getConnection failed");
3504
        mConnection = null;
3505
        throw new SQLException();
3506
      }
3507
    }
3508
  }
3509
 
3510
  /**disconnect from oracle
3511
   */
3512
  public void disconnect()
3513
  {
3514
    mLogger.debug("disconnect");
3515
    if ( mUseDatabase )
3516
    {
3517
      try
3518
      {
3519
        mConnection.close();
3520
      }
3521
      catch(SQLException e)
3522
      {
3523
        // special case do nothing
3524
        mLogger.error("disconnect caught Exception");
3525
      }
3526
    }
3527
  }
3528
 
3529
  /**returns true if the mReleaseConfigCollection is not empty and returns the rcon_id of the first element
3530
   */
3531
  public boolean getFirstReleaseConfig(MutableInt rcon_id)
3532
  {
3533
    mLogger.debug("getFirstReleaseConfig 1");
3534
    boolean retVal = true;
3535
 
3536
    try
3537
    {
3538
      mReleaseConfigIndex = 0;
3539
      ReleaseConfig rc = (ReleaseConfig)mReleaseConfigCollection.get( mReleaseConfigIndex );
3540
      rcon_id.value = rc.get_rcon_id();
3541
    }
3542
    catch( ArrayIndexOutOfBoundsException e )
3543
    {
3544
      retVal = false;
3545
    }
3546
 
3547
    mLogger.info("getFirstReleaseConfig 1 returning " + retVal);
3548
    return retVal;
3549
  }
3550
 
3551
  /**returns true if the mReleaseConfigCollection is not empty and returns the rcon_id, rtag_id, daemon_mode and gbebuildfilter of the first element
3552
   */
3553
  public boolean getFirstReleaseConfig(MutableInt rtag_id, 
3554
                                       MutableInt rcon_id, 
3555
                                       MutableChar daemon_mode, 
3556
                                       MutableString gbebuildfilter)
3557
  {
3558
    mLogger.debug("getFirstReleaseConfig 2");
3559
    boolean retVal = true;
3560
 
3561
    try
3562
    {
3563
      mReleaseConfigIndex = 0;
3564
      ReleaseConfig rc = (ReleaseConfig)mReleaseConfigCollection.get( mReleaseConfigIndex );
3565
      rtag_id.value = rc.get_rtag_id();
3566
      rcon_id.value = rc.get_rcon_id();
3567
      daemon_mode.value = rc.get_daemon_mode();
3568
      gbebuildfilter.value = rc.get_gbebuildfilter();
3569
    }
3570
    catch( ArrayIndexOutOfBoundsException e )
3571
    {
3572
      retVal = false;
3573
    }
3574
 
3575
    mLogger.info("getFirstReleaseConfig 2 returning " + retVal);
3576
    return retVal;
3577
  }
3578
 
3579
  /**returns true if the mRunLevelCollection is not empty and returns the rcon_id and current_run_level of the first element
3580
   */
3581
  public boolean getFirstRunLevel(MutableInt rcon_id, 
3582
                                  MutableInt current_run_level)
3583
  {
3584
    mLogger.debug("getFirstRunLevel");
3585
    boolean retVal = true;
3586
 
3587
    try
3588
    {
3589
      mRunLevelIndex = 0;
3590
      RunLevel rl = (RunLevel)mRunLevelCollection.get( mRunLevelIndex );
3591
      rcon_id.value = rl.get_rcon_id();
3592
      current_run_level.value = rl.get_current_run_level();
3593
    }
3594
    catch( ArrayIndexOutOfBoundsException e )
3595
    {
3596
      retVal = false;
3597
    }
3598
 
3599
    mLogger.info("getFirstRunLevel returning " + retVal);
3600
    return retVal;
3601
  }
3602
 
3603
  /**returns true if the mReleaseConfigCollection contains a next element and returns the rcon_id of the next element
3604
   */
3605
  public boolean getNextReleaseConfig(MutableInt rcon_id)
3606
  {
3607
    mLogger.debug("getNextReleaseConfig 1");
3608
    boolean retVal = true;
3609
 
3610
    try
3611
    {
3612
      mReleaseConfigIndex++;
3613
      ReleaseConfig rc = (ReleaseConfig)mReleaseConfigCollection.get( mReleaseConfigIndex );
3614
      rcon_id.value = rc.get_rcon_id();
3615
    }
3616
    catch( ArrayIndexOutOfBoundsException e )
3617
    {
3618
      retVal = false;
3619
    }
3620
 
3621
    mLogger.info("getNextReleaseConfig 1 returning " + retVal);
3622
    return retVal;
3623
  }
3624
 
3625
  /**returns true if the mReleaseConfigCollection contains a next element and returns the rcon_id, rtag_id, daemon_mode and gbebuildfilter of the next element
3626
   */
3627
  public boolean getNextReleaseConfig(MutableInt rtag_id, 
3628
                                      MutableInt rcon_id, 
3629
                                      MutableChar daemon_mode, 
3630
                                      MutableString gbebuildfilter)
3631
  {
3632
    mLogger.debug("getNextReleaseConfig 2");
3633
    boolean retVal = true;
3634
 
3635
    try
3636
    {
3637
      mReleaseConfigIndex++;
3638
      ReleaseConfig rc = (ReleaseConfig)mReleaseConfigCollection.get( mReleaseConfigIndex );
3639
      rtag_id.value = rc.get_rtag_id();
3640
      rcon_id.value = rc.get_rcon_id();
3641
      daemon_mode.value = rc.get_daemon_mode();
3642
      gbebuildfilter.value = rc.get_gbebuildfilter();
3643
    }
3644
    catch( ArrayIndexOutOfBoundsException e )
3645
    {
3646
      retVal = false;
3647
    }
3648
 
3649
    mLogger.info("getNextReleaseConfig 2 returning " + retVal);
3650
    return retVal;
3651
  }
3652
 
3653
  /**returns true if the mRunLevelCollection contains a next element and returns the rcon_id and current_run_level of the next element
3654
   */
3655
  public boolean getNextRunLevel(MutableInt rcon_id, 
3656
                                 MutableInt current_run_level)
3657
  {
3658
    mLogger.debug("getNextRunLevel");
3659
    boolean retVal = true;
3660
 
3661
    try
3662
    {
3663
      mRunLevelIndex++;
3664
      RunLevel rl = (RunLevel)mRunLevelCollection.get( mRunLevelIndex );
3665
      rcon_id.value = rl.get_rcon_id();
3666
      current_run_level.value = rl.get_current_run_level();
3667
    }
3668
    catch( ArrayIndexOutOfBoundsException e )
3669
    {
3670
      retVal = false;
3671
    }
3672
 
3673
    mLogger.info("getNextRunLevel returning " + retVal);
3674
    return retVal;
3675
  }
3676
 
3677
  /**queries the RUN_LEVEL table using the rcon_id primary key
3678
   * returns false if the query returns a result set containing one row with a non NULL pause column
3679
   * (indicating intent to pause the thread)
3680
   * refer to sequence diagram allowed to proceed
3681
   */
3682
  public boolean queryDirectedRunLevel(final int rcon_id) throws SQLException, Exception
3683
  {
3684
    mLogger.debug("queryDirectedRunLevel " + rcon_id);
3685
    boolean retVal = true;
3686
 
3687
    if ( mUseDatabase )
3688
    {
3689
      try
3690
      {
3691
        CallableStatement stmt = mConnection.prepareCall("select pause from release_manager.run_level where rcon_id=" + rcon_id);
3692
        ResultSet rset = stmt.executeQuery();
3693
        int rsetSize = 0;
3694
 
3695
        while( rset.next() )
3696
        {
3697
          rsetSize++;
3698
          rset.getInt("pause");
3699
 
3700
          if ( !rset.wasNull() )
3701
          {
3702
            retVal = false;
3703
          }
3704
        }
830 mhunt 3705
 
3706
        rset.close();
3707
        stmt.close();
814 mhunt 3708
 
3709
        if ( rsetSize > 1 )
3710
        {
3711
          mLogger.fatal("queryDirectedRunLevel rsetSize > 1");
3712
          // show stopper
3713
          throw new Exception();
3714
        }
3715
      }
3716
      catch ( SQLException e )
3717
      {
3718
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3719
        {
3720
          mLogger.error("queryDirectedRunLevel database access error only");
3721
          throw new SQLException();
3722
        }
3723
        else
3724
        {
3725
          mLogger.fatal("queryDirectedRunLevel show stopper");
3726
          throw new Exception();
3727
        }
3728
      }
3729
    }
3730
 
3731
    mLogger.info("queryDirectedRunLevel returning " + retVal);
3732
    return retVal;
3733
  }
3734
 
3735
  /**queries the RELEASE_CONFIG table using the rcon_id primary key, rtag_id, daemon_hostname, daemon_mode, gbebuildfilter
3736
   * return true if the query contains a result set containing one row
3737
   * (indicating the rcon_id is still configured and its configuration is unchanged)
3738
   * refer to sequence diagram allowed to proceed
3739
   */
3740
  public boolean queryReleaseConfig(final int rtag_id, final int rcon_id, 
3741
                                    final String daemon_hostname, 
3742
                                    final char daemon_mode, 
3743
                                    final String gbebuildfilter) throws SQLException, Exception
3744
  {
3745
    mLogger.debug("queryReleaseConfig 1");
3746
    boolean retVal = false;
3747
 
3748
    if ( !mUseDatabase )
3749
    {
3750
      mLogger.info("queryReleaseConfig 1 !mUseDatabase");
3751
 
3752
      if ( mConnectionString.compareTo("unit test exit") != 0 )
3753
      {
3754
        retVal = true;
3755
      }
3756
    }
3757
    else
3758
    {
3759
      try
3760
      {
3761
        String sql = new String("select gbe_buildfilter from release_manager.release_config where rtag_id=" + rtag_id + " and rcon_id=" + rcon_id + " and daemon_hostname='" + daemon_hostname + "' and daemon_mode='" + daemon_mode + "'" );
3762
        CallableStatement stmt = mConnection.prepareCall( sql );
3763
        ResultSet rset = stmt.executeQuery();
3764
        int rsetSize = 0;
3765
 
3766
        while( rset.next() )
3767
        {
3768
          rsetSize++;
3769
          String gbe_buildfilter = rset.getString("gbe_buildfilter");
3770
 
3771
          if ( gbe_buildfilter == null )
3772
          {
3773
            mLogger.info("queryReleaseConfig 1 gbe_buildfilter == null");
3774
            if ( gbebuildfilter.length() == 0 )
3775
            {
3776
              retVal = true;
3777
            }
3778
          }
3779
          else
3780
          {
3781
            if ( gbebuildfilter.compareTo( gbe_buildfilter ) == 0 )
3782
            {
3783
              retVal = true;
3784
            }
3785
          }
3786
        }
830 mhunt 3787
 
3788
        rset.close();
3789
        stmt.close();
814 mhunt 3790
 
3791
        if ( rsetSize > 1 )
3792
        {
3793
          mLogger.fatal("queryReleaseConfig 1 rsetSize > 1");
3794
          // show stopper
3795
          throw new Exception();
3796
        }
3797
      }
3798
      catch ( SQLException e )
3799
      {
3800
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3801
        {
3802
          mLogger.error("queryReleaseConfig 1 database access error only");
3803
          throw new SQLException();
3804
        }
3805
        else
3806
        {
3807
          mLogger.fatal("queryReleaseConfig 1 show stopper");
3808
          throw new Exception();
3809
        }
3810
      }
3811
    }
3812
 
3813
    mLogger.info("queryReleaseConfig 1 returning " + retVal);
3814
    return retVal;
3815
  }
3816
 
3817
  /**removes all elements from the mReleaseConfigCollection
3818
   * handles database connection and disconnection
3819
   * queries the RELEASE_CONFIG table using the rtag_id
3820
   * populates the mReleaseConfigCollection with the query result set
3821
   * partially implements the sequence diagrams coordinate slave threads generate build files
3822
   */
3823
  public void queryReleaseConfig(final int rtag_id) throws SQLException, Exception
3824
  {
3825
    mLogger.debug("queryReleaseConfig 2");
3826
    mReleaseConfigCollection.removeAllElements();
3827
 
3828
    if ( !mUseDatabase )
3829
    {
3830
      mLogger.info("queryReleaseConfig 2 !mUseDatabase");
3831
      ReleaseConfig releaseConfig = new ReleaseConfig(1,1,'M',"unittestbuildfilter");
3832
      mReleaseConfigCollection.add(releaseConfig);
3833
      releaseConfig = new ReleaseConfig(1,2,'S',"anotherunittestbuildfilter");
3834
      mReleaseConfigCollection.add(releaseConfig);
3835
    }
3836
    else
3837
    {
3838
      try
3839
      {
3840
        connect();
3841
        CallableStatement stmt = mConnection.prepareCall("select rcon_id, daemon_mode, gbe_buildfilter from release_manager.release_config where rtag_id=" + rtag_id );
3842
        ResultSet rset = stmt.executeQuery();
3843
 
3844
        while( rset.next() )
3845
        {
3846
          int rcon_id = rset.getInt("rcon_id");
3847
 
3848
          if ( rset.wasNull() )
3849
          {
3850
            mLogger.fatal("queryReleaseConfig 2 null rcon_id " + rtag_id);
3851
            // show stopper
3852
            throw new Exception();
3853
          }
3854
 
3855
          char dm = 'S';          
3856
          String daemon_mode = rset.getString("daemon_mode");
3857
 
3858
          if ( daemon_mode != null )
3859
          {
3860
            mLogger.info("queryReleaseConfig 2 daemon_mode " + daemon_mode + ".");
3861
 
3862
            if ( daemon_mode.compareTo("M") == 0 )
3863
            {
3864
              dm = 'M';
3865
            }
3866
          }
3867
 
3868
          String gbe_buildfilter = rset.getString("gbe_buildfilter");
3869
 
3870
          if ( gbe_buildfilter == null )
3871
          {
3872
            gbe_buildfilter = new String("");
3873
          }
3874
 
3875
          ReleaseConfig releaseConfig = new ReleaseConfig( rtag_id, rcon_id, dm, gbe_buildfilter );
3876
          mReleaseConfigCollection.add(releaseConfig);
3877
        }
3878
 
830 mhunt 3879
 
3880
        rset.close();
3881
        stmt.close();
814 mhunt 3882
        disconnect();
3883
      }
3884
      catch ( SQLException e )
3885
      {
3886
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3887
        {
3888
          mLogger.error("queryReleaseConfig 2 daemon_mode database access error only");
3889
          throw new SQLException();
3890
        }
3891
        else
3892
        {
3893
          mLogger.fatal("queryReleaseConfig 2 show stopper");
3894
          throw new Exception();
3895
        }
3896
      }
3897
    }
3898
  }
3899
 
3900
  /**removes all elements from the mReleaseConfigCollection
3901
   * handles database connection and disconnection
3902
   * queries the RELEASE_CONFIG table using the daemon_hostname
3903
   * populates the mReleaseConfigCollection with the query result set
3904
   * partially implements the sequence diagram spawn thread
3905
   */
3906
  public void queryReleaseConfig(final String hostname) throws SQLException, Exception
3907
  {
3908
    mLogger.debug("queryReleaseConfig 3 " + hostname);
3909
    mReleaseConfigCollection.removeAllElements();
3910
 
3911
    if ( mConnectionString.compareTo("unit test spawn thread") == 0)
3912
    {
3913
      mLogger.info("queryReleaseConfig 3 unit test spawn thread");
3914
      // specifying a gbebuildfilter of unit test is designed to invoke a benign thread for unit test purposes
3915
      ReleaseConfig releaseConfig = new ReleaseConfig(1,1,'M',"unit test spawn thread");
3916
      mReleaseConfigCollection.add(releaseConfig);
3917
      releaseConfig = new ReleaseConfig(2,2,'S',"unit test spawn thread");
3918
      mReleaseConfigCollection.add(releaseConfig);
3919
    }
3920
    else
3921
    {
3922
      try
3923
      {
3924
        connect();
3925
        CallableStatement stmt = mConnection.prepareCall("select rtag_id, rcon_id, daemon_mode, gbe_buildfilter from release_manager.release_config where daemon_hostname='" + hostname + "'" );
3926
        ResultSet rset = stmt.executeQuery();
3927
 
3928
        while( rset.next() )
3929
        {
3930
          int rtag_id = rset.getInt("rtag_id");
3931
 
3932
          if ( rset.wasNull() )
3933
          {
3934
            mLogger.fatal("queryReleaseConfig 3 null rtag_id");
3935
            // show stopper
3936
            throw new Exception();
3937
          }
3938
 
3939
          int rcon_id = rset.getInt("rcon_id");
3940
 
3941
          if ( rset.wasNull() )
3942
          {
3943
            mLogger.fatal("queryReleaseConfig 3 null rcon_id");
3944
            // show stopper
3945
            throw new Exception();
3946
          }
3947
 
3948
          char dm = 'S';          
3949
          String daemon_mode = rset.getString("daemon_mode");
3950
 
3951
          if ( daemon_mode != null )
3952
          {
3953
            mLogger.info("queryReleaseConfig 3 daemon_mode " + daemon_mode + ".");
3954
 
3955
            if ( daemon_mode.compareTo("M") == 0 )
3956
            {
3957
              dm = 'M';
3958
            }
3959
          }
3960
 
3961
          String gbe_buildfilter = rset.getString("gbe_buildfilter");
3962
 
3963
          if ( gbe_buildfilter == null )
3964
          {
3965
            gbe_buildfilter = new String("");
3966
          }
3967
 
3968
          ReleaseConfig releaseConfig = new ReleaseConfig( rtag_id, rcon_id, dm, gbe_buildfilter );
3969
          mReleaseConfigCollection.add(releaseConfig);
3970
        }
3971
 
830 mhunt 3972
        rset.close();
3973
        stmt.close();
814 mhunt 3974
        disconnect();
3975
      }
3976
      catch ( SQLException e )
3977
      {
3978
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
3979
        {
3980
          mLogger.error("queryReleaseConfig 3 database access error only");
3981
          throw new SQLException();
3982
        }
3983
        else
3984
        {
3985
          mLogger.fatal("queryReleaseConfig 3 show stopper");
3986
          throw new Exception();
3987
        }
3988
      }
3989
    }
3990
  }
3991
 
3992
  /**queries the RUN_LEVEL table using the rcon_id primary key
3993
   * handles database connection and disconnection
3994
   * polls indefinitely until CURRENT_BUILD_FILES column is non NULL
3995
   * returns the current_build_files
3996
   * implements the sequence diagram consume build files
3997
   */
3998
  public void queryRunLevel(int rcon_id, MutableString currentBuildFiles) throws SQLException, Exception
3999
  {
4000
    mLogger.debug("queryRunLevel 1 rcon_id " + rcon_id);
4001
    if ( !mUseDatabase )
4002
    {
4003
      mLogger.info("queryRunLevel 1 !mUseDatabase");
4004
      currentBuildFiles.value = "unit test build file content";
4005
    }
4006
    else
4007
    {
4008
      try
4009
      {
4010
        connect();
4011
        CallableStatement stmt = mConnection.prepareCall("select current_build_files from release_manager.run_level where rcon_id=" + rcon_id);
4012
        ResultSet rset = stmt.executeQuery();
4013
        int rsetSize = 0;
4014
 
4015
        while( rset.next() )
4016
        {
4017
          rsetSize++;
4018
          currentBuildFiles.value = rset.getString("current_build_files");
4019
          if (rset.wasNull())
4020
          {
4021
            currentBuildFiles.value = "";
4022
          }
4023
        }
4024
 
4025
        if ( rsetSize > 1 )
4026
        {
4027
          mLogger.fatal("queryRunLevel 1 rsetSize > 1");
4028
          // show stopper
4029
          throw new Exception();
4030
        }
4031
 
830 mhunt 4032
        rset.close();
4033
        stmt.close();
814 mhunt 4034
        disconnect();
4035
      }
4036
      catch ( SQLException e )
4037
      {
4038
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4039
        {
4040
          mLogger.error("queryRunLevel 1 database access error only");
4041
          throw new SQLException();
4042
        }
4043
        else
4044
        {
4045
          mLogger.fatal("queryRunLevel 1 show stopper");
4046
          throw new Exception();
4047
        }
4048
      }
4049
    }
4050
  }
4051
 
4052
  /**removes all elements from the mRunLevelCollection
4053
   * handles database connection and disconnection
4054
   *   select rl.rcon_id, rl.current_run_level from release_config rc, run_level rl
4055
   *   where rc.rtag_id=<rtag_id> and rl.rcon_id=rc.rcon_id;
4056
   * populates the mRunLevelCollection with the query result set
4057
   * refer to sequence diagram coordinate slave threads
4058
   */
4059
  public void queryRunLevel(final int rtag_id) throws SQLException, Exception
4060
  {
4061
    mLogger.debug("queryRunLevel 2 rtag_id " + rtag_id);
4062
    if ( mConnectionString.compareTo("unit test coordinate slave threads") == 0)
4063
    {
4064
      mLogger.info("queryRunLevel 2 unit test coordinate slave threads");
4065
 
4066
      if ( mRunLevelCollection.size() == 0)
4067
      {
4068
        // first time not all slave threads are waiting
4069
        RunLevel runLevel = new RunLevel(1, "", DB_WAITING, false);
4070
        mRunLevelCollection.add(runLevel);
4071
        runLevel = new RunLevel(2, "", DB_IDLE, false);
4072
        mRunLevelCollection.add(runLevel);
4073
      }
4074
      else
4075
      {
4076
        // subsequent times all slave threads are waiting
4077
        mRunLevelCollection.removeAllElements();
4078
        RunLevel runLevel = new RunLevel(1, "", DB_WAITING, false);
4079
        mRunLevelCollection.add(runLevel);
4080
        runLevel = new RunLevel(2, "", DB_WAITING, false);
4081
        mRunLevelCollection.add(runLevel);
4082
      }
4083
    }
4084
 
4085
    if ( mUseDatabase )
4086
    {
4087
      mRunLevelCollection.removeAllElements();
4088
 
4089
      try
4090
      {
4091
        connect();
4092
        CallableStatement stmt = mConnection.prepareCall(
4093
        "select rl.rcon_id, rl.current_run_level from release_config rc, run_level rl " +
4094
        "where rc.rtag_id=" +rtag_id + " and rl.rcon_id=rc.rcon_id");
4095
        ResultSet rset = stmt.executeQuery();
4096
        int rsetSize = 0;
4097
        int rcon_id = 0;
4098
        int current_run_level = 0;
4099
 
4100
        while( rset.next() )
4101
        {
4102
          rsetSize++;
4103
          rcon_id = rset.getInt("rcon_id");
4104
 
4105
          if ( rset.wasNull() )
4106
          {
4107
            mLogger.fatal("queryRunLevel 2 null rcon_id");
4108
            // show stopper
4109
            throw new Exception();
4110
          }
4111
 
4112
          current_run_level = rset.getInt("current_run_level");
4113
 
4114
          if ( rset.wasNull() )
4115
          {
4116
            mLogger.fatal("queryRunLevel 2 null current_run_level");
4117
            // show stopper
4118
            throw new Exception();
4119
          }
4120
 
4121
          RunLevel runLevel = new RunLevel(rcon_id, "", current_run_level, false);
4122
          mRunLevelCollection.add(runLevel);
4123
        }
4124
 
4125
        if ( rsetSize == 0 )
4126
        {
4127
          mLogger.fatal("queryRunLevel 2 rsetSize == 0");
4128
          // show stopper
4129
          throw new Exception();
4130
        }
4131
 
830 mhunt 4132
        rset.close();
4133
        stmt.close();
814 mhunt 4134
        disconnect();
4135
      }
4136
      catch ( SQLException e )
4137
      {
4138
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4139
        {
4140
          mLogger.error("queryRunLevel 2 database access error only");
4141
          throw new SQLException();
4142
        }
4143
        else
4144
        {
4145
          mLogger.fatal("queryRunLevel 2 show stopper");
4146
          throw new Exception();
4147
        }
4148
      }
4149
 
4150
 
4151
    }
4152
  }
4153
 
818 mhunt 4154
  /**removes all elements from the mRunLevelCollection
4155
   * handles database connection and disconnection
4156
   *   select rcon_id, current_run_level from run_level
4157
   *   where rcon_id=<rcon_id>;
4158
   * populates the mRunLevelCollection with the query result set
4159
   */
4160
  public void querySingleRunLevel(final int rcon_id) throws SQLException, Exception
4161
  {
4162
    mLogger.debug("querySingleRunLevel rcon_id " + rcon_id);
4163
    if ( !mUseDatabase )
4164
    {
4165
      mLogger.info("querySingleRunLevel !mUseDatabase");
4166
 
4167
      mRunLevelCollection.removeAllElements();
4168
      RunLevel runLevel = new RunLevel(rcon_id, "", DB_ACTIVE, false);
4169
      mRunLevelCollection.add(runLevel);
4170
    }
4171
    else
4172
    {
4173
      mRunLevelCollection.removeAllElements();
4174
 
4175
      try
4176
      {
4177
        connect();
4178
        CallableStatement stmt = mConnection.prepareCall(
4179
        "select rcon_id, current_run_level from run_level " +
4180
        "where rcon_id=" +rcon_id);
4181
        ResultSet rset = stmt.executeQuery();
4182
        int rsetSize = 0;
4183
        int current_run_level = 0;
4184
 
4185
        while( rset.next() )
4186
        {
4187
          rsetSize++;
4188
          current_run_level = rset.getInt("current_run_level");
4189
 
4190
          if ( rset.wasNull() )
4191
          {
4192
            mLogger.fatal("querySingleRunLevel null current_run_level");
4193
            // show stopper
4194
            throw new Exception();
4195
          }
4196
 
4197
          RunLevel runLevel = new RunLevel(rcon_id, "", current_run_level, false);
4198
          mRunLevelCollection.add(runLevel);
4199
        }
4200
 
4201
        if ( rsetSize != 1 )
4202
        {
4203
          mLogger.fatal("querySingleRunLevel rsetSize != 1");
4204
          // show stopper
4205
          throw new Exception();
4206
        }
4207
 
830 mhunt 4208
        rset.close();
4209
        stmt.close();
818 mhunt 4210
        disconnect();
4211
      }
4212
      catch ( SQLException e )
4213
      {
4214
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4215
        {
4216
          mLogger.error("querySingleRunLevel database access error only");
4217
          throw new SQLException();
4218
        }
4219
        else
4220
        {
4221
          mLogger.fatal("querySingleRunLevel show stopper");
4222
          throw new Exception();
4223
        }
4224
      }
4225
    }
4226
  }
4227
 
814 mhunt 4228
  /**queries the RUN_LEVEL_SCHEDULE table
4229
   * returns false if a row in the query result set indicates build service downtime is scheduled
4230
   * returns false if a row in the query result set has a non NULL indefinite_pause
4231
   * refer to the sequence diagram allowed to proceed
4232
   */
4233
  public boolean queryRunLevelSchedule(Date resumeTime) throws SQLException, Exception
4234
  {
4235
    mLogger.debug("queryRunLevelSchedule");
4236
    boolean retVal = true;
4237
 
4238
    if ( !mUseDatabase )
4239
    {
4240
      mLogger.info("queryRunLevelSchedule !mUseDatabase");
4241
 
4242
      if ( mConnectionString.compareTo("unit test not allowed to proceed") == 0 )
4243
      {
4244
        // schedule a 100ms max wait
4245
        resumeTime.setTime( resumeTime.getTime() + 100 );
4246
        retVal = false;
4247
      }
4248
    }
4249
    else
4250
    {
4251
      try
4252
      {
4253
        CallableStatement stmt = mConnection.prepareCall("select scheduled_pause, scheduled_resume, repeat, indefinite_pause from release_manager.run_level_schedule");
4254
        ResultSet rset = stmt.executeQuery();
4255
        Date now = new Date();
4256
 
4257
        while( rset.next() )
4258
        {
4259
          // retain date and time component
4260
          Timestamp sp = rset.getTimestamp("scheduled_pause");
4261
 
4262
          if ( sp != null )
4263
          {
4264
            Date scheduled_pause = new Date( sp.getTime() );
4265
            Timestamp sr = rset.getTimestamp("scheduled_resume");
4266
 
4267
            if ( sr != null )
4268
            {
4269
              Date scheduled_resume = new Date( sr.getTime() );
4270
              int repeat = rset.getInt("repeat");
4271
              mLogger.info("queryRunLevelSchedule repeat " + repeat);
4272
 
4273
              if ( !rset.wasNull() )
4274
              {
4275
                switch( repeat )
4276
                {
4277
                  case 0:
4278
                  {
4279
                    // one off
4280
                    if ( scheduled_pause.before(now) && scheduled_resume.after(now) )
4281
                    {
4282
                      mLogger.warn("queryRunLevelSchedule one off scheduled downtime");
4283
                      retVal = false;
4284
                    }
4285
                    break;
4286
                  }
4287
                  case 1:
4288
                  {
4289
                    // daily
4290
                    GregorianCalendar startOfDowntime = new GregorianCalendar();
4291
                    startOfDowntime.setTime(scheduled_pause);
4292
                    GregorianCalendar endOfDowntime = new GregorianCalendar();
4293
                    endOfDowntime.setTime(scheduled_resume);
4294
                    GregorianCalendar clock = new GregorianCalendar();
4295
                    clock.setTime(now);
4296
                    // normalise
4297
                    endOfDowntime.set( startOfDowntime.get(Calendar.YEAR), startOfDowntime.get(Calendar.MONTH), startOfDowntime.get(Calendar.DAY_OF_MONTH) );
4298
                    clock.set( startOfDowntime.get(Calendar.YEAR), startOfDowntime.get(Calendar.MONTH), startOfDowntime.get(Calendar.DAY_OF_MONTH) );
4299
 
4300
                    if ( startOfDowntime.before(clock) && endOfDowntime.after(clock) )
4301
                    {
4302
                      mLogger.warn("queryRunLevelSchedule daily scheduled downtime");
4303
                      retVal = false;
4304
                    }
4305
                    break;
4306
                  }
4307
                  case 7:
4308
                  {
4309
                    // weekly
4310
                    GregorianCalendar startOfDowntime = new GregorianCalendar();
4311
                    startOfDowntime.setTime(scheduled_pause);
4312
                    GregorianCalendar endOfDowntime = new GregorianCalendar();
4313
                    endOfDowntime.setTime(scheduled_resume);
4314
                    GregorianCalendar clock = new GregorianCalendar();
4315
                    clock.setTime(now);
4316
 
4317
                    if ( startOfDowntime.get(Calendar.DAY_OF_WEEK) == clock.get(Calendar.DAY_OF_WEEK) )
4318
                    {
4319
                      // normalise
4320
                      endOfDowntime.set( startOfDowntime.get(Calendar.YEAR), startOfDowntime.get(Calendar.MONTH), startOfDowntime.get(Calendar.DAY_OF_MONTH) );
4321
                      clock.set( startOfDowntime.get(Calendar.YEAR), startOfDowntime.get(Calendar.MONTH), startOfDowntime.get(Calendar.DAY_OF_MONTH) );
4322
 
4323
                      if ( startOfDowntime.before(clock) && endOfDowntime.after(clock) )
4324
                      {
4325
                        mLogger.warn("queryRunLevelSchedule weekly scheduled downtime");
4326
                        retVal = false;
4327
                      }
4328
                    }
4329
                    break;
4330
                  }
4331
                }
4332
              }
4333
            }
4334
          }
4335
 
4336
          int ip = rset.getInt("indefinite_pause");
4337
 
4338
          if ( !rset.wasNull() )
4339
          {
4340
            // indefinite pause is non null
4341
            mLogger.warn("queryRunLevelSchedule indefinite pause");
4342
            retVal = false;
4343
          }
4344
        }
830 mhunt 4345
 
4346
        rset.close();
4347
        stmt.close();
814 mhunt 4348
      }
4349
      catch ( SQLException e )
4350
      {
4351
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4352
        {
4353
          mLogger.error("queryRunLevelSchedule database access error only");
4354
          throw new SQLException();
4355
        }
4356
        else
4357
        {
4358
          mLogger.fatal("queryRunLevelSchedule show stopper");
4359
          throw new Exception();
4360
        }
4361
      }
4362
    }
4363
 
4364
    mLogger.info("queryRunLevelSchedule returning " + retVal);
4365
    return retVal;
4366
  }
4367
 
4368
  /**persists the runLevel in the RUN_LEVEL table for the rcon_id primary key
4369
   * refer to sequence diagrams generate build files, allowed to proceed, not allowed to proceed, exit, check environment
4370
   */
4371
  public void updateCurrentRunLevel(final int rcon_id, final int runLevel) throws SQLException, Exception
4372
  {
4373
    mLogger.debug("updateCurrentRunLevel");
4374
    if ( !mUseDatabase )
4375
    {
4376
      mLogger.info("updateCurrentRunLevel !mUseDatabase");
4377
      Integer i = new Integer(runLevel);
4378
      mPersistedRunLevelCollection.add(i);
4379
    }
4380
    else
4381
    {
4382
      try
4383
      {
4384
        connect();
4385
        boolean update = false;
4386
        {
4387
          // check if the rcon_id exists in the table
4388
          CallableStatement stmt = mConnection.prepareCall("select rcon_id from release_manager.run_level where rcon_id=" + rcon_id);
4389
          ResultSet rset = stmt.executeQuery();
4390
 
4391
          while( rset.next() )
4392
          {
4393
            update = true;
4394
          }
830 mhunt 4395
 
4396
          rset.close();
4397
          stmt.close();
814 mhunt 4398
        }
4399
 
4400
        if ( !update )
4401
        {
4402
          // check if the rcon_id is still configured
4403
          boolean configured = false;
4404
          {
4405
            CallableStatement stmt = mConnection.prepareCall("select rcon_id from release_manager.release_config where rcon_id=" + rcon_id);
4406
            ResultSet rset = stmt.executeQuery();
4407
 
4408
            while( rset.next() )
4409
            {
4410
              configured = true;
4411
            }
830 mhunt 4412
 
4413
            rset.close();
4414
            stmt.close();
814 mhunt 4415
          }
4416
          CallableStatement stmt = mConnection.prepareCall("insert into release_manager.run_level (rcon_id) values (" + rcon_id + ")" );
4417
          stmt.executeUpdate();
830 mhunt 4418
          stmt.close();
814 mhunt 4419
        }
4420
 
4421
        {
4422
          CallableStatement stmt = mConnection.prepareCall("update release_manager.run_level set current_run_level=" + runLevel + " where rcon_id=" + rcon_id);
4423
          stmt.executeUpdate();
830 mhunt 4424
          stmt.close();
814 mhunt 4425
        }
4426
        mConnection.commit();
4427
        disconnect();
4428
      }
4429
      catch( SQLException e )
4430
      {
4431
        if ( mConnection == null || ( mConnection != null && !mConnection.isValid(10) ) )
4432
        {
4433
          mLogger.error("updateCurrentRunLevel database access error only");
4434
          throw new Exception();
4435
        }
4436
        else
4437
        {
4438
          mLogger.fatal("updateCurrentRunLevel show stopper");
4439
          throw new Exception();
4440
        }
4441
      }
4442
    }
4443
  }
4444
 
4445
}