javax.persistence.MapKeyClass Java Examples

The following examples show how to use javax.persistence.MapKeyClass. 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: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void getMapKeyClass(List<Annotation> annotationList, Element element, XMLContext.Default defaults) {
	String nodeName = "map-key-class";
	Element subelement = element != null ? element.element( nodeName ) : null;
	if ( subelement != null ) {
		String mapKeyClassName = subelement.attributeValue( "class" );
		AnnotationDescriptor ad = new AnnotationDescriptor( MapKeyClass.class );
		if ( StringHelper.isNotEmpty( mapKeyClassName ) ) {
			Class clazz;
			try {
				clazz = classLoaderAccess.classForName(
						XMLContext.buildSafeClassName( mapKeyClassName, defaults )
				);
			}
			catch ( ClassLoadingException e ) {
				throw new AnnotationException(
						"Unable to find " + element.getPath() + " " + nodeName + ": " + mapKeyClassName, e
				);
			}
			ad.setValue( "value", clazz );
		}
		annotationList.add( AnnotationFactory.create( ad ) );
	}
}
 
Example #2
Source File: CollectionPropertyHolder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public void prepare(XProperty collectionProperty) {
	// fugly
	if ( prepared ) {
		return;
	}

	if ( collectionProperty == null ) {
		return;
	}

	prepared = true;

	if ( collection.isMap() ) {
		if ( collectionProperty.isAnnotationPresent( MapKeyEnumerated.class ) ) {
			canKeyBeConverted = false;
		}
		else if ( collectionProperty.isAnnotationPresent( MapKeyTemporal.class ) ) {
			canKeyBeConverted = false;
		}
		else if ( collectionProperty.isAnnotationPresent( MapKeyClass.class ) ) {
			canKeyBeConverted = false;
		}
		else if ( collectionProperty.isAnnotationPresent( MapKeyType.class ) ) {
			canKeyBeConverted = false;
		}
	}
	else {
		canKeyBeConverted = false;
	}

	if ( collectionProperty.isAnnotationPresent( ManyToAny.class ) ) {
		canElementBeConverted = false;
	}
	else if ( collectionProperty.isAnnotationPresent( OneToMany.class ) ) {
		canElementBeConverted = false;
	}
	else if ( collectionProperty.isAnnotationPresent( ManyToMany.class ) ) {
		canElementBeConverted = false;
	}
	else if ( collectionProperty.isAnnotationPresent( Enumerated.class ) ) {
		canElementBeConverted = false;
	}
	else if ( collectionProperty.isAnnotationPresent( Temporal.class ) ) {
		canElementBeConverted = false;
	}
	else if ( collectionProperty.isAnnotationPresent( CollectionType.class ) ) {
		canElementBeConverted = false;
	}

	// Is it valid to reference a collection attribute in a @Convert attached to the owner (entity) by path?
	// if so we should pass in 'clazzToProcess' also
	if ( canKeyBeConverted || canElementBeConverted ) {
		buildAttributeConversionInfoMaps( collectionProperty, elementAttributeConversionInfoMap, keyAttributeConversionInfoMap );
	}
}