+//******************** Version comparator **********************************/\r
+ \r
+ public static class VersionComparator implements Comparator<String>{\r
+ Integer depth;\r
+ IProgressMonitor monitor;\r
+ \r
+ public VersionComparator(Integer depth, IProgressMonitor monitor){\r
+ this.depth = depth;\r
+ this.monitor = monitor;\r
+ }\r
+ \r
+ /* (non-Javadoc)\r
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)\r
+ */\r
+ public int compare(String version1, String version2) {\r
+ int result = 0;\r
+ String[] version1Split = version1.split("\\.");\r
+ String[] version2Split = version2.split("\\.");\r
+ \r
+ if(version1Split.length == 1 || version2Split.length == 1){\r
+ throwException("Tried to compare version but given Strings don't seem to " +\r
+ "contain version numbers. version1: " + version1 + ", version2:" + version2); \r
+ }\r
+ \r
+ if(depth != null && (version1Split.length < depth || version2Split.length < depth )){\r
+ throwException("Desired depth can not be achieved with the given strings. depth: " + depth + ", version1: " + version1 + ", version2:" + version2); \r
+ } \r
+ \r
+ int length = (depth == null ||version1Split.length < depth) ? version1Split.length : depth;\r
+ for (int i = 0; i < length; i++){\r
+ Long version1Part = Long.valueOf(version1Split[i]);\r
+ Long version2Part = Long.valueOf(version2Split[i]);\r
+ int partCompare = version1Part.compareTo(version2Part);\r
+ if (partCompare != 0){\r
+ return partCompare;\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+ \r
+ private Throwable throwException(String message){\r
+ RuntimeException exception = new RuntimeException(message);\r
+ if (monitor != null){\r
+ monitor.warning(message, exception);\r
+ }\r
+ throw exception;\r
+ }\r
+ \r
+ }\r
+\r
+ /**\r
+ * Compares two version string. If version1 is higher than version2 a positive result is returned.\r
+ * If both are equal 0 is returned, otherwise -1 is returned.\r
+ * @see Comparator#compare(Object, Object)\r
+ * @param version1\r
+ * @param version2\r
+ * @param depth\r
+ * @param monitor\r
+ * @return\r
+ */\r
+ public static int compareVersion(String version1, String version2, Integer depth, IProgressMonitor monitor){\r
+ VersionComparator versionComparator = new VersionComparator(depth, monitor);\r
+ return versionComparator.compare(version1, version2);\r
+ }\r
+ \r
+ public static boolean isDbSchemaVersionCompatible(String version){\r
+ return compareVersion(dbSchemaVersion, version, 3, null) == 0;\r
+ }\r
+\r
+ public static String getDbSchemaVersion() {\r
+ return dbSchemaVersion;\r
+ }\r