org.hibernate.mapping.Property Java Examples

The following examples show how to use org.hibernate.mapping.Property. 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: PropertyFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static Getter getGetter(Property mappingProperty) {
	if ( mappingProperty == null || !mappingProperty.getPersistentClass().hasPojoRepresentation() ) {
		return null;
	}

	final PropertyAccessStrategyResolver propertyAccessStrategyResolver =
			mappingProperty.getPersistentClass().getServiceRegistry().getService( PropertyAccessStrategyResolver.class );

	final PropertyAccessStrategy propertyAccessStrategy = propertyAccessStrategyResolver.resolvePropertyAccessStrategy(
			mappingProperty.getClass(),
			mappingProperty.getPropertyAccessorName(),
			EntityMode.POJO
	);

	final PropertyAccess propertyAccess = propertyAccessStrategy.buildPropertyAccess(
			mappingProperty.getPersistentClass().getMappedClass(),
			mappingProperty.getName()
	);

	return propertyAccess.getGetter();
}
 
Example #2
Source File: ClassPropertyHolder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void addProperty(Property prop, XClass declaringClass) {
	if ( prop.getValue() instanceof Component ) {
		//TODO handle quote and non quote table comparison
		String tableName = prop.getValue().getTable().getName();
		if ( getJoinsPerRealTableName().containsKey( tableName ) ) {
			final Join join = getJoinsPerRealTableName().get( tableName );
			addPropertyToJoin( prop, declaringClass, join );
		}
		else {
			addPropertyToPersistentClass( prop, declaringClass );
		}
	}
	else {
		addPropertyToPersistentClass( prop, declaringClass );
	}
}
 
Example #3
Source File: ClassPropertyHolder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void addPropertyToJoin(Property prop, XClass declaringClass, Join join) {
	if ( declaringClass != null ) {
		final InheritanceState inheritanceState = inheritanceStatePerClass.get( declaringClass );
		if ( inheritanceState == null ) {
			throw new AssertionFailure(
					"Declaring class is not found in the inheritance state hierarchy: " + declaringClass
			);
		}
		if ( inheritanceState.isEmbeddableSuperclass() ) {
			join.addMappedsuperclassProperty(prop);
			addPropertyToMappedSuperclass( prop, declaringClass );
		}
		else {
			join.addProperty( prop );
		}
	}
	else {
		join.addProperty( prop );
	}
}
 
Example #4
Source File: HibernatePropertyParser.java    From mPaaS with Apache License 2.0 6 votes vote down vote up
/**
 * 构造Hibernate的Property
 */
private Property buildProperty(MetaProperty property,
							   HibernatePropertyFeature feature,
							   PersistentClass pclazz) {
	Property prop = new Property();
	prop.setName(property.getName());
	if (property.isDynamic()) {
		prop.setPropertyAccessorName(
				DynamicPropertyAccessStrategy.class.getName());
	} else {
		prop.setPropertyAccessorName(
				ExtendPropertyAccessStrategy.class.getName());
	}
	prop.setValueGenerationStrategy(NoValueGeneration.INSTANCE);
	prop.setLazy(property.isLazy());
	prop.setOptional(property.isNotNull());
	return prop;
}
 
Example #5
Source File: HibernatePropertyParser.java    From mPaaS with Apache License 2.0 6 votes vote down vote up
/**
 * 将数据字典解析成Hibernate的字段,不支持级联,不支持一对多
 */
public void parse(MetaProperty property, PersistentClass pclazz) {
	// feature
	HibernatePropertyFeature feature = property
			.getFeature(HibernatePropertyFeature.class);
	if (feature == null) {
		feature = new HibernatePropertyFeature();
	}
	// value
	Value value;
	if (property.isCollection()) {
		value = buildCollectionValue(property, feature, pclazz);
	} else {
		value = buildElement(pclazz, property, feature, pclazz.getTable());
	}
	// property
	Property prop = buildProperty(property, feature, pclazz);
	prop.setValue(value);
	pclazz.addProperty(prop);
	// version
	if (feature.isVersion()) {
		handleVersion(prop, pclazz);
	}
}
 
Example #6
Source File: TypeSafeActivator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static void applyMin(Property property, ConstraintDescriptor<?> descriptor, Dialect dialect) {
	if ( Min.class.equals( descriptor.getAnnotation().annotationType() ) ) {
		@SuppressWarnings("unchecked")
		ConstraintDescriptor<Min> minConstraint = (ConstraintDescriptor<Min>) descriptor;
		long min = minConstraint.getAnnotation().value();

		@SuppressWarnings("unchecked")
		final Iterator<Selectable> itor = property.getColumnIterator();
		if ( itor.hasNext() ) {
			final Selectable selectable = itor.next();
			if ( Column.class.isInstance( selectable ) ) {
				Column col = (Column) selectable;
				String checkConstraint = col.getQuotedName(dialect) + ">=" + min;
				applySQLCheck( col, checkConstraint );
			}
		}
	}
}
 
Example #7
Source File: TypeSafeActivator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static void applyMax(Property property, ConstraintDescriptor<?> descriptor, Dialect dialect) {
	if ( Max.class.equals( descriptor.getAnnotation().annotationType() ) ) {
		@SuppressWarnings("unchecked")
		ConstraintDescriptor<Max> maxConstraint = (ConstraintDescriptor<Max>) descriptor;
		long max = maxConstraint.getAnnotation().value();

		@SuppressWarnings("unchecked")
		final Iterator<Selectable> itor = property.getColumnIterator();
		if ( itor.hasNext() ) {
			final Selectable selectable = itor.next();
			if ( Column.class.isInstance( selectable ) ) {
				Column col = (Column) selectable;
				String checkConstraint = col.getQuotedName( dialect ) + "<=" + max;
				applySQLCheck( col, checkConstraint );
			}
		}
	}
}
 
Example #8
Source File: ModelBinder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private Property createAnyAssociationAttribute(
		MappingDocument sourceDocument,
		SingularAttributeSourceAny anyMapping,
		Any anyBinding,
		String entityName) {
	final String attributeName = anyMapping.getName();

	bindAny( sourceDocument, anyMapping, anyBinding, anyMapping.getAttributeRole(), anyMapping.getAttributePath() );

	prepareValueTypeViaReflection( sourceDocument, anyBinding, entityName, attributeName, anyMapping.getAttributeRole() );

	anyBinding.createForeignKey();

	Property prop = new Property();
	prop.setValue( anyBinding );
	bindProperty(
			sourceDocument,
			anyMapping,
			prop
	);

	return prop;
}
 
Example #9
Source File: BinderHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * create a property copy reusing the same value
 */
public static Property shallowCopy(Property property) {
	Property clone = new Property();
	clone.setCascade( property.getCascade() );
	clone.setInsertable( property.isInsertable() );
	clone.setLazy( property.isLazy() );
	clone.setName( property.getName() );
	clone.setNaturalIdentifier( property.isNaturalIdentifier() );
	clone.setOptimisticLocked( property.isOptimisticLocked() );
	clone.setOptional( property.isOptional() );
	clone.setPersistentClass( property.getPersistentClass() );
	clone.setPropertyAccessorName( property.getPropertyAccessorName() );
	clone.setSelectable( property.isSelectable() );
	clone.setUpdateable( property.isUpdateable() );
	clone.setValue( property.getValue() );
	return clone;
}
 
Example #10
Source File: ComponentPropertyHolder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void addProperty(Property prop, Ejb3Column[] columns, XClass declaringClass) {
	//Ejb3Column.checkPropertyConsistency( ); //already called earlier
	/*
	 * Check table matches between the component and the columns
	 * if not, change the component table if no properties are set
	 * if a property is set already the core cannot support that
	 */
	if (columns != null) {
		Table table = columns[0].getTable();
		if ( !table.equals( component.getTable() ) ) {
			if ( component.getPropertySpan() == 0 ) {
				component.setTable( table );
			}
			else {
				throw new AnnotationException(
						"A component cannot hold properties split into 2 different tables: "
								+ this.getPath()
				);
			}
		}
	}
	addProperty( prop, declaringClass );
}
 
Example #11
Source File: PropertyAccessorFactory.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
    * Retrieves a PropertyAccessor instance based on the given property definition and
    * entity mode.
    *
    * @param property The property for which to retrieve an accessor.
    * @param mode The mode for the resulting entity.
    * @return An appropriate accessor.
    * @throws MappingException
    */
public static PropertyAccessor getPropertyAccessor(Property property, EntityMode mode) throws MappingException {
	//TODO: this is temporary in that the end result will probably not take a Property reference per-se.
    if ( null == mode || EntityMode.POJO.equals( mode ) ) {
	    return getPojoPropertyAccessor( property.getPropertyAccessorName() );
    }
    else if ( EntityMode.MAP.equals( mode ) ) {
	    return getDynamicMapPropertyAccessor();
    }
    else if ( EntityMode.DOM4J.equals( mode ) ) {
    	//TODO: passing null here, because this method is not really used for DOM4J at the moment
    	//      but it is still a bug, if we don't get rid of this!
	    return getDom4jPropertyAccessor( property.getAccessorPropertyName( mode ), property.getType(), null );
    }
    else {
	    throw new MappingException( "Unknown entity mode [" + mode + "]" );
    }
}
 
Example #12
Source File: MetadataContext.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private <X> void applyIdMetadata(MappedSuperclass mappingType, MappedSuperclassTypeImpl<X> jpaMappingType) {
	if ( mappingType.hasIdentifierProperty() ) {
		final Property declaredIdentifierProperty = mappingType.getDeclaredIdentifierProperty();
		if ( declaredIdentifierProperty != null ) {
			jpaMappingType.getBuilder().applyIdAttribute(
					attributeFactory.buildIdAttribute( jpaMappingType, declaredIdentifierProperty )
			);
		}
	}
	//a MappedSuperclass can have no identifier if the id is set below in the hierarchy
	else if ( mappingType.getIdentifierMapper() != null ) {
		@SuppressWarnings("unchecked")
		Iterator<Property> propertyIterator = mappingType.getIdentifierMapper().getPropertyIterator();
		Set<SingularAttribute<? super X, ?>> attributes = buildIdClassAttributes(
				jpaMappingType,
				propertyIterator
		);
		jpaMappingType.getBuilder().applyIdClassAttributes( attributes );
	}
}
 
Example #13
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 #14
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 #15
Source File: DynamicMapEntityTuplizer.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private PropertyAccess buildPropertyAccess(Property mappedProperty) {
	if ( mappedProperty.isBackRef() ) {
		return mappedProperty.getPropertyAccessStrategy( null ).buildPropertyAccess( null, mappedProperty.getName() );
	}
	else {
		return PropertyAccessStrategyMapImpl.INSTANCE.buildPropertyAccess( null, mappedProperty.getName() );
	}
}
 
Example #16
Source File: Dom4jAccessorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testLongAttributeExtraction() throws Throwable {
	Property property = generateIdProperty();
	Getter getter = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.DOM4J )
			.getGetter( null, null );
	Long id = ( Long ) getter.get( DOM );
	assertEquals( "Not equals", new Long( 123 ), id );
}
 
Example #17
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 #18
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 #19
Source File: Dom4jAccessorTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testStringElementExtraction() throws Throwable {
	Property property = generateNameProperty();
	Getter getter = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.DOM4J )
			.getGetter( null, null );
	String name = ( String ) getter.get( DOM );
	assertEquals( "Not equals", "JBoss", name );
}
 
Example #20
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 #21
Source File: AttributeFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private SingularAttributeMetadataImpl(
		Property propertyMapping,
		AbstractManagedType<X> ownerType,
		Member member,
		Attribute.PersistentAttributeType persistentAttributeType) {
	super( propertyMapping, ownerType, member, persistentAttributeType );
	valueContext = new ValueContext() {
		public Value getValue() {
			return getPropertyMapping().getValue();
		}

		public Class getBindableType() {
			return getAttributeMetadata().getJavaType();
		}

		public ValueClassification getValueClassification() {
			switch ( getPersistentAttributeType() ) {
				case EMBEDDED: {
					return ValueClassification.EMBEDDABLE;
				}
				case BASIC: {
					return ValueClassification.BASIC;
				}
				default: {
					return ValueClassification.ENTITY;
				}
			}
		}

		public AttributeMetadata getAttributeMetadata() {
			return SingularAttributeMetadataImpl.this;
		}
	};
}
 
Example #22
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 #23
Source File: AbstractComponentTuplizer.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected AbstractComponentTuplizer(Component component) {
	propertySpan = component.getPropertySpan();
	getters = new Getter[propertySpan];
	setters = new Setter[propertySpan];

	Iterator iter = component.getPropertyIterator();
	boolean foundCustomAccessor=false;
	int i = 0;
	while ( iter.hasNext() ) {
		Property prop = ( Property ) iter.next();
		getters[i] = buildGetter( component, prop );
		setters[i] = buildSetter( component, prop );
		if ( !prop.isBasicPropertyAccessor() ) {
			foundCustomAccessor = true;
		}
		i++;
	}
	hasCustomAccessors = foundCustomAccessor;

	String[] getterNames = new String[propertySpan];
	String[] setterNames = new String[propertySpan];
	Class[] propTypes = new Class[propertySpan];
	for ( int j = 0; j < propertySpan; j++ ) {
		getterNames[j] = getters[j].getMethodName();
		setterNames[j] = setters[j].getMethodName();
		propTypes[j] = getters[j].getReturnType();
	}
	instantiator = buildInstantiator( component );
}
 
Example #24
Source File: AttributeFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private <X> AttributeContext<X> wrap(final AbstractManagedType<X> ownerType, final Property property) {
	return new AttributeContext<X>() {
		public AbstractManagedType<X> getOwnerType() {
			return ownerType;
		}

		public Property getPropertyMapping() {
			return property;
		}
	};
}
 
Example #25
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 #26
Source File: MetadataContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private <X> Set<SingularAttribute<? super X, ?>> buildIdClassAttributes(
		AbstractIdentifiableType<X> ownerType,
		Iterator<Property> propertyIterator) {
	if ( LOG.isTraceEnabled() ) {
		LOG.trace( "Building old-school composite identifier [" + ownerType.getJavaType().getName() + ']' );
	}
	Set<SingularAttribute<? super X, ?>> attributes = new HashSet<SingularAttribute<? super X, ?>>();
	while ( propertyIterator.hasNext() ) {
		attributes.add( attributeFactory.buildIdAttribute( ownerType, propertyIterator.next() ) );
	}
	return attributes;
}
 
Example #27
Source File: MetadataContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private <X> void applyVersionAttribute(MappedSuperclass mappingType, MappedSuperclassTypeImpl<X> jpaMappingType) {
	final Property declaredVersion = mappingType.getDeclaredVersion();
	if ( declaredVersion != null ) {
		jpaMappingType.getBuilder().applyVersionAttribute(
				attributeFactory.buildVersionAttribute( jpaMappingType, declaredVersion )
		);
	}
}
 
Example #28
Source File: MetadataContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private <X> void applyVersionAttribute(PersistentClass persistentClass, EntityTypeImpl<X> jpaEntityType) {
	final Property declaredVersion = persistentClass.getDeclaredVersion();
	if ( declaredVersion != null ) {
		jpaEntityType.getBuilder().applyVersionAttribute(
				attributeFactory.buildVersionAttribute( jpaEntityType, declaredVersion )
		);
	}
}
 
Example #29
Source File: HbmBinder.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void bindVersioningProperty(Table table, Element subnode, Mappings mappings,
		String name, RootClass entity, java.util.Map inheritedMetas) {

	String propertyName = subnode.attributeValue( "name" );
	SimpleValue val = new SimpleValue( table );
	bindSimpleValue( subnode, val, false, propertyName, mappings );
	if ( !val.isTypeSpecified() ) {
		// this is either a <version/> tag with no type attribute,
		// or a <timestamp/> tag
		if ( "version".equals( name ) ) {
			val.setTypeName( "integer" );
		}
		else {
			if ( "db".equals( subnode.attributeValue( "source" ) ) ) {
				val.setTypeName( "dbtimestamp" );
			}
			else {
				val.setTypeName( "timestamp" );
			}
		}
	}
	Property prop = new Property();
	prop.setValue( val );
	bindProperty( subnode, prop, mappings, inheritedMetas );
	// for version properties marked as being generated, make sure they are "always"
	// generated; aka, "insert" is invalid; this is dis-allowed by the DTD,
	// but just to make sure...
	if ( prop.getGeneration() == PropertyGeneration.INSERT ) {
		throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" );
	}
	makeVersion( subnode, val );
	entity.setVersion( prop );
	entity.addProperty( prop );
}
 
Example #30
Source File: EntityMetamodel.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static GenerationStrategyPair buildGenerationStrategyPair(
		final SessionFactoryImplementor sessionFactory,
		final Property mappingProperty) {
	final ValueGeneration valueGeneration = mappingProperty.getValueGenerationStrategy();
	if ( valueGeneration != null && valueGeneration.getGenerationTiming() != GenerationTiming.NEVER ) {
		// the property is generated in full. build the generation strategy pair.
		if ( valueGeneration.getValueGenerator() != null ) {
			// in-memory generation
			return new GenerationStrategyPair(
					FullInMemoryValueGenerationStrategy.create( valueGeneration )
			);
		}
		else {
			// in-db generation
			return new GenerationStrategyPair(
					create(
							sessionFactory,
							mappingProperty,
							valueGeneration
					)
			);
		}
	}
	else if ( mappingProperty.getValue() instanceof Component ) {
		final CompositeGenerationStrategyPairBuilder builder = new CompositeGenerationStrategyPairBuilder( mappingProperty );
		interpretPartialCompositeValueGeneration( sessionFactory, (Component) mappingProperty.getValue(), builder );
		return builder.buildPair();
	}

	return NO_GEN_PAIR;
}