001 package org.cumulus4j.store.datastoreversion.command; 002 003 import org.cumulus4j.store.datastoreversion.AbstractDatastoreVersionCommand; 004 import org.cumulus4j.store.datastoreversion.CommandApplyParam; 005 import org.slf4j.Logger; 006 import org.slf4j.LoggerFactory; 007 008 public class MinimumCumulus4jVersion extends AbstractDatastoreVersionCommand { 009 private static final Logger logger = LoggerFactory.getLogger(MinimumCumulus4jVersion.class); 010 011 private int version = -1; 012 013 /** 014 * {@inheritDoc} 015 * <p> 016 * The version returned by the implementation of this method in {@link MinimumCumulus4jVersion} is the 017 * lowest version of cumulus4j that runs with the current datastore. 018 * <p> 019 * In other words: This version here must be set to the current Cumulus4j version, 020 * if a lower version of Cumulus4j cannot be used with the datastore structure represented by the current source code, 021 * anymore. 022 * <p> 023 * This version is composed of the following parts: 024 * <ul> 025 * <li>major: 1 or 2 digits 026 * <li>minor: 2 digits 027 * <li>release: 2 digits 028 * <li>serial: 3 digits 029 * </ul> 030 * <p> 031 * For example, the 3rd non-downgradable change to the version <i>9.08.07-SNAPSHOT</i> would result in the numeric 032 * result <i>90807002</i> (the serial starts at 0, hence 3rd change = 2). 033 * This number is not incremented at the release of 9.08.07! It is only incremented, if 034 * the data structure changes in a way that prevents older versions from operating! 035 */ 036 @Override 037 public int getCommandVersion() { 038 if (this.version >= 0) 039 return this.version; 040 041 // BEGIN: maintain this - i.e. manually update the following!!! 042 // Last updated: 2012-07-20 by Marco 043 // Current version in pom.xml: 1.1.0-SNAPSHOT 044 int major = getCommandVersionMajor(); 045 int minor = getCommandVersionMinor(); 046 int release = getCommandVersionRelease(); 047 int serial = getCommandVersionSerial(); 048 // END 049 050 // Calculate version number from elements. 051 int version = ( 052 major * 100 /*minor*/ * 100 /*release*/ * 1000 /*serial*/ + 053 minor * 100 /*release*/ * 1000 /*serial*/ + 054 release * 1000 /*serial*/ + 055 serial 056 ); 057 logger.info("version={}", version); 058 this.version = version; 059 return version; 060 } 061 062 public int getCommandVersionMajor() { 063 return 01; 064 } 065 066 public int getCommandVersionMinor() { 067 return 01; 068 } 069 070 public int getCommandVersionRelease() { 071 return 00; 072 } 073 074 public int getCommandVersionSerial() { 075 return 001; 076 } 077 078 @Override 079 public boolean isFinal() { 080 return false; 081 } 082 083 @Override 084 public void apply(CommandApplyParam commandApplyParam) { 085 // nothing - this command is only used to have a general version and to ensure a minimum database version. 086 } 087 088 public static void main(String[] args) { 089 System.out.println(new MinimumCumulus4jVersion().getCommandVersion()); 090 } 091 092 }