org.hibernate.mapping.ManyToOne#setFetchMode ( )源码实例Demo

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

源代码1 项目: gorm-hibernate5   文件: GrailsDomainBinder.java
/**
 */
protected void bindManyToOneValues(org.grails.datastore.mapping.model.types.Association property, ManyToOne manyToOne) {
    PropertyConfig config = getPropertyConfig(property);

    if (config != null && config.getFetchMode() != null) {
        manyToOne.setFetchMode(config.getFetchMode());
    }
    else {
        manyToOne.setFetchMode(FetchMode.DEFAULT);
    }

    manyToOne.setLazy(getLaziness(property));

    if (config != null) {
        manyToOne.setIgnoreNotFound(config.getIgnoreNotFound());
    }

    // set referenced entity
    manyToOne.setReferencedEntityName(property.getAssociatedEntity().getName());
}
 
源代码2 项目: lams   文件: ModelBinder.java
private void bindManyToOneAttribute(
		final MappingDocument sourceDocument,
		final SingularAttributeSourceManyToOne manyToOneSource,
		ManyToOne manyToOneBinding,
		String referencedEntityName) {
	// NOTE : no type information to bind

	manyToOneBinding.setReferencedEntityName( referencedEntityName );
	if ( StringHelper.isNotEmpty( manyToOneSource.getReferencedEntityAttributeName() ) ) {
		manyToOneBinding.setReferencedPropertyName( manyToOneSource.getReferencedEntityAttributeName() );
		manyToOneBinding.setReferenceToPrimaryKey( false );
	}
	else {
		manyToOneBinding.setReferenceToPrimaryKey( true );
	}

	manyToOneBinding.setLazy( manyToOneSource.getFetchCharacteristics().getFetchTiming() == FetchTiming.DELAYED );
	manyToOneBinding.setUnwrapProxy( manyToOneSource.getFetchCharacteristics().isUnwrapProxies() );
	manyToOneBinding.setFetchMode(
			manyToOneSource.getFetchCharacteristics().getFetchStyle() == FetchStyle.SELECT
					? FetchMode.SELECT
					: FetchMode.JOIN
	);

	if ( manyToOneSource.isEmbedXml() == Boolean.TRUE ) {
		DeprecationLogger.DEPRECATION_LOGGER.logDeprecationOfEmbedXmlSupport();
	}

	manyToOneBinding.setIgnoreNotFound( manyToOneSource.isIgnoreNotFound() );

	if ( StringHelper.isNotEmpty( manyToOneSource.getExplicitForeignKeyName() ) ) {
		manyToOneBinding.setForeignKeyName( manyToOneSource.getExplicitForeignKeyName() );
	}

	final ManyToOneColumnBinder columnBinder = new ManyToOneColumnBinder(
			sourceDocument,
			manyToOneSource,
			manyToOneBinding,
			referencedEntityName
	);
	final boolean canBindColumnsImmediately = columnBinder.canProcessImmediately();
	if ( canBindColumnsImmediately ) {
		columnBinder.doSecondPass( null );
	}
	else {
		sourceDocument.getMetadataCollector().addSecondPass( columnBinder );
	}

	if ( !manyToOneSource.isIgnoreNotFound() ) {
		// we skip creating the FK here since this setting tells us there
		// cannot be a suitable/proper FK
		final ManyToOneFkSecondPass fkSecondPass = new ManyToOneFkSecondPass(
				sourceDocument,
				manyToOneSource,
				manyToOneBinding,
				referencedEntityName
		);

		if ( canBindColumnsImmediately && fkSecondPass.canProcessImmediately() ) {
			fkSecondPass.doSecondPass( null );
		}
		else {
			sourceDocument.getMetadataCollector().addSecondPass( fkSecondPass );
		}
	}

	manyToOneBinding.setCascadeDeleteEnabled( manyToOneSource.isCascadeDeleteEnabled() );
}