Java源码示例:javax.persistence.AssociationOverride

示例1
private static AssociationOverride[] buildAssociationOverrides(XAnnotatedElement element, String path) {
	AssociationOverride singleOverride = element.getAnnotation( AssociationOverride.class );
	AssociationOverrides pluralOverrides = element.getAnnotation( AssociationOverrides.class );

	AssociationOverride[] overrides;
	if ( singleOverride != null ) {
		overrides = new AssociationOverride[] { singleOverride };
	}
	else if ( pluralOverrides != null ) {
		overrides = pluralOverrides.value();
	}
	else {
		overrides = null;
	}
	return overrides;
}
 
示例2
private static Map<String, JoinTable> buildJoinTableOverride(XAnnotatedElement element, String path) {
	Map<String, JoinTable> tableOverride = new HashMap<String, JoinTable>();
	if ( element != null ) {
		AssociationOverride[] overrides = buildAssociationOverrides( element, path );
		if ( overrides != null ) {
			for ( AssociationOverride depAttr : overrides ) {
				if ( depAttr.joinColumns().length == 0 ) {
					tableOverride.put(
							StringHelper.qualify( path, depAttr.name() ),
							depAttr.joinTable()
					);
				}
			}
		}
	}
	return tableOverride;
}
 
示例3
/**
 * @param mergeWithAnnotations Whether to use Java annotations for this
 * element, if present and not disabled by the XMLContext defaults.
 * In some contexts (such as an element-collection mapping) merging
 * with annotations is never allowed.
 */
private AssociationOverrides getAssociationOverrides(Element tree, XMLContext.Default defaults, boolean mergeWithAnnotations) {
	List<AssociationOverride> attributes = buildAssociationOverrides( tree, defaults );
	if ( mergeWithAnnotations && defaults.canUseJavaAnnotations() ) {
		AssociationOverride annotation = getPhysicalAnnotation( AssociationOverride.class );
		addAssociationOverrideIfNeeded( annotation, attributes );
		AssociationOverrides annotations = getPhysicalAnnotation( AssociationOverrides.class );
		if ( annotations != null ) {
			for ( AssociationOverride current : annotations.value() ) {
				addAssociationOverrideIfNeeded( current, attributes );
			}
		}
	}
	if ( attributes.size() > 0 ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( AssociationOverrides.class );
		ad.setValue( "value", attributes.toArray( new AssociationOverride[attributes.size()] ) );
		return AnnotationFactory.create( ad );
	}
	else {
		return null;
	}
}
 
示例4
private List<AssociationOverride> buildAssociationOverrides(Element element, XMLContext.Default defaults) {
	List<Element> subelements = element == null ? null : element.elements( "association-override" );
	List<AssociationOverride> overrides = new ArrayList<>();
	if ( subelements != null && subelements.size() > 0 ) {
		for ( Element current : subelements ) {
			AnnotationDescriptor override = new AnnotationDescriptor( AssociationOverride.class );
			copyStringAttribute( override, current, "name", true );
			override.setValue( "joinColumns", getJoinColumns( current, false ) );
			JoinTable joinTable = buildJoinTable( current, defaults );
			if ( joinTable != null ) {
				override.setValue( "joinTable", joinTable );
			}
			overrides.add( AnnotationFactory.create( override ) );
		}
	}
	return overrides;
}
 
示例5
private static Map<String, JoinColumn[]> buildJoinColumnOverride(XAnnotatedElement element, String path) {
	Map<String, JoinColumn[]> columnOverride = new HashMap<String, JoinColumn[]>();
	if ( element != null ) {
		AssociationOverride[] overrides = buildAssociationOverrides( element, path );
		if ( overrides != null ) {
			for ( AssociationOverride depAttr : overrides ) {
				columnOverride.put(
						StringHelper.qualify( path, depAttr.name() ),
						depAttr.joinColumns()
				);
			}
		}
	}
	return columnOverride;
}
 
示例6
private static Map<String, ForeignKey> buildForeignKeyOverride(XAnnotatedElement element, String path) {
	Map<String, ForeignKey> foreignKeyOverride = new HashMap<String, ForeignKey>();
	if ( element != null ) {
		AssociationOverride[] overrides = buildAssociationOverrides( element, path );
		if ( overrides != null ) {
			for ( AssociationOverride depAttr : overrides ) {
				foreignKeyOverride.put( StringHelper.qualify( path, depAttr.name() ), depAttr.foreignKey() );
			}
		}
	}
	return foreignKeyOverride;
}
 
示例7
private void addAssociationOverrideIfNeeded(AssociationOverride annotation, List<AssociationOverride> overrides) {
	if ( annotation != null ) {
		String overrideName = annotation.name();
		boolean present = false;
		for ( AssociationOverride current : overrides ) {
			if ( current.name().equals( overrideName ) ) {
				present = true;
				break;
			}
		}
		if ( !present ) {
			overrides.add( annotation );
		}
	}
}
 
示例8
@Embedded
@AssociationOverride(name = "f"/*, joinColumns = { @JoinColumn(name = "E_F") }*/)
public E getE() {
	return e;
}