當前位置: 首頁>>代碼示例>>Java>>正文


Java Convert類代碼示例

本文整理匯總了Java中javax.persistence.Convert的典型用法代碼示例。如果您正苦於以下問題:Java Convert類的具體用法?Java Convert怎麽用?Java Convert使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Convert類屬於javax.persistence包,在下文中一共展示了Convert類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getConverts

import javax.persistence.Convert; //導入依賴的package包/類
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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:JPAOverriddenAnnotationReader.java

示例2: getConverter

import javax.persistence.Convert; //導入依賴的package包/類
@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;
}
 
開發者ID:michaelliao,項目名稱:warpdb,代碼行數:21,代碼來源:AccessibleProperty.java

示例3: AttributeConversionInfo

import javax.persistence.Convert; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public AttributeConversionInfo(Convert convertAnnotation, XAnnotatedElement xAnnotatedElement) {
	this(
			convertAnnotation.converter(),
			convertAnnotation.disableConversion(),
			convertAnnotation.attributeName(),
			xAnnotatedElement
	);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:AttributeConversionInfo.java

示例4: getConvertsForAttribute

import javax.persistence.Convert; //導入依賴的package包/類
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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:41,代碼來源:JPAOverriddenAnnotationReader.java

示例5: applyXmlDefinedConverts

import javax.persistence.Convert; //導入依賴的package包/類
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 );
	}

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:35,代碼來源:JPAOverriddenAnnotationReader.java

示例6: getSearchBean

import javax.persistence.Convert; //導入依賴的package包/類
/**
 * Get searchBean
 * @return searchBean SearchBean.
 */
@Lob
@Column(name = "MARSHALLED_SEARCH")
@Convert(converter = SearchBeanConverter.class)
public SearchBean getSearchBean() {
    return searchBean;
}
 
開發者ID:cucina,項目名稱:opencucina,代碼行數:11,代碼來源:PersistableSearch.java

示例7: getAttributes

import javax.persistence.Convert; //導入依賴的package包/類
/**
 * JAVADOC Method Level Comments
 *
 * @return JAVADOC.
 */

//    @Lob
@Convert(converter = JsonMapConverter.class)
public Map<String, Object> getAttributes() {
    return attributes;
}
 
開發者ID:cucina,項目名稱:opencucina,代碼行數:12,代碼來源:ListItem.java

示例8: getDefaultValue

import javax.persistence.Convert; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:cucina,項目名稱:opencucina,代碼行數:11,代碼來源:ListItem.java

示例9: getRetired

import javax.persistence.Convert; //導入依賴的package包/類
/**
 * @return Returns the retired.
 */
@ProjectionColumn
@Convert(converter = BooleanConverter.class)
@Column(columnDefinition = "CHAR(1) not null")
public Boolean getRetired() {
    return retired;
}
 
開發者ID:cucina,項目名稱:opencucina,代碼行數:10,代碼來源:ListItem.java

示例10: applyLocalConvert

import javax.persistence.Convert; //導入依賴的package包/類
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'"
				);
			}
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:62,代碼來源:CollectionPropertyHolder.java

示例11: getAction

import javax.persistence.Convert; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:11,代碼來源:MCRJob.java

示例12: getURI

import javax.persistence.Convert; //導入依賴的package包/類
@Override
@Column
@Convert(converter = MCRURIConverter.class)
public URI getURI() {
    return super.getURI();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:7,代碼來源:MCRCategoryImpl.java

示例13: getCountryCode

import javax.persistence.Convert; //導入依賴的package包/類
@Column(name = "COUNTRY_CODE", length = 6)
@Convert(converter = CountryCodeConverter.class)
public CountryCode getCountryCode() {
    return countryCode;
}
 
開發者ID:jaxio,項目名稱:celerio-angular-quickstart,代碼行數:6,代碼來源:User.java

示例14: isComplete

import javax.persistence.Convert; //導入依賴的package包/類
/**
 * JAVADOC Method Level Comments
 *
 * @return JAVADOC.
 */
@Convert(converter = BooleanConverter.class)
@Column(columnDefinition = "CHAR(1) not null")
public boolean isComplete() {
    return complete;
}
 
開發者ID:cucina,項目名稱:opencucina,代碼行數:11,代碼來源:ClusterControl.java

示例15: getProperties

import javax.persistence.Convert; //導入依賴的package包/類
/**
 * JAVADOC Method Level Comments
 *
 * @return JAVADOC.
 */
@Column(length = 1000)
@Convert(converter = JsonMapConverter.class)
public Map<Object, Object> getProperties() {
    return properties;
}
 
開發者ID:cucina,項目名稱:opencucina,代碼行數:11,代碼來源:ClusterControl.java


注:本文中的javax.persistence.Convert類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。