Skip to main content
summaryrefslogtreecommitdiffstats
blob: b583525f41fa4947db625bd5bad2aed1877c7ced (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
/*******************************************************************************
 * Copyright (c) 2006, 2007 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.core.internal;

import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.resources.IResource;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.jpt.db.internal.ConnectionProfile;
import org.eclipse.jpt.db.internal.Database;

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 *
 * @see org.eclipse.jpt.core.internal.JpaCorePackage#getJpaEObject()
 * @model kind="class" abstract="true"
 * @generated
 */
public abstract class JpaEObject extends EObjectImpl implements IJpaEObject
{
	/**
	 * Sets of "insignificant" feature ids, keyed by class.
	 * This is built up lazily, as the objects are modified.
	 */
	private static final Map<Class<? extends JpaEObject>, Set<Integer>> insignificantFeatureIdSets = new Hashtable<Class<? extends JpaEObject>, Set<Integer>>();

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected JpaEObject() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return JpaCorePackage.Literals.JPA_EOBJECT;
	}

	public IJpaProject getJpaProject() {
		IJpaEObject container = (IJpaEObject) this.eContainer();
		return (container == null) ? null : container.getJpaProject();
	}

	public IResource getResource() {
		return this.getJpaProject().project();
	}

	public IJpaPlatform jpaPlatform() {
		return getJpaProject().jpaPlatform();
	}

	public IJpaFactory jpaFactory() {
		return jpaPlatform().getJpaFactory();
	}

	public ConnectionProfile connectionProfile() {
		return this.getJpaProject().connectionProfile();
	}

	public Database database() {
		return this.connectionProfile().getDatabase();
	}

	public boolean isConnected() {
		ConnectionProfile cp = this.connectionProfile();
		return (cp != null) && cp.isConnected();
	}

	// ********** change notification **********
	/**
	 * override to prevent notification when the object's state is unchanged
	 */
	@Override
	public void eNotify(Notification notification) {
		if (!notification.isTouch()) {
			super.eNotify(notification);
			this.featureChanged(notification.getFeatureID(this.getClass()));
		}
	}

	protected void featureChanged(int featureId) {
		if (this.featureIsSignificant(featureId)) {
			IJpaProject project = this.getJpaProject();
			// check that the model is fully initialized
			if (project != null) {
				project.update();
			}
		}
	}

	protected boolean featureIsSignificant(int featureId) {
		return !this.featureIsInsignificant(featureId);
	}

	protected boolean featureIsInsignificant(int featureId) {
		return this.insignificantFeatureIds().contains(featureId);
	}

	/**
	 * Return a set of the object's "insignificant" feature ids.
	 * These are the EMF features that, when they change, will NOT cause the
	 * object (or its containing tree) to be resynched, i.e. defaults calculated.
	 * If you need instance-based calculation of your "insignificant" aspects,
	 * override this method. If class-based calculation is sufficient,
	 * override #addInsignificantFeatureIdsTo(Set).
	 */
	protected Set<Integer> insignificantFeatureIds() {
		synchronized (insignificantFeatureIdSets) {
			Set<Integer> insignificantFeatureIds = insignificantFeatureIdSets.get(this.getClass());
			if (insignificantFeatureIds == null) {
				insignificantFeatureIds = new HashSet<Integer>();
				this.addInsignificantFeatureIdsTo(insignificantFeatureIds);
				insignificantFeatureIdSets.put(this.getClass(), insignificantFeatureIds);
			}
			return insignificantFeatureIds;
		}
	}

	/**
	 * Add the object's "insignificant" feature ids to the specified set.
	 * These are the EMF features that, when they change, will NOT cause the
	 * object (or its containing tree) to be resynched, i.e. defaults calculated.
	 * If class-based calculation of your "insignificant" features is sufficient,
	 * override this method. If you need instance-based calculation,
	 * override #insignificantFeatureIds().
	 */
	protected void addInsignificantFeatureIdsTo(Set<Integer> insignificantFeatureIds) {
	// when you override this method, don't forget to include:
	//	super.addInsignificantFeatureIdsTo(insignificantFeatureIds);
	}
}

Back to the top