org.hibernate.mapping.RootClass#setDeclaredIdentifierProperty ( )源码实例Demo

下面列出了org.hibernate.mapping.RootClass#setDeclaredIdentifierProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lams   文件: ModelBinder.java
private void finishBindingCompositeIdentifier(
		MappingDocument sourceDocument,
		RootClass rootEntityDescriptor,
		CompositeIdentifierSource identifierSource,
		Component cid,
		String propertyName) {
	if ( propertyName == null ) {
		rootEntityDescriptor.setEmbeddedIdentifier( cid.isEmbedded() );
		if ( cid.isEmbedded() ) {
			// todo : what is the implication of this?
			cid.setDynamic( !rootEntityDescriptor.hasPojoRepresentation() );
			/*
			 * Property prop = new Property(); prop.setName("id");
			 * prop.setPropertyAccessorName("embedded"); prop.setValue(id);
			 * entity.setIdentifierProperty(prop);
			 */
		}
	}
	else {
		Property prop = new Property();
		prop.setValue( cid );
		bindProperty(
				sourceDocument,
				( (IdentifierSourceAggregatedComposite) identifierSource ).getIdentifierAttributeSource(),
				prop
		);
		rootEntityDescriptor.setIdentifierProperty( prop );
		rootEntityDescriptor.setDeclaredIdentifierProperty( prop );
	}

	makeIdentifier(
			sourceDocument,
			identifierSource.getIdentifierGeneratorDescriptor(),
			null,
			cid
	);
}
 
源代码2 项目: lams   文件: PropertyBinder.java
private Property bind(Property prop) {
	if (isId) {
		final RootClass rootClass = ( RootClass ) holder.getPersistentClass();
		//if an xToMany, it as to be wrapped today.
		//FIXME this pose a problem as the PK is the class instead of the associated class which is not really compliant with the spec
		if ( isXToMany || entityBinder.wrapIdsInEmbeddedComponents() ) {
			Component identifier = (Component) rootClass.getIdentifier();
			if (identifier == null) {
				identifier = AnnotationBinder.createComponent(
						holder,
						new PropertyPreloadedData(null, null, null),
						true,
						false,
						buildingContext
				);
				rootClass.setIdentifier( identifier );
				identifier.setNullValue( "undefined" );
				rootClass.setEmbeddedIdentifier( true );
				rootClass.setIdentifierMapper( identifier );
			}
			//FIXME is it good enough?
			identifier.addProperty( prop );
		}
		else {
			rootClass.setIdentifier( ( KeyValue ) getValue() );
			if (embedded) {
				rootClass.setEmbeddedIdentifier( true );
			}
			else {
				rootClass.setIdentifierProperty( prop );
				final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
						declaringClass,
						inheritanceStatePerClass,
						buildingContext
				);
				if (superclass != null) {
					superclass.setDeclaredIdentifierProperty(prop);
				}
				else {
					//we know the property is on the actual entity
					rootClass.setDeclaredIdentifierProperty( prop );
				}
			}
		}
	}
	else {
		holder.addProperty( prop, columns, declaringClass );
	}
	return prop;
}
 
源代码3 项目: lams   文件: ModelBinder.java
private void bindSimpleEntityIdentifier(
		MappingDocument sourceDocument,
		final EntityHierarchySourceImpl hierarchySource,
		RootClass rootEntityDescriptor) {
	final IdentifierSourceSimple idSource = (IdentifierSourceSimple) hierarchySource.getIdentifierSource();

	final SimpleValue idValue = new SimpleValue(
			sourceDocument,
			rootEntityDescriptor.getTable()
	);
	rootEntityDescriptor.setIdentifier( idValue );

	bindSimpleValueType(
			sourceDocument,
			idSource.getIdentifierAttributeSource().getTypeInformation(),
			idValue
	);

	final String propertyName = idSource.getIdentifierAttributeSource().getName();
	if ( propertyName == null || !rootEntityDescriptor.hasPojoRepresentation() ) {
		if ( !idValue.isTypeSpecified() ) {
			throw new MappingException(
					"must specify an identifier type: " + rootEntityDescriptor.getEntityName(),
					sourceDocument.getOrigin()
			);
		}
	}
	else {
		idValue.setTypeUsingReflection( rootEntityDescriptor.getClassName(), propertyName );
	}

	relationalObjectBinder.bindColumnsAndFormulas(
			sourceDocument,
			( (RelationalValueSourceContainer) idSource.getIdentifierAttributeSource() ).getRelationalValueSources(),
			idValue,
			false,
			new RelationalObjectBinder.ColumnNamingDelegate() {
				@Override
				public Identifier determineImplicitName(final LocalMetadataBuildingContext context) {
					context.getBuildingOptions().getImplicitNamingStrategy().determineIdentifierColumnName(
							new ImplicitIdentifierColumnNameSource() {
								@Override
								public EntityNaming getEntityNaming() {
									return hierarchySource.getRoot().getEntityNamingSource();
								}

								@Override
								public AttributePath getIdentifierAttributePath() {
									return idSource.getIdentifierAttributeSource().getAttributePath();
								}

								@Override
								public MetadataBuildingContext getBuildingContext() {
									return context;
								}
							}
					);
					return database.toIdentifier( propertyName );
				}
			}
	);

	if ( propertyName != null ) {
		Property prop = new Property();
		prop.setValue( idValue );
		bindProperty(
				sourceDocument,
				idSource.getIdentifierAttributeSource(),
				prop
		);
		rootEntityDescriptor.setIdentifierProperty( prop );
		rootEntityDescriptor.setDeclaredIdentifierProperty( prop );
	}

	makeIdentifier(
			sourceDocument,
			idSource.getIdentifierGeneratorDescriptor(),
			idSource.getUnsavedValue(),
			idValue
	);
}