PropertyFactorypublic class PropertyFactory extends Object Responsible for generation of runtime metamodel {@link Property} representations.
Makes distinction between identifier, version, and other (standard) properties. |
Methods Summary |
---|
public static IdentifierProperty | buildIdentifierProperty(org.hibernate.mapping.PersistentClass mappedEntity, org.hibernate.id.IdentifierGenerator generator)Generates an IdentifierProperty representation of the for a given entity mapping.
String mappedUnsavedValue = mappedEntity.getIdentifier().getNullValue();
Type type = mappedEntity.getIdentifier().getType();
Property property = mappedEntity.getIdentifierProperty();
IdentifierValue unsavedValue = UnsavedValueFactory.getUnsavedIdentifierValue(
mappedUnsavedValue,
getGetter( property ),
type,
getConstructor(mappedEntity)
);
if ( property == null ) {
// this is a virtual id property...
return new IdentifierProperty(
type,
mappedEntity.hasEmbeddedIdentifier(),
mappedEntity.hasIdentifierMapper(),
unsavedValue,
generator
);
}
else {
return new IdentifierProperty(
property.getName(),
property.getNodeName(),
type,
mappedEntity.hasEmbeddedIdentifier(),
unsavedValue,
generator
);
}
| public static StandardProperty | buildStandardProperty(org.hibernate.mapping.Property property, boolean lazyAvailable)Generate a "standard" (i.e., non-identifier and non-version) based on the given
mapped property.
final Type type = property.getValue().getType();
// we need to dirty check collections, since they can cause an owner
// version number increment
// we need to dirty check many-to-ones with not-found="ignore" in order
// to update the cache (not the database), since in this case a null
// entity reference can lose information
boolean alwaysDirtyCheck = type.isAssociationType() &&
( (AssociationType) type ).isAlwaysDirtyChecked();
return new StandardProperty(
property.getName(),
property.getNodeName(),
type,
lazyAvailable && property.isLazy(),
property.isInsertable(),
property.isUpdateable(),
property.getGeneration() == PropertyGeneration.INSERT || property.getGeneration() == PropertyGeneration.ALWAYS,
property.getGeneration() == PropertyGeneration.ALWAYS,
property.isOptional(),
alwaysDirtyCheck || property.isUpdateable(),
property.isOptimisticLocked(),
property.getCascadeStyle(),
property.getValue().getFetchMode()
);
| public static VersionProperty | buildVersionProperty(org.hibernate.mapping.Property property, boolean lazyAvailable)Generates a VersionProperty representation for an entity mapping given its
version mapping Property.
String mappedUnsavedValue = ( (KeyValue) property.getValue() ).getNullValue();
VersionValue unsavedValue = UnsavedValueFactory.getUnsavedVersionValue(
mappedUnsavedValue,
getGetter( property ),
(VersionType) property.getType(),
getConstructor( property.getPersistentClass() )
);
boolean lazy = lazyAvailable && property.isLazy();
return new VersionProperty(
property.getName(),
property.getNodeName(),
property.getValue().getType(),
lazy,
property.isInsertable(),
property.isUpdateable(),
property.getGeneration() == PropertyGeneration.INSERT || property.getGeneration() == PropertyGeneration.ALWAYS,
property.getGeneration() == PropertyGeneration.ALWAYS,
property.isOptional(),
property.isUpdateable() && !lazy,
property.isOptimisticLocked(),
property.getCascadeStyle(),
unsavedValue
);
| private static java.lang.reflect.Constructor | getConstructor(org.hibernate.mapping.PersistentClass persistentClass)
if ( persistentClass == null || !persistentClass.hasPojoRepresentation() ) {
return null;
}
try {
return ReflectHelper.getDefaultConstructor( persistentClass.getMappedClass() );
}
catch( Throwable t ) {
return null;
}
| private static org.hibernate.property.Getter | getGetter(org.hibernate.mapping.Property mappingProperty)
if ( mappingProperty == null || !mappingProperty.getPersistentClass().hasPojoRepresentation() ) {
return null;
}
PropertyAccessor pa = PropertyAccessorFactory.getPropertyAccessor( mappingProperty, EntityMode.POJO );
return pa.getGetter( mappingProperty.getPersistentClass().getMappedClass(), mappingProperty.getName() );
|
|