Java AssertionFailure类使用实例

时间:2022-05-17
本文章向大家介绍Java AssertionFailure类代码示例,你可以查看下面代码实例来了解Java AssertionFailure类的使用方法及注意事项。文章结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

实例1: addAttributeConverter

import org.hibernate.AssertionFailure; //导入依赖的package包/类
public void addAttributeConverter(AttributeConverterDefinition definition) {
	if ( attributeConverterDefinitionsByClass == null ) {
		attributeConverterDefinitionsByClass = new ConcurrentHashMap<Class, AttributeConverterDefinition>();
	}

	final Object old = attributeConverterDefinitionsByClass.put( definition.getAttributeConverter().getClass(), definition );

	if ( old != null ) {
		throw new AssertionFailure(
				String.format(
						"AttributeConverter class [%s] registered multiple times",
						definition.getAttributeConverter().getClass()
				)
		);
	}
}
 

实例2: doSecondPass

import org.hibernate.AssertionFailure; //导入依赖的package包/类
public void doSecondPass(java.util.Map persistentClasses) throws MappingException {
	if ( value instanceof ManyToOne ) {
		ManyToOne manyToOne = (ManyToOne) value;
		PersistentClass ref = (PersistentClass) persistentClasses.get( manyToOne.getReferencedEntityName() );
		if ( ref == null ) {
			throw new AnnotationException(
					"@OneToOne or @ManyToOne on "
							+ StringHelper.qualify( entityClassName, path )
							+ " references an unknown entity: "
							+ manyToOne.getReferencedEntityName()
			);
		}
		BinderHelper.createSyntheticPropertyReference( columns, ref, null, manyToOne, false, mappings );
		TableBinder.bindFk( ref, null, columns, manyToOne, unique, mappings );
		/*
		 * HbmMetadataSourceProcessorImpl does this only when property-ref != null, but IMO, it makes sense event if it is null
		 */
		if ( !manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses );
	}
	else if ( value instanceof OneToOne ) {
		value.createForeignKey();
	}
	else {
		throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() );
	}
}
 

实例3: getMappedSuperclassOrNull

import org.hibernate.AssertionFailure; //导入依赖的package包/类
public static MappedSuperclass getMappedSuperclassOrNull(
		XClass declaringClass,
		Map<XClass, InheritanceState> inheritanceStatePerClass,
		Mappings mappings) {
	boolean retrieve = false;
	if ( declaringClass != null ) {
		final InheritanceState inheritanceState = inheritanceStatePerClass.get( declaringClass );
		if ( inheritanceState == null ) {
			throw new org.hibernate.annotations.common.AssertionFailure(
					"Declaring class is not found in the inheritance state hierarchy: " + declaringClass
			);
		}
		if ( inheritanceState.isEmbeddableSuperclass() ) {
			retrieve = true;
		}
	}
	return retrieve ?
			mappings.getMappedSuperclass( mappings.getReflectionManager().toClass( declaringClass ) ) :
	        null;
}
 

实例4: getSuperEntity

import org.hibernate.AssertionFailure; //导入依赖的package包/类
private static PersistentClass getSuperEntity(XClass clazzToProcess, Map<XClass, InheritanceState> inheritanceStatePerClass, Mappings mappings, InheritanceState inheritanceState) {
	InheritanceState superEntityState = InheritanceState.getInheritanceStateOfSuperEntity(
			clazzToProcess, inheritanceStatePerClass
	);
	PersistentClass superEntity = superEntityState != null ?
			mappings.getClass(
					superEntityState.getClazz().getName()
			) :
			null;
	if ( superEntity == null ) {
		//check if superclass is not a potential persistent class
		if ( inheritanceState.hasParents() ) {
			throw new AssertionFailure(
					"Subclass has to be binded after it's mother class: "
							+ superEntityState.getClazz().getName()
			);
		}
	}
	return superEntity;
}
 

实例5: bindDiscriminatorColumnToRootPersistentClass

import org.hibernate.AssertionFailure; //导入依赖的package包/类
private static void bindDiscriminatorColumnToRootPersistentClass(
		RootClass rootClass,
		Ejb3DiscriminatorColumn discriminatorColumn,
		Map<String, Join> secondaryTables,
		PropertyHolder propertyHolder,
		Mappings mappings) {
	if ( rootClass.getDiscriminator() == null ) {
		if ( discriminatorColumn == null ) {
			throw new AssertionFailure( "discriminator column should have been built" );
		}
		discriminatorColumn.setJoins( secondaryTables );
		discriminatorColumn.setPropertyHolder( propertyHolder );
		SimpleValue discriminatorColumnBinding = new SimpleValue( mappings, rootClass.getTable() );
		rootClass.setDiscriminator( discriminatorColumnBinding );
		discriminatorColumn.linkWithValue( discriminatorColumnBinding );
		discriminatorColumnBinding.setTypeName( discriminatorColumn.getDiscriminatorTypeName() );
		rootClass.setPolymorphic( true );
		if ( LOG.isTraceEnabled() ) {
			LOG.tracev( "Setting discriminator for entity {0}", rootClass.getEntityName() );
		}
	}
}