FileDocCategorySizeDatePackage
PersistenceClassElement.javaAPI DocGlassfish v2 API19572Fri May 04 22:34:42 BST 2007com.sun.jdo.api.persistence.model.jdo

PersistenceClassElement

public class PersistenceClassElement extends PersistenceElement implements FieldElementHolder
author
raccah
version
%I%

Fields Summary
public static final int
APPLICATION_IDENTITY
Constant representing jdo identity managed by the application.
public static final int
DATABASE_IDENTITY
Constant representing jdo identity managed by the database.
public static final int
UNMANAGED_IDENTITY
Constant representing unmanaged jdo identity.
Constructors Summary
public PersistenceClassElement()
Create new PersistenceClassElement with no implementation. This constructor should only be used for cloning and archiving.

    
	                 	 
	  
	
		this(null);
	
public PersistenceClassElement(Impl impl)
Create new PersistenceClassElement with the provided implementation. The implementation is responsible for storing all properties of the object.

param
impl the implementation to use

		super(impl);
	
Methods Summary
public voidaddConcurrencyGroup(ConcurrencyGroupElement group)
Add the supplied group to the collection of concurrency groups for this class.

param
group the concurrency group to be added
exception
ModelException if impossible

		addConcurrencyGroups(new ConcurrencyGroupElement[]{group});
	
public voidaddConcurrencyGroups(ConcurrencyGroupElement[] groups)
Add the supplied groups to the collection of concurrency groups for this class.

param
groups the array of concurrency groups to be added
exception
ModelException if impossible

		getClassImpl().changeConcurrencyGroups(groups, Impl.ADD);
	
public voidaddField(PersistenceFieldElement field)
Add the supplied field to the collection of fields maintained by this holder.

param
field the field to be added
exception
ModelException if impossible

		addFields(new PersistenceFieldElement[]{field});
	
public voidaddFields(PersistenceFieldElement[] fields)
Add the supplied fields to the collection of fields maintained by this holder.

param
fields the array of fields to be added
exception
ModelException if impossible

		getClassImpl().changeFields(fields, Impl.ADD);
	
public booleancontainsConcurrencyGroup(ConcurrencyGroupElement group)
Tests whether the supplied group is in the collection of groups maintained by this class.

param
group the concurrency group to be tested

		return (getClassImpl().getConcurrencyGroup(group.getName()) != null);
	
public booleancontainsField(PersistenceFieldElement field)
Tests whether the supplied field is in the collection of fields maintained by this holder.

param
field the field to be tested

		return (getClassImpl().getField(field.getName()) != null);
	
public static com.sun.jdo.api.persistence.model.jdo.PersistenceClassElementforName(java.lang.String name, com.sun.jdo.api.persistence.model.Model model)
Returns the persistence class element associated with the class with the given string name, using the given model object to look it up.

param
name the fully qualified name of the desired class
param
model the model object to be used to look it up
return
persistence class element representing the desired class

		return model.getPersistenceClass(name);
	
final com.sun.jdo.api.persistence.model.jdo.PersistenceClassElement$ImplgetClassImpl()

return
implemetation factory for this class

 return (Impl)getImpl(); 
public ConcurrencyGroupElementgetConcurrencyGroup(java.lang.String name)
Returns the concurrency group with the supplied name from the collection of groups maintained by this class.

param
name the name of the concurrency group to be found
return
the concurrency group with the supplied name, null if none exists

		return getClassImpl().getConcurrencyGroup(name);
	
public ConcurrencyGroupElement[]getConcurrencyGroups()
Returns the collection of fields groups by this class in the form of an array.

return
the concurrency groups maintained by this class

		return getClassImpl().getConcurrencyGroups();
	
public PersistenceFieldElementgetField(java.lang.String name)
Returns the field with the supplied name from the collection of fields maintained by this holder.

param
name the name of the field to be found
return
the field with the supplied name, null if none exists

		return getClassImpl().getField(name);
	
public PersistenceFieldElement[]getFields()
Returns the collection of fields maintained by this holder in the form of an array.

return
the fields maintained by this holder

		return getClassImpl().getFields();
	
public java.lang.StringgetKeyClass()
Get the fully qualified name of the primary key class for this class element. This value is only used if getObjectIdentityType returns APPLICATION_IDENTITY

return
the fully qualified key class name, null if the identity type is not managed by the application
see
#setObjectIdentityType
see
#APPLICATION_IDENTITY

 return getClassImpl().getKeyClass(); 
public intgetObjectIdentityType()
Get the object identity type of this class element.

return
the object identity type, one of {@link #APPLICATION_IDENTITY}, {@link #DATABASE_IDENTITY}, or {@link #UNMANAGED_IDENTITY}

		return getClassImpl().getObjectIdentityType();
	
public java.lang.StringgetPackage()
Get the package name of this class element.

return
the package
see
PersistenceElement#getName

		String className = getName();
		int index = className.lastIndexOf('.");

		return ((index != -1) ? className.substring(0, index) : "");	// NOI18N
	
public RelationshipElementgetRelationship(java.lang.String name)
Returns the relationship with the supplied name from the collection of relationships maintained by this holder.

param
name the name of the relationship to be found
return
the relationship with the supplied name, null if none exists
see
PersistenceClassElement#getRelationships
see
PersistenceClassElement#getField

		RelationshipElement[] relationships = getRelationships();
		int i, count = ((relationships != null) ? relationships.length : 0);
		
		for (i = 0; i < count; i++)
		{
			RelationshipElement relationship = relationships[i];

			if (name.equals(relationship.getName()))
				return relationship;
		}

		return null;
	
public RelationshipElement[]getRelationships()
Returns the subset of the collection of fields which are relationahips.

return
the relationship fields maintained by this holder
see
PersistenceClassElement#getFields

		PersistenceFieldElement[] fields = getFields();
		int i, count = ((fields != null) ? fields.length : 0);
		ArrayList relationships = new ArrayList(count);

		for (i = 0; i < count; i++)
		{
			PersistenceFieldElement field = fields[i];

			if (field instanceof RelationshipElement)
				relationships.add(field);
		}
		
		count = relationships.size();

		return ((RelationshipElement[])relationships.toArray(
			new RelationshipElement[count]));
	
public booleanisModified()
Gets the modified flag for this persistence class.

return
true if there have been (property) changes to this class, false otherwise.

 return getClassImpl().isModified(); 
public voidremoveConcurrencyGroup(ConcurrencyGroupElement group)
Remove the supplied group from the collection of concurrency groups for this class.

param
group the concurrency group to be removed
exception
ModelException if impossible

		removeConcurrencyGroups(new ConcurrencyGroupElement[]{group});
	
public voidremoveConcurrencyGroups(ConcurrencyGroupElement[] groups)
Removed the supplied groups from the collection of concurrency groups for this class.

param
groups the array of concurrency groups to be removed
exception
ModelException if impossible

		getClassImpl().changeConcurrencyGroups(groups, Impl.REMOVE);
	
public voidremoveField(PersistenceFieldElement field)
Remove the supplied field from the collection of fields maintained by this holder.

param
field the field to be removed
exception
ModelException if impossible

		removeFields(new PersistenceFieldElement[]{field});
	
public voidremoveFields(PersistenceFieldElement[] fields)
Removed the supplied fields from the collection of fields maintained by this holder.

param
fields the array of fields to be removed
exception
ModelException if impossible

		int i, count = ((fields != null) ? fields.length : 0);

		// first remove the fields from this class
		getClassImpl().changeFields(fields, Impl.REMOVE);

		// now remove the fields from any concurrency groups
		for (i = 0; i < count; i++)
		{
			PersistenceFieldElement field = fields[i];
			ConcurrencyGroupElement[] groups = field.getConcurrencyGroups();
			int j, groupCount = ((groups != null) ? groups.length : 0);

			for (j = 0; j < groupCount; j++)
				groups[j].removeField(field);
		}	
	
public voidsetConcurrencyGroups(ConcurrencyGroupElement[] groups)
Sets the collection of concurrency groups maintained by this class to the contents of the supplied array.

param
groups the concurrency groups maintained by this holder
exception
ModelException if impossible

		getClassImpl().changeConcurrencyGroups(groups, Impl.SET);
	
public voidsetFields(PersistenceFieldElement[] fields)
Sets the collection of fields maintained by this holder to the contents of the supplied array.

param
fields the fields maintained by this holder
exception
ModelException if impossible

		getClassImpl().changeFields(fields, Impl.SET);
	
public voidsetKeyClass(java.lang.String name)
Set the primary key class for this class element. For now the key class is required to be in the same package with the same name as this class and the suffix "Key" (any capitalization), or an inner class of this class with the name "OID" (any capitalization).

param
name - the fully qualified name which represents the primary key class. This value is only used if getObjectIdentityType returns APPLICATION_IDENTITY
exception
ModelException if impossible
see
#setObjectIdentityType
see
#APPLICATION_IDENTITY

		boolean hasValue = (name != null);

		if (hasValue)
			name = name.trim();

		if (hasValue && (name.length() > 0))
		{
			String className = getName();
			boolean hasPrefix = name.startsWith(className);
			String nameSuffix = ((hasPrefix) ? 
				name.substring(className.length()) : name);

			if (!hasPrefix || (!nameSuffix.equalsIgnoreCase("Key") && 	// NOI18N
				!nameSuffix.equalsIgnoreCase(".OID")					// NOI18N
				&& !nameSuffix.equalsIgnoreCase("$OID")))				// NOI18N
			{
				throw new ModelException(I18NHelper.getMessage(getMessages(),
					"jdo.class.key_class_invalid", 						// NOI18N
					new Object[]{name, className}));
			}
		}

		getClassImpl().setKeyClass(name);
	
public voidsetModified(boolean flag)
Set the modified flag for this persistence class to flag. This is usually set to true by property changes and false after a save.

param
flag if true, this class is marked as modified; if false, it is marked as unmodified.

 getClassImpl().setModified(flag); 
public voidsetName(java.lang.String name)
Set the name of this persistence element. This method overrides the one in PersistenceElement in order to keep the {@link #getKeyClass key class} in sync if possible.

param
name the name
exception
ModelException if impossible

		String oldName = getName();

		super.setName(name);

		if (!StringHelper.isEmpty(name))
		{
			String oldKeyClass = getKeyClass();

			// a rename -- set the key class too
			if ((oldKeyClass != null) && oldKeyClass.startsWith(oldName))
				setKeyClass(name + oldKeyClass.substring(oldName.length()));
		}
	
public voidsetObjectIdentityType(int type)
Set the object identity type of this class element.

param
type - an integer indicating the object identity type, one of: {@link #APPLICATION_IDENTITY}, {@link #DATABASE_IDENTITY}, or {@link #UNMANAGED_IDENTITY}
exception
ModelException if impossible

		getClassImpl().setObjectIdentityType(type);