本文整理汇总了Java中javax.persistence.Converter类的典型用法代码示例。如果您正苦于以下问题:Java Converter类的具体用法?Java Converter怎么用?Java Converter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Converter类属于javax.persistence包,在下文中一共展示了Converter类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addAttributeConverter
import javax.persistence.Converter; //导入依赖的package包/类
/**
* Adds the AttributeConverter instance to this Configuration. This form is mainly intended for developers
* to programatically add their own AttributeConverter instance. HEM, instead, uses the
* {@link #addAttributeConverter(Class, boolean)} form
*
* @param attributeConverter The AttributeConverter instance.
*/
public void addAttributeConverter(AttributeConverter attributeConverter) {
boolean autoApply = false;
Converter converterAnnotation = attributeConverter.getClass().getAnnotation( Converter.class );
if ( converterAnnotation != null ) {
autoApply = converterAnnotation.autoApply();
}
addAttributeConverter( new AttributeConverterDefinition( attributeConverter, autoApply ) );
}
示例2: doAutoJpa
import javax.persistence.Converter; //导入依赖的package包/类
public static void doAutoJpa(final IAnnotationFinder finder, final org.apache.openejb.jee.jpa.unit.PersistenceUnit pu) {
final String packageName = pu.getProperties().getProperty(OPENEJB_JPA_AUTO_SCAN_PACKAGE);
String[] packageNames = null;
if (packageName != null) {
packageNames = packageName.split(",");
}
// no need of meta currently since JPA providers doesn't support it
final List<Class<?>> classes = new ArrayList<Class<?>>();
classes.addAll(finder.findAnnotatedClasses(Entity.class));
classes.addAll(finder.findAnnotatedClasses(Embeddable.class));
classes.addAll(finder.findAnnotatedClasses(MappedSuperclass.class));
classes.addAll(finder.findAnnotatedClasses(Converter.class));
final List<String> existingClasses = pu.getClazz();
for (final Class<?> clazz : classes) {
final String name = clazz.getName();
if (existingClasses.contains(name)) {
continue;
}
if (packageNames == null) {
pu.getClazz().add(name);
} else {
for (final String pack : packageNames) {
if (name.startsWith(pack)) {
pu.getClazz().add(name);
}
}
}
}
pu.setScanned(true);
}
示例3: createUnit
import javax.persistence.Converter; //导入依赖的package包/类
public MutablePersistenceUnitInfo createUnit(Class<? extends Annotation> qualifier, String unitName) {
ClassLoader classLoader = holder.getCurrentReloadableClassLoader();
MutablePersistenceUnitInfo result = new MutablePersistenceUnitInfo();
result.setExcludeUnlistedClasses(true);
result.setValidationMode(ValidationMode.NONE);
result.setPersistenceUnitName(unitName);
result.setSharedCacheMode(SharedCacheMode.ENABLE_SELECTIVE);
try {
result.setPersistenceUnitRootUrl(new URL("http://foo.foo"));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
result.addProperty(PersistenceUnitProperties.SESSION_CUSTOMIZER, CompositeSessionCustomizer.class.getName());
// search for entities
{
Set<Class<?>> jpaAnnotations = new HashSet<>(
Arrays.asList(Entity.class, MappedSuperclass.class, Embeddable.class));
for (ClassNode classNode : index.getAllNodes()) {
String className = Type.getObjectType(classNode.name).getClassName();
if (classNode.visibleAnnotations == null)
continue;
boolean jpaAnnotationFound = false;
for (AnnotationNode annotation : classNode.visibleAnnotations) {
Class<?> annotationClass = AsmUtil.loadClass(Type.getType(annotation.desc), classLoader);
// test if the annotation is one of the jpa annotations
if (jpaAnnotations.contains(annotationClass))
jpaAnnotationFound = true;
}
if (jpaAnnotationFound && isPartOfPU(classNode, qualifier, classLoader)) {
result.addManagedClassName(className);
}
}
}
// search converters
{
index.getAllChildren(AttributeConverter.class).stream()
.filter(node -> isPartOfPU(node, qualifier, classLoader))
.map(node -> AsmUtil.loadClass(Type.getObjectType(node.name), classLoader)).forEach(cls -> {
Converter converter = cls.getAnnotation(Converter.class);
if (converter != null && converter.autoApply())
result.addManagedClassName(cls.getName());
});
}
return result;
}
示例4: getJpaConverterClass
import javax.persistence.Converter; //导入依赖的package包/类
public Class<? extends Converter> getJpaConverterClass() {
return getEntityMethod().getAnnotation(Convert.class).converter();
}
示例5: match
import javax.persistence.Converter; //导入依赖的package包/类
@Override
protected boolean match(Class<?> clazz) {
return clazz.isAnnotationPresent(Converter.class);
}
示例6: findEntities
import javax.persistence.Converter; //导入依赖的package包/类
private Set<String> findEntities(ScanResult scanResult)
{
return new TreeSet<>(scanResult.getNamesOfClassesWithAnnotationsAnyOf(Entity.class, MappedSuperclass.class, Embeddable.class, Converter.class));
}