1 package org.openecomp.sdc.asdctool.migration.core;
3 import java.math.BigInteger;
5 public class DBVersion implements Comparable<DBVersion>{
7 private static final String VERSION_PARTS_SEPARATOR = "\\.";
8 private static final int MAJOR_PART_IDX = 0;
9 private static final int MINOR_PART_IDX = 1;
10 private BigInteger major;
11 private BigInteger minor;
14 * The current db version. should be tested against real db to verify it is compatible to the db version
16 public static final DBVersion CURRENT_VERSION = new DBVersion(1802, 0);
18 private DBVersion(BigInteger major, BigInteger minor) {
23 private DBVersion(int major, int minor) {
24 this.major = BigInteger.valueOf(major);
25 this.minor = BigInteger.valueOf(minor);
28 public BigInteger getMajor() {
32 public BigInteger getMinor() {
36 public static DBVersion from(BigInteger major, BigInteger minor) {
37 return new DBVersion(major, minor);
40 public static DBVersion fromString(String version) {
41 String[] split = version.split(VERSION_PARTS_SEPARATOR);
42 if (split.length != 2) {
43 throw new MigrationException("version must be of pattern: <major>.<minor>");
45 return new DBVersion(getVersionPart(split[MAJOR_PART_IDX]),
46 getVersionPart(split[MINOR_PART_IDX]));
50 private static BigInteger getVersionPart(String versionPart) {
52 return new BigInteger(versionPart);
53 } catch (NumberFormatException e) {
54 throw new MigrationException(String.format("version part %s is non numeric", versionPart));
59 public String toString() {
60 return String.format("%s.%s", major, minor);
64 public boolean equals(Object o) {
68 if (o == null || getClass() != o.getClass()) {
72 DBVersion dbVersion = (DBVersion) o;
74 return major.equals(dbVersion.major) && minor.equals(dbVersion.minor);
78 public int hashCode() {
79 int result = major.hashCode();
80 result = 31 * result + minor.hashCode();
85 public int compareTo(DBVersion o) {
89 int majorsComparision = this.major.compareTo(o.major);
90 if (majorsComparision != 0) {
91 return majorsComparision;
93 int minorsComparision = this.minor.compareTo(o.minor);
94 if (minorsComparision != 0) {
95 return minorsComparision;