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 16 public class Version { 17 18 21 public final static int MAJOR = 0; 22 public final static int MINOR = 10; 23 public final static int MICRO = 1; 24 25 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 36 public final static String CVSTAG = "$Name: WM-1_6_17-1_5_0 $"; 37 38 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 48 public static String getVersion() 49 { 50 return genVersionString(MAJOR, MINOR, MICRO); 51 } 52 53 56 public static String getCompatibleDBVersion() 57 { 58 return genVersionString(COMPATIBLE_DB_MAJOR,COMPATIBLE_DB_MINOR, 59 COMPATIBLE_DB_MICRO); 60 } 61 62 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 [] 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 genVersionString(int major, int minor, int micro) 101 { 102 return new String (major + "." + minor + "." + micro); 103 } 104 } 105 | Popular Tags |