public void updateSchemaVersion ( VersionComparator version ) throws SQLException { PreparedStatement statement = null ; PreparedStatement updateStatement = null ; ResultSet results = null ; try { statement = connection . prepareStatement ( "SELECT \"VERSION\" FROM \"SCHEMAVERSION\"" ) ; results = statement . executeQuery ( ) ; if ( results . next ( ) ) { final VersionComparator currentVersion = new VersionComparator ( results . getString ( 1 ) ) ; if ( version == null || currentVersion . isNewerThan ( version ) ) { return ; } updateStatement = connection . prepareStatement ( "UPDATE \"SCHEMAVERSION\" SET \"VERSION\" = ?" ) ; } else { // Does not exist. Populate schema table with current running version version = new VersionComparator ( Config . getInstance ( ) . getApplicationVersion ( ) ) ; updateStatement = connection . prepareStatement ( "INSERT INTO \"SCHEMAVERSION\" (\"VERSION\") VALUES (?)" ) ; } LOGGER . debug ( "Updating database schema to: " + version . toString ( ) ) ; updateStatement . setString ( 1 , version . toString ( ) ) ; updateStatement . executeUpdate ( ) ; connection . commit ( ) ; } finally { DbUtil . close ( results ) ; DbUtil . close ( updateStatement ) ; DbUtil . close ( statement ) ; //DbUtil.close(connection); // do not close connection } }
Updates the schema version in the database .