Skip to main content
summaryrefslogtreecommitdiffstats
blob: d98d2d76358bd15d51bb721375a2941a750ee497 (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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
/*******************************************************************************
 *  Copyright (c) 2008, 2009  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.eclipselink.core.internal.context.orm;

import org.eclipse.jpt.core.context.orm.OrmTypeMapping;
import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.eclipselink.core.context.CacheCoordinationType;
import org.eclipse.jpt.eclipselink.core.context.CacheType;
import org.eclipse.jpt.eclipselink.core.context.ExistenceType;
import org.eclipse.jpt.eclipselink.core.context.ExpiryTimeOfDay;
import org.eclipse.jpt.eclipselink.core.context.java.JavaCaching;
import org.eclipse.jpt.eclipselink.core.context.orm.OrmCaching;
import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlCache;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlCacheHolder;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlTimeOfDay;

public class EclipseLinkOrmCaching extends AbstractXmlContextNode
	implements OrmCaching
{
	protected XmlCacheHolder resource;
	
	protected int defaultSize;
	protected Integer specifiedSize;
	
	protected boolean defaultShared;
	protected Boolean specifiedShared;
	
	protected CacheType defaultType;
	protected CacheType specifiedType;
	
	protected boolean defaultAlwaysRefresh;
	protected Boolean specifiedAlwaysRefresh;
	
	protected boolean defaultRefreshOnlyIfNewer;
	protected Boolean specifiedRefreshOnlyIfNewer;
	
	protected boolean defaultDisableHits;
	protected Boolean specifiedDisableHits;
	
	protected CacheCoordinationType defaultCoordinationType;
	protected CacheCoordinationType specifiedCoordinationType;
	
	protected ExistenceType specifiedExistenceType;
	protected ExistenceType defaultExistenceType;
	
	protected Integer expiry;
	protected EclipseLinkOrmExpiryTimeOfDay expiryTimeOfDay;
	
	public EclipseLinkOrmCaching(OrmTypeMapping parent) {
		super(parent);
	}

	public int getSize() {
		return (this.specifiedSize == null) ? this.defaultSize : this.specifiedSize.intValue();
	}
	
	public int getDefaultSize() {
		return this.defaultSize;
	}
	
	protected void setDefaultSize(int newSize) {
		int oldSize = this.defaultSize;
		this.defaultSize = newSize;
		firePropertyChanged(DEFAULT_SIZE_PROPERTY, oldSize, newSize);
	}
	
	public Integer getSpecifiedSize() {
		return this.specifiedSize;
	}
	
	public void setSpecifiedSize(Integer newSpecifiedSize) {
		Integer oldSpecifiedSize = this.specifiedSize;
		this.specifiedSize = newSpecifiedSize;
		if (oldSpecifiedSize != newSpecifiedSize) {
			if (this.getResourceCache() != null) {
				this.getResourceCache().setSize(newSpecifiedSize);						
				if (this.getResourceCache().isAllFeaturesUnset()) {
					removeResourceCache();
				}
			}
			else if (newSpecifiedSize != null) {
				addResourceCache();
				getResourceCache().setSize(newSpecifiedSize);
			}
		}
		firePropertyChanged(SPECIFIED_SIZE_PROPERTY, oldSpecifiedSize, newSpecifiedSize);		
	}
	
	protected void setSpecifiedSize_(Integer newSpecifiedSize) {
		Integer oldSpecifiedSize = this.specifiedSize;
		this.specifiedSize = newSpecifiedSize;
		firePropertyChanged(SPECIFIED_SIZE_PROPERTY, oldSpecifiedSize, newSpecifiedSize);
	}
	
	
	public boolean isShared() {
		return (this.specifiedShared == null) ? this.defaultShared : this.specifiedShared.booleanValue();
	}
	
	public boolean isDefaultShared() {
		return this.defaultShared;
	}
	
	protected void setDefaultShared(boolean newDefaultShared) {
		boolean oldDefaultShared = this.defaultShared;
		this.defaultShared = newDefaultShared;
		firePropertyChanged(DEFAULT_SHARED_PROPERTY, oldDefaultShared, newDefaultShared);	
	}
	
	public Boolean getSpecifiedShared() {
		return this.specifiedShared;
	}
	
	public void setSpecifiedShared(Boolean newSpecifiedShared) {
		Boolean oldSpecifiedShared = this.specifiedShared;
		this.specifiedShared = newSpecifiedShared;
		if (oldSpecifiedShared != newSpecifiedShared) {
			if (this.getResourceCache() != null) {
				this.getResourceCache().setShared(newSpecifiedShared);						
				if (this.getResourceCache().isAllFeaturesUnset()) {
					removeResourceCache();
				}
			}
			else if (newSpecifiedShared != null) {
				addResourceCache();
				getResourceCache().setShared(newSpecifiedShared);
			}
		}
		firePropertyChanged(SPECIFIED_SHARED_PROPERTY, oldSpecifiedShared, newSpecifiedShared);		
		if (newSpecifiedShared == Boolean.FALSE) {
			setSpecifiedType(null);
			setSpecifiedSize(null);
			setSpecifiedAlwaysRefresh(null);
			setSpecifiedRefreshOnlyIfNewer(null);
			setSpecifiedDisableHits(null);
			setSpecifiedCoordinationType(null);
			setExpiry(null);
			if (this.expiryTimeOfDay != null) {
				removeExpiryTimeOfDay();
			}
		}
	}
	
	protected void setSpecifiedShared_(Boolean newSpecifiedShared) {
		Boolean oldSpecifiedShared = this.specifiedShared;
		this.specifiedShared = newSpecifiedShared;
		firePropertyChanged(SPECIFIED_SHARED_PROPERTY, oldSpecifiedShared, newSpecifiedShared);	
	}
	
	
	public boolean isAlwaysRefresh() {
		return (this.specifiedAlwaysRefresh == null) ? this.defaultAlwaysRefresh : this.specifiedAlwaysRefresh.booleanValue();
	}
	
	public boolean isDefaultAlwaysRefresh() {
		return this.defaultAlwaysRefresh;
	}
	
	protected void setDefaultAlwaysRefresh(boolean newDefaultAlwaysRefresh) {
		boolean oldDefaultAlwaysRefresh = this.defaultAlwaysRefresh;
		this.defaultAlwaysRefresh = newDefaultAlwaysRefresh;
		firePropertyChanged(DEFAULT_ALWAYS_REFRESH_PROPERTY, oldDefaultAlwaysRefresh, newDefaultAlwaysRefresh);	
	}
	
	public Boolean getSpecifiedAlwaysRefresh() {
		return this.specifiedAlwaysRefresh;
	}
	
	public void setSpecifiedAlwaysRefresh(Boolean newSpecifiedAlwaysRefresh) {
		Boolean oldSpecifiedAlwaysRefresh = this.specifiedAlwaysRefresh;
		this.specifiedAlwaysRefresh = newSpecifiedAlwaysRefresh;
		if (oldSpecifiedAlwaysRefresh != newSpecifiedAlwaysRefresh) {
			if (this.getResourceCache() != null) {
				this.getResourceCache().setAlwaysRefresh(newSpecifiedAlwaysRefresh);						
				if (this.getResourceCache().isAllFeaturesUnset()) {
					removeResourceCache();
				}
			}
			else if (newSpecifiedAlwaysRefresh != null) {
				addResourceCache();
				getResourceCache().setAlwaysRefresh(newSpecifiedAlwaysRefresh);
			}
		}
		firePropertyChanged(SPECIFIED_ALWAYS_REFRESH_PROPERTY, oldSpecifiedAlwaysRefresh, newSpecifiedAlwaysRefresh);		
	}
	
	protected void setSpecifiedAlwaysRefresh_(Boolean newSpecifiedAlwaysRefresh) {
		Boolean oldSpecifiedAlwaysRefresh = this.specifiedAlwaysRefresh;
		this.specifiedAlwaysRefresh = newSpecifiedAlwaysRefresh;
		firePropertyChanged(SPECIFIED_ALWAYS_REFRESH_PROPERTY, oldSpecifiedAlwaysRefresh, newSpecifiedAlwaysRefresh);	
	}
	
	
	public boolean isRefreshOnlyIfNewer() {
		return (this.specifiedRefreshOnlyIfNewer == null) ? this.defaultRefreshOnlyIfNewer : this.specifiedRefreshOnlyIfNewer.booleanValue();
	}
	
	public boolean isDefaultRefreshOnlyIfNewer() {
		return this.defaultRefreshOnlyIfNewer;
	}
	
	protected void setDefaultRefreshOnlyIfNewer(boolean newDefaultRefreshOnlyIfNewer) {
		boolean oldDefaultRefreshOnlyIfNewer = this.defaultRefreshOnlyIfNewer;
		this.defaultRefreshOnlyIfNewer = newDefaultRefreshOnlyIfNewer;
		firePropertyChanged(DEFAULT_REFRESH_ONLY_IF_NEWER_PROPERTY, oldDefaultRefreshOnlyIfNewer, newDefaultRefreshOnlyIfNewer);	
	}
	
	public Boolean getSpecifiedRefreshOnlyIfNewer() {
		return this.specifiedRefreshOnlyIfNewer;
	}
	
	public void setSpecifiedRefreshOnlyIfNewer(Boolean newSpecifiedRefreshOnlyIfNewer) {
		Boolean oldSpecifiedRefreshOnlyIfNewer = this.specifiedRefreshOnlyIfNewer;
		this.specifiedRefreshOnlyIfNewer = newSpecifiedRefreshOnlyIfNewer;
		if (oldSpecifiedRefreshOnlyIfNewer != newSpecifiedRefreshOnlyIfNewer) {
			if (this.getResourceCache() != null) {
				this.getResourceCache().setRefreshOnlyIfNewer(newSpecifiedRefreshOnlyIfNewer);						
				if (this.getResourceCache().isAllFeaturesUnset()) {
					removeResourceCache();
				}
			}
			else if (newSpecifiedRefreshOnlyIfNewer != null) {
				addResourceCache();
				getResourceCache().setRefreshOnlyIfNewer(newSpecifiedRefreshOnlyIfNewer);
			}
		}
		firePropertyChanged(SPECIFIED_REFRESH_ONLY_IF_NEWER_PROPERTY, oldSpecifiedRefreshOnlyIfNewer, newSpecifiedRefreshOnlyIfNewer);		
	}
	
	protected void setSpecifiedRefreshOnlyIfNewer_(Boolean newSpecifiedRefreshOnlyIfNewer) {
		Boolean oldSpecifiedRefreshOnlyIfNewer = this.specifiedRefreshOnlyIfNewer;
		this.specifiedRefreshOnlyIfNewer = newSpecifiedRefreshOnlyIfNewer;
		firePropertyChanged(SPECIFIED_REFRESH_ONLY_IF_NEWER_PROPERTY, oldSpecifiedRefreshOnlyIfNewer, newSpecifiedRefreshOnlyIfNewer);	
	}
	
	
	public boolean isDisableHits() {
		return (this.specifiedDisableHits == null) ? this.defaultDisableHits : this.specifiedDisableHits.booleanValue();
	}
	
	public boolean isDefaultDisableHits() {
		return this.defaultDisableHits;
	}
	
	protected void setDefaultDisableHits(boolean newDefaultDisableHits) {
		boolean oldDefaultDisableHits = this.defaultDisableHits;
		this.defaultDisableHits = newDefaultDisableHits;
		firePropertyChanged(DEFAULT_DISABLE_HITS_PROPERTY, oldDefaultDisableHits, newDefaultDisableHits);	
	}
	
	public Boolean getSpecifiedDisableHits() {
		return this.specifiedDisableHits;
	}
	
	public void setSpecifiedDisableHits(Boolean newSpecifiedDisableHits) {
		Boolean oldSpecifiedDisableHits = this.specifiedDisableHits;
		this.specifiedDisableHits = newSpecifiedDisableHits;
		if (oldSpecifiedDisableHits != newSpecifiedDisableHits) {
			if (this.getResourceCache() != null) {
				this.getResourceCache().setDisableHits(newSpecifiedDisableHits);						
				if (this.getResourceCache().isAllFeaturesUnset()) {
					removeResourceCache();
				}
			}
			else if (newSpecifiedDisableHits != null) {
				addResourceCache();
				getResourceCache().setDisableHits(newSpecifiedDisableHits);
			}
		}
		firePropertyChanged(SPECIFIED_DISABLE_HITS_PROPERTY, oldSpecifiedDisableHits, newSpecifiedDisableHits);		
	}
	
	protected void setSpecifiedDisableHits_(Boolean newSpecifiedDisableHits) {
		Boolean oldSpecifiedDisableHits = this.specifiedDisableHits;
		this.specifiedDisableHits = newSpecifiedDisableHits;
		firePropertyChanged(SPECIFIED_DISABLE_HITS_PROPERTY, oldSpecifiedDisableHits, newSpecifiedDisableHits);	
	}
	
	public CacheType getType() {
		return (this.specifiedType == null) ? this.defaultType : this.specifiedType;
	}

	public CacheType getDefaultType() {
		return this.defaultType;
	}
	
	protected void setDefaultType(CacheType newDefaultType) {
		CacheType oldDefaultType= this.defaultType;
		this.defaultType = newDefaultType;
		firePropertyChanged(DEFAULT_TYPE_PROPERTY, oldDefaultType, newDefaultType);				
	}
	
	public CacheType getSpecifiedType() {
		return this.specifiedType;
	}
	
	public void setSpecifiedType(CacheType newSpecifiedType) {
		CacheType oldSpecifiedType = this.specifiedType;
		this.specifiedType = newSpecifiedType;
		if (oldSpecifiedType != newSpecifiedType) {
			if (this.getResourceCache() != null) {
				this.getResourceCache().setType(CacheType.toOrmResourceModel(newSpecifiedType));						
				if (this.getResourceCache().isAllFeaturesUnset()) {
					removeResourceCache();
				}
			}
			else if (newSpecifiedType != null) {
				addResourceCache();
				getResourceCache().setType(CacheType.toOrmResourceModel(newSpecifiedType));
			}
		}
		firePropertyChanged(SPECIFIED_TYPE_PROPERTY, oldSpecifiedType, newSpecifiedType);		
	}
	
	protected void setSpecifiedType_(CacheType newSpecifiedType) {
		CacheType oldSpecifiedType= this.specifiedType;
		this.specifiedType = newSpecifiedType;
		firePropertyChanged(SPECIFIED_TYPE_PROPERTY, oldSpecifiedType, newSpecifiedType);		
	}
	
	
	public CacheCoordinationType getCoordinationType() {
		return (this.specifiedCoordinationType == null) ? this.defaultCoordinationType : this.specifiedCoordinationType;
	}
	
	public CacheCoordinationType getDefaultCoordinationType() {
		return this.defaultCoordinationType;
	}
	
	protected void setDefaultCoordinationType(CacheCoordinationType newDefaultcCoordinationType) {
		CacheCoordinationType oldDefaultcCoordinationType= this.defaultCoordinationType;
		this.defaultCoordinationType = newDefaultcCoordinationType;
		firePropertyChanged(DEFAULT_COORDINATION_TYPE_PROPERTY, oldDefaultcCoordinationType, newDefaultcCoordinationType);				
	}
	
	public CacheCoordinationType getSpecifiedCoordinationType() {
		return this.specifiedCoordinationType;
	}
	
	public void setSpecifiedCoordinationType(CacheCoordinationType newSpecifiedCoordinationType) {
		CacheCoordinationType oldSpecifiedCoordinationType = this.specifiedCoordinationType;
		this.specifiedCoordinationType = newSpecifiedCoordinationType;
		if (oldSpecifiedCoordinationType != newSpecifiedCoordinationType) {
			if (this.getResourceCache() != null) {
				this.getResourceCache().setCoordinationType(CacheCoordinationType.toOrmResourceModel(newSpecifiedCoordinationType));						
				if (this.getResourceCache().isAllFeaturesUnset()) {
					removeResourceCache();
				}
			}
			else if (newSpecifiedCoordinationType != null) {
				addResourceCache();
				getResourceCache().setCoordinationType(CacheCoordinationType.toOrmResourceModel(newSpecifiedCoordinationType));
			}
		}
		firePropertyChanged(SPECIFIED_COORDINATION_TYPE_PROPERTY, oldSpecifiedCoordinationType, newSpecifiedCoordinationType);		
	}
	
	protected void setSpecifiedCoordinationType_(CacheCoordinationType newSpecifiedCoordinationType) {
		CacheCoordinationType oldSpecifiedCoordinationType = this.specifiedCoordinationType;
		this.specifiedCoordinationType = newSpecifiedCoordinationType;
		firePropertyChanged(SPECIFIED_COORDINATION_TYPE_PROPERTY, oldSpecifiedCoordinationType, newSpecifiedCoordinationType);		
	}
	
	public ExistenceType getExistenceType() {
		return (this.specifiedExistenceType == null) ? this.defaultExistenceType : this.specifiedExistenceType;
	}
	
	public ExistenceType getDefaultExistenceType() {
		return this.defaultExistenceType;
	}
	
	protected void setDefaultExistenceType(ExistenceType newDefaultExistenceType) {
		ExistenceType oldDefaultExistenceType = this.defaultExistenceType;
		this.defaultExistenceType = newDefaultExistenceType;
		firePropertyChanged(DEFAULT_EXISTENCE_TYPE_PROPERTY, oldDefaultExistenceType, newDefaultExistenceType);
	}
	
	public ExistenceType getSpecifiedExistenceType() {
		return this.specifiedExistenceType;
	}
	
	public void setSpecifiedExistenceType(ExistenceType newSpecifiedExistenceType) {
		ExistenceType oldSpecifiedExistenceType = this.specifiedExistenceType;
		this.specifiedExistenceType = newSpecifiedExistenceType;
		this.resource.setExistenceChecking(ExistenceType.toOrmResourceModel(newSpecifiedExistenceType));
		firePropertyChanged(SPECIFIED_EXISTENCE_TYPE_PROPERTY, oldSpecifiedExistenceType, newSpecifiedExistenceType);			
	}
	
	protected void setSpecifiedExistenceType_(ExistenceType newSpecifiedExistenceType) {
		ExistenceType oldSpecifiedExistenceType = this.specifiedExistenceType;
		this.specifiedExistenceType = newSpecifiedExistenceType;
		firePropertyChanged(SPECIFIED_EXISTENCE_TYPE_PROPERTY, oldSpecifiedExistenceType, newSpecifiedExistenceType);		
	}	
	
	public Integer getExpiry() {
		return this.expiry;
	}
	
	public void setExpiry(Integer newExpiry) {
		Integer oldExpiry = this.expiry;
		this.expiry = newExpiry;
		if (oldExpiry != newExpiry) {
			if (this.getResourceCache() != null) {
				this.getResourceCache().setExpiry(newExpiry);						
				if (this.getResourceCache().isAllFeaturesUnset()) {
					removeResourceCache();
				}
			}
			else if (newExpiry != null) {
				addResourceCache();
				this.getResourceCache().setExpiry(newExpiry);						
			}
		}
		firePropertyChanged(EXPIRY_PROPERTY, oldExpiry, newExpiry);
		if (newExpiry != null && this.expiryTimeOfDay != null) {
			removeExpiryTimeOfDay();
		}
	}
	
	protected void setExpiry_(Integer newExpiry) {
		Integer oldExpiry = this.expiry;
		this.expiry = newExpiry;		
		firePropertyChanged(EXPIRY_PROPERTY, oldExpiry, newExpiry);
	}
	
	public ExpiryTimeOfDay getExpiryTimeOfDay() {
		return this.expiryTimeOfDay;
	}
	
	public ExpiryTimeOfDay addExpiryTimeOfDay() {
		if (this.expiryTimeOfDay != null) {
			throw new IllegalStateException("expiryTimeOfDay already exists, use getExpiryTimeOfDay()"); //$NON-NLS-1$
		}
		if (getResourceCache() == null) {
			addResourceCache();
		}
		EclipseLinkOrmExpiryTimeOfDay newExpiryTimeOfDay = new EclipseLinkOrmExpiryTimeOfDay(this);
		this.expiryTimeOfDay = newExpiryTimeOfDay;
		XmlTimeOfDay resourceTimeOfDay = EclipseLinkOrmFactory.eINSTANCE.createXmlTimeOfDay();
		newExpiryTimeOfDay.initialize(resourceTimeOfDay);
		getResourceCache().setExpiryTimeOfDay(resourceTimeOfDay);
		firePropertyChanged(EXPIRY_TIME_OF_DAY_PROPERTY, null, newExpiryTimeOfDay);
		setExpiry(null);
		return newExpiryTimeOfDay;
	}
	
	public void removeExpiryTimeOfDay() {
		if (this.expiryTimeOfDay == null) {
			throw new IllegalStateException("timeOfDayExpiry does not exist"); //$NON-NLS-1$
		}
		ExpiryTimeOfDay oldExpiryTimeOfDay = this.expiryTimeOfDay;
		this.expiryTimeOfDay = null;
		getResourceCache().setExpiryTimeOfDay(null);
		if (this.getResourceCache().isAllFeaturesUnset()) {
			removeResourceCache();
		}
		firePropertyChanged(EXPIRY_TIME_OF_DAY_PROPERTY, oldExpiryTimeOfDay, null);
	}
	
	protected void setExpiryTimeOfDay(EclipseLinkOrmExpiryTimeOfDay newExpiryTimeOfDay) {
		EclipseLinkOrmExpiryTimeOfDay oldExpiryTimeOfDay = this.expiryTimeOfDay;
		this.expiryTimeOfDay = newExpiryTimeOfDay;
		firePropertyChanged(EXPIRY_TIME_OF_DAY_PROPERTY, oldExpiryTimeOfDay, newExpiryTimeOfDay);
	}
	
	protected XmlCache getResourceCache() {
		return this.resource.getCache();
	}
	
	protected void addResourceCache() {
		this.resource.setCache(EclipseLinkOrmFactory.eINSTANCE.createXmlCache());		
	}
	
	protected void removeResourceCache() {
		this.resource.setCache(null);
	}
	
	
	// **************** initialize/update **************************************
	
	protected void initialize(XmlCacheHolder resource, JavaCaching javaCaching) {
		this.resource = resource;
		XmlCache resourceCache = getResourceCache();
		this.defaultSize = this.defaultSize(javaCaching);
		this.specifiedSize = getResourceSize(resourceCache);
		this.defaultShared = this.defaultShared(javaCaching);
		this.specifiedShared = this.getResourceShared(resourceCache);
		this.defaultAlwaysRefresh = this.defaultAlwaysRefresh(javaCaching);
		this.specifiedAlwaysRefresh = this.getResourceAlwaysRefresh(resourceCache);
		this.defaultRefreshOnlyIfNewer = this.defaultRefreshOnlyIfNewer(javaCaching);
		this.specifiedRefreshOnlyIfNewer = this.getResourceRefreshOnlyIfNewer(resourceCache);
		this.defaultDisableHits = this.defaultDisableHits(javaCaching);
		this.specifiedDisableHits = this.getResourceDisableHits(resourceCache);
		this.defaultType = this.defaultType(javaCaching);
		this.specifiedType = this.getResourceType(resourceCache);
		this.defaultCoordinationType = this.defaultCoordinationType(javaCaching);
		this.specifiedCoordinationType = this.getResourceCoordinationType(resourceCache);
		this.defaultExistenceType = this.defaultExistenceType(javaCaching);
		this.specifiedExistenceType = this.getResourceExistenceChecking();
		this.initializeExpiry(resourceCache);
	}

	protected void initializeExpiry(XmlCache resourceCache) {
		if (resourceCache == null) {
			return;
		}
		if (resourceCache.getExpiryTimeOfDay() == null) {
			this.expiry = resourceCache.getExpiry();
		}
		else {
			if (resourceCache.getExpiry() == null) { //handle with validation if both expiry and expiryTimeOfDay are set
				this.expiryTimeOfDay = new EclipseLinkOrmExpiryTimeOfDay(this);
				this.expiryTimeOfDay.initialize(resourceCache.getExpiryTimeOfDay());
			}
		}
	}

	protected void update(JavaCaching javaCaching) {
		XmlCache resourceCache = getResourceCache();
		setDefaultSize(this.defaultSize(javaCaching));
		setSpecifiedSize_(this.getResourceSize(resourceCache));
		setDefaultShared(this.defaultShared(javaCaching));
		setSpecifiedShared_(this.getResourceShared(resourceCache));
		setDefaultAlwaysRefresh(this.defaultAlwaysRefresh(javaCaching));
		setSpecifiedAlwaysRefresh_(this.getResourceAlwaysRefresh(resourceCache));
		setDefaultRefreshOnlyIfNewer(this.defaultRefreshOnlyIfNewer(javaCaching));
		setSpecifiedRefreshOnlyIfNewer_(this.getResourceRefreshOnlyIfNewer(resourceCache));
		setDefaultDisableHits(this.defaultDisableHits(javaCaching));
		setSpecifiedDisableHits_(this.getResourceDisableHits(resourceCache));
		setDefaultType(this.defaultType(javaCaching));
		setSpecifiedType_(this.getResourceType(resourceCache));
		setDefaultCoordinationType(this.defaultCoordinationType(javaCaching));
		setSpecifiedCoordinationType_(this.getResourceCoordinationType(resourceCache));
		setDefaultExistenceType(this.defaultExistenceType(javaCaching));
		setSpecifiedExistenceType_(this.getResourceExistenceChecking());
		this.updateExpiry(resourceCache);
	}
	
	protected void updateExpiry(XmlCache resourceCache) {
		if (resourceCache == null) {
			setExpiryTimeOfDay(null);
			setExpiry_(null);
			return;
		}
		if (resourceCache.getExpiryTimeOfDay() == null) {
			setExpiryTimeOfDay(null);
			setExpiry_(resourceCache.getExpiry());
		}
		else {
			if (this.expiryTimeOfDay != null) {
				this.expiryTimeOfDay.update(resourceCache.getExpiryTimeOfDay());
			}
			else if (resourceCache.getExpiry() == null){
				setExpiryTimeOfDay(new EclipseLinkOrmExpiryTimeOfDay(this));
				this.expiryTimeOfDay.initialize(resourceCache.getExpiryTimeOfDay());
			}
			else { //handle with validation if both expiry and expiryTimeOfDay are set
				setExpiryTimeOfDay(null);
			}
		}
	}
	
	protected int defaultSize(JavaCaching javaCaching) {
		return (javaCaching == null) ? DEFAULT_SIZE : javaCaching.getSize();
	}
	
	protected Integer getResourceSize(XmlCache resource) {
		return (resource == null) ? null : resource.getSize();
	}
	
	protected boolean defaultShared(JavaCaching javaCaching) {
		if (javaCaching == null) {
			return DEFAULT_SHARED;
		}
		return getResourceCache() == null ? javaCaching.isShared() : DEFAULT_SHARED;
	}
	
	protected Boolean getResourceShared(XmlCache resource) {
		return (resource == null) ? null : resource.getShared();
	}
	
	protected boolean defaultAlwaysRefresh(JavaCaching javaCaching) {
		if (javaCaching == null) {
			return DEFAULT_ALWAYS_REFRESH;
		}
		return getResourceCache() == null ? javaCaching.isAlwaysRefresh() : DEFAULT_ALWAYS_REFRESH;
	}
	
	protected Boolean getResourceAlwaysRefresh(XmlCache resource) {
		return (resource == null) ? null : resource.getAlwaysRefresh();
	}
	
	protected boolean defaultRefreshOnlyIfNewer(JavaCaching javaCaching) {
		if (javaCaching == null) {
			return DEFAULT_REFRESH_ONLY_IF_NEWER;
		}
		return getResourceCache() == null ? javaCaching.isRefreshOnlyIfNewer() : DEFAULT_REFRESH_ONLY_IF_NEWER;
	}
	
	protected Boolean getResourceRefreshOnlyIfNewer(XmlCache resource) {
		return (resource == null) ? null : resource.getRefreshOnlyIfNewer();
	}
	
	protected boolean defaultDisableHits(JavaCaching javaCaching) {
		if (javaCaching == null) {
			return DEFAULT_DISABLE_HITS;
		}
		return getResourceCache() == null ? javaCaching.isDisableHits() : DEFAULT_DISABLE_HITS;
	}
	
	protected Boolean getResourceDisableHits(XmlCache resource) {
		return (resource == null) ? null : resource.getDisableHits();
	}
	
	protected CacheType defaultType(JavaCaching javaCaching) {
		if (javaCaching == null) {
			return DEFAULT_TYPE;
		}
		return getResourceCache() == null ? javaCaching.getType() : DEFAULT_TYPE;
	}
	
	protected CacheType getResourceType(XmlCache resource) {
		return (resource == null) ? null : CacheType.fromOrmResourceModel(resource.getType());
	}
	
	protected CacheCoordinationType defaultCoordinationType(JavaCaching javaCaching) {
		if (javaCaching == null) {
			return DEFAULT_COORDINATION_TYPE;
		}
		return getResourceCache() == null ? javaCaching.getCoordinationType() : DEFAULT_COORDINATION_TYPE;
	}
	
	protected CacheCoordinationType getResourceCoordinationType(XmlCache resource) {
		return (resource == null) ? null : CacheCoordinationType.fromOrmResourceModel(resource.getCoordinationType());
	}
	
	protected ExistenceType defaultExistenceType(JavaCaching javaCaching) {
		return (javaCaching == null) ? DEFAULT_EXISTENCE_TYPE : javaCaching.getExistenceType();
	}
	
	protected ExistenceType getResourceExistenceChecking() {
		return (this.resource == null) ? null : ExistenceType.fromOrmResourceModel(this.resource.getExistenceChecking());
	}
	
	protected Integer getResourceExpiry(XmlCache resource) {
		return (resource == null) ? null : resource.getExpiry();
	}
	
	// **************** validation **************************************
	
	public TextRange getValidationTextRange() {
		XmlCache resource = getResourceCache();
		return resource == null ? null : resource.getValidationTextRange();
	}

}

Back to the top