|
| 1 | +/** |
| 2 | + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. |
| 3 | + * |
| 4 | + * This software is licensed under the GNU General Public License v3 or later. |
| 5 | + * |
| 6 | + * It is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or any later version. |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + * |
| 17 | + */ |
| 18 | +package com.cloud.upgrade.dao; |
| 19 | + |
| 20 | +import java.io.File; |
| 21 | +import java.io.FileNotFoundException; |
| 22 | +import java.io.FileReader; |
| 23 | +import java.io.IOException; |
| 24 | +import java.sql.Connection; |
| 25 | +import java.sql.SQLException; |
| 26 | + |
| 27 | +import com.cloud.utils.PropertiesUtil; |
| 28 | +import com.cloud.utils.db.ScriptRunner; |
| 29 | +import com.cloud.utils.db.Transaction; |
| 30 | +import com.cloud.utils.exception.CloudRuntimeException; |
| 31 | + |
| 32 | +public class Upgrade217to22 implements DbUpgrade { |
| 33 | + |
| 34 | + @Override |
| 35 | + public void prepare() { |
| 36 | + File file = PropertiesUtil.findConfigFile("schema-21to22.sql"); |
| 37 | + if (file == null) { |
| 38 | + throw new CloudRuntimeException("Unable to find the upgrade script, schema-21to22.sql"); |
| 39 | + } |
| 40 | + |
| 41 | + try { |
| 42 | + FileReader reader = new FileReader(file); |
| 43 | + Connection conn = Transaction.getStandaloneConnection(); |
| 44 | + ScriptRunner runner = new ScriptRunner(conn, false, false); |
| 45 | + runner.runScript(reader); |
| 46 | + } catch (FileNotFoundException e) { |
| 47 | + throw new CloudRuntimeException("Unable to find upgrade script, schema-21to22.sql", e); |
| 48 | + } catch (IOException e) { |
| 49 | + throw new CloudRuntimeException("Unable to read upgrade script, schema-21to22.sql", e); |
| 50 | + } catch (SQLException e) { |
| 51 | + throw new CloudRuntimeException("Unable to execute upgrade script, schema-21to22.sql", e); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public void upgrade() { |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public void cleanup() { |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public String[] getUpgradableVersionRange() { |
| 65 | + return new String[] { "2.1.7", "2.1.7" }; |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public String getUpgradedVersion() { |
| 70 | + return "2.2.0"; |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public boolean supportsRollingUpgrade() { |
| 75 | + return false; |
| 76 | + } |
| 77 | +} |
0 commit comments