1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.impl.config.ds;
17
18 import javax.annotation.concurrent.ThreadSafe;
19
20 import de.smartics.properties.api.config.domain.Property;
21 import de.smartics.properties.api.config.domain.PropertyCollection;
22 import de.smartics.properties.api.config.domain.PropertyProvider;
23 import de.smartics.properties.api.config.domain.PropertyStoreAccessor;
24 import de.smartics.properties.api.config.domain.PropertyStoreCode;
25 import de.smartics.properties.api.config.domain.PropertyStoreException;
26 import de.smartics.properties.api.config.domain.PropertyStoreMessageBean;
27 import de.smartics.properties.api.config.domain.SerializableConfigurationPropertiesManagement;
28 import de.smartics.properties.api.config.domain.key.ConfigurationKey;
29 import de.smartics.properties.api.core.domain.PropertyDescriptorRegistry;
30 import de.smartics.properties.api.core.security.PropertyValueSecurity;
31 import de.smartics.properties.spi.config.ds.DataSourceException;
32 import de.smartics.properties.spi.config.ds.PropertiesStore;
33 import de.smartics.properties.spi.config.support.AbstractExternalConfigurationPropertiesManagement;
34 import de.smartics.properties.spi.config.support.SerializableConfigurationPropertiesManagementSpi;
35 import de.smartics.util.lang.NullArgumentException;
36
37
38
39
40 @ThreadSafe
41 public final class DataSourceConfigurationProperties extends
42 AbstractExternalConfigurationPropertiesManagement implements
43 SerializableConfigurationPropertiesManagement,
44 SerializableConfigurationPropertiesManagementSpi
45 {
46
47
48
49
50
51
52
53 private static final long serialVersionUID = 1L;
54
55
56
57
58
59
60
61
62 private final PropertiesStore store;
63
64
65
66
67
68
69 private final PropertyStoreAccessor propertyStoreAccessor =
70 new DsPropertyStoreAccessor();
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 public DataSourceConfigurationProperties(final ConfigurationKey<?> key,
87 final PropertyDescriptorRegistry registry, final PropertiesStore store,
88 final PropertyValueSecurity decrypter) throws NullArgumentException
89 {
90 super(key, registry, decrypter);
91
92 this.store = store;
93 }
94
95
96
97
98
99
100 private final class DsPropertyStoreAccessor implements PropertyStoreAccessor
101 {
102
103
104
105
106
107
108 private static final long serialVersionUID = 1L;
109
110 @Override
111 public Property getPropertyFromStore(final String name)
112 throws PropertyStoreException
113 {
114 try
115 {
116 final String config = getKey().toString();
117 return store.getProperty(config, name);
118 }
119 catch (final DataSourceException e)
120 {
121 throw new PropertyStoreException(new PropertyStoreMessageBean(
122 PropertyStoreCode.CANNOT_GET_PROPERTY, e, getKey(), name));
123 }
124 }
125
126 @Override
127 public Property setPropertyToStore(final String name, final String value)
128 throws PropertyStoreException
129 {
130 try
131 {
132 final String config = getKey().toString();
133 final Property oldProperty = getPropertyFromStore(name);
134 store.setProperty(config, name, value);
135 return oldProperty;
136 }
137 catch (final PropertyStoreException e)
138 {
139 throw new PropertyStoreException(new PropertyStoreMessageBean(
140 PropertyStoreCode.CANNOT_SET_PROPERTY, e, getKey(), name));
141 }
142 catch (final DataSourceException e)
143 {
144 throw new PropertyStoreException(new PropertyStoreMessageBean(
145 PropertyStoreCode.CANNOT_SET_PROPERTY, e, getKey(), name));
146 }
147 }
148
149 @Override
150 public Property deletePropertyInStore(final String name)
151 throws PropertyStoreException
152 {
153 try
154 {
155 final String config = getKey().toString();
156 final Property oldValue = getPropertyFromStore(name);
157 store.deleteProperty(config, name);
158 return oldValue;
159 }
160 catch (final DataSourceException e)
161 {
162 throw new PropertyStoreException(new PropertyStoreMessageBean(
163 PropertyStoreCode.CANNOT_DELETE_PROPERTY, e, getKey(), name));
164 }
165 }
166
167 @Override
168 public PropertyCollection getPropertyCollectionFromStore()
169 throws PropertyStoreException
170 {
171 try
172 {
173 final String config = getKey().toString();
174 return store.getCollection(config);
175 }
176 catch (final DataSourceException e)
177 {
178 throw new PropertyStoreException(PropertyStoreMessageBean.collection(e,
179 getKey()));
180 }
181 }
182 }
183
184
185
186
187
188
189
190 @Override
191 public PropertyStoreAccessor getPropertyStoreAccessor()
192 {
193 return propertyStoreAccessor;
194 }
195
196
197
198 @Override
199 protected void setPropertiesToStore(final PropertyProvider provider)
200 {
201 store.setProperties(provider);
202 }
203
204 @Override
205 public SerializableConfigurationPropertiesManagement toSerializable()
206 {
207 return this;
208 }
209
210
211
212 }