Java Code Examples for org.hibernate.mapping.Property#isOptional()

The following examples show how to use org.hibernate.mapping.Property#isOptional() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AttributeFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
public <X, Y> AttributeImplementor<X, Y> buildAttribute(AbstractManagedType<X> ownerType, Property property) {
	if ( property.isSynthetic() ) {
		// hide synthetic/virtual properties (fabricated by Hibernate) from the JPA metamodel.
		LOG.tracef( "Skipping synthetic property %s(%s)", ownerType.getTypeName(), property.getName() );
		return null;
	}
	LOG.trace( "Building attribute [" + ownerType.getTypeName() + "." + property.getName() + "]" );
	final AttributeContext<X> attributeContext = wrap( ownerType, property );
	final AttributeMetadata<X, Y> attributeMetadata =
			determineAttributeMetadata( attributeContext, normalMemberResolver );
	if ( attributeMetadata == null ) {
		return null;
	}
	if ( attributeMetadata.isPlural() ) {
		return buildPluralAttribute( (PluralAttributeMetadata) attributeMetadata );
	}
	final SingularAttributeMetadata<X, Y> singularAttributeMetadata = (SingularAttributeMetadata<X, Y>) attributeMetadata;
	final Type<Y> metaModelType = getMetaModelType( singularAttributeMetadata.getValueContext() );
	return new SingularAttributeImpl<X, Y>(
			attributeMetadata.getName(),
			attributeMetadata.getJavaType(),
			ownerType,
			attributeMetadata.getMember(),
			false,
			false,
			property.isOptional(),
			metaModelType,
			attributeMetadata.getPersistentAttributeType()
	);
}
 
Example 2
Source File: PropertyFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated See mainly {@link #buildEntityBasedAttribute}
 */
@Deprecated
public static StandardProperty buildStandardProperty(Property property, boolean lazyAvailable) {
	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(),
			type,
			lazyAvailable && property.isLazy(),
			property.isInsertable(),
			property.isUpdateable(),
			property.getValueGenerationStrategy(),
			property.isOptional(),
			alwaysDirtyCheck || property.isUpdateable(),
			property.isOptimisticLocked(),
			property.getCascadeStyle(),
			property.getValue().getFetchMode()
	);
}
 
Example 3
Source File: PropertyFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Generates a VersionProperty representation for an entity mapping given its
 * version mapping Property.
 *
 * @param property The version mapping Property.
 * @param lazyAvailable Is property lazy loading currently available.
 * @return The appropriate VersionProperty definition.
 */
public static VersionProperty buildVersionProperty(Property property, boolean lazyAvailable) {
	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
		);
}
 
Example 4
Source File: PropertyFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Generate a "standard" (i.e., non-identifier and non-version) based on the given
 * mapped property.
 *
 * @param property The mapped property.
 * @param lazyAvailable Is property lazy loading currently available.
 * @return The appropriate StandardProperty definition.
 */
public static StandardProperty buildStandardProperty(Property property, boolean lazyAvailable) {
	
	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()
		);
}