Java Code Examples for javax.persistence.Convert

The following are top voted examples for showing how to use javax.persistence.Convert. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: lams   File: JPAOverriddenAnnotationReader.java   View source code 6 votes vote down vote up
private Converts getConverts(Element tree, XMLContext.Default defaults) {
	// NOTE : we use a map here to make sure that an xml and annotation referring to the same attribute
	// properly overrides.  Bit sparse, but easy...
	final Map<String,Convert> convertAnnotationsMap = new HashMap<String, Convert>();

	if ( tree != null ) {
		applyXmlDefinedConverts( tree, defaults, null, convertAnnotationsMap );
	}

	// NOTE : per section 12.2.3.16 of the spec <convert/> is additive, although only if "metadata-complete" is not
	// specified in the XML

	if ( defaults.canUseJavaAnnotations() ) {
		applyPhysicalConvertAnnotations( null, convertAnnotationsMap );
	}

	if ( !convertAnnotationsMap.isEmpty() ) {
		final AnnotationDescriptor groupingDescriptor = new AnnotationDescriptor( Converts.class );
		groupingDescriptor.setValue( "value", convertAnnotationsMap.values().toArray( new Convert[convertAnnotationsMap.size()]) );
		return AnnotationFactory.create( groupingDescriptor );
	}

	return null;
}
 
Example 2
Project: warpdb   File: AccessibleProperty.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
private AttributeConverter<Object, Object> getConverter(AccessibleObject accessible) {
	Convert converter = accessible.getAnnotation(Convert.class);
	if (converter != null) {
		Class<?> converterClass = converter.converter();
		if (!AttributeConverter.class.isAssignableFrom(converterClass)) {
			throw new RuntimeException(
					"Converter class must be AttributeConverter rather than " + converterClass.getName());
		}
		try {
			Constructor<?> cs = converterClass.getDeclaredConstructor();
			cs.setAccessible(true);
			return (AttributeConverter<Object, Object>) cs.newInstance();
		} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException
				| InvocationTargetException e) {
			throw new RuntimeException("Cannot instantiate Converter: " + converterClass.getName(), e);
		}
	}
	return null;
}
 
Example 3
Project: lams   File: AttributeConversionInfo.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
public AttributeConversionInfo(Convert convertAnnotation, XAnnotatedElement xAnnotatedElement) {
	this(
			convertAnnotation.converter(),
			convertAnnotation.disableConversion(),
			convertAnnotation.attributeName(),
			xAnnotatedElement
	);
}
 
Example 4
Project: lams   File: JPAOverriddenAnnotationReader.java   View source code 5 votes vote down vote up
private Annotation getConvertsForAttribute(List<Element> elementsForProperty, XMLContext.Default defaults) {
	// NOTE : we use a map here to make sure that an xml and annotation referring to the same attribute
	// properly overrides.  Very sparse map, yes, but easy setup.
	// todo : revisit this
	// although bear in mind that this code is no longer used in 5.0...

	final Map<String,Convert> convertAnnotationsMap = new HashMap<String, Convert>();

	for ( Element element : elementsForProperty ) {
		final boolean isBasic = "basic".equals( element.getName() );
		final boolean isEmbedded = "embedded".equals( element.getName() );

		// todo : can be collections too

		final boolean canHaveConverts = isBasic || isEmbedded;

		if ( !canHaveConverts ) {
			continue;
		}

		final String attributeNamePrefix = isBasic ? null : propertyName;
		applyXmlDefinedConverts( element, defaults, attributeNamePrefix, convertAnnotationsMap );
	}

	// NOTE : per section 12.2.3.16 of the spec <convert/> is additive, although only if "metadata-complete" is not
	// specified in the XML

	if ( defaults.canUseJavaAnnotations() ) {
		// todo : note sure how to best handle attributeNamePrefix here
		applyPhysicalConvertAnnotations( propertyName, convertAnnotationsMap );
	}

	if ( !convertAnnotationsMap.isEmpty() ) {
		final AnnotationDescriptor groupingDescriptor = new AnnotationDescriptor( Converts.class );
		groupingDescriptor.setValue( "value", convertAnnotationsMap.values().toArray( new Convert[convertAnnotationsMap.size()]) );
		return AnnotationFactory.create( groupingDescriptor );
	}

	return null;
}
 
Example 5
Project: lams   File: JPAOverriddenAnnotationReader.java   View source code 5 votes vote down vote up
private void applyXmlDefinedConverts(
		Element containingElement,
		XMLContext.Default defaults,
		String attributeNamePrefix,
		Map<String,Convert> convertAnnotationsMap) {
	final List<Element> convertElements = containingElement.elements( "convert" );
	for ( Element convertElement : convertElements ) {
		final AnnotationDescriptor convertAnnotationDescriptor = new AnnotationDescriptor( Convert.class );
		copyStringAttribute( convertAnnotationDescriptor, convertElement, "attribute-name", false );
		copyBooleanAttribute( convertAnnotationDescriptor, convertElement, "disable-conversion" );

		final Attribute converterClassAttr = convertElement.attribute( "converter" );
		if ( converterClassAttr != null ) {
			final String converterClassName = XMLContext.buildSafeClassName(
					converterClassAttr.getValue(),
					defaults
			);
			try {
				final Class converterClass = ReflectHelper.classForName( converterClassName, this.getClass() );
				convertAnnotationDescriptor.setValue( "converter", converterClass );
			}
			catch (ClassNotFoundException e) {
				throw new AnnotationException( "Unable to find specified converter class id-class: " + converterClassName, e );
			}
		}
		final Convert convertAnnotation = AnnotationFactory.create( convertAnnotationDescriptor );
		final String qualifiedAttributeName = qualifyConverterAttributeName(
				attributeNamePrefix,
				convertAnnotation.attributeName()
		);
		convertAnnotationsMap.put( qualifiedAttributeName, convertAnnotation );
	}

}
 
Example 6
Project: opencucina   File: PersistableSearch.java   View source code 5 votes vote down vote up
/**
 * Get searchBean
 * @return searchBean SearchBean.
 */
@Lob
@Column(name = "MARSHALLED_SEARCH")
@Convert(converter = SearchBeanConverter.class)
public SearchBean getSearchBean() {
    return searchBean;
}
 
Example 7
Project: opencucina   File: ListItem.java   View source code 5 votes vote down vote up
/**
 * JAVADOC Method Level Comments
 *
 * @return JAVADOC.
 */

//    @Lob
@Convert(converter = JsonMapConverter.class)
public Map<String, Object> getAttributes() {
    return attributes;
}
 
Example 8
Project: opencucina   File: ListItem.java   View source code 5 votes vote down vote up
/**
 * Gets the defaultValue flag on the object
 * @return Returns the defaultValue.
 */
@Convert(converter = BooleanConverter.class)
@Column(columnDefinition = "CHAR(1) not null")
@ProjectionColumn
public Boolean getDefaultValue() {
    return defaultValue;
}
 
Example 9
Project: opencucina   File: ListItem.java   View source code 5 votes vote down vote up
/**
 * @return Returns the retired.
 */
@ProjectionColumn
@Convert(converter = BooleanConverter.class)
@Column(columnDefinition = "CHAR(1) not null")
public Boolean getRetired() {
    return retired;
}
 
Example 10
Project: lams   File: CollectionPropertyHolder.java   View source code 4 votes vote down vote up
private void applyLocalConvert(
		Convert convertAnnotation,
		XProperty collectionProperty,
		Map<String,AttributeConversionInfo> elementAttributeConversionInfoMap,
		Map<String,AttributeConversionInfo> keyAttributeConversionInfoMap) {

	// IMPL NOTE : the rules here are quite more lenient than what JPA says.  For example, JPA says
	// that @Convert on a Map always needs to specify attributeName of key/value (or prefixed with
	// key./value. for embedded paths).  However, we try to see if conversion of either is disabled
	// for whatever reason.  For example, if the Map is annotated with @Enumerated the elements cannot
	// be converted so any @Convert likely meant the key, so we apply it to the key

	final AttributeConversionInfo info = new AttributeConversionInfo( convertAnnotation, collectionProperty );
	if ( collection.isMap() ) {
		boolean specCompliant = StringHelper.isNotEmpty( info.getAttributeName() )
				&& ( info.getAttributeName().startsWith( "key" )
				|| info.getAttributeName().startsWith( "value" ) );
		if ( !specCompliant ) {
			log.nonCompliantMapConversion( collection.getRole() );
		}
	}

	if ( StringHelper.isEmpty( info.getAttributeName() ) ) {
		if ( canElementBeConverted && canKeyBeConverted ) {
			throw new IllegalStateException(
					"@Convert placed on Map attribute [" + collection.getRole()
							+ "] must define attributeName of 'key' or 'value'"
			);
		}
		else if ( canKeyBeConverted ) {
			keyAttributeConversionInfoMap.put( "", info );
		}
		else if ( canElementBeConverted ) {
			elementAttributeConversionInfoMap.put( "", info );
		}
		// if neither, we should not be here...
	}
	else {
		if ( canElementBeConverted && canKeyBeConverted ) {
			// specified attributeName needs to have 'key.' or 'value.' prefix
			if ( info.getAttributeName().startsWith( "key." ) ) {
				keyAttributeConversionInfoMap.put(
						info.getAttributeName().substring( 4 ),
						info
				);
			}
			else if ( info.getAttributeName().startsWith( "value." ) ) {
				elementAttributeConversionInfoMap.put(
						info.getAttributeName().substring( 6 ),
						info
				);
			}
			else {
				throw new IllegalStateException(
						"@Convert placed on Map attribute [" + collection.getRole()
								+ "] must define attributeName of 'key' or 'value'"
				);
			}
		}
	}
}
 
Example 11
Project: mycore   File: MCRJob.java   View source code 4 votes vote down vote up
/**
 * Returns the action class ({@link MCRJobAction}).
 * 
 * @return the action class
 */
@Column(name = "action", nullable = false)
@Convert(converter = MCRJobActionConverter.class)
public Class<? extends MCRJobAction> getAction() {
    return action;
}
 
Example 12
Project: mycore   File: MCRCategoryImpl.java   View source code 4 votes vote down vote up
@Override
@Column
@Convert(converter = MCRURIConverter.class)
public URI getURI() {
    return super.getURI();
}
 
Example 13
Project: celerio-angular-quickstart   File: User.java   View source code 4 votes vote down vote up
@Column(name = "COUNTRY_CODE", length = 6)
@Convert(converter = CountryCodeConverter.class)
public CountryCode getCountryCode() {
    return countryCode;
}
 
Example 14
Project: opencucina   File: ClusterControl.java   View source code 4 votes vote down vote up
/**
 * JAVADOC Method Level Comments
 *
 * @return JAVADOC.
 */
@Convert(converter = BooleanConverter.class)
@Column(columnDefinition = "CHAR(1) not null")
public boolean isComplete() {
    return complete;
}
 
Example 15
Project: opencucina   File: ClusterControl.java   View source code 4 votes vote down vote up
/**
 * JAVADOC Method Level Comments
 *
 * @return JAVADOC.
 */
@Column(length = 1000)
@Convert(converter = JsonMapConverter.class)
public Map<Object, Object> getProperties() {
    return properties;
}
 
Example 16
Project: opencucina   File: PersistableSearch.java   View source code 4 votes vote down vote up
/**
 * Get is public search
 *
 * @return isPublic.
 */
@Convert(converter = BooleanConverter.class)
@Column(name = "IS_PUBLIC", columnDefinition = "CHAR(1) not null")
public boolean isPublic() {
    return isPublic;
}
 
Example 17
Project: pedal-dialect   File: CopyAttribute.java   View source code 4 votes vote down vote up
public boolean isJpaConverter() {
    return getEntityMethod().isAnnotationPresent(Convert.class);
}
 
Example 18
Project: pedal-dialect   File: CopyAttribute.java   View source code 4 votes vote down vote up
public Class<? extends Converter> getJpaConverterClass() {
    return getEntityMethod().getAnnotation(Convert.class).converter();
}
 
Example 19
Project: pedal-dialect   File: ExoticTypes.java   View source code 4 votes vote down vote up
@Column(name = "status", nullable = false, length = 2)
@Convert(converter = StatusConverter.class)
public Status getStatus() {
    return status;
}
 
Example 20
Project: pedal-dialect   File: ExoticTypes.java   View source code 4 votes vote down vote up
@Column(name = "color")
@Convert(converter = ColorConverter.class)
public Color getColor() {
    return color;
}
 
Example 21
Project: blaze-storage   File: Storage.java   View source code 4 votes vote down vote up
@NotNull
@Convert(converter = URIConverter.class)
public URI getUri() {
	return uri;
}
 
Example 22
Project: pedal-loader   File: ExoticTypes.java   View source code 4 votes vote down vote up
@Column(name = "status", nullable = false, length = 2)
@Convert(converter = StatusConverter.class)
public Status getStatus() {
    return status;
}
 
Example 23
Project: pedal-dialect   File: CopyAttribute.java   View source code 4 votes vote down vote up
public boolean isJpaConverter() {
    return getEntityMethod().isAnnotationPresent(Convert.class);
}
 
Example 24
Project: pedal-dialect   File: CopyAttribute.java   View source code 4 votes vote down vote up
public Class<? extends Converter> getJpaConverterClass() {
    return getEntityMethod().getAnnotation(Convert.class).converter();
}
 
Example 25
Project: pedal-dialect   File: ExoticTypes.java   View source code 4 votes vote down vote up
@Column(name = "status", nullable = false, length = 2)
@Convert(converter = StatusConverter.class)
public Status getStatus() {
    return status;
}
 
Example 26
Project: pedal-dialect   File: ExoticTypes.java   View source code 4 votes vote down vote up
@Column(name = "color")
@Convert(converter = ColorConverter.class)
public Color getColor() {
    return color;
}
 
Example 27
Project: pedal-loader   File: ExoticTypes.java   View source code 4 votes vote down vote up
@Column(name = "status", nullable = false, length = 2)
@Convert(converter = StatusConverter.class)
public Status getStatus() {
    return status;
}
 
Example 28
Project: pedal-tx   File: Embedee.java   View source code 4 votes vote down vote up
@Column(name = "name", nullable = false, length = 100)
@Convert(converter = NameConverter.class)
public Name getName() {
    return name;
}
 
Example 29
Project: pedal-tx   File: Student.java   View source code 4 votes vote down vote up
@Column(name = "do-not-use", nullable = true, length = 1)
@Convert(converter = GradeConverter.class)
public Grade getGrade() {
    return grade;
}
 
Example 30
Project: log4j2   File: TestBaseEntity.java   View source code 4 votes vote down vote up
@Override
@Convert(converter = MessageAttributeConverter.class)
@Column(name = "message")
public Message getMessage() {
    return this.getWrappedEvent().getMessage();
}
 
Example 31
Project: log4j2   File: TestBaseEntity.java   View source code 4 votes vote down vote up
@Override
@Convert(converter = ThrowableAttributeConverter.class)
@Column(name = "exception")
public Throwable getThrown() {
    return this.getWrappedEvent().getThrown();
}
 
Example 32
Project: log4j2   File: TestBasicEntity.java   View source code 4 votes vote down vote up
@Override
@Convert(converter = ContextMapJsonAttributeConverter.class)
@Column(name = "contextMapJson")
public Map<String, String> getContextMap() {
    return super.getContextMap();
}
 
Example 33
Project: logging-log4j2   File: TestBasicEntity.java   View source code 4 votes vote down vote up
@Override
@Convert(converter = ContextMapJsonAttributeConverter.class)
@Column(name = "contextMapJson")
public Map<String, String> getContextMap() {
    return super.getContextMap();
}
 
Example 34
Project: logging-log4j2   File: BasicLogEventEntity.java   View source code 4 votes vote down vote up
/**
 * Gets the level. Annotated with {@code @Basic} and {@code @Enumerated(EnumType.STRING)}.
 *
 * @return the level.
 */
@Override
@Convert(converter = LevelAttributeConverter.class)
public Level getLevel() {
    return this.getWrappedEvent().getLevel();
}
 
Example 35
Project: logging-log4j2   File: BasicLogEventEntity.java   View source code 4 votes vote down vote up
@Override
@Convert(converter = InstantAttributeConverter.class)
public Instant getInstant() {
    return this.getWrappedEvent().getInstant();
}
 
Example 36
Project: logging-log4j2   File: TestBaseEntity.java   View source code 4 votes vote down vote up
@Override
@Convert(converter = LevelAttributeConverter.class)
@Column(name = "level")
public Level getLevel() {
    return this.getWrappedEvent().getLevel();
}
 
Example 37
Project: logging-log4j2   File: TestBaseEntity.java   View source code 4 votes vote down vote up
@Override
@Convert(converter = MessageAttributeConverter.class)
@Column(name = "message")
public Message getMessage() {
    return this.getWrappedEvent().getMessage();
}
 
Example 38
Project: logging-log4j2   File: TestBaseEntity.java   View source code 4 votes vote down vote up
@Override
@Convert(converter = InstantAttributeConverter.class)
@Column(name = "instant")
public Instant getInstant() {
    return this.getWrappedEvent().getInstant();
}
 
Example 39
Project: logging-log4j2   File: TestBaseEntity.java   View source code 4 votes vote down vote up
@Override
@Convert(converter = ThrowableAttributeConverter.class)
@Column(name = "exception")
public Throwable getThrown() {
    return this.getWrappedEvent().getThrown();
}
 
Example 40
Project: logging-log4j2   File: TestBasicEntity.java   View source code 4 votes vote down vote up
@Override
@Convert(converter = ContextMapJsonAttributeConverter.class)
@Column(name = "contextMapJson")
public Map<String, String> getContextMap() {
    return super.getContextMap();
}