Skip to main content
summaryrefslogtreecommitdiffstats
blob: df59739fc02820aa0718c03b259a7d241cddeb88 (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
/*******************************************************************************
* Copyright (c) 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.persistence.caching;

import java.io.Serializable;

import org.eclipse.jpt.eclipselink.core.context.persistence.caching.CacheType;
import org.eclipse.jpt.eclipselink.core.context.persistence.caching.Caching;
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.model.AbstractModel;

/**
 *  Entity
 */
public class Entity extends AbstractModel implements Cloneable, Serializable
{
	private String name;
	private Caching parent;

	public static final String CACHE_TYPE_PROPERTY = Caching.CACHE_TYPE_PROPERTY; //$NON-NLS-1$
	public static final String CACHE_SIZE_PROPERTY = Caching.CACHE_SIZE_PROPERTY; //$NON-NLS-1$
	public static final String SHARED_CACHE_PROPERTY = Caching.SHARED_CACHE_PROPERTY; //$NON-NLS-1$

	// ********** EclipseLink properties **********
	private CacheType cacheType;
	private Integer cacheSize;
	private Boolean cacheIsShared;

	private static final long serialVersionUID = 1L;

	// ********** constructors **********
	public Entity(Caching parent, String name) {
		this(parent);
		this.initialize(name);
	}
	
	private Entity(Caching parent) {
		this.parent = parent;
	}
	
	private void initialize(String name) {
		if(StringTools.stringIsEmpty(name)) {
			throw new IllegalArgumentException();
		}
		this.name = name;
	}

	// ********** behaviors **********
	@Override
	public boolean equals(Object o) {
		if(o == null) {
			return false;
		}
		Entity entity = (Entity) o;
		return (
			(this.cacheType == null ?
				entity.cacheType == null : this.cacheType.equals(entity.cacheType)) &&
			(this.cacheIsShared == null ?
				entity.cacheIsShared == null : this.cacheIsShared.equals(entity.cacheIsShared)) &&
			(this.cacheSize == null ?
				entity.cacheSize == null : this.cacheSize.equals(entity.cacheSize)));
	}
	
	 @Override
	 public Entity clone() {
		 try {
			 return (Entity)super.clone();
		 }
		 catch (CloneNotSupportedException ex) {
			 throw new InternalError();
		 }
	 }

	public boolean isEmpty() {
		return (this.cacheType == null) &&
					(this.cacheSize == null) &&
					(this.cacheIsShared == null);
	}
	
	public boolean entityNameIsValid() {
		return ! StringTools.stringIsEmpty(this.name);
	}

	public Caching getParent() {
		return this.parent;
	}
	
	// ********** name **********
	public String getName() {
		return name;
	}

	// ********** cacheType **********
	protected CacheType getCacheType() {
		return this.cacheType;
	}

	protected void setCacheType(CacheType cacheType) {
		CacheType old = this.cacheType;
		this.cacheType = cacheType;
		this.firePropertyChanged(CACHE_TYPE_PROPERTY, old, cacheType);
	}

	// ********** cacheSize **********
	protected Integer getCacheSize() {
		return this.cacheSize;
	}

	protected void setCacheSize(Integer cacheSize) {
		Integer old = this.cacheSize;
		this.cacheSize = cacheSize;
		this.firePropertyChanged(CACHE_SIZE_PROPERTY, old, cacheSize);
	}

	// ********** cacheIsShared **********
	protected Boolean cacheIsShared() {
		return this.cacheIsShared;
	}

	protected void setSharedCache(Boolean isShared) {
		Boolean old = this.cacheIsShared;
		this.cacheIsShared = isShared;
		this.firePropertyChanged(SHARED_CACHE_PROPERTY, old, isShared);
	}

	public void toString(StringBuilder sb) {
		sb.append("name: ");
		sb.append(this.name);
		sb.append(", cacheType: ");
		sb.append(this.cacheType);
		sb.append(", cacheSize: ");
		sb.append(this.cacheSize);
		sb.append(", cacheIsShared: ");
		sb.append(this.cacheIsShared);
	}
}

Back to the top