| /******************************************************************************* |
| * Copyright (c) 2010, 2011 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.core.internal.jpa2.context.orm; |
| |
| import java.util.List; |
| import org.eclipse.jpt.common.core.utility.TextRange; |
| import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinColumn; |
| import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinTable; |
| import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinTableRelationship; |
| import org.eclipse.jpt.jpa.core.context.ReadOnlyJoinTableRelationshipStrategy; |
| import org.eclipse.jpt.jpa.core.context.ReadOnlyRelationship; |
| import org.eclipse.jpt.jpa.core.context.ReadOnlyTable; |
| import org.eclipse.jpt.jpa.core.context.orm.OrmVirtualJoinTable; |
| import org.eclipse.jpt.jpa.core.context.orm.OrmVirtualJoinTableRelationshipStrategy; |
| import org.eclipse.jpt.jpa.core.internal.context.JoinColumnTextRangeResolver; |
| import org.eclipse.jpt.jpa.core.internal.context.JptValidator; |
| import org.eclipse.jpt.jpa.core.internal.context.MappingTools; |
| import org.eclipse.jpt.jpa.core.internal.context.TableTextRangeResolver; |
| import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNode; |
| import org.eclipse.jpt.jpa.core.jpa2.context.orm.OrmVirtualOverrideRelationship2_0; |
| import org.eclipse.wst.validation.internal.provisional.core.IMessage; |
| import org.eclipse.wst.validation.internal.provisional.core.IReporter; |
| |
| public class GenericOrmVirtualOverrideJoinTableRelationshipStrategy2_0 |
| extends AbstractOrmXmlContextNode |
| implements OrmVirtualJoinTableRelationshipStrategy, ReadOnlyTable.Owner |
| { |
| protected OrmVirtualJoinTable joinTable; |
| |
| |
| public GenericOrmVirtualOverrideJoinTableRelationshipStrategy2_0(OrmVirtualOverrideRelationship2_0 parent) { |
| super(parent); |
| } |
| |
| |
| // ********** synchronize/update ********** |
| |
| @Override |
| public void update() { |
| super.update(); |
| this.updateJoinTable(); |
| } |
| |
| |
| // ********** join table ********** |
| |
| public OrmVirtualJoinTable getJoinTable() { |
| return this.joinTable; |
| } |
| |
| protected void setJoinTable(OrmVirtualJoinTable joinTable) { |
| OrmVirtualJoinTable old = this.joinTable; |
| this.joinTable = joinTable; |
| this.firePropertyChanged(JOIN_TABLE_PROPERTY, old, joinTable); |
| } |
| |
| protected void updateJoinTable() { |
| ReadOnlyJoinTable overriddenJoinTable = this.getOverriddenJoinTable(); |
| if (overriddenJoinTable == null) { |
| if (this.joinTable != null) { |
| this.setJoinTable(null); |
| } |
| } else { |
| if ((this.joinTable != null) && (this.joinTable.getOverriddenTable() == overriddenJoinTable)) { |
| this.joinTable.update(); |
| } else { |
| this.setJoinTable(this.buildJoinTable(overriddenJoinTable)); |
| } |
| } |
| } |
| |
| protected ReadOnlyJoinTable getOverriddenJoinTable() { |
| ReadOnlyJoinTableRelationshipStrategy overriddenStrategy = this.getOverriddenStrategy(); |
| return (overriddenStrategy == null) ? null : overriddenStrategy.getJoinTable(); |
| } |
| |
| protected OrmVirtualJoinTable buildJoinTable(ReadOnlyJoinTable overriddenJoinTable) { |
| return this.getContextNodeFactory().buildOrmVirtualJoinTable(this, this, overriddenJoinTable); |
| } |
| |
| |
| // ********** misc ********** |
| |
| @Override |
| public OrmVirtualOverrideRelationship2_0 getParent() { |
| return (OrmVirtualOverrideRelationship2_0) super.getParent(); |
| } |
| |
| public OrmVirtualOverrideRelationship2_0 getRelationship() { |
| return this.getParent(); |
| } |
| |
| protected ReadOnlyJoinTableRelationshipStrategy getOverriddenStrategy() { |
| ReadOnlyJoinTableRelationship relationship = this.getOverriddenJoinTableRelationship(); |
| return (relationship == null) ? null : relationship.getJoinTableStrategy(); |
| } |
| |
| protected ReadOnlyJoinTableRelationship getOverriddenJoinTableRelationship() { |
| ReadOnlyRelationship relationship = this.resolveOverriddenRelationship(); |
| return (relationship instanceof ReadOnlyJoinTableRelationship) ? (ReadOnlyJoinTableRelationship) relationship : null; |
| } |
| |
| protected ReadOnlyRelationship resolveOverriddenRelationship() { |
| return this.getRelationship().resolveOverriddenRelationship(); |
| } |
| |
| public String getTableName() { |
| return this.joinTable.getName(); |
| } |
| |
| public String getJoinTableDefaultName() { |
| return MappingTools.buildJoinTableDefaultName(this.getRelationship()); |
| } |
| |
| |
| // ********** validation ********** |
| |
| @Override |
| public void validate(List<IMessage> messages, IReporter reporter) { |
| super.validate(messages, reporter); |
| if (this.joinTable != null) { |
| this.joinTable.validate(messages, reporter); |
| } |
| } |
| |
| public boolean validatesAgainstDatabase() { |
| return this.getRelationship().getTypeMapping().validatesAgainstDatabase(); |
| } |
| |
| public TextRange getValidationTextRange() { |
| return this.getRelationship().getValidationTextRange(); |
| } |
| |
| public JptValidator buildTableValidator(ReadOnlyTable table, TableTextRangeResolver textRangeResolver) { |
| return this.getRelationship().buildJoinTableValidator((ReadOnlyJoinTable) table, textRangeResolver); |
| } |
| |
| public JptValidator buildJoinTableJoinColumnValidator(ReadOnlyJoinColumn column, ReadOnlyJoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) { |
| return this.getRelationship().buildJoinTableJoinColumnValidator(column, owner, textRangeResolver); |
| } |
| |
| public JptValidator buildJoinTableInverseJoinColumnValidator(ReadOnlyJoinColumn column, ReadOnlyJoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) { |
| return this.getRelationship().buildJoinTableInverseJoinColumnValidator(column, owner, textRangeResolver); |
| } |
| } |