Commit d0250b0a authored by Matt Tucker's avatar Matt Tucker Committed by matt

Fixed plugin database upgrades.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5311 b35dd754-fafc-0310-a699-88a17e54d16e
parent 3bc19c83
...@@ -15,7 +15,6 @@ import org.jivesoftware.util.LocaleUtils; ...@@ -15,7 +15,6 @@ import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.XMPPServer; import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.container.Plugin; import org.jivesoftware.wildfire.container.Plugin;
import org.jivesoftware.wildfire.container.PluginClassLoader;
import org.jivesoftware.wildfire.container.PluginManager; import org.jivesoftware.wildfire.container.PluginManager;
import java.io.*; import java.io.*;
...@@ -71,7 +70,8 @@ public class SchemaManager { ...@@ -71,7 +70,8 @@ public class SchemaManager {
"resources" + File.separator + "database", resourceName); "resources" + File.separator + "database", resourceName);
try { try {
return new FileInputStream(file); return new FileInputStream(file);
} catch (FileNotFoundException e) { }
catch (FileNotFoundException e) {
return null; return null;
} }
} }
...@@ -107,12 +107,17 @@ public class SchemaManager { ...@@ -107,12 +107,17 @@ public class SchemaManager {
try { try {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
return checkSchema(con, schemaKey, schemaVersion, new ResourceLoader() { return checkSchema(con, schemaKey, schemaVersion, new ResourceLoader() {
public InputStream loadResource(String resourceName) { public InputStream loadResource(String resourceName) {
PluginClassLoader pluginClassLoader = pluginManager.getPluginClassloader(plugin); File file = new File(pluginManager.getPluginDirectory(plugin) +
ClassLoader classLoader = pluginClassLoader.getClassLoader(); File.separator + "database", resourceName);
return classLoader.getResourceAsStream(resourceName); try {
} return new FileInputStream(file);
}); }
catch (FileNotFoundException e) {
return null;
}
}
});
} }
catch (Exception e) { catch (Exception e) {
Log.error(LocaleUtils.getLocalizedString("upgrade.database.failure"), e); Log.error(LocaleUtils.getLocalizedString("upgrade.database.failure"), e);
...@@ -234,7 +239,7 @@ public class SchemaManager { ...@@ -234,7 +239,7 @@ public class SchemaManager {
// Run all upgrade scripts until we're up to the latest schema. // Run all upgrade scripts until we're up to the latest schema.
for (int i = currentVersion + 1; i <= requiredVersion; i++) { for (int i = currentVersion + 1; i <= requiredVersion; i++) {
InputStream resource = getUpgradeResource(resourceLoader, i, schemaKey); InputStream resource = getUpgradeResource(resourceLoader, i, schemaKey);
if(resource == null) { if (resource == null) {
continue; continue;
} }
try { try {
...@@ -260,7 +265,7 @@ public class SchemaManager { ...@@ -260,7 +265,7 @@ public class SchemaManager {
} }
private InputStream getUpgradeResource(ResourceLoader resourceLoader, int upgradeVersion, private InputStream getUpgradeResource(ResourceLoader resourceLoader, int upgradeVersion,
String schemaKey) String schemaKey)
{ {
InputStream resource = null; InputStream resource = null;
if ("wildfire".equals(schemaKey)) { if ("wildfire".equals(schemaKey)) {
...@@ -278,7 +283,7 @@ public class SchemaManager { ...@@ -278,7 +283,7 @@ public class SchemaManager {
} }
} }
else { else {
String resourceName = "database/upgrade/" + upgradeVersion + "/" + schemaKey + "_" + String resourceName = "upgrade/" + upgradeVersion + "/" + schemaKey + "_" +
DbConnectionManager.getDatabaseType() + ".sql"; DbConnectionManager.getDatabaseType() + ".sql";
resource = resourceLoader.loadResource(resourceName); resource = resourceLoader.loadResource(resourceName);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment