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

MappingFieldElementImpl

public class MappingFieldElementImpl extends MappingMemberElementImpl implements MappingFieldElement
author
Mark Munro
author
Rochelle Raccah
version
%I%

Fields Summary
private ArrayList
_columns
private transient ArrayList
_columnObjects
private int
_fetchGroup
private int
_properties
private boolean
_isVersion
Version field flag of the field element.
public static final int
CLONE_FIELD
public static final int
CLONE_DEEP
public static final int
CLONE_MASK
public static final int
LOG_ON_ACCESS
public static final int
LOG_ON_MASK
public static final int
LOG_ON_UPDATE
public static final int
MOD_BI_ON_UPDATE
public static final int
OBSERVE_ON_ACCESS
public static final int
RECORD_ON_UPDATE
public static final int
SEND_BEFORE_IMAGE
public static final int
READ_ONLY
public static final int
REF_INTEGRITY_UPDATES
public static final int
IN_CONCURRENCY_CHECK
public static final int
XLATE_FIELD
Constructors Summary
public MappingFieldElementImpl()
Create new MappingFieldElementImpl with no corresponding name or declaring class. This constructor should only be used for cloning and archiving.


	                     	 
	  
	
		this(null, null);
	
public MappingFieldElementImpl(String name, MappingClassElement declaringClass)
Create new MappingFieldElementImpl 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_DEFAULT);
	
Methods Summary
public voidaddColumn(org.netbeans.modules.dbschema.DBMemberElement column)
Adds a column to the list of columns mapped by this mapping field.

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

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

			if (!columns.contains(columnName))
			{
				try
				{
					fireVetoableChange(PROP_COLUMNS, null, null);
					columns.add(columnName);
					firePropertyChange(PROP_COLUMNS, null, null);

					// sync up runtime's object list too
					_columnObjects = null;
				}
				catch (PropertyVetoException e)
				{
					throw new ModelVetoException(e);
				}
			}
			else
			{
				// this part was blank -- do we want an error or skip here?
			}
		}
		else
		{
			throw new ModelException(I18NHelper.getMessage(getMessages(),
				"mapping.element.null_argument"));				// NOI18N
		}
	
public intgetCloneDepth()

 return (_properties & CLONE_MASK); 
public java.util.ArrayListgetColumnObjects()
Returns the list of columns (ColumnElements) to which this mapping field is mapped. This method should only be used by the runtime.

return
the columns mapped by this mapping field

		//@olsen: compute objects on access
		if (_columnObjects == null)
		{
			//@olsen: calculate the column objects based on
			//        the column names as stored in _columns
			//_columnObjects = new ArrayList();
			_columnObjects = MappingClassElementImpl.toColumnObjects(
				getDeclaringClass().getDatabaseRoot(), getColumns());
		}

		return _columnObjects;
	
public java.util.ArrayListgetColumns()
Returns the list of column names to which this mapping field is mapped.

return
the names of the columns mapped by this mapping field

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

		return _columns;
	
public ConcurrencyGroupElement[]getConcurrencyGroups()
Returns the array of concurrency groups to which this field belongs.

return
the concurrency groups in which this field participates
see
PersistenceClassElement#getConcurrencyGroups

		return getPersistenceFieldElement().getConcurrencyGroups();
	
public intgetFetchGroup()
Get the fetch group of this field element.

return
the fetch group, one of {@link #GROUP_DEFAULT}, {@link #GROUP_NONE}, or anything less than or equal to {@link #GROUP_INDEPENDENT}

 return _fetchGroup; 
public intgetFieldNumber()
Computes the field number of this field element.

return
the field number of this field

		return getPersistenceFieldElement().getFieldNumber();
	
public booleangetLogOnAccess()

 return getProperty(LOG_ON_ACCESS); 
public booleangetLogOnUpdate()

 return getProperty(LOG_ON_UPDATE); 
public booleangetModifyBeforeImageOnUpdate()

		return getProperty(MOD_BI_ON_UPDATE);
	
public booleangetObserveOnAccess()

		return getProperty(OBSERVE_ON_ACCESS);
	
final PersistenceFieldElementgetPersistenceFieldElement()

		return ((MappingClassElementImpl)getDeclaringClass()).
			getPersistenceElement().getField(getName());
	
public intgetProperties()

 return _properties;
private booleangetProperty(int propertyBit)

		return ((getProperties() & propertyBit) > 0);
	
public booleangetRecordOnUpdate()

		return getProperty(RECORD_ON_UPDATE);
	
public booleangetReferentialIntegrityUpdates()

		return getProperty(REF_INTEGRITY_UPDATES);
	
public booleangetSendBeforeImage()

		return getProperty(SEND_BEFORE_IMAGE);
	
public booleanisInConcurrencyCheck()
Determines whether this field element is in a concurrency check or not.

return
true if the field is in a concurrency check, false otherwise

		return getProperty(IN_CONCURRENCY_CHECK);
	
protected booleanisMappedToTable(MappingTableElement table)

		String tableName = table.getName();
		Iterator iterator = getColumns().iterator();

		while (iterator.hasNext())
		{
			String columnName = iterator.next().toString();

			if (NameUtil.getTableName(columnName).equals(tableName))
				return true;
		}

		return false;
	
public booleanisReadOnly()
Determines whether this field element is read only or not.

return
true if the field is read only, false otherwise

 return getProperty(READ_ONLY); 
public booleanisVersion()
Determines whether this field element is a version field or not.

return
true if the field is a version field, false otherwise

 return _isVersion; 
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

		if (columnName != null)
		{
			try
			{
				fireVetoableChange(PROP_COLUMNS, null, null);

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

				firePropertyChange(PROP_COLUMNS, null, null);

				// sync up runtime's object list too
				_columnObjects = null;
			}
			catch (PropertyVetoException e)
			{
				throw new ModelVetoException(e);
			}
		}
	
public voidsetCloneDepth(int cloneDepth)

		if (cloneDepth < CLONE_FIELD || cloneDepth > CLONE_DEEP)
		{
		}

		_properties = _properties & ~CLONE_MASK | cloneDepth;
	
public voidsetFetchGroup(int group)
Set the fetch group of this field element.

param
group - an integer indicating the fetch group, one of: {@link #GROUP_DEFAULT}, {@link #GROUP_NONE}, or anything less than or equal to {@link #GROUP_INDEPENDENT}
exception
ModelException if impossible

		Integer old = new Integer(getFetchGroup());
		Integer newGroup = new Integer(group);

		try
		{
			fireVetoableChange(PROP_FETCH_GROUP, old, newGroup);
			setFetchGroupInternal(group);
			firePropertyChange(PROP_FETCH_GROUP, old, newGroup);
		}
		catch (PropertyVetoException e)
		{
			throw new ModelVetoException(e);
		}
	
protected voidsetFetchGroupInternal(int group)
Set the fetch group of this field element. Meant to be used in the constructor and by subclasses when there should be no exceptions and no property change events fired.

param
group - an integer indicating the fetch group, one of: {@link #GROUP_DEFAULT}, {@link #GROUP_NONE}, or anything less than or equal to {@link #GROUP_INDEPENDENT}

		_fetchGroup = group;
	
public voidsetInConcurrencyCheck(boolean flag)
Set whether this field element is in a concurrency check or not.

param
flag - if true, the field element is marked as being in a concurrency check; otherwise, it is not
exception
ModelException if impossible

		Boolean old = JavaTypeHelper.valueOf(isInConcurrencyCheck());
		Boolean newFlag = JavaTypeHelper.valueOf(flag);

		try
		{
			fireVetoableChange(PROP_IN_CONCURRENCY_CHECK, old, newFlag);
			setProperty(flag, IN_CONCURRENCY_CHECK);
			firePropertyChange(PROP_IN_CONCURRENCY_CHECK, old, newFlag);
		}
		catch (PropertyVetoException e)
		{
			throw new ModelVetoException(e);
		}
	
public voidsetLogOnAccess(boolean flag)

		setProperty(flag, LOG_ON_ACCESS);
	
public voidsetLogOnUpdate(boolean flag)

		setProperty(flag, LOG_ON_UPDATE);
	
public voidsetModifyBeforeImageOnUpdate(boolean flag)

		setProperty(flag, MOD_BI_ON_UPDATE);
	
public voidsetObserveOnAccess(boolean flag)

		setProperty(flag, OBSERVE_ON_ACCESS);
	
public voidsetProperty(boolean flag, int propertyBit)

		_properties =
			(flag) ? (_properties | propertyBit) : (_properties & ~propertyBit);
	
public voidsetReadOnly(boolean flag)
Set whether this field element is read only or not.

param
flag - if true, the field element is marked as read only; otherwise, it is not
exception
ModelException if impossible

		Boolean old = JavaTypeHelper.valueOf(isReadOnly());
		Boolean newFlag = JavaTypeHelper.valueOf(flag);

		try
		{
			fireVetoableChange(PROP_READ_ONLY, old, newFlag);
			setProperty(flag, READ_ONLY);
			firePropertyChange(PROP_READ_ONLY, old, newFlag);
		}
		catch (PropertyVetoException e)
		{
			throw new ModelVetoException(e);
		}
	
public voidsetRecordOnUpdate(boolean flag)

		setProperty(flag, RECORD_ON_UPDATE);
	
public voidsetReferentialIntegrityUpdates(boolean flag)

		setProperty(flag, REF_INTEGRITY_UPDATES);
	
public voidsetSendBeforeImage(boolean flag)

		setProperty(flag, SEND_BEFORE_IMAGE);
	
public voidsetVersion(boolean flag)
Set whether this field element is a version field or not.

param
flag - if true, the field element is marked as a version field; otherwise, it is not
exception
ModelException if impossible

		Boolean old = JavaTypeHelper.valueOf(isVersion());
		Boolean newFlag = JavaTypeHelper.valueOf(flag);

		try
		{
			fireVetoableChange(PROP_VERSION_FIELD, old, newFlag);
			_isVersion = flag;
			firePropertyChange(PROP_VERSION_FIELD, old, newFlag);
		}
		catch (PropertyVetoException e)
		{
			throw new ModelVetoException(e);
		}
	
protected voidstripSchemaName()
Boston to Pilsen conversion. This method converts the absolute column names to relative names.

		if (_columns != null)		// handle _columns
		{
			// 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 = _columns.listIterator();

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