KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > teamkonzept > webman > Version


1 package com.teamkonzept.webman;
2
3 import java.sql.*;
4
5 import com.teamkonzept.db.*;
6 import com.teamkonzept.webman.db.*;
7 import com.teamkonzept.webman.db.queries.TKDBVersion;
8
9 /**
10  * Contains the software version number and the compatible
11  * database version number.
12  * A version number is a triple of the form (MAJOR, MINOR, MICRO).
13  * @author $Author: mischa $
14  * @version $Revision: 1.2 $
15 */

16 public class Version {
17
18     /**
19     The software version number
20     */

21     public final static int MAJOR = 0;
22     public final static int MINOR = 10;
23     public final static int MICRO = 1;
24     
25     /**
26     The compatible database version number.
27     The actual database version number must coiincide with this number.
28     */

29     public final static int COMPATIBLE_DB_MAJOR = 0;
30     public final static int COMPATIBLE_DB_MINOR = 10;
31     public final static int COMPATIBLE_DB_MICRO = 1;
32     
33     /**
34     The CVS tag. Set automatically by CVS if checking out atagged version.
35     */

36     public final static String JavaDoc CVSTAG = "$Name: WM-1_6_17-1_5_0 $";
37     
38     /**
39     Classifcation strings returned by classifyDBVersion
40     */

41     public final static int DB_IS_UP_TO_DATE = 1;
42     public final static int DB_IS_OLDER = 2;
43     public final static int DB_IS_NEWER = 3;
44     
45     /**
46     @return the software version string in the form "xx.yy.zz"
47     */

48     public static String JavaDoc getVersion()
49     {
50         return genVersionString(MAJOR, MINOR, MICRO);
51     }
52     
53     /**
54     @return the compatible db version string in the form "xx.yy.zz"
55     */

56     public static String JavaDoc getCompatibleDBVersion()
57     {
58         return genVersionString(COMPATIBLE_DB_MAJOR,COMPATIBLE_DB_MINOR,
59                                 COMPATIBLE_DB_MICRO);
60     }
61     
62     /**
63     Classifies a database versiuon mumber with respect to the
64     compatible-db-version number of this class.
65     @return DB_IS_UP_TO_DATE, DB_IS_OLDER or DB_IS_NEWER.
66     */

67     public static int classifyDBVersion() throws SQLException
68     {
69         TKQuery q = TKWebmanDBManager.newQuery(TKDBVersion.class);
70         q.execute();
71         ResultSet rs = q.fetchResultSet();
72         if (!rs.next()) {
73             q.close();
74             return DB_IS_OLDER;
75         }
76         
77         int result = DB_IS_UP_TO_DATE;
78         int[] dbver = {rs.getInt("MAJOR"), rs.getInt("MINOR"), rs.getInt("MICRO")};
79         int[] swver = {COMPATIBLE_DB_MAJOR, COMPATIBLE_DB_MINOR, COMPATIBLE_DB_MICRO};
80         for (int i=0; i<3 && result==DB_IS_UP_TO_DATE; ++i) {
81             if (dbver[i] > swver[i]) {
82                 result = DB_IS_NEWER;
83             }
84             else if (dbver[i] < swver[i]) {
85                 result = DB_IS_OLDER;
86             }
87         }
88         
89         q.close();
90         return result;
91     }
92     
93     public static void main(String JavaDoc[] args)
94     {
95         System.out.println("Software version : " + getVersion());
96         System.out.println("Compatible DB version : " + getCompatibleDBVersion());
97         System.out.println("CVS tag : " + CVSTAG);
98     }
99     
100     private static String JavaDoc genVersionString(int major, int minor, int micro)
101     {
102         return new String JavaDoc(major + "." + minor + "." + micro);
103     }
104 }
105
Popular Tags