use of org.apereo.portal.version.om.Version in project uPortal by Jasig.
the class VersionVerifier method afterPropertiesSet.
@SuppressWarnings("FallThrough")
@Override
public void afterPropertiesSet() throws Exception {
for (final Map.Entry<String, Version> productVersionEntry : this.requiredProductVersions.entrySet()) {
final String product = productVersionEntry.getKey();
final Version dbVersion = this.versionDao.getVersion(product);
if (dbVersion == null) {
throw new ApplicationContextException("No Version exists for " + product + " in the database. Please check the upgrade instructions for this release.");
}
final Version codeVersion = productVersionEntry.getValue();
final Field mostSpecificMatchingField = VersionUtils.getMostSpecificMatchingField(dbVersion, codeVersion);
switch(mostSpecificMatchingField) {
// Versions completely match
case LOCAL:
{
logger.info("Software and Database versions are both {} for {}", dbVersion, product);
continue;
}
// Versions match except for local part
case PATCH:
// Versions match except for patch.local part
case MINOR:
{
// If db is before code and auto-update is enabled run hibernate-update
final Field upgradeField = mostSpecificMatchingField.getLessImportant();
if (dbVersion.isBefore(codeVersion) && this.updatePolicy != null && (upgradeField.equals(this.updatePolicy) || upgradeField.isLessImportantThan(this.updatePolicy))) {
logger.info("Automatically updating database from {} to {} for {}", dbVersion, codeVersion, product);
this.portalShellBuildHelper.hibernateUpdate("automated-hibernate-update", product, true, null);
continue;
} else if (codeVersion.isBefore(dbVersion)) {
// It is ok to run older code on a newer DB within the local/patch range
continue;
}
}
// Versions match except for minor.patch.local part
case MAJOR:
// Versions do not match at all
default:
{
if (dbVersion.isBefore(codeVersion)) {
throw new ApplicationContextException("Database Version for " + product + " is " + dbVersion + " but the code version is " + codeVersion + ". Please check the upgrade instructions for this release");
} else {
throw new ApplicationContextException("Database Version for " + product + " is " + dbVersion + " but the code version is " + codeVersion + ". It is not possible to run ");
}
}
}
}
}
use of org.apereo.portal.version.om.Version in project uPortal by Jasig.
the class JpaVersionDaoTest method testVersionBadSql.
@Test
public void testVersionBadSql() {
final String productName = "TEST_VERSION";
// Create
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
Version version = versionDao.getVersion(productName);
assertNull(version);
version = versionDao.setVersion(productName, 1, 2, 3, null);
assertNotNull(version);
assertEquals(1, version.getMajor());
assertEquals(2, version.getMinor());
assertEquals(3, version.getPatch());
assertNull(version.getLocal());
}
});
jdbcOperations.execute("ALTER TABLE UP_VERSION DROP LOCAL_VER");
try {
// Doesn't exist
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final Version version = versionDao.getVersion(productName);
assertNotNull(version);
assertEquals(1, version.getMajor());
assertEquals(2, version.getMinor());
assertEquals(3, version.getPatch());
assertNull(version.getLocal());
}
});
} finally {
jdbcOperations.execute("ALTER TABLE UP_VERSION ADD COLUMN LOCAL_VER INTEGER");
}
}
use of org.apereo.portal.version.om.Version in project uPortal by Jasig.
the class AbstractVersion method equals.
@Override
public final boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || obj.hashCode() != this.hashCode())
return false;
if (!(obj instanceof Version))
return false;
Version other = (Version) obj;
if (getMajor() != other.getMajor())
return false;
if (getMinor() != other.getMinor())
return false;
if (getPatch() != other.getPatch())
return false;
final Integer local = getLocal();
final Integer oLocal = other.getLocal();
if (local == null) {
if (oLocal != null)
return false;
} else if (!local.equals(oLocal))
return false;
return true;
}
use of org.apereo.portal.version.om.Version in project uPortal by Jasig.
the class VersionedDataUpdaterImpl method postInitDatabase.
@Override
@PortalTransactional
public void postInitDatabase(String product) {
final Version version = this.requiredProductVersions.get(product);
if (version == null) {
throw new IllegalArgumentException("No Version is configured for: " + product);
}
logger.info("PostInit - Set {} version to {}", product, version);
this.versionDao.setVersion(product, version);
}
use of org.apereo.portal.version.om.Version in project uPortal by Jasig.
the class VersionedDataUpdaterImpl method getAndVerifyDatabaseVersionForUpdate.
protected Version getAndVerifyDatabaseVersionForUpdate(String product) {
final Version codeVersion = this.requiredProductVersions.get(product);
if (codeVersion == null) {
throw new IllegalStateException("No code version configured for " + product);
}
Version dbVersion = this.versionDao.getVersion(product);
if (dbVersion == null) {
// If null assume version 4.0.0
dbVersion = VersionUtils.parseVersion("4.0.0");
}
if (!VersionUtils.canUpdate(dbVersion, codeVersion)) {
throw new IllegalStateException("Cannot update " + product + " db from " + dbVersion + " to " + codeVersion);
}
if (codeVersion.equals(dbVersion)) {
logger.info("{} code version matches database version. No update needed.", product);
}
return dbVersion;
}
Aggregations