/*******************************************************************************
* Copyright (c) 2007, 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.context.orm;
import java.util.List;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.jpa.core.context.ReadOnlyBaseJoinColumn;
import org.eclipse.jpt.jpa.core.context.ReadOnlyNamedColumn;
import org.eclipse.jpt.jpa.core.context.XmlContextNode;
import org.eclipse.jpt.jpa.core.context.orm.OrmNamedColumn;
import org.eclipse.jpt.jpa.core.context.orm.OrmReadOnlyNamedColumn;
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
import org.eclipse.jpt.jpa.core.internal.context.NamedColumnTextRangeResolver;
import org.eclipse.jpt.jpa.core.resource.orm.AbstractXmlNamedColumn;
import org.eclipse.jpt.jpa.core.resource.orm.XmlNamedColumn;
import org.eclipse.jpt.jpa.db.Column;
import org.eclipse.jpt.jpa.db.Table;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
/**
* orm.xml
null
if XML column does not exists.
*/
public abstract X getXmlColumn();
/**
* see class comment...
*/
protected void setXmlColumn(X xmlColumn) {
if (xmlColumn != null) {
throw new IllegalArgumentException("this method must be overridden if the XML column is not null: " + xmlColumn); //$NON-NLS-1$
}
}
/**
* Build the XML column if it does not exist.
*/
protected X getXmlColumnForUpdate() {
X xmlColumn = this.getXmlColumn();
return (xmlColumn != null) ? xmlColumn : this.buildXmlColumn();
}
protected abstract X buildXmlColumn();
protected void removeXmlColumnIfUnset() {
if (this.getXmlColumn().isUnset()) {
this.removeXmlColumn();
}
}
protected abstract void removeXmlColumn();
// ********** name **********
public String getName() {
return (this.specifiedName != null) ? this.specifiedName : this.defaultName;
}
public String getSpecifiedName() {
return this.specifiedName;
}
public void setSpecifiedName(String name) {
if (this.valuesAreDifferent(this.specifiedName, name)) {
X xmlColumn = this.getXmlColumnForUpdate();
this.setSpecifiedName_(name);
xmlColumn.setName(name);
this.removeXmlColumnIfUnset();
}
}
protected void setSpecifiedName_(String name) {
String old = this.specifiedName;
this.specifiedName = name;
this.firePropertyChanged(SPECIFIED_NAME_PROPERTY, old, name);
}
protected String buildSpecifiedName() {
X xmlColumn = this.getXmlColumn();
return (xmlColumn == null) ? null : xmlColumn.getName();
}
public String getDefaultName() {
return this.defaultName;
}
protected void setDefaultName(String name) {
String old = this.defaultName;
this.defaultName = name;
this.firePropertyChanged(DEFAULT_NAME_PROPERTY, old, name);
}
protected String buildDefaultName() {
return this.owner.getDefaultColumnName();
}
// ********** column definition **********
public String getColumnDefinition() {
return this.columnDefinition;
}
public void setColumnDefinition(String columnDefinition) {
if (this.valuesAreDifferent(this.columnDefinition, columnDefinition)) {
X xmlColumn = this.getXmlColumnForUpdate();
this.setColumnDefinition_(columnDefinition);
xmlColumn.setColumnDefinition(columnDefinition);
this.removeXmlColumnIfUnset();
}
}
protected void setColumnDefinition_(String columnDefinition) {
String old = this.columnDefinition;
this.columnDefinition = columnDefinition;
this.firePropertyChanged(COLUMN_DEFINITION_PROPERTY, old, columnDefinition);
}
protected String buildColumnDefinition() {
X xmlColumn = this.getXmlColumn();
return (xmlColumn == null) ? null : xmlColumn.getColumnDefinition();
}
// ********** database stuff **********
protected Column getDbColumn() {
Table table = this.getDbTable();
return (table == null) ? null : table.getColumnForIdentifier(this.getName());
}
public Table getDbTable() {
return this.owner.resolveDbTable(this.getTable());
}
/**
* Return the name of the column's table. This is overridden in
* {@link AbstractOrmBaseColumn} (and other places) where a table can be
* defined.
*/
public String getTable() {
return this.owner.getTypeMapping().getPrimaryTableName();
}
public boolean isResolved() {
return this.getDbColumn() != null;
}
// ********** validation **********
@Override
public void validate(List