private static void persistSchemaVersion(IntactContext context) { IntactSession session = context.getSession(); SchemaVersion requiredVersion = context.getConfig().getDefaultDataConfig().getMinimumRequiredVersion(); DbInfo dbInfo = new DbInfo(DbInfo.SCHEMA_VERSION, requiredVersion.toString()); if (log.isDebugEnabled()) log.debug("Persisting schema version: " + requiredVersion.toString()); DaoFactory daoFactory = DaoFactory.getCurrentInstance(session, RuntimeConfig.getCurrentInstance(session).getDefaultDataConfig()); context.getDataContext().beginTransaction(); daoFactory.getDbInfoDao().persist(dbInfo); try { context.getDataContext().commitTransaction(); } catch (IntactTransactionException e) { log.error(e); } }
private static void checkSchemaCompatibility( DataConfig dataConfig, IntactSession session ) { SchemaVersion requiredVersion = dataConfig.getMinimumRequiredVersion(); DaoFactory daoFactory = DaoFactory.getCurrentInstance( session, RuntimeConfig.getCurrentInstance( session ).getDefaultDataConfig() ); IntactTransaction tx = daoFactory.beginTransaction(); DbInfo dbInfoSchemaVersion = daoFactory.getDbInfoDao().get( DbInfo.SCHEMA_VERSION ); try { tx.commit(); } catch ( IntactTransactionException e ) { log.error( "Exception commiting " + e ); } SchemaVersion schemaVersion; if ( dbInfoSchemaVersion == null ) { log.warn( "Schema version does not exist. Will be created" ); setSchemaVersionToBePersisted( session ); return; } try { schemaVersion = SchemaVersion.parse( dbInfoSchemaVersion.getValue() ); } catch ( Exception e ) { throw new IntactInitializationError( "Error getting schema version", e ); } log.info( "Schema Version: " + schemaVersion ); if ( !schemaVersion.isCompatibleWith( requiredVersion ) ) { throw new IntactInitializationError( "Database schema version " + requiredVersion + " is required" + " to use this version of intact-core. Schema version found: " + schemaVersion ); } }