blob: a03b8b1557ec526b33b9a1389e3d31049cf5be88 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2008, 2010 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.jpa.eclipselink.core.internal.context.orm;
import java.util.List;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable;
import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmMappedSuperclass;
import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmCacheable2_0;
import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmCacheableHolder2_0;
import org.eclipse.jpt.jpa.core.resource.orm.v2_0.XmlCacheable_2_0;
import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkChangeTracking;
import org.eclipse.jpt.jpa.eclipselink.core.context.EclipseLinkCustomizer;
import org.eclipse.jpt.jpa.eclipselink.core.context.java.JavaEclipseLinkMappedSuperclass;
import org.eclipse.jpt.jpa.eclipselink.core.context.orm.OrmEclipseLinkCaching;
import org.eclipse.jpt.jpa.eclipselink.core.context.orm.OrmEclipseLinkConverterContainer;
import org.eclipse.jpt.jpa.eclipselink.core.context.orm.OrmEclipseLinkMappedSuperclass;
import org.eclipse.jpt.jpa.eclipselink.core.internal.v1_1.context.EclipseLinkMappedSuperclassPrimaryKeyValidator;
import org.eclipse.jpt.jpa.eclipselink.core.internal.v1_1.context.EclipseLinkMappedSuperclassValidator;
import org.eclipse.jpt.jpa.eclipselink.core.resource.orm.XmlMappedSuperclass;
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
/**
* EclipseLink
* <code>orm.xml</code> mapped superclass
*/
public class OrmEclipseLinkMappedSuperclassImpl
extends AbstractOrmMappedSuperclass<XmlMappedSuperclass>
implements OrmEclipseLinkMappedSuperclass, OrmCacheableHolder2_0
{
protected final OrmEclipseLinkReadOnly readOnly;
protected final OrmEclipseLinkCustomizer customizer;
protected final OrmEclipseLinkChangeTracking changeTracking;
protected final OrmEclipseLinkCaching caching;
protected final OrmEclipseLinkConverterContainer converterContainer;
public OrmEclipseLinkMappedSuperclassImpl(OrmPersistentType parent, XmlMappedSuperclass xmlMappedSuperclass) {
super(parent, xmlMappedSuperclass);
this.caching = this.buildCaching();
this.readOnly = this.buildReadOnly();
this.converterContainer = this.buildConverterContainer();
this.changeTracking = this.buildChangeTracking();
this.customizer = this.buildCustomizer();
}
// ********** synchronize/update **********
@Override
public void synchronizeWithResourceModel() {
super.synchronizeWithResourceModel();
this.caching.synchronizeWithResourceModel();
this.readOnly.synchronizeWithResourceModel();
this.converterContainer.synchronizeWithResourceModel();
this.changeTracking.synchronizeWithResourceModel();
this.customizer.synchronizeWithResourceModel();
}
@Override
public void update() {
super.update();
this.caching.update();
this.readOnly.update();
this.converterContainer.update();
this.changeTracking.update();
this.customizer.update();
}
// ********** caching **********
public OrmEclipseLinkCaching getCaching() {
return this.caching;
}
protected OrmEclipseLinkCaching buildCaching() {
return new OrmEclipseLinkCachingImpl(this);
}
// ********** read only **********
public OrmEclipseLinkReadOnly getReadOnly() {
return this.readOnly;
}
protected OrmEclipseLinkReadOnly buildReadOnly() {
return new OrmEclipseLinkReadOnly(this);
}
// ********** converter container **********
public OrmEclipseLinkConverterContainer getConverterContainer() {
return this.converterContainer;
}
protected OrmEclipseLinkConverterContainer buildConverterContainer() {
return new OrmEclipseLinkConverterContainerImpl(this, this.xmlTypeMapping);
}
// ********** change tracking **********
public EclipseLinkChangeTracking getChangeTracking() {
return this.changeTracking;
}
protected OrmEclipseLinkChangeTracking buildChangeTracking() {
return new OrmEclipseLinkChangeTracking(this);
}
// ********** customizer **********
public EclipseLinkCustomizer getCustomizer() {
return this.customizer;
}
protected OrmEclipseLinkCustomizer buildCustomizer() {
return new OrmEclipseLinkCustomizer(this);
}
// ********** misc **********
@Override
public JavaEclipseLinkMappedSuperclass getJavaTypeMapping() {
return (JavaEclipseLinkMappedSuperclass) super.getJavaTypeMapping();
}
@Override
public JavaEclipseLinkMappedSuperclass getJavaTypeMappingForDefaults() {
return (JavaEclipseLinkMappedSuperclass) super.getJavaTypeMappingForDefaults();
}
public boolean usesPrimaryKeyColumns() {
return (this.getXmlTypeMapping().getPrimaryKey() != null)
|| this.usesJavaPrimaryKeyColumns();
}
protected boolean usesJavaPrimaryKeyColumns() {
JavaEclipseLinkMappedSuperclass javaMappedSuperclass = this.getJavaTypeMappingForDefaults();
return (javaMappedSuperclass != null) && javaMappedSuperclass.usesPrimaryKeyColumns();
}
public OrmCacheable2_0 getCacheable() {
return this.getCacheableHolder().getCacheable();
}
public boolean calculateDefaultCacheable() {
return this.getCacheableHolder().calculateDefaultCacheable();
}
protected OrmCacheableHolder2_0 getCacheableHolder() {
return (OrmCacheableHolder2_0) this.caching;
}
public XmlCacheable_2_0 getXmlCacheable() {
return this.getXmlTypeMapping();
}
// ********** refactoring **********
@Override
@SuppressWarnings("unchecked")
public Iterable<ReplaceEdit> createRenameTypeEdits(IType originalType, String newName) {
return new CompositeIterable<ReplaceEdit>(
super.createRenameTypeEdits(originalType, newName),
this.createCustomizerRenameTypeEdits(originalType, newName),
this.createConverterHolderRenameTypeEdits(originalType, newName)
);
}
protected Iterable<ReplaceEdit> createCustomizerRenameTypeEdits(IType originalType, String newName) {
return this.customizer.createRenameTypeEdits(originalType, newName);
}
protected Iterable<ReplaceEdit> createConverterHolderRenameTypeEdits(IType originalType, String newName) {
return this.converterContainer.createRenameTypeEdits(originalType, newName);
}
@Override
@SuppressWarnings("unchecked")
public Iterable<ReplaceEdit> createMoveTypeEdits(IType originalType, IPackageFragment newPackage) {
return new CompositeIterable<ReplaceEdit>(
super.createMoveTypeEdits(originalType, newPackage),
this.createCustomizerMoveTypeEdits(originalType, newPackage),
this.createConverterHolderMoveTypeEdits(originalType, newPackage)
);
}
protected Iterable<ReplaceEdit> createCustomizerMoveTypeEdits(IType originalType, IPackageFragment newPackage) {
return this.customizer.createMoveTypeEdits(originalType, newPackage);
}
protected Iterable<ReplaceEdit> createConverterHolderMoveTypeEdits(IType originalType, IPackageFragment newPackage) {
return this.converterContainer.createMoveTypeEdits(originalType, newPackage);
}
@Override
@SuppressWarnings("unchecked")
public Iterable<ReplaceEdit> createRenamePackageEdits(IPackageFragment originalPackage, String newName) {
return new CompositeIterable<ReplaceEdit>(
super.createRenamePackageEdits(originalPackage, newName),
this.createCustomizerRenamePackageEdits(originalPackage, newName),
this.createConverterHolderRenamePackageEdits(originalPackage, newName)
);
}
protected Iterable<ReplaceEdit> createCustomizerRenamePackageEdits(IPackageFragment originalPackage, String newName) {
return this.customizer.createRenamePackageEdits(originalPackage, newName);
}
protected Iterable<ReplaceEdit> createConverterHolderRenamePackageEdits(IPackageFragment originalPackage, String newName) {
return this.converterContainer.createRenamePackageEdits(originalPackage, newName);
}
// ********** validation **********
@Override
public void validate(List<IMessage> messages, IReporter reporter) {
super.validate(messages, reporter);
this.caching.validate(messages, reporter);
this.readOnly.validate(messages, reporter);
this.converterContainer.validate(messages, reporter);
this.changeTracking.validate(messages, reporter);
this.customizer.validate(messages, reporter);
}
@Override
protected JptValidator buildPrimaryKeyValidator() {
return new EclipseLinkMappedSuperclassPrimaryKeyValidator(this, this.buildTextRangeResolver());
}
@Override
protected JptValidator buildTypeMappingValidator() {
return new EclipseLinkMappedSuperclassValidator(this, this.getJavaResourcePersistentType(), this.buildTextRangeResolver());
}
}