Search in sources :

Example 6 with AttributeConverterDefinition

use of org.hibernate.cfg.AttributeConverterDefinition in project hibernate-orm by hibernate.

the class EntityManagerFactoryBuilderImpl method populate.

protected void populate(MetadataBuilder metamodelBuilder, MergedSettings mergedSettings, StandardServiceRegistry ssr, List<AttributeConverterDefinition> attributeConverterDefinitions) {
    if (persistenceUnit.getTempClassLoader() != null) {
        metamodelBuilder.applyTempClassLoader(persistenceUnit.getTempClassLoader());
    }
    metamodelBuilder.applyScanEnvironment(new StandardJpaScanEnvironmentImpl(persistenceUnit));
    metamodelBuilder.applyScanOptions(new StandardScanOptions((String) configurationValues.get(org.hibernate.cfg.AvailableSettings.SCANNER_DISCOVERY), persistenceUnit.isExcludeUnlistedClasses()));
    if (mergedSettings.cacheRegionDefinitions != null) {
        for (CacheRegionDefinition localCacheRegionDefinition : mergedSettings.cacheRegionDefinitions) {
            metamodelBuilder.applyCacheRegionDefinition(localCacheRegionDefinition);
        }
    }
    final TypeContributorList typeContributorList = (TypeContributorList) configurationValues.remove(TYPE_CONTRIBUTORS);
    if (typeContributorList != null) {
        for (TypeContributor typeContributor : typeContributorList.getTypeContributors()) {
            metamodelBuilder.applyTypes(typeContributor);
        }
    }
    if (attributeConverterDefinitions != null) {
        for (AttributeConverterDefinition attributeConverterDefinition : attributeConverterDefinitions) {
            metamodelBuilder.applyAttributeConverter(attributeConverterDefinition);
        }
    }
}
Also used : AttributeConverterDefinition(org.hibernate.cfg.AttributeConverterDefinition) CacheRegionDefinition(org.hibernate.boot.CacheRegionDefinition) TypeContributorList(org.hibernate.jpa.boot.spi.TypeContributorList) StandardScanOptions(org.hibernate.boot.archive.scan.internal.StandardScanOptions) TypeContributor(org.hibernate.boot.model.TypeContributor)

Example 7 with AttributeConverterDefinition

use of org.hibernate.cfg.AttributeConverterDefinition in project hibernate-orm by hibernate.

the class EntityManagerFactoryBuilderImpl method populate.

@SuppressWarnings("unchecked")
protected List<AttributeConverterDefinition> populate(MetadataSources metadataSources, MergedSettings mergedSettings, StandardServiceRegistry ssr) {
    //		final ClassLoaderService classLoaderService = ssr.getService( ClassLoaderService.class );
    //
    //		// todo : make sure MetadataSources/Metadata are capable of handling duplicate sources
    //
    //		// explicit persistence unit mapping files listings
    //		if ( persistenceUnit.getMappingFileNames() != null ) {
    //			for ( String name : persistenceUnit.getMappingFileNames() ) {
    //				metadataSources.addResource( name );
    //			}
    //		}
    //
    //		// explicit persistence unit managed class listings
    //		//		IMPL NOTE : managed-classes can contain class or package names!!!
    //		if ( persistenceUnit.getManagedClassNames() != null ) {
    //			for ( String managedClassName : persistenceUnit.getManagedClassNames() ) {
    //				// try it as a class name first...
    //				final String classFileName = managedClassName.replace( '.', '/' ) + ".class";
    //				final URL classFileUrl = classLoaderService.locateResource( classFileName );
    //				if ( classFileUrl != null ) {
    //					// it is a class
    //					metadataSources.addAnnotatedClassName( managedClassName );
    //					continue;
    //				}
    //
    //				// otherwise, try it as a package name
    //				final String packageInfoFileName = managedClassName.replace( '.', '/' ) + "/package-info.class";
    //				final URL packageInfoFileUrl = classLoaderService.locateResource( packageInfoFileName );
    //				if ( packageInfoFileUrl != null ) {
    //					// it is a package
    //					metadataSources.addPackage( managedClassName );
    //					continue;
    //				}
    //
    //				LOG.debugf(
    //						"Unable to resolve class [%s] named in persistence unit [%s]",
    //						managedClassName,
    //						persistenceUnit.getName()
    //				);
    //			}
    //		}
    List<AttributeConverterDefinition> attributeConverterDefinitions = null;
    // add any explicit Class references passed in
    final List<Class> loadedAnnotatedClasses = (List<Class>) configurationValues.remove(AvailableSettings.LOADED_CLASSES);
    if (loadedAnnotatedClasses != null) {
        for (Class cls : loadedAnnotatedClasses) {
            if (AttributeConverter.class.isAssignableFrom(cls)) {
                if (attributeConverterDefinitions == null) {
                    attributeConverterDefinitions = new ArrayList<>();
                }
                attributeConverterDefinitions.add(AttributeConverterDefinition.from((Class<? extends AttributeConverter>) cls));
            } else {
                metadataSources.addAnnotatedClass(cls);
            }
        }
    }
    // add any explicit hbm.xml references passed in
    final String explicitHbmXmls = (String) configurationValues.remove(AvailableSettings.HBXML_FILES);
    if (explicitHbmXmls != null) {
        for (String hbmXml : StringHelper.split(", ", explicitHbmXmls)) {
            metadataSources.addResource(hbmXml);
        }
    }
    // add any explicit orm.xml references passed in
    final List<String> explicitOrmXmlList = (List<String>) configurationValues.remove(AvailableSettings.XML_FILE_NAMES);
    if (explicitOrmXmlList != null) {
        for (String ormXml : explicitOrmXmlList) {
            metadataSources.addResource(ormXml);
        }
    }
    return attributeConverterDefinitions;
}
Also used : AttributeConverter(javax.persistence.AttributeConverter) AttributeConverterDefinition(org.hibernate.cfg.AttributeConverterDefinition) ArrayList(java.util.ArrayList) StrategyRegistrationProviderList(org.hibernate.jpa.boot.spi.StrategyRegistrationProviderList) List(java.util.List) TypeContributorList(org.hibernate.jpa.boot.spi.TypeContributorList) UnloadedClass(org.hibernate.bytecode.enhance.spi.UnloadedClass)

Example 8 with AttributeConverterDefinition

use of org.hibernate.cfg.AttributeConverterDefinition in project hibernate-orm by hibernate.

the class ParameterizedAttributeConverterParameterTypeTest method testGenericTypeParameters.

@Test
@TestForIssue(jiraKey = "HHH-8804")
public void testGenericTypeParameters() {
    AttributeConverterDefinition def = AttributeConverterDefinition.from(CustomAttributeConverter.class);
    assertEquals(List.class, def.getEntityAttributeType());
}
Also used : AttributeConverterDefinition(org.hibernate.cfg.AttributeConverterDefinition) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 9 with AttributeConverterDefinition

use of org.hibernate.cfg.AttributeConverterDefinition in project hibernate-orm by hibernate.

the class AttributeConverterOnSuperclassTest method testAttributeConverterOnSuperclass.

@Test
public void testAttributeConverterOnSuperclass() {
    AttributeConverterDefinition def = AttributeConverterDefinition.from(StringIntegerConverterSubclass.class);
    assertEquals(String.class, def.getEntityAttributeType());
}
Also used : AttributeConverterDefinition(org.hibernate.cfg.AttributeConverterDefinition) Test(org.junit.Test)

Example 10 with AttributeConverterDefinition

use of org.hibernate.cfg.AttributeConverterDefinition in project hibernate-orm by hibernate.

the class AttributeConverterOnSuperclassTest method testParameterizedTypeWithTypeVariableAttributeConverterTypeArguments.

@Test
public void testParameterizedTypeWithTypeVariableAttributeConverterTypeArguments() {
    AttributeConverterDefinition def = AttributeConverterDefinition.from(StringListNoopAttributeConverter.class);
    assertEquals(List.class, def.getEntityAttributeType());
}
Also used : AttributeConverterDefinition(org.hibernate.cfg.AttributeConverterDefinition) Test(org.junit.Test)

Aggregations

AttributeConverterDefinition (org.hibernate.cfg.AttributeConverterDefinition)10 Test (org.junit.Test)5 TypeContributorList (org.hibernate.jpa.boot.spi.TypeContributorList)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 AttributeConverter (javax.persistence.AttributeConverter)1 Element (org.dom4j.Element)1 AnnotationException (org.hibernate.AnnotationException)1 CacheRegionDefinition (org.hibernate.boot.CacheRegionDefinition)1 StandardScanOptions (org.hibernate.boot.archive.scan.internal.StandardScanOptions)1 ClassLoaderAccessImpl (org.hibernate.boot.internal.ClassLoaderAccessImpl)1 InFlightMetadataCollectorImpl (org.hibernate.boot.internal.InFlightMetadataCollectorImpl)1 MetadataBuildingContextRootImpl (org.hibernate.boot.internal.MetadataBuildingContextRootImpl)1 MappingBinder (org.hibernate.boot.jaxb.internal.MappingBinder)1 TypeContributor (org.hibernate.boot.model.TypeContributor)1 AnnotationMetadataSourceProcessorImpl (org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl)1 EntityHierarchyBuilder (org.hibernate.boot.model.source.internal.hbm.EntityHierarchyBuilder)1 EntityHierarchySourceImpl (org.hibernate.boot.model.source.internal.hbm.EntityHierarchySourceImpl)1