FileDocCategorySizeDatePackage
MappingRelationshipElementImpl.javaAPI DocGlassfish v2 API12488Fri May 04 22:34:44 BST 2007com.sun.jdo.api.persistence.model.mapping.impl

MappingRelationshipElementImpl

public class MappingRelationshipElementImpl extends MappingFieldElementImpl implements MappingRelationshipElement
author
Mark Munro
author
Rochelle Raccah
version
%I%

Fields Summary
private ArrayList
_associatedColumns
private transient ArrayList
_associatedColumnObjects
Constructors Summary
public MappingRelationshipElementImpl()
Create new MappingRelationshipElementImpl with no corresponding name or declaring class. This constructor should only be used for cloning and archiving.

		this(null, null);
	
public MappingRelationshipElementImpl(String name, MappingClassElement declaringClass)
Create new MappingRelationshipElementImpl with the corresponding name and declaring class.

param
name the name of the element
param
declaringClass the class to attach to

		super(name, declaringClass);
		setFetchGroupInternal(GROUP_NONE);
	
Methods Summary
public voidaddAssociatedColumn(ColumnPairElement column)
Adds a column to the list of associated columns mapped by this mapping field. Call this method instead of addColumn when mapping join tables. This method is used to map between the join table column and the foreign table column, while addLocalColumn is used to map between the local table and the join table.

param
column column pair element to be added to the mapping
exception
ModelException if impossible
see
MappingFieldElement#addColumn
see
#addLocalColumn

		if (column != null)
		{
			ArrayList columns = getAssociatedColumns();
			String columnName = NameUtil.getRelativeMemberName(
				column.getName().getFullName());

			// double check that this pair is not already in the column list
			if (!columns.contains(columnName))
			{
				try
				{
					fireVetoableChange(PROP_ASSOCIATED_COLUMNS, null, null);
					columns.add(columnName);
					firePropertyChange(PROP_ASSOCIATED_COLUMNS, null, null);

					// sync up runtime's object list too
					_associatedColumnObjects = null;
				}
				catch (PropertyVetoException e)
				{
					throw new ModelVetoException(e);
				}
			}
			else
			{
				throw new ModelException(I18NHelper.getMessage(getMessages(),
					"mapping.column.column_defined", columnName));	// NOI18N
			}
		}
		else
		{
			throw new ModelException(I18NHelper.getMessage(getMessages(),
				"mapping.element.null_argument"));					// NOI18N
		}
	
public voidaddColumn(DBMemberElement column)
Adds a column to the list of columns mapped by this mapping relationship. This method overrides the one in MappingFieldElement to check that the argument is a ColumnPairElement.

param
column column element to be added to the mapping
exception
ModelException if impossible

		if (column instanceof ColumnPairElement)
		{
			if (!getAssociatedColumns().isEmpty())
			{
				throw new ModelException(I18NHelper.getMessage(getMessages(),
					"mapping.column.associated_columns_defined", 		// NOI18N
					NameUtil.getRelativeMemberName(
					column.getName().getFullName())));
			}

			super.addColumn(column);
		}
		else
		{
			throw new ModelException(I18NHelper.getMessage(getMessages(),
				"mapping.column.column_invalid", 			// NOI18N
				NameUtil.getRelativeMemberName(
				column.getName().getFullName())));
		}
	
public voidaddLocalColumn(ColumnPairElement column)
Adds a column to the list of columns mapped by this mapping field. Call this method instead of addColumn when mapping join tables. This method is used to map between the local column and the join table, while addAssociatedColumn is used to map between the join table and the foreign table.

param
column column pair element to be added to the mapping
exception
ModelException if impossible
see
MappingFieldElement#addColumn
see
#addAssociatedColumn

		// can't call addColumn in this class because there will be an 
		// exception since the associated columns will be (legally) populated
		super.addColumn(column);
	
public java.util.ArrayListgetAssociatedColumnObjects()
Returns the list of associated columns (ColumnPairElements) to which this mapping field is mapped. This is used for join tables. This method should only be used by the runtime.

return
the columns mapped by this mapping field
see
MappingFieldElement#getColumns

		if (_associatedColumnObjects == null)
		{
			_associatedColumnObjects = MappingClassElementImpl. 
				toColumnObjects(getDeclaringClass().getDatabaseRoot(), 
				getAssociatedColumns());
		}

		return _associatedColumnObjects;
	
public java.util.ArrayListgetAssociatedColumns()
Returns the list of associated column names to which this mapping field is mapped. This is used for join tables.

return
the names of the columns mapped by this mapping field
see
MappingFieldElement#getColumns

		if (_associatedColumns == null)
			_associatedColumns = new ArrayList();

		return _associatedColumns;
	
public intgetDeleteAction()
Get the delete action for this relationship element.

return
the delete action, one of {@link RelationshipElement#NONE_ACTION}, {@link RelationshipElement#NULLIFY_ACTION}, {@link RelationshipElement#RESTRICT_ACTION}, {@link RelationshipElement#CASCADE_ACTION}, or {@link RelationshipElement#AGGREGATE_ACTION}

		return getRelationshipElement().getDeleteAction();
	
public java.lang.StringgetElementClass()
Get the element class for this relationship element. If primitive types are supported, you can use wrapperclass.TYPE to specify them.

return
the element class

		return getRelationshipElement().getElementClass();
	
public intgetLowerBound()
Get the lower cardinality bound for this relationship element.

return
the lower cardinality bound

		return getRelationshipElement().getLowerBound();
	
final com.sun.jdo.api.persistence.model.jdo.RelationshipElementgetRelationshipElement()

		return ((MappingClassElementImpl)getDeclaringClass()).
			getPersistenceElement().getRelationship(getName());
	
public intgetUpdateAction()
Get the update action for this relationship element.

return
the update action, one of {@link RelationshipElement#NONE_ACTION}, {@link RelationshipElement#NULLIFY_ACTION}, {@link RelationshipElement#RESTRICT_ACTION}, {@link RelationshipElement#CASCADE_ACTION}, or {@link RelationshipElement#AGGREGATE_ACTION}

		return getRelationshipElement().getUpdateAction();
	
public intgetUpperBound()
Get the upper cardinality bound for this relationship element. Returns {@link java.lang.Integer#MAX_VALUE} for n

return
the upper cardinality bound

		return getRelationshipElement().getUpperBound();
	
public voidremoveColumn(java.lang.String columnName)
Removes a column from the list of columns mapped by this mapping field. This method overrides the one in MappingFieldElement to remove the argument from the associated columns if necessary.

param
columnName the relative name of the column to be removed from the mapping
exception
ModelException if impossible

		try
		{
			super.removeColumn(columnName);
		}
		catch (ModelException e)	// not found in regular columns
		{
			try
			{
				fireVetoableChange(PROP_ASSOCIATED_COLUMNS, null, null);

				if (!getAssociatedColumns().remove(columnName))
				{
					throw new ModelException(
						I18NHelper.getMessage(getMessages(),
						"mapping.element.element_not_removed",		// NOI18N
						columnName));
				}

				firePropertyChange(PROP_ASSOCIATED_COLUMNS, null, null);

				// sync up runtime's object list too
				_associatedColumnObjects = null;
			}
			catch (PropertyVetoException ve)
			{
				throw new ModelVetoException(ve);
			}
		}
	
public voidsetAssociatedColumns(java.util.ArrayList associatedColumns)
Set the list of associated column names to which this mapping field is mapped. This method should only be used internally and for cloning and archiving.

param
associatedColumns the list of names of the columns mapped by this mapping field

		_associatedColumns = associatedColumns;
	
protected voidstripSchemaName()
Boston to Pilsen conversion. This method converts the absolute column names to relative names.

		// call super to handle the columns stored in _columns
		super.stripSchemaName();

		// handle _associatedColumns
		if (_associatedColumns != null)
		{
			// Use ListIterator here, because I want to replace the value 
			// stored in the ArrayList.  The ListIterator returned by 
			// ArrayList.listIterator() supports the set method.
			ListIterator i = _associatedColumns.listIterator(); 

			while (i.hasNext())
				i.set(NameUtil.getRelativeMemberName((String)i.next()));
		}