/** * Copyright (c) 2012-2016 Marsha Chechik, Alessio Di Sandro, Michalis Famelis, * Rick Salay. * 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: * Alessio Di Sandro - Implementation. */ package edu.toronto.cs.se.modelepedia.relationaldatabase.impl; import edu.toronto.cs.se.modelepedia.relationaldatabase.Column; import edu.toronto.cs.se.modelepedia.relationaldatabase.ForeignKey; import edu.toronto.cs.se.modelepedia.relationaldatabase.RelationalDatabasePackage; import edu.toronto.cs.se.modelepedia.relationaldatabase.Table; import java.util.Collection; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.NotificationChain; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.InternalEObject; import org.eclipse.emf.ecore.impl.ENotificationImpl; import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList; import org.eclipse.emf.ecore.util.InternalEList; /** * <!-- begin-user-doc --> * An implementation of the model object '<em><b>Table</b></em>'. * <!-- end-user-doc --> * <p> * The following features are implemented: * <ul> * <li>{@link edu.toronto.cs.se.modelepedia.relationaldatabase.impl.TableImpl#getColumns <em>Columns</em>}</li> * <li>{@link edu.toronto.cs.se.modelepedia.relationaldatabase.impl.TableImpl#getPrimaryKey <em>Primary Key</em>}</li> * <li>{@link edu.toronto.cs.se.modelepedia.relationaldatabase.impl.TableImpl#getForeignKeys <em>Foreign Keys</em>}</li> * </ul> * </p> * * @generated */ public class TableImpl extends NamedElementImpl implements Table { /** * The cached value of the '{@link #getColumns() <em>Columns</em>}' containment reference list. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getColumns() * @generated * @ordered */ protected EList<Column> columns; /** * The cached value of the '{@link #getPrimaryKey() <em>Primary Key</em>}' reference. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getPrimaryKey() * @generated * @ordered */ protected Column primaryKey; /** * The cached value of the '{@link #getForeignKeys() <em>Foreign Keys</em>}' containment reference list. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @see #getForeignKeys() * @generated * @ordered */ protected EList<ForeignKey> foreignKeys; /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected TableImpl() { super(); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override protected EClass eStaticClass() { return RelationalDatabasePackage.Literals.TABLE; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EList<Column> getColumns() { if (columns == null) { columns = new EObjectContainmentWithInverseEList<Column>(Column.class, this, RelationalDatabasePackage.TABLE__COLUMNS, RelationalDatabasePackage.COLUMN__TABLE); } return columns; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Column getPrimaryKey() { if (primaryKey != null && primaryKey.eIsProxy()) { InternalEObject oldPrimaryKey = (InternalEObject)primaryKey; primaryKey = (Column)eResolveProxy(oldPrimaryKey); if (primaryKey != oldPrimaryKey) { if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.RESOLVE, RelationalDatabasePackage.TABLE__PRIMARY_KEY, oldPrimaryKey, primaryKey)); } } return primaryKey; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public Column basicGetPrimaryKey() { return primaryKey; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public NotificationChain basicSetPrimaryKey(Column newPrimaryKey, NotificationChain msgs) { Column oldPrimaryKey = primaryKey; primaryKey = newPrimaryKey; if (eNotificationRequired()) { ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, RelationalDatabasePackage.TABLE__PRIMARY_KEY, oldPrimaryKey, newPrimaryKey); if (msgs == null) msgs = notification; else msgs.add(notification); } return msgs; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public void setPrimaryKey(Column newPrimaryKey) { if (newPrimaryKey != primaryKey) { NotificationChain msgs = null; if (primaryKey != null) msgs = ((InternalEObject)primaryKey).eInverseRemove(this, RelationalDatabasePackage.COLUMN__TABLE_AS_PRIMARY_KEY, Column.class, msgs); if (newPrimaryKey != null) msgs = ((InternalEObject)newPrimaryKey).eInverseAdd(this, RelationalDatabasePackage.COLUMN__TABLE_AS_PRIMARY_KEY, Column.class, msgs); msgs = basicSetPrimaryKey(newPrimaryKey, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) eNotify(new ENotificationImpl(this, Notification.SET, RelationalDatabasePackage.TABLE__PRIMARY_KEY, newPrimaryKey, newPrimaryKey)); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ public EList<ForeignKey> getForeignKeys() { if (foreignKeys == null) { foreignKeys = new EObjectContainmentWithInverseEList<ForeignKey>(ForeignKey.class, this, RelationalDatabasePackage.TABLE__FOREIGN_KEYS, RelationalDatabasePackage.FOREIGN_KEY__TABLE); } return foreignKeys; } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case RelationalDatabasePackage.TABLE__COLUMNS: return ((InternalEList<InternalEObject>)(InternalEList<?>)getColumns()).basicAdd(otherEnd, msgs); case RelationalDatabasePackage.TABLE__PRIMARY_KEY: if (primaryKey != null) msgs = ((InternalEObject)primaryKey).eInverseRemove(this, RelationalDatabasePackage.COLUMN__TABLE_AS_PRIMARY_KEY, Column.class, msgs); return basicSetPrimaryKey((Column)otherEnd, msgs); case RelationalDatabasePackage.TABLE__FOREIGN_KEYS: return ((InternalEList<InternalEObject>)(InternalEList<?>)getForeignKeys()).basicAdd(otherEnd, msgs); } return super.eInverseAdd(otherEnd, featureID, msgs); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { switch (featureID) { case RelationalDatabasePackage.TABLE__COLUMNS: return ((InternalEList<?>)getColumns()).basicRemove(otherEnd, msgs); case RelationalDatabasePackage.TABLE__PRIMARY_KEY: return basicSetPrimaryKey(null, msgs); case RelationalDatabasePackage.TABLE__FOREIGN_KEYS: return ((InternalEList<?>)getForeignKeys()).basicRemove(otherEnd, msgs); } return super.eInverseRemove(otherEnd, featureID, msgs); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public Object eGet(int featureID, boolean resolve, boolean coreType) { switch (featureID) { case RelationalDatabasePackage.TABLE__COLUMNS: return getColumns(); case RelationalDatabasePackage.TABLE__PRIMARY_KEY: if (resolve) return getPrimaryKey(); return basicGetPrimaryKey(); case RelationalDatabasePackage.TABLE__FOREIGN_KEYS: return getForeignKeys(); } return super.eGet(featureID, resolve, coreType); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @SuppressWarnings("unchecked") @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case RelationalDatabasePackage.TABLE__COLUMNS: getColumns().clear(); getColumns().addAll((Collection<? extends Column>)newValue); return; case RelationalDatabasePackage.TABLE__PRIMARY_KEY: setPrimaryKey((Column)newValue); return; case RelationalDatabasePackage.TABLE__FOREIGN_KEYS: getForeignKeys().clear(); getForeignKeys().addAll((Collection<? extends ForeignKey>)newValue); return; } super.eSet(featureID, newValue); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case RelationalDatabasePackage.TABLE__COLUMNS: getColumns().clear(); return; case RelationalDatabasePackage.TABLE__PRIMARY_KEY: setPrimaryKey((Column)null); return; case RelationalDatabasePackage.TABLE__FOREIGN_KEYS: getForeignKeys().clear(); return; } super.eUnset(featureID); } /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public boolean eIsSet(int featureID) { switch (featureID) { case RelationalDatabasePackage.TABLE__COLUMNS: return columns != null && !columns.isEmpty(); case RelationalDatabasePackage.TABLE__PRIMARY_KEY: return primaryKey != null; case RelationalDatabasePackage.TABLE__FOREIGN_KEYS: return foreignKeys != null && !foreignKeys.isEmpty(); } return super.eIsSet(featureID); } } //TableImpl