| /******************************************************************************* |
| * 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.core.internal.jpa2.context.orm; |
| |
| import org.eclipse.jpt.core.context.FetchType; |
| import org.eclipse.jpt.core.context.Fetchable; |
| import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; |
| import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; |
| import org.eclipse.jpt.core.internal.context.orm.AbstractOrmAttributeMapping; |
| import org.eclipse.jpt.core.jpa2.MappingKeys2_0; |
| import org.eclipse.jpt.core.jpa2.context.orm.OrmElementCollectionMapping2_0; |
| import org.eclipse.jpt.core.resource.orm.Attributes; |
| import org.eclipse.jpt.core.resource.orm.XmlElementCollection; |
| |
| |
| public class GenericOrmElementCollectionMapping2_0 |
| extends AbstractOrmAttributeMapping<XmlElementCollection> |
| implements OrmElementCollectionMapping2_0 |
| { |
| |
| protected FetchType specifiedFetch; |
| |
| public GenericOrmElementCollectionMapping2_0(OrmPersistentAttribute parent, XmlElementCollection resourceMapping) { |
| super(parent, resourceMapping); |
| this.specifiedFetch = this.getResourceFetch(); |
| } |
| |
| @Override |
| public void update() { |
| super.update(); |
| this.setSpecifiedFetch_(this.getResourceFetch()); |
| } |
| |
| //************* AttributeMapping implementation *************** |
| |
| public String getKey() { |
| return MappingKeys2_0.ELEMENT_COLLECTION_ATTRIBUTE_MAPPING_KEY; |
| } |
| |
| //************* OrmAttributeMapping implementation *************** |
| public void initializeOn(OrmAttributeMapping newMapping) { |
| newMapping.initializeFromOrmAttributeMapping(this); |
| } |
| |
| public int getXmlSequence() { |
| return 75; |
| } |
| |
| public void addToResourceModel(Attributes resourceAttributes) { |
| resourceAttributes.getElementCollections().add(this.resourceAttributeMapping); |
| } |
| |
| public void removeFromResourceModel(Attributes resourceAttributes) { |
| resourceAttributes.getElementCollections().remove(this.resourceAttributeMapping); |
| } |
| |
| |
| //************* Fetchable ************* |
| |
| public FetchType getFetch() { |
| return (this.getSpecifiedFetch() == null) ? this.getDefaultFetch() : this.getSpecifiedFetch(); |
| } |
| |
| public FetchType getDefaultFetch() { |
| return DEFAULT_FETCH_TYPE; |
| } |
| |
| public FetchType getSpecifiedFetch() { |
| return this.specifiedFetch; |
| } |
| |
| public void setSpecifiedFetch(FetchType newSpecifiedFetch) { |
| FetchType oldFetch = this.specifiedFetch; |
| this.specifiedFetch = newSpecifiedFetch; |
| this.resourceAttributeMapping.setFetch(FetchType.toOrmResourceModel(newSpecifiedFetch)); |
| firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); |
| } |
| |
| protected void setSpecifiedFetch_(FetchType newSpecifiedFetch) { |
| FetchType oldFetch = this.specifiedFetch; |
| this.specifiedFetch = newSpecifiedFetch; |
| firePropertyChanged(Fetchable.SPECIFIED_FETCH_PROPERTY, oldFetch, newSpecifiedFetch); |
| } |
| |
| protected FetchType getResourceFetch() { |
| return FetchType.fromOrmResourceModel(this.resourceAttributeMapping.getFetch()); |
| } |
| |
| } |