javax.persistence.InheritanceType#SINGLE_TABLE源码实例Demo

下面列出了javax.persistence.InheritanceType#SINGLE_TABLE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: celerio   文件: InheritanceFactory.java
private void putEntityByTableNameForEntityWithInheritance() {
    // Attention, for SINGLE_TABLE inheritance strategy, we only put the root entity.

    for (EntityConfig entityConfig : config.getCelerio().getEntityConfigs()) {
        Entity entity = config.getProject().getEntityByName(entityConfig.getEntityName());

        if (entity.hasInheritance() && !config.getProject().hasEntityBySchemaAndTableName(entity.getTable().getSchemaName(), entity.getTable().getName())) {
            InheritanceType inheritanceType = entity.getInheritance().getStrategy();

            if (inheritanceType == InheritanceType.SINGLE_TABLE) {
                if (entity.isRoot()) {
                    config.getProject().putEntity(entity);
                }
            } else if (inheritanceType == InheritanceType.JOINED || inheritanceType == InheritanceType.TABLE_PER_CLASS) {
                config.getProject().putEntity(entity);
            } else {
                log.warning("Invalid case, there should be an inheritance type");
            }
        }
    }
}
 
源代码2 项目: lams   文件: JPAOverriddenAnnotationReader.java
private Inheritance getInheritance(Element tree, XMLContext.Default defaults) {
	Element element = tree != null ? tree.element( "inheritance" ) : null;
	if ( element != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( Inheritance.class );
		Attribute attr = element.attribute( "strategy" );
		InheritanceType strategy = InheritanceType.SINGLE_TABLE;
		if ( attr != null ) {
			String value = attr.getValue();
			if ( "SINGLE_TABLE".equals( value ) ) {
				strategy = InheritanceType.SINGLE_TABLE;
			}
			else if ( "JOINED".equals( value ) ) {
				strategy = InheritanceType.JOINED;
			}
			else if ( "TABLE_PER_CLASS".equals( value ) ) {
				strategy = InheritanceType.TABLE_PER_CLASS;
			}
			else {
				throw new AnnotationException(
						"Unknown InheritanceType in XML: " + value + " (" + SCHEMA_VALIDATION + ")"
				);
			}
		}
		ad.setValue( "strategy", strategy );
		return AnnotationFactory.create( ad );
	}
	else if ( defaults.canUseJavaAnnotations() ) {
		return getPhysicalAnnotation( Inheritance.class );
	}
	else {
		return null;
	}
}
 
private static boolean isSingleTable(Class<?> entity) {
  Inheritance inheritance = entity.getSuperclass().getAnnotation(Inheritance.class);
  return inheritance != null && inheritance.strategy() == InheritanceType.SINGLE_TABLE;
}
 
 同类方法