From: David ‘Bombe’ Roden Date: Wed, 10 Nov 2010 07:33:02 +0000 (+0100) Subject: Save the plugin store after each modification. X-Git-Tag: 0.2-RC3~1 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=763715116898c7def5cf72e2c560af3b89450839;p=Sone.git Save the plugin store after each modification. --- diff --git a/src/main/java/net/pterodactylus/sone/freenet/PluginStoreConfigurationBackend.java b/src/main/java/net/pterodactylus/sone/freenet/PluginStoreConfigurationBackend.java index 97b463c..eebfe3e 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/PluginStoreConfigurationBackend.java +++ b/src/main/java/net/pterodactylus/sone/freenet/PluginStoreConfigurationBackend.java @@ -17,10 +17,16 @@ package net.pterodactylus.sone.freenet; +import java.util.logging.Level; +import java.util.logging.Logger; + import net.pterodactylus.util.config.AttributeNotFoundException; import net.pterodactylus.util.config.Configuration; import net.pterodactylus.util.config.ConfigurationException; import net.pterodactylus.util.config.ExtendedConfigurationBackend; +import net.pterodactylus.util.logging.Logging; +import freenet.client.async.DatabaseDisabledException; +import freenet.pluginmanager.PluginRespirator; import freenet.pluginmanager.PluginStore; /** @@ -30,17 +36,26 @@ import freenet.pluginmanager.PluginStore; */ public class PluginStoreConfigurationBackend implements ExtendedConfigurationBackend { + /** The logger. */ + private static final Logger logger = Logging.getLogger(PluginStoreConfigurationBackend.class); + + /** The plugin respirator. */ + private final PluginRespirator pluginRespirator; + /** The backing plugin store. */ private final PluginStore pluginStore; /** * Creates a new configuration backend based on a plugin store. * - * @param pluginStore - * The backing plugin store + * @param pluginRespirator + * The plugin respirator + * @throws DatabaseDisabledException + * if the plugin store is not available */ - public PluginStoreConfigurationBackend(PluginStore pluginStore) { - this.pluginStore = pluginStore; + public PluginStoreConfigurationBackend(PluginRespirator pluginRespirator) throws DatabaseDisabledException { + this.pluginRespirator = pluginRespirator; + this.pluginStore = pluginRespirator.getStore(); } /** @@ -60,6 +75,7 @@ public class PluginStoreConfigurationBackend implements ExtendedConfigurationBac @Override public void putValue(String attribute, String value) throws ConfigurationException { pluginStore.strings.put(attribute, value); + save(); } /** @@ -79,6 +95,7 @@ public class PluginStoreConfigurationBackend implements ExtendedConfigurationBac @Override public void setBooleanValue(String attribute, Boolean value) throws ConfigurationException { pluginStore.booleans.put(attribute, value); + save(); } /** @@ -106,6 +123,7 @@ public class PluginStoreConfigurationBackend implements ExtendedConfigurationBac @Override public void setDoubleValue(String attribute, Double value) throws ConfigurationException { pluginStore.strings.put(attribute, String.valueOf(value)); + save(); } /** @@ -125,6 +143,7 @@ public class PluginStoreConfigurationBackend implements ExtendedConfigurationBac @Override public void setIntegerValue(String attribute, Integer value) throws ConfigurationException { pluginStore.integers.put(attribute, value); + save(); } /** @@ -144,6 +163,22 @@ public class PluginStoreConfigurationBackend implements ExtendedConfigurationBac @Override public void setLongValue(String attribute, Long value) throws ConfigurationException { pluginStore.longs.put(attribute, value); + save(); + } + + // + // PRIVATE METHODS + // + + /** + * Saves the configuration to the plugin store. + */ + private void save() { + try { + pluginRespirator.putStore(pluginStore); + } catch (DatabaseDisabledException dde1) { + logger.log(Level.WARNING, "Could not store plugin store, database is disabled.", dde1); + } } } diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index d0dda00..77a1151 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -149,7 +149,7 @@ public class SonePlugin implements FredPlugin, FredPluginL10n, FredPluginBaseL10 /* create a configuration. */ Configuration configuration; try { - configuration = new Configuration(new PluginStoreConfigurationBackend(pluginStore = pluginRespirator.getStore())); + configuration = new Configuration(new PluginStoreConfigurationBackend(pluginRespirator)); } catch (DatabaseDisabledException dde1) { logger.log(Level.WARNING, "Could not load plugin store, using XML files."); try {