--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.services.monitor.UpdateServiceProperties\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.services.monitor;\r
+\r
+import org.apache.derby.iapi.services.monitor.PersistentService;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import java.util.Properties;\r
+import java.util.Hashtable;\r
+import org.apache.derby.io.WritableStorageFactory;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.error.PassThroughException;\r
+import org.apache.derby.iapi.reference.Property;\r
+\r
+/**\r
+*/\r
+public class UpdateServiceProperties extends Properties {\r
+\r
+ private PersistentService serviceType;\r
+ private String serviceName;\r
+ private WritableStorageFactory storageFactory;\r
+ \r
+ /*\r
+ Fix for bug 3668: Following would allow user to change properties while in the session\r
+ in which the database was created.\r
+ While the database is being created, serviceBooted would be false. What that means\r
+ is, don't save changes into services.properties file from here until the database\r
+ is created. Instead, let BaseMonitor save the properties at the end of the database\r
+ creation and also set serviceBooted to true at that point. From then on, the\r
+ services.properties file updates will be made here.\r
+ */\r
+ private boolean serviceBooted;\r
+\r
+ public UpdateServiceProperties(PersistentService serviceType, String serviceName,\r
+ Properties actualSet, boolean serviceBooted) {\r
+ super(actualSet);\r
+ this.serviceType = serviceType;\r
+ this.serviceName = serviceName;\r
+ this.serviceBooted = serviceBooted;\r
+ }\r
+\r
+ //look at the comments for serviceBooted at the top to understand this.\r
+ public void setServiceBooted() {\r
+ serviceBooted = true;\r
+ }\r
+\r
+ public void setStorageFactory( WritableStorageFactory storageFactory)\r
+ {\r
+ this.storageFactory = storageFactory;\r
+ }\r
+\r
+ public WritableStorageFactory getStorageFactory()\r
+ {\r
+ return storageFactory;\r
+ }\r
+ \r
+ /*\r
+ ** Methods of Hashtable (overridden)\r
+ */\r
+\r
+ /** \r
+ Put the key-value pair in the Properties set and\r
+ mark this set as modified.\r
+\r
+ @see Hashtable#put\r
+ */\r
+ public Object put(Object key, Object value) {\r
+ Object ref = defaults.put(key, value);\r
+ if (!((String) key).startsWith(Property.PROPERTY_RUNTIME_PREFIX))\r
+ update();\r
+ return ref;\r
+ }\r
+\r
+ /** \r
+ Remove the key-value pair from the Properties set and\r
+ mark this set as modified.\r
+\r
+ @see Hashtable#remove\r
+ */\r
+ public Object remove(Object key) {\r
+ Object ref = defaults.remove(key);\r
+ if ((ref != null) &&\r
+ (!((String) key).startsWith(Property.PROPERTY_RUNTIME_PREFIX)))\r
+ update();\r
+ return ref;\r
+ }\r
+\r
+ /**\r
+ Saves the service properties to the disk.\r
+ */\r
+ public void saveServiceProperties()\r
+ {\r
+ if( SanityManager.DEBUG)\r
+ SanityManager.ASSERT( storageFactory != null,\r
+ "UpdateServiceProperties.saveServiceProperties() called before storageFactory set.");\r
+ try{\r
+ serviceType.saveServiceProperties(serviceName, storageFactory,\r
+ BaseMonitor.removeRuntimeProperties(defaults), false);\r
+ } catch (StandardException mse) {\r
+ throw new PassThroughException(mse);\r
+ }\r
+ }\r
+\r
+ /*\r
+ ** Class specific methods.\r
+ */\r
+\r
+ private void update() {\r
+\r
+ try {\r
+ //look at the comments for serviceBooted at the top to understand this if.\r
+ if (serviceBooted)\r
+ serviceType.saveServiceProperties(serviceName, storageFactory,\r
+ BaseMonitor.removeRuntimeProperties(defaults), true);\r
+ } catch (StandardException mse) {\r
+ throw new PassThroughException(mse);\r
+ }\r
+ }\r
+\r
+}\r