Skip to main content
summaryrefslogtreecommitdiffstats
blob: 58ac0a7bf429852289aedd696861df3371be9730 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/*******************************************************************************
* Copyright (c) 2009, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
* 
* Contributors:
*     Oracle - initial API and implementation
*******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.core.internal.v2_0.context.persistence.logging;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.jpt.jpa.core.jpa2.context.persistence.PersistenceUnit2_0;
import org.eclipse.jpt.jpa.eclipselink.core.context.persistence.logging.LoggingLevel;
import org.eclipse.jpt.jpa.eclipselink.core.internal.context.persistence.logging.EclipseLinkLogging;
import org.eclipse.jpt.jpa.eclipselink.core.v2_0.context.persistence.logging.Logging2_0;

/**
 *  EclipseLinkLogging2_0
 */
public class EclipseLinkLogging2_0 extends EclipseLinkLogging
	implements Logging2_0
{
	// ********** EclipseLink properties **********

	/** 
	 * Store Category levels in a map
	 * key/value pairs, where: 
	 * 		key = Category property id
	 * 		value = value
	 */
	private Map<String, LoggingLevel> categoryValues;

	private Boolean connection;
	
	private LoggingLevel categoriesDefaultValue;
	
	// ********** constructors **********
	public EclipseLinkLogging2_0(PersistenceUnit2_0 parent) {
		super(parent);
	}

	// ********** initialization **********
	/**
	 * Initializes properties with values from the persistence unit.
	 */
	@Override
	protected void initializeProperties() {
		super.initializeProperties();

		this.connection = 
			this.getBooleanValue(ECLIPSELINK_CONNECTION);
		
		this.categoriesDefaultValue = 
			this.getEnumValue(ECLIPSELINK_LEVEL, LoggingLevel.values());
		this.initializeCategory(SQL_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(TRANSACTION_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(EVENT_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(CONNECTION_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(QUERY_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(CACHE_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(PROPAGATION_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(SEQUENCING_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(EJB_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(DMS_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(EJB_OR_METADATA_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(METAMODEL_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(WEAVER_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(PROPERTIES_CATEGORY_LOGGING_PROPERTY);
		this.initializeCategory(SERVER_CATEGORY_LOGGING_PROPERTY);
	}
	
	@Override
	protected void initialize() {
		super.initialize();

		this.categoryValues = new HashMap<String, LoggingLevel>();
	}

	/**
	 * Convenience method to set a logging level category value from the value in the persistence unit.
	 * 
	 * key = Category property id; value = value (LoggingLevel)
	 * @param categoryId - Category property id
	 */
	private void initializeCategory(String categoryId) {
		String puKey = this.persistenceUnitKeyOf(categoryId);
		LoggingLevel puValue = this.getEnumValue(puKey, LoggingLevel.values());

		this.categoryValues.put(categoryId, puValue);
	}

	// ********** behavior **********
	
	@Override
	public void propertyValueChanged(String propertyName, String newValue) {
		super.propertyValueChanged(propertyName, newValue);

		if (propertyName.equals(ECLIPSELINK_CONNECTION)) {
			this.connectionChanged(newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_SQL_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_SQL_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_TRANSACTION_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_TRANSACTION_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_EVENT_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_EVENT_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_CONNECTION_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_CONNECTION_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_QUERY_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_QUERY_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_CACHE_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_CACHE_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_PROPAGATION_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_PROPAGATION_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_SEQUENCING_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_SEQUENCING_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_EJB_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_EJB_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_DMS_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_DMS_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_EJB_OR_METADATA_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_EJB_OR_METADATA_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_METAMODEL_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_METAMODEL_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_WEAVER_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_WEAVER_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_PROPERTIES_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_PROPERTIES_CATEGORY_LOGGING_LEVEL, newValue);
		}
		else if (propertyName.equals(ECLIPSELINK_SERVER_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_SERVER_CATEGORY_LOGGING_LEVEL, newValue);
		}
	}
	
	@Override
	public void propertyRemoved(String propertyName) {
		super.propertyRemoved(propertyName);

		if (propertyName.equals(ECLIPSELINK_CONNECTION)) {
			this.connectionChanged(null);
		}
		else if (propertyName.equals(ECLIPSELINK_SQL_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_SQL_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_TRANSACTION_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_TRANSACTION_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_EVENT_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_EVENT_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_CONNECTION_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_CONNECTION_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_QUERY_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_QUERY_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_CACHE_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_CACHE_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_PROPAGATION_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_PROPAGATION_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_SEQUENCING_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_SEQUENCING_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_EJB_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_EJB_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_DMS_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_DMS_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_EJB_OR_METADATA_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_EJB_OR_METADATA_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_METAMODEL_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_METAMODEL_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_WEAVER_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_WEAVER_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_PROPERTIES_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_PROPERTIES_CATEGORY_LOGGING_LEVEL, null);
		}
		else if (propertyName.equals(ECLIPSELINK_SERVER_CATEGORY_LOGGING_LEVEL)) {
			this.categoryLoggingChanged_(ECLIPSELINK_SERVER_CATEGORY_LOGGING_LEVEL, null);
		}
	}

	/**
	 * Adds property names key/value pairs, where: 
	 * 		key = EclipseLink property key
	 * 		value = property id
	 */
	@Override
	protected void addPropertyNames(Map<String, String> propertyNames) {
		super.addPropertyNames(propertyNames);

		propertyNames.put(
			ECLIPSELINK_CONNECTION,
			CONNECTION_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_SQL_CATEGORY_LOGGING_LEVEL,
			SQL_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_TRANSACTION_CATEGORY_LOGGING_LEVEL,
			TRANSACTION_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_EVENT_CATEGORY_LOGGING_LEVEL,
			EVENT_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_CONNECTION_CATEGORY_LOGGING_LEVEL,
			CONNECTION_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_QUERY_CATEGORY_LOGGING_LEVEL,
			QUERY_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_CACHE_CATEGORY_LOGGING_LEVEL,
			CACHE_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_PROPAGATION_CATEGORY_LOGGING_LEVEL,
			PROPAGATION_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_SEQUENCING_CATEGORY_LOGGING_LEVEL,
			SEQUENCING_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_EJB_CATEGORY_LOGGING_LEVEL,
			EJB_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_DMS_CATEGORY_LOGGING_LEVEL,
			DMS_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_EJB_OR_METADATA_CATEGORY_LOGGING_LEVEL,
			EJB_OR_METADATA_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_METAMODEL_CATEGORY_LOGGING_LEVEL,
			METAMODEL_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_WEAVER_CATEGORY_LOGGING_LEVEL,
			WEAVER_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_PROPERTIES_CATEGORY_LOGGING_LEVEL,
			PROPERTIES_CATEGORY_LOGGING_PROPERTY);
		propertyNames.put(
			ECLIPSELINK_SERVER_CATEGORY_LOGGING_LEVEL,
			SERVER_CATEGORY_LOGGING_PROPERTY);
	}

	// ********** Connection **********
	public Boolean getConnection() {
		return this.connection;
	}

	public void setConnection(Boolean newConnection) {
		Boolean old = this.connection;
		this.connection = newConnection;
		this.putProperty(CONNECTION_PROPERTY, newConnection);
		this.firePropertyChanged(CONNECTION_PROPERTY, old, newConnection);
	}

	private void connectionChanged(String stringValue) {
		Boolean newValue = getBooleanValueOf(stringValue);
		
		Boolean old = this.connection;
		this.connection = newValue;
		this.firePropertyChanged(CONNECTION_PROPERTY, old, newValue);
	}

	public Boolean getDefaultConnection() {
		return DEFAULT_CONNECTION;
	}
	
	// ********** Category Levels **********
	
	public LoggingLevel getLevel(String category) {

		return this.categoryValues.get(category);
	}

	public void setLevel(String category, LoggingLevel newLevel) {
		LoggingLevel old = this.getLevel(category);
		this.categoryValues.put(category, newLevel);
		this.putProperty(category, newLevel);
		this.firePropertyChanged(category, old, newLevel);
	}

	private void categoryLoggingChanged_(String eclipselinkKey, String stringValue) {
		String category = this.propertyIdOf(eclipselinkKey);
		this.categoryLoggingChanged(category, stringValue);
	}

	private void categoryLoggingChanged(String category, String stringValue) {
		LoggingLevel enumValue = getEnumValueOf(stringValue, LoggingLevel.values());
		LoggingLevel old = this.getLevel(category);
		this.categoryValues.put(category, enumValue);
		this.firePropertyChanged(category, old, enumValue);
	}

	public LoggingLevel getCategoriesDefaultLevel() {
		return (this.categoriesDefaultValue == null) ? super.getDefaultLevel() : this.categoriesDefaultValue;
	}

	@Override
	public void setLevel(LoggingLevel level) {
		super.setLevel(level);
		this.setDefaultLevel(level);
	}

	public void setDefaultLevel(LoggingLevel level) {
		LoggingLevel old = this.categoriesDefaultValue;
		this.categoriesDefaultValue = level;
		this.firePropertyChanged(CATEGORIES_DEFAULT_LOGGING_PROPERTY, old, level);
	}
}

Back to the top