javax.persistence.AssociationOverride Java Examples

The following examples show how to use javax.persistence.AssociationOverride. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractPropertyHolder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: AbstractPropertyHolder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @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;
	}
}
 
Example #4
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: AbstractPropertyHolder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #6
Source File: AbstractPropertyHolder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #7
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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 );
		}
	}
}
 
Example #8
Source File: D.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Embedded
@AssociationOverride(name = "f"/*, joinColumns = { @JoinColumn(name = "E_F") }*/)
public E getE() {
	return e;
}