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

The following examples show how to use org.hibernate.mapping.Property#getName() . 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 6 votes vote down vote up
@SuppressWarnings({"unchecked"})
public <X, Y> SingularAttributeImpl<X, Y> buildIdAttribute(
		AbstractIdentifiableType<X> ownerType,
		Property property) {
	LOG.trace( "Building identifier attribute [" + ownerType.getTypeName() + "." + property.getName() + "]" );
	final AttributeContext<X> attributeContext = wrap( ownerType, property );
	final SingularAttributeMetadata<X, Y> attributeMetadata =
			(SingularAttributeMetadata<X, Y>) determineAttributeMetadata(
					attributeContext,
					identifierMemberResolver
			);
	final Type<Y> metaModelType = getMetaModelType( attributeMetadata.getValueContext() );
	return new SingularAttributeImpl.Identifier(
			property.getName(),
			attributeMetadata.getJavaType(),
			ownerType,
			attributeMetadata.getMember(),
			metaModelType,
			attributeMetadata.getPersistentAttributeType()
	);
}
 
Example 2
Source File: AttributeFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked"})
public <X, Y> SingularAttributeImpl<X, Y> buildVersionAttribute(
		AbstractIdentifiableType<X> ownerType,
		Property property) {
	LOG.trace( "Building version attribute [ownerType.getTypeName()" + "." + "property.getName()]" );
	final AttributeContext<X> attributeContext = wrap( ownerType, property );
	final SingularAttributeMetadata<X, Y> attributeMetadata =
			(SingularAttributeMetadata<X, Y>) determineAttributeMetadata( attributeContext, versionMemberResolver );
	final Type<Y> metaModelType = getMetaModelType( attributeMetadata.getValueContext() );
	return new SingularAttributeImpl.Version(
			property.getName(),
			attributeMetadata.getJavaType(),
			ownerType,
			attributeMetadata.getMember(),
			metaModelType,
			attributeMetadata.getPersistentAttributeType()
	);
}
 
Example 3
Source File: LazyAttributeDescriptor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static LazyAttributeDescriptor from(
		Property property,
		int attributeIndex,
		int lazyIndex) {
	String fetchGroupName = property.getLazyGroup();
	if ( fetchGroupName == null ) {
		fetchGroupName = property.getType().isCollectionType()
				? property.getName()
				: "DEFAULT";
	}

	return new LazyAttributeDescriptor(
			attributeIndex,
			lazyIndex,
			property.getName(),
			property.getType(),
			fetchGroupName
	);
}
 
Example 4
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) {
	while ( propertyIterator.hasNext() ) {

		Property prop = (Property) propertyIterator.next();
		String propname = path == null ? prop.getName() : path + "." + prop.getName();
		if ( prop.isComposite() ) {
			Component component = (Component) prop.getValue();
			Iterator compProps = component.getPropertyIterator();
			internalInitSubclassPropertyAliasesMap( propname, compProps );
		}
		else {
			String[] aliases = new String[prop.getColumnSpan()];
			String[] cols = new String[prop.getColumnSpan()];
			Iterator colIter = prop.getColumnIterator();
			int l = 0;
			while ( colIter.hasNext() ) {
				Selectable thing = (Selectable) colIter.next();
				aliases[l] = thing.getAlias( getFactory().getDialect(), prop.getValue().getTable() );
				cols[l] = thing.getText( getFactory().getDialect() ); // TODO: skip formulas?
				l++;
			}

			subclassPropertyAliases.put( propname, aliases );
			subclassPropertyColumnNames.put( propname, cols );
		}
	}

}
 
Example 5
Source File: PropertyFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates the attribute representation of the identifier for a given entity mapping.
 *
 * @param mappedEntity The mapping definition of the entity.
 * @param generator The identifier value generator to use for this identifier.
 *
 * @return The appropriate IdentifierProperty definition.
 */
public static IdentifierProperty buildIdentifierAttribute(
		PersistentClass mappedEntity,
		IdentifierGenerator generator) {
	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(),
				type,
				mappedEntity.hasEmbeddedIdentifier(),
				unsavedValue,
				generator
		);
	}
}
 
Example 6
Source File: PropertyFactory.java    From lams with GNU General Public License v2.0 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(
		EntityPersister persister,
		SessionFactoryImplementor sessionFactory,
		int attributeNumber,
		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(
			persister,
			sessionFactory,
			attributeNumber,
			property.getName(),
			property.getValue().getType(),
			new BaselineAttributeInformation.Builder()
					.setLazy( lazy )
					.setInsertable( property.isInsertable() )
					.setUpdateable( property.isUpdateable() )
					.setValueGenerationStrategy( property.getValueGenerationStrategy() )
					.setNullable( property.isOptional() )
					.setDirtyCheckable( property.isUpdateable() && !lazy )
					.setVersionable( property.isOptimisticLocked() )
					.setCascadeStyle( property.getCascadeStyle() )
					.createInformation(),
			unsavedValue
	);
}
 
Example 7
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 8
Source File: AbstractEntityPersister.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void internalInitSubclassPropertyAliasesMap(String path, Iterator propertyIterator) {
	while ( propertyIterator.hasNext() ) {

		Property prop = ( Property ) propertyIterator.next();
		String propname = path == null ? prop.getName() : path + "." + prop.getName();
		if ( prop.isComposite() ) {
			Component component = ( Component ) prop.getValue();
			Iterator compProps = component.getPropertyIterator();
			internalInitSubclassPropertyAliasesMap( propname, compProps );
		}
		else {
			String[] aliases = new String[prop.getColumnSpan()];
			String[] cols = new String[prop.getColumnSpan()];
			Iterator colIter = prop.getColumnIterator();
			int l = 0;
			while ( colIter.hasNext() ) {
				Selectable thing = ( Selectable ) colIter.next();
				aliases[l] = thing.getAlias( getFactory().getDialect(), prop.getValue().getTable() );
				cols[l] = thing.getText( getFactory().getDialect() ); // TODO: skip formulas?
				l++;
			}

			subclassPropertyAliases.put( propname, aliases );
			subclassPropertyColumnNames.put( propname, cols );
		}
	}

}
 
Example 9
Source File: PropertyFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Generates an IdentifierProperty representation of the for a given entity mapping.
 *
 * @param mappedEntity The mapping definition of the entity.
 * @param generator The identifier value generator to use for this identifier.
 * @return The appropriate IdentifierProperty definition.
 */
public static IdentifierProperty buildIdentifierProperty(PersistentClass mappedEntity, IdentifierGenerator generator) {

	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
			);
	}
}
 
Example 10
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 11
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()
		);
}
 
Example 12
Source File: EntityMetamodel.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public GenerationStrategyPair buildPair() {
	if ( hadInMemoryGeneration && hadInDatabaseGeneration ) {
		throw new ValueGenerationStrategyException(
				"Composite attribute [" + mappingProperty.getName() + "] contained both in-memory"
						+ " and in-database value generation"
		);
	}
	else if ( hadInMemoryGeneration ) {
		throw new NotYetImplementedException( "Still need to wire in composite in-memory value generation" );

	}
	else if ( hadInDatabaseGeneration ) {
		final Component composite = (Component) mappingProperty.getValue();

		// we need the numbers to match up so we can properly handle 'referenced sql column values'
		if ( inDatabaseStrategies.size() != composite.getPropertySpan() ) {
			throw new ValueGenerationStrategyException(
					"Internal error : mismatch between number of collected in-db generation strategies" +
							" and number of attributes for composite attribute : " + mappingProperty.getName()
			);
		}

		// the base-line values for the aggregated InDatabaseValueGenerationStrategy we will build here.
		GenerationTiming timing = GenerationTiming.INSERT;
		boolean referenceColumns = false;
		String[] columnValues = new String[ composite.getColumnSpan() ];

		// start building the aggregate values
		int propertyIndex = -1;
		int columnIndex = 0;
		Iterator subProperties = composite.getPropertyIterator();
		while ( subProperties.hasNext() ) {
			propertyIndex++;
			final Property subProperty = (Property) subProperties.next();
			final InDatabaseValueGenerationStrategy subStrategy = inDatabaseStrategies.get( propertyIndex );

			if ( subStrategy.getGenerationTiming() == GenerationTiming.ALWAYS ) {
				// override the base-line to the more often "ALWAYS"...
				timing = GenerationTiming.ALWAYS;

			}
			if ( subStrategy.referenceColumnsInSql() ) {
				// override base-line value
				referenceColumns = true;
			}
			if ( subStrategy.getReferencedColumnValues() != null ) {
				if ( subStrategy.getReferencedColumnValues().length != subProperty.getColumnSpan() ) {
					throw new ValueGenerationStrategyException(
							"Internal error : mismatch between number of collected 'referenced column values'" +
									" and number of columns for composite attribute : " + mappingProperty.getName() +
									'.' + subProperty.getName()
					);
				}
				System.arraycopy(
						subStrategy.getReferencedColumnValues(),
						0,
						columnValues,
						columnIndex,
						subProperty.getColumnSpan()
				);
			}
		}

		// then use the aggregated values to build the InDatabaseValueGenerationStrategy
		return new GenerationStrategyPair(
				new InDatabaseValueGenerationStrategyImpl( timing, referenceColumns, columnValues )
		);
	}
	else {
		return NO_GEN_PAIR;
	}
}
 
Example 13
Source File: PropertyFactory.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generate a non-identifier (and non-version) attribute based on the given mapped property from the given entity
 *
 * @param property The mapped property.
 * @param lazyAvailable Is property lazy loading currently available.
 *
 * @return The appropriate NonIdentifierProperty definition.
 */
public static NonIdentifierAttribute buildEntityBasedAttribute(
		EntityPersister persister,
		SessionFactoryImplementor sessionFactory,
		int attributeNumber,
		Property property,
		boolean lazyAvailable) {
	final Type type = property.getValue().getType();

	final NonIdentifierAttributeNature nature = decode( type );

	// 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();

	switch ( nature ) {
		case BASIC: {
			return new EntityBasedBasicAttribute(
					persister,
					sessionFactory,
					attributeNumber,
					property.getName(),
					type,
					new BaselineAttributeInformation.Builder()
							.setLazy( lazyAvailable && property.isLazy() )
							.setInsertable( property.isInsertable() )
							.setUpdateable( property.isUpdateable() )
							.setValueGenerationStrategy( property.getValueGenerationStrategy() )
							.setNullable( property.isOptional() )
							.setDirtyCheckable( alwaysDirtyCheck || property.isUpdateable() )
							.setVersionable( property.isOptimisticLocked() )
							.setCascadeStyle( property.getCascadeStyle() )
							.setFetchMode( property.getValue().getFetchMode() )
							.createInformation()
			);
		}
		case COMPOSITE: {
			return new EntityBasedCompositionAttribute(
					persister,
					sessionFactory,
					attributeNumber,
					property.getName(),
					(CompositeType) type,
					new BaselineAttributeInformation.Builder()
							.setLazy( lazyAvailable && property.isLazy() )
							.setInsertable( property.isInsertable() )
							.setUpdateable( property.isUpdateable() )
							.setValueGenerationStrategy( property.getValueGenerationStrategy() )
							.setNullable( property.isOptional() )
							.setDirtyCheckable( alwaysDirtyCheck || property.isUpdateable() )
							.setVersionable( property.isOptimisticLocked() )
							.setCascadeStyle( property.getCascadeStyle() )
							.setFetchMode( property.getValue().getFetchMode() )
							.createInformation()
			);
		}
		case ENTITY:
		case ANY:
		case COLLECTION: {
			return new EntityBasedAssociationAttribute(
					persister,
					sessionFactory,
					attributeNumber,
					property.getName(),
					(AssociationType) type,
					new BaselineAttributeInformation.Builder()
							.setLazy( lazyAvailable && property.isLazy() )
							.setInsertable( property.isInsertable() )
							.setUpdateable( property.isUpdateable() )
							.setValueGenerationStrategy( property.getValueGenerationStrategy() )
							.setNullable( property.isOptional() )
							.setDirtyCheckable( alwaysDirtyCheck || property.isUpdateable() )
							.setVersionable( property.isOptimisticLocked() )
							.setCascadeStyle( property.getCascadeStyle() )
							.setFetchMode( property.getValue().getFetchMode() )
							.createInformation()
			);
		}
		default: {
			throw new HibernateException( "Internal error" );
		}
	}
}