当前位置: 首页>>代码示例>>Java>>正文


Java DiscriminatorType类代码示例

本文整理汇总了Java中javax.persistence.DiscriminatorType的典型用法代码示例。如果您正苦于以下问题:Java DiscriminatorType类的具体用法?Java DiscriminatorType怎么用?Java DiscriminatorType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DiscriminatorType类属于javax.persistence包,在下文中一共展示了DiscriminatorType类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDiscriminatorColumn

import javax.persistence.DiscriminatorType; //导入依赖的package包/类
private DiscriminatorColumn getDiscriminatorColumn(Element tree, XMLContext.Default defaults) {
	Element element = tree != null ? tree.element( "discriminator-column" ) : null;
	if ( element != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( DiscriminatorColumn.class );
		copyStringAttribute( ad, element, "name", false );
		copyStringAttribute( ad, element, "column-definition", false );
		String value = element.attributeValue( "discriminator-type" );
		DiscriminatorType type = DiscriminatorType.STRING;
		if ( value != null ) {
			if ( "STRING".equals( value ) ) {
				type = DiscriminatorType.STRING;
			}
			else if ( "CHAR".equals( value ) ) {
				type = DiscriminatorType.CHAR;
			}
			else if ( "INTEGER".equals( value ) ) {
				type = DiscriminatorType.INTEGER;
			}
			else {
				throw new AnnotationException(
						"Unknown DiscrimiatorType in XML: " + value + " (" + SCHEMA_VALIDATION + ")"
				);
			}
		}
		ad.setValue( "discriminatorType", type );
		copyIntegerAttribute( ad, element, "length" );
		return AnnotationFactory.create( ad );
	}
	else if ( defaults.canUseJavaAnnotations() ) {
		return getPhysicalAnnotation( DiscriminatorColumn.class );
	}
	else {
		return null;
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:36,代码来源:JPAOverriddenAnnotationReader.java

示例2: buildDiscriminator

import javax.persistence.DiscriminatorType; //导入依赖的package包/类
private ColumnExpression buildDiscriminator(final EntityClass<?> c, final DiscriminatorColumn column) {
	final DiscriminatorType type;
	final int maxLength;
	if (column == null) {
		type = DiscriminatorType.STRING;
		final int defaultMaxLength = 31;
		maxLength = defaultMaxLength;
	} else {
		type = column.discriminatorType();
		maxLength = column.length();
	}

	final DiscriminatorValue value = this.entityClass.getAnnotation(DiscriminatorValue.class);
	if (type == DiscriminatorType.INTEGER) {
		return PrimitiveColumnExpression.create(
				value == null ? c.getEntityName().hashCode() : Integer.parseInt(value.value()),
				getContext().getDialect());
	}
	final String v = value == null ? c.getEntityName() : value.value();
	if (StringUtils.isEmpty(v)) {
		throw new IllegalArgumentException("Missing discriminator value for: " + c.getEntityClass());
	}
	if (type == DiscriminatorType.STRING) {
		return PrimitiveColumnExpression.create(v.length() <= maxLength ? v : v.substring(0, maxLength),
				getContext().getDialect());
	} else if (type == DiscriminatorType.CHAR) {
		return PrimitiveColumnExpression.create(v.substring(0, 1), getContext().getDialect());
	}
	throw new IllegalArgumentException("Unknown discriminator type: " + type);
}
 
开发者ID:liefke,项目名称:org.fastnate,代码行数:31,代码来源:EntityClass.java

示例3: buildDiscriminatorColumn

import javax.persistence.DiscriminatorType; //导入依赖的package包/类
public static Ejb3DiscriminatorColumn buildDiscriminatorColumn(
		DiscriminatorType type, DiscriminatorColumn discAnn,
		DiscriminatorFormula discFormulaAnn,
		Mappings mappings) {
	Ejb3DiscriminatorColumn discriminatorColumn = new Ejb3DiscriminatorColumn();
	discriminatorColumn.setMappings( mappings );
	discriminatorColumn.setImplicit( true );
	if ( discFormulaAnn != null ) {
		discriminatorColumn.setImplicit( false );
		discriminatorColumn.setFormula( discFormulaAnn.value() );
	}
	else if ( discAnn != null ) {
		discriminatorColumn.setImplicit( false );
		if ( !BinderHelper.isEmptyAnnotationValue( discAnn.columnDefinition() ) ) {
			discriminatorColumn.setSqlType(
					discAnn.columnDefinition()
			);
		}
		if ( !BinderHelper.isEmptyAnnotationValue( discAnn.name() ) ) {
			discriminatorColumn.setLogicalColumnName( discAnn.name() );
		}
		discriminatorColumn.setNullable( false );
	}
	if ( DiscriminatorType.CHAR.equals( type ) ) {
		discriminatorColumn.setDiscriminatorTypeName( "character" );
		discriminatorColumn.setImplicit( false );
	}
	else if ( DiscriminatorType.INTEGER.equals( type ) ) {
		discriminatorColumn.setDiscriminatorTypeName( "integer" );
		discriminatorColumn.setImplicit( false );
	}
	else if ( DiscriminatorType.STRING.equals( type ) || type == null ) {
		if ( discAnn != null ) discriminatorColumn.setLength( discAnn.length() );
		discriminatorColumn.setDiscriminatorTypeName( "string" );
	}
	else {
		throw new AssertionFailure( "Unknown discriminator type: " + type );
	}
	discriminatorColumn.bind();
	return discriminatorColumn;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:42,代码来源:Ejb3DiscriminatorColumn.java

示例4: processSingleTableDiscriminatorProperties

import javax.persistence.DiscriminatorType; //导入依赖的package包/类
/**
 * Process all discriminator-related metadata per rules for "single table" inheritance
 */
private static Ejb3DiscriminatorColumn processSingleTableDiscriminatorProperties(
		XClass clazzToProcess,
		Mappings mappings,
		InheritanceState inheritanceState,
		EntityBinder entityBinder) {
	final boolean isRoot = !inheritanceState.hasParents();

	Ejb3DiscriminatorColumn discriminatorColumn = null;
	javax.persistence.DiscriminatorColumn discAnn = clazzToProcess.getAnnotation(
			javax.persistence.DiscriminatorColumn.class
	);
	DiscriminatorType discriminatorType = discAnn != null
			? discAnn.discriminatorType()
			: DiscriminatorType.STRING;

	org.hibernate.annotations.DiscriminatorFormula discFormulaAnn = clazzToProcess.getAnnotation(
			org.hibernate.annotations.DiscriminatorFormula.class
	);
	if ( isRoot ) {
		discriminatorColumn = Ejb3DiscriminatorColumn.buildDiscriminatorColumn(
				discriminatorType,
				discAnn,
				discFormulaAnn,
				mappings
		);
	}
	if ( discAnn != null && !isRoot ) {
		LOG.invalidDiscriminatorAnnotation( clazzToProcess.getName() );
	}

	final String discriminatorValue = clazzToProcess.isAnnotationPresent( DiscriminatorValue.class )
			? clazzToProcess.getAnnotation( DiscriminatorValue.class ).value()
			: null;
	entityBinder.setDiscriminatorValue( discriminatorValue );

	DiscriminatorOptions discriminatorOptions = clazzToProcess.getAnnotation( DiscriminatorOptions.class );
	if ( discriminatorOptions != null) {
		entityBinder.setForceDiscriminator( discriminatorOptions.force() );
		entityBinder.setInsertableDiscriminator( discriminatorOptions.insert() );
	}

	return discriminatorColumn;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:47,代码来源:AnnotationBinder.java

示例5: processJoinedDiscriminatorProperties

import javax.persistence.DiscriminatorType; //导入依赖的package包/类
/**
 * Process all discriminator-related metadata per rules for "joined" inheritance
 */
private static Ejb3DiscriminatorColumn processJoinedDiscriminatorProperties(
		XClass clazzToProcess,
		Mappings mappings,
		InheritanceState inheritanceState,
		EntityBinder entityBinder) {
	if ( clazzToProcess.isAnnotationPresent( DiscriminatorFormula.class ) ) {
		throw new MappingException( "@DiscriminatorFormula on joined inheritance not supported at this time" );
	}


	// DiscriminatorValue handling ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	final DiscriminatorValue discriminatorValueAnnotation = clazzToProcess.getAnnotation( DiscriminatorValue.class );
	final String discriminatorValue = discriminatorValueAnnotation != null
			? clazzToProcess.getAnnotation( DiscriminatorValue.class ).value()
			: null;
	entityBinder.setDiscriminatorValue( discriminatorValue );


	// DiscriminatorColumn handling ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	final DiscriminatorColumn discriminatorColumnAnnotation = clazzToProcess.getAnnotation( DiscriminatorColumn.class );
	if ( !inheritanceState.hasParents() ) {
		// we want to process the discriminator column if either:
		//		1) There is an explicit DiscriminatorColumn annotation && we are not told to ignore them
		//		2) There is not an explicit DiscriminatorColumn annotation && we are told to create them implicitly
		final boolean generateDiscriminatorColumn;
		if ( discriminatorColumnAnnotation != null ) {
			if ( mappings.ignoreExplicitDiscriminatorColumnForJoinedInheritance() ) {
				LOG.debugf( "Ignoring explicit DiscriminatorColumn annotation on ", clazzToProcess.getName() );
				generateDiscriminatorColumn = false;
			}
			else {
				LOG.applyingExplicitDiscriminatorColumnForJoined(
						clazzToProcess.getName(),
						AvailableSettings.IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS
				);
				generateDiscriminatorColumn = true;
			}
		}
		else {
			if ( mappings.useImplicitDiscriminatorColumnForJoinedInheritance() ) {
				LOG.debug( "Applying implicit DiscriminatorColumn using DiscriminatorColumn defaults" );
				generateDiscriminatorColumn = true;
			}
			else {
				LOG.debug( "Ignoring implicit (absent) DiscriminatorColumn" );
				generateDiscriminatorColumn = false;
			}
		}

		if ( generateDiscriminatorColumn ) {
			final DiscriminatorType discriminatorType = discriminatorColumnAnnotation != null
					? discriminatorColumnAnnotation.discriminatorType()
					: DiscriminatorType.STRING;
			return Ejb3DiscriminatorColumn.buildDiscriminatorColumn(
					discriminatorType,
					discriminatorColumnAnnotation,
					null,
					mappings
			);
		}
	}
	else {
		if ( discriminatorColumnAnnotation != null ) {
			LOG.invalidDiscriminatorAnnotation( clazzToProcess.getName() );
		}
	}

	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:75,代码来源:AnnotationBinder.java

示例6: getDiscriminatorType

import javax.persistence.DiscriminatorType; //导入依赖的package包/类
public DiscriminatorType getDiscriminatorType() {
    return discriminatorType;
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:4,代码来源:SingleTableInheritanceInfo.java

示例7: setDiscriminatorType

import javax.persistence.DiscriminatorType; //导入依赖的package包/类
public void setDiscriminatorType(DiscriminatorType discriminatorType) {
    this.discriminatorType = discriminatorType;
}
 
开发者ID:passion1014,项目名称:metaworks_framework,代码行数:4,代码来源:SingleTableInheritanceInfo.java


注:本文中的javax.persistence.DiscriminatorType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。