当前位置: 首页>>代码示例>>Java>>正文


Java Converter类代码示例

本文整理汇总了Java中org.eclipse.persistence.mappings.converters.Converter的典型用法代码示例。如果您正苦于以下问题:Java Converter类的具体用法?Java Converter怎么用?Java Converter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Converter类属于org.eclipse.persistence.mappings.converters包,在下文中一共展示了Converter类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testConvertersEstabished_directAssignment

import org.eclipse.persistence.mappings.converters.Converter; //导入依赖的package包/类
@Test
public void testConvertersEstabished_directAssignment() throws Exception {
	ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class);
	DatabaseMapping attribute = classDescriptor.getMappingForAttributeName("nonStandardDataType");
	assertEquals("attribute data type mismatch", DirectToFieldMapping.class, attribute.getClass());
	Converter converter = ((org.eclipse.persistence.mappings.DirectToFieldMapping) attribute).getConverter();
	assertNotNull("converter not assigned", converter);
	assertEquals("Mismatch - converter should have been the EclipseLink JPA wrapper class", ConverterClass.class,
               converter.getClass());
	Field f = ConverterClass.class.getDeclaredField("attributeConverterClassName");
	f.setAccessible(true);
	String attributeConverterClassName = (String) f.get(converter);
	assertNotNull("attributeConverterClassName missing", attributeConverterClassName);
	assertEquals("Converter class incorrect", "org.kuali.rice.krad.data.jpa.testbo.NonStandardDataTypeConverter",
               attributeConverterClassName);
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:17,代码来源:EclipseLinkAnnotationMetadataProviderImplTest.java

示例2: testConvertersEstabished_autoApply

import org.eclipse.persistence.mappings.converters.Converter; //导入依赖的package包/类
@Test
public void testConvertersEstabished_autoApply() throws Exception {
	ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class);
	DatabaseMapping attribute = classDescriptor.getMappingForAttributeName("currencyProperty");
	assertEquals("attribute data type mismatch", DirectToFieldMapping.class, attribute.getClass());
	Converter converter = ((org.eclipse.persistence.mappings.DirectToFieldMapping) attribute).getConverter();
	assertNotNull("converter not assigned", converter);
	assertEquals("Mismatch - converter should have been the EclipseLink JPA wrapper class", ConverterClass.class,
               converter.getClass());
	Field f = ConverterClass.class.getDeclaredField("attributeConverterClassName");
	f.setAccessible(true);
	String attributeConverterClassName = (String) f.get(converter);
	assertNotNull("attributeConverterClassName missing", attributeConverterClassName);
	assertEquals("Converter class incorrect", "org.kuali.rice.krad.data.jpa.converters.KualiDecimalConverter",
               attributeConverterClassName);
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:17,代码来源:EclipseLinkAnnotationMetadataProviderImplTest.java

示例3: testConvertersEstabished_autoApply_Boolean

import org.eclipse.persistence.mappings.converters.Converter; //导入依赖的package包/类
@Test
public void testConvertersEstabished_autoApply_Boolean() throws Exception {
	ClassDescriptor classDescriptor = jpaMetadataProvider.getClassDescriptor(TestDataObject.class);
	DatabaseMapping attribute = classDescriptor.getMappingForAttributeName("booleanProperty");
	assertEquals("attribute data type mismatch", DirectToFieldMapping.class, attribute.getClass());
	Converter converter = ((org.eclipse.persistence.mappings.DirectToFieldMapping) attribute).getConverter();
	assertNotNull("converter not assigned", converter);
	assertEquals("Mismatch - converter should have been the EclipseLink JPA wrapper class", ConverterClass.class,
               converter.getClass());
	Field f = ConverterClass.class.getDeclaredField("attributeConverterClassName");
	f.setAccessible(true);
	String attributeConverterClassName = (String) f.get(converter);
	assertNotNull("attributeConverterClassName missing", attributeConverterClassName);
	assertEquals("Converter class incorrect", "org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter",
               attributeConverterClassName);
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:17,代码来源:EclipseLinkAnnotationMetadataProviderImplTest.java

示例4: populateImplementationSpecificAttributeLevelMetadata

import org.eclipse.persistence.mappings.converters.Converter; //导入依赖的package包/类
/**
    * {@inheritDoc}
    */
@Override
protected void populateImplementationSpecificAttributeLevelMetadata(DataObjectAttributeImpl attribute,
		SingularAttribute<?, ?> attr) {

	if (attr instanceof SingularAttributeImpl) {
		DatabaseMapping mapping = ((SingularAttributeImpl<?, ?>) attr).getMapping();
		if (mapping != null && mapping.getField() != null) {
               attribute.setReadOnly(mapping.isReadOnly());
			attribute.setBackingObjectName(mapping.getField().getName());
			if (mapping.getField().getLength() != 0) {
				attribute.setMaxLength((long) mapping.getField().getLength());
			}

			// Special check on the converters to attempt to default secure attributes from being shown on the UI
			// We check for a converter which has "encrypt" in its name and auto-set the attribute security
			// to mask the attribute.
			if (mapping instanceof DirectToFieldMapping) {
				Converter converter = ((DirectToFieldMapping) mapping).getConverter();
				// ConverterClass is the internal wrapper EclipseLink uses to wrap the JPA AttributeConverter
				// classes
				// and make them conform to the EclipseLink internal API
				if (converter != null && converter instanceof ConverterClass) {
					// Unfortunately, there is no access to the actual converter class, so we have to hack it
					try {
						Field f = ConverterClass.class.getDeclaredField("attributeConverterClassName");
						f.setAccessible(true);
						String attributeConverterClassName = (String) f.get(converter);
						if (StringUtils.containsIgnoreCase(attributeConverterClassName, "encrypt")) {
							attribute.setSensitive(true);
						}
					} catch (Exception e) {
						LOG.warn("Unable to access the converter name for attribute: "
								+ attribute.getOwningType().getName() + "." + attribute.getName()
								+ "  Skipping attempt to detect converter.");
					}
				}
			}

		}
	}
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:45,代码来源:EclipseLinkJpaMetadataProviderImpl.java

示例5: preLogin

import org.eclipse.persistence.mappings.converters.Converter; //导入依赖的package包/类
@Override
public void preLogin( final SessionEvent event )
{
  final Session session = event.getSession();

  boolean isSqlServer = false;
  boolean isPostgreSQL = false;

  final String geomDriver = (String) session.getProperty( "geolatte.geom.driver" );
  if ( null != geomDriver )
  {
    isSqlServer = geomDriver.equals( "sqlserver" );
    isPostgreSQL = geomDriver.equals( "postgres" );
  }
  else
  {
    final String driver = (String) session.getProperty( "javax.persistence.jdbc.driver" );
    if ( null != driver )
    {
      isSqlServer = driver.contains( ".jtds." );
      isPostgreSQL = driver.contains( "org.postgresql." );
    }
  }

  if ( !isSqlServer && !isPostgreSQL )
  {
    final String message =
      "Unable to determine database type. Explicitly set jpa " +
      "property 'geolatte.geom.driver' to 'sqlserver' or 'postgres'" ;
    throw new IllegalStateException( message );
  }

  final Map<Class, ClassDescriptor> descriptorMap = session.getDescriptors();

  // Walk through all descriptors...
  for ( final Map.Entry<Class, ClassDescriptor> entry : descriptorMap.entrySet() )
  {
    final ClassDescriptor desc = entry.getValue();
    final Vector<DatabaseMapping> mappings = desc.getMappings();
    // walk through all mappings for some class...
    for ( final DatabaseMapping mapping : mappings )
    {
      if ( mapping instanceof DirectToFieldMapping )
      {
        final DirectToFieldMapping dfm = (DirectToFieldMapping) mapping;
        if ( isCandidateConverter( dfm ) )
        {
          final Class type = entry.getKey();
          final String attributeName = dfm.getAttributeName();
          final Field field = getField( type, attributeName );
          final Class<?> fieldType = field.getType();
          if ( Point.class == fieldType ||
               Polygon.class == fieldType ||
               LinearRing.class == fieldType ||
               LineString.class == fieldType ||
               MultiPoint.class == fieldType ||
               MultiPolygon.class == fieldType ||
               MultiLineString.class == fieldType ||
               Geometry.class == fieldType ||
               GeometryCollection.class == fieldType )
          {
            final Converter converter = isSqlServer ? new SqlServerConverter() : new PostgisConverter();
            converter.initialize( mapping, session );
            dfm.setConverter( converter );
          }
        }
      }
    }
  }
}
 
开发者ID:realityforge,项目名称:geolatte-geom-eclipselink,代码行数:71,代码来源:GeolatteExtension.java

示例6: isCandidateConverter

import org.eclipse.persistence.mappings.converters.Converter; //导入依赖的package包/类
private boolean isCandidateConverter( final DirectToFieldMapping mapping )
{
  final Converter converter = mapping.getConverter();
  return null != converter && converter instanceof SerializedObjectConverter;
}
 
开发者ID:realityforge,项目名称:geolatte-geom-eclipselink,代码行数:6,代码来源:GeolatteExtension.java


注:本文中的org.eclipse.persistence.mappings.converters.Converter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。