Package org.jasig.portal.version.om

Examples of org.jasig.portal.version.om.Version


            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))
View Full Code Here


   
    @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
View Full Code Here

    }
   

    @Test
    public void testVersionUpgrade() {
        Version v1 = VersionUtils.parseVersion("4.0.5");
        Version v2 = VersionUtils.parseVersion("4.0.5");
       
        assertTrue(VersionUtils.canUpdate(v1, v2));
        assertTrue(VersionUtils.canUpdate(v2, v1));
       
        v2 = VersionUtils.parseVersion("4.0.5.1");
View Full Code Here

    }
   

    @Test
    public void testGetMostSpecificMatchingField() {
        Version v1 = VersionUtils.parseVersion("4.0.5");
        Version v2 = VersionUtils.parseVersion("4.0.5");
       
        assertEquals(Version.Field.LOCAL, VersionUtils.getMostSpecificMatchingField(v1, v2));
        assertEquals(Version.Field.LOCAL, VersionUtils.getMostSpecificMatchingField(v2, v1));
       
        v2 = VersionUtils.parseVersion("4.0.5.1");
View Full Code Here

       
        //Doesn't exist
        this.execute(new CallableWithoutResult() {
            @Override
            protected void callWithoutResult() {
                final Version version = versionDao.getVersion(productName);
                assertNull(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());
            }
        });

        //Update
        this.execute(new CallableWithoutResult() {
            @Override
            protected void callWithoutResult() {
                Version version = versionDao.getVersion(productName);
                assertNotNull(version);
                assertEquals(1, version.getMajor());
                assertEquals(2, version.getMinor());
                assertEquals(3, version.getPatch());
                assertNull(version.getLocal());
               

                version = versionDao.setVersion(productName, 4, 5, 6, null);
                assertNotNull(version);
                assertEquals(4, version.getMajor());
                assertEquals(5, version.getMinor());
                assertEquals(6, version.getPatch());
                assertNull(version.getLocal());
            }
        });

        //verify
        this.execute(new CallableWithoutResult() {
            @Override
            protected void callWithoutResult() {
                Version version = versionDao.getVersion(productName);
                assertNotNull(version);
                assertEquals(4, version.getMajor());
                assertEquals(5, version.getMinor());
                assertEquals(6, version.getPatch());
                assertNull(version.getLocal());
            }
        });
    }
View Full Code Here

       
        //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");
View Full Code Here

   
    /**
     * Check if the database and software versions match
     */
    private boolean checkDatabaseVersion(String databaseName) {
        final Version softwareVersion = this.requiredProductVersions.get(databaseName);
        if (softwareVersion == null) {
            throw new IllegalStateException("No version number is configured for: " + databaseName);
        }
       
        final Version databaseVersion = this.versionDao.getVersion(databaseName);
        if (databaseVersion == null) {
            throw new IllegalStateException("No version number is exists in the database for: " + databaseName);
        }
       
        return softwareVersion.equals(databaseVersion);
View Full Code Here

import org.junit.Test;

public class VersionUtilsTest {
    @Test
    public void testVersionParsing() {
        Version version = VersionUtils.parseVersion("4.0.5");
        assertNotNull(version);
        assertEquals(4, version.getMajor());
        assertEquals(0, version.getMinor());
        assertEquals(5, version.getPatch());
        assertNull(version.getLocal());
       
       
        version = VersionUtils.parseVersion("4.0.5.3");
        assertNotNull(version);
        assertEquals(4, version.getMajor());
        assertEquals(0, version.getMinor());
        assertEquals(5, version.getPatch());
        assertEquals(Integer.valueOf(3), version.getLocal());
    }
View Full Code Here

    }

    @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);
View Full Code Here

   
    @Override
    @OpenEntityManager(unitName = BasePortalJpaDao.PERSISTENCE_UNIT_NAME)
    public void preUpdateDatabase(String product) {
        //This happens first because even if there are no updaters we need to make sure the attempted update is valid
        final Version dbVersion = getAndVerifyDatabaseVersionForUpdate(product);
       
        final SortedSet<IVersionedDatabaseUpdateHelper> updateHelpers = this.databaseUpdateHelpers.get(product);
        if (updateHelpers == null || updateHelpers.isEmpty()) {
            logger.info("No IVersionedDatabaseUpdateHelpers configured for database {}, nothing will be done in preUpdate", product);
        }
        else {
            //updateHelpers is sorted oldest to newest by version so iterate through and run the updaters that apply
            for (final IVersionedDatabaseUpdateHelper updateHelper : updateHelpers) {
                final Version updateVersion = updateHelper.getVersion();
                if (dbVersion.equals(updateVersion) || dbVersion.isBefore(updateVersion)) {
                    logger.info("PreUpdate {} from {} to {}", product, dbVersion, updateVersion);
                    updateHelper.preUpdate();
                    logger.info("PreUpdate {} from {} to {} complete", product, dbVersion, updateVersion);
                }
View Full Code Here

TOP

Related Classes of org.jasig.portal.version.om.Version

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.