KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > services > monitor > UpdateServiceProperties


1 /*
2
3    Derby - Class org.apache.derby.impl.services.monitor.UpdateServiceProperties
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.services.monitor;
23
24 import org.apache.derby.iapi.services.monitor.PersistentService;
25 import org.apache.derby.iapi.services.sanity.SanityManager;
26
27 import java.util.Properties JavaDoc;
28 import java.util.Hashtable JavaDoc;
29 import org.apache.derby.io.WritableStorageFactory;
30
31 import org.apache.derby.iapi.error.StandardException;
32 import org.apache.derby.iapi.error.PassThroughException;
33 import org.apache.derby.iapi.reference.Property;
34
35 /**
36 */

37 public class UpdateServiceProperties extends Properties JavaDoc {
38
39     private PersistentService serviceType;
40     private String JavaDoc serviceName;
41     private WritableStorageFactory storageFactory;
42     
43     /*
44     Fix for bug 3668: Following would allow user to change properties while in the session
45     in which the database was created.
46     While the database is being created, serviceBooted would be false. What that means
47     is, don't save changes into services.properties file from here until the database
48     is created. Instead, let BaseMonitor save the properties at the end of the database
49   creation and also set serviceBooted to true at that point. From then on, the
50   services.properties file updates will be made here.
51     */

52     private boolean serviceBooted;
53
54     public UpdateServiceProperties(PersistentService serviceType, String JavaDoc serviceName,
55     Properties JavaDoc actualSet, boolean serviceBooted) {
56         super(actualSet);
57         this.serviceType = serviceType;
58         this.serviceName = serviceName;
59         this.serviceBooted = serviceBooted;
60     }
61
62     //look at the comments for serviceBooted at the top to understand this.
63
public void setServiceBooted() {
64         serviceBooted = true;
65     }
66
67     public void setStorageFactory( WritableStorageFactory storageFactory)
68     {
69         this.storageFactory = storageFactory;
70     }
71
72     public WritableStorageFactory getStorageFactory()
73     {
74         return storageFactory;
75     }
76     
77     /*
78     ** Methods of Hashtable (overridden)
79     */

80
81     /**
82         Put the key-value pair in the Properties set and
83         mark this set as modified.
84
85         @see Hashtable#put
86     */

87     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
88         Object JavaDoc ref = defaults.put(key, value);
89         if (!((String JavaDoc) key).startsWith(Property.PROPERTY_RUNTIME_PREFIX))
90             update();
91         return ref;
92     }
93
94     /**
95         Remove the key-value pair from the Properties set and
96         mark this set as modified.
97
98         @see Hashtable#remove
99     */

100     public Object JavaDoc remove(Object JavaDoc key) {
101         Object JavaDoc ref = defaults.remove(key);
102         if ((ref != null) &&
103             (!((String JavaDoc) key).startsWith(Property.PROPERTY_RUNTIME_PREFIX)))
104             update();
105         return ref;
106     }
107
108     /**
109        Saves the service properties to the disk.
110      */

111     public void saveServiceProperties()
112     {
113         if( SanityManager.DEBUG)
114             SanityManager.ASSERT( storageFactory != null,
115                                   "UpdateServiceProperties.saveServiceProperties() called before storageFactory set.");
116         try{
117             serviceType.saveServiceProperties(serviceName, storageFactory,
118                     BaseMonitor.removeRuntimeProperties(defaults), false);
119         } catch (StandardException mse) {
120             throw new PassThroughException(mse);
121         }
122     }
123
124     /*
125     ** Class specific methods.
126     */

127
128     private void update() {
129
130         try {
131             //look at the comments for serviceBooted at the top to understand this if.
132
if (serviceBooted)
133                 serviceType.saveServiceProperties(serviceName, storageFactory,
134                     BaseMonitor.removeRuntimeProperties(defaults), true);
135         } catch (StandardException mse) {
136             throw new PassThroughException(mse);
137         }
138     }
139
140 }
141
Popular Tags