Spring Data Core

org.springframework.data.mapping.model
Class BasicPersistentEntity<T,P extends PersistentProperty<P>>

java.lang.Object
  extended by org.springframework.data.mapping.model.BasicPersistentEntity<T,P>
All Implemented Interfaces:
MutablePersistentEntity<T,P>, PersistentEntity<T,P>

public class BasicPersistentEntity<T,P extends PersistentProperty<P>>
extends Object
implements MutablePersistentEntity<T,P>

Simple value object to capture information of PersistentEntitys.

Author:
Oliver Gierke, Jon Brisbin, Patryk Wasik, Thomas Darimont

Constructor Summary
BasicPersistentEntity(TypeInformation<T> information)
          Creates a new BasicPersistentEntity from the given TypeInformation.
BasicPersistentEntity(TypeInformation<T> information, Comparator<P> comparator)
          Creates a new BasicPersistentEntity for the given TypeInformation and Comparator.
 
Method Summary
 void addAssociation(Association<P> association)
          Adds an Association to the entity.
 void addPersistentProperty(P property)
          Adds a PersistentProperty to the entity.
 void doWithAssociations(AssociationHandler<P> handler)
          Applies the given AssociationHandler to all Association contained in this PersistentEntity.
 void doWithProperties(PropertyHandler<P> handler)
          Applies the given PropertyHandler to all PersistentPropertys contained in this PersistentEntity.
 P getIdProperty()
          Returns the id property of the PersistentEntity.
 String getName()
          The entity name including any package prefix.
 PreferredConstructor<T,P> getPersistenceConstructor()
          Returns the PreferredConstructor to be used to instantiate objects of this PersistentEntity.
 P getPersistentProperty(String name)
          Obtains a PersistentProperty instance by name.
 Class<T> getType()
          Returns the resolved Java type of this entity.
 Object getTypeAlias()
          Returns the alias to be used when storing type information.
 TypeInformation<T> getTypeInformation()
          Returns the TypeInformation backing this PersistentEntity.
 P getVersionProperty()
          Returns the version property of the PersistentEntity.
 boolean hasIdProperty()
          Returns whether the PersistentEntity has an id property.
 boolean hasVersionProperty()
          Returns whether the PersistentEntity has a version property.
 boolean isConstructorArgument(PersistentProperty<?> property)
          Returns whether the given PersistentProperty is referred to by a constructor argument of the PersistentEntity.
 boolean isIdProperty(PersistentProperty<?> property)
          Returns whether the given PersistentProperty is the id property of the entity.
 boolean isVersionProperty(PersistentProperty<?> property)
          Returns whether the given PersistentProperty is the version property of the entity.
protected  P returnPropertyIfBetterIdPropertyCandidateOrNull(P property)
          Returns the given property if it is a better candidate for the id property than the current id property.
 void verify()
          Callback method to trigger validation of the PersistentEntity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicPersistentEntity

public BasicPersistentEntity(TypeInformation<T> information)
Creates a new BasicPersistentEntity from the given TypeInformation.

Parameters:
information - must not be null.

BasicPersistentEntity

public BasicPersistentEntity(TypeInformation<T> information,
                             Comparator<P> comparator)
Creates a new BasicPersistentEntity for the given TypeInformation and Comparator. The given Comparator will be used to define the order of the PersistentProperty instances added to the entity.

Parameters:
information - must not be null
comparator -
Method Detail

getPersistenceConstructor

public PreferredConstructor<T,P> getPersistenceConstructor()
Description copied from interface: PersistentEntity
Returns the PreferredConstructor to be used to instantiate objects of this PersistentEntity.

Specified by:
getPersistenceConstructor in interface PersistentEntity<T,P extends PersistentProperty<P>>
Returns:
null in case no suitable constructor for automatic construction can be found. This usually indicates that the instantiation of the object of tthat persistent entity is done through either a customer EntityInstantiator or handled by custom conversion mechanisms entirely.

isConstructorArgument

public boolean isConstructorArgument(PersistentProperty<?> property)
Description copied from interface: PersistentEntity
Returns whether the given PersistentProperty is referred to by a constructor argument of the PersistentEntity.

Specified by:
isConstructorArgument in interface PersistentEntity<T,P extends PersistentProperty<P>>
Returns:
true if the given PersistentProperty is referred to by a constructor argument or false if not or null.

isIdProperty

public boolean isIdProperty(PersistentProperty<?> property)
Description copied from interface: PersistentEntity
Returns whether the given PersistentProperty is the id property of the entity.

Specified by:
isIdProperty in interface PersistentEntity<T,P extends PersistentProperty<P>>
Returns:

isVersionProperty

public boolean isVersionProperty(PersistentProperty<?> property)
Description copied from interface: PersistentEntity
Returns whether the given PersistentProperty is the version property of the entity.

Specified by:
isVersionProperty in interface PersistentEntity<T,P extends PersistentProperty<P>>
Returns:

getName

public String getName()
Description copied from interface: PersistentEntity
The entity name including any package prefix.

Specified by:
getName in interface PersistentEntity<T,P extends PersistentProperty<P>>
Returns:
must never return null

getIdProperty

public P getIdProperty()
Description copied from interface: PersistentEntity
Returns the id property of the PersistentEntity. Can be null in case this is an entity completely handled by a custom conversion.

Specified by:
getIdProperty in interface PersistentEntity<T,P extends PersistentProperty<P>>
Returns:
the id property of the PersistentEntity.

getVersionProperty

public P getVersionProperty()
Description copied from interface: PersistentEntity
Returns the version property of the PersistentEntity. Can be null in case no version property is available on the entity.

Specified by:
getVersionProperty in interface PersistentEntity<T,P extends PersistentProperty<P>>
Returns:
the version property of the PersistentEntity.

hasIdProperty

public boolean hasIdProperty()
Description copied from interface: PersistentEntity
Returns whether the PersistentEntity has an id property. If this call returns true, PersistentEntity.getIdProperty() will return a non-null value.

Specified by:
hasIdProperty in interface PersistentEntity<T,P extends PersistentProperty<P>>
Returns:

hasVersionProperty

public boolean hasVersionProperty()
Description copied from interface: PersistentEntity
Returns whether the PersistentEntity has a version property. If this call returns true, PersistentEntity.getVersionProperty() will return a non-null value.

Specified by:
hasVersionProperty in interface PersistentEntity<T,P extends PersistentProperty<P>>
Returns:

addPersistentProperty

public void addPersistentProperty(P property)
Description copied from interface: MutablePersistentEntity
Adds a PersistentProperty to the entity.

Specified by:
addPersistentProperty in interface MutablePersistentEntity<T,P extends PersistentProperty<P>>

returnPropertyIfBetterIdPropertyCandidateOrNull

protected P returnPropertyIfBetterIdPropertyCandidateOrNull(P property)
Returns the given property if it is a better candidate for the id property than the current id property.

Parameters:
property - the new id property candidate, will never be null.
Returns:
the given id property or null if the given property is not an id property.

addAssociation

public void addAssociation(Association<P> association)
Description copied from interface: MutablePersistentEntity
Adds an Association to the entity.

Specified by:
addAssociation in interface MutablePersistentEntity<T,P extends PersistentProperty<P>>

getPersistentProperty

public P getPersistentProperty(String name)
Description copied from interface: PersistentEntity
Obtains a PersistentProperty instance by name.

Specified by:
getPersistentProperty in interface PersistentEntity<T,P extends PersistentProperty<P>>
Parameters:
name - The name of the property
Returns:
the PersistentProperty or null if it doesn't exist.

getType

public Class<T> getType()
Description copied from interface: PersistentEntity
Returns the resolved Java type of this entity.

Specified by:
getType in interface PersistentEntity<T,P extends PersistentProperty<P>>
Returns:
The underlying Java class for this entity

getTypeAlias

public Object getTypeAlias()
Description copied from interface: PersistentEntity
Returns the alias to be used when storing type information. Might be null to indicate that there was no alias defined through the mapping metadata.

Specified by:
getTypeAlias in interface PersistentEntity<T,P extends PersistentProperty<P>>
Returns:

getTypeInformation

public TypeInformation<T> getTypeInformation()
Description copied from interface: PersistentEntity
Returns the TypeInformation backing this PersistentEntity.

Specified by:
getTypeInformation in interface PersistentEntity<T,P extends PersistentProperty<P>>
Returns:

doWithProperties

public void doWithProperties(PropertyHandler<P> handler)
Description copied from interface: PersistentEntity
Applies the given PropertyHandler to all PersistentPropertys contained in this PersistentEntity.

Specified by:
doWithProperties in interface PersistentEntity<T,P extends PersistentProperty<P>>
Parameters:
handler - must not be null.

doWithAssociations

public void doWithAssociations(AssociationHandler<P> handler)
Description copied from interface: PersistentEntity
Applies the given AssociationHandler to all Association contained in this PersistentEntity.

Specified by:
doWithAssociations in interface PersistentEntity<T,P extends PersistentProperty<P>>
Parameters:
handler - must not be null.

verify

public void verify()
Description copied from interface: MutablePersistentEntity
Callback method to trigger validation of the PersistentEntity. As MutablePersistentEntity is not immutable there might be some verification steps necessary after the object has reached is final state.

Specified by:
verify in interface MutablePersistentEntity<T,P extends PersistentProperty<P>>

Spring Data Core

Copyright © 2011-2013-2013 Pivotal. All Rights Reserved.