org.hibernate.jpa.boot.spi.TypeContributorList Java Examples

The following examples show how to use org.hibernate.jpa.boot.spi.TypeContributorList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FastBootMetadataBuilder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Greatly simplified copy of
 * org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl#populate(org.hibernate.boot.MetadataBuilder,
 * org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.MergedSettings,
 * org.hibernate.boot.registry.StandardServiceRegistry, java.util.List)
 */
protected void populate(MetadataBuilder metamodelBuilder, List<CacheRegionDefinition> cacheRegionDefinitions,
        StandardServiceRegistry ssr) {

    ((MetadataBuilderImplementor) metamodelBuilder).getBootstrapContext().markAsJpaBootstrap();

    metamodelBuilder.applyScanEnvironment(new StandardJpaScanEnvironmentImpl(persistenceUnit));
    metamodelBuilder.applyScanOptions(new StandardScanOptions(
            (String) buildTimeSettings.get(org.hibernate.cfg.AvailableSettings.SCANNER_DISCOVERY),
            persistenceUnit.isExcludeUnlistedClasses()));

    if (cacheRegionDefinitions != null) {
        cacheRegionDefinitions.forEach(metamodelBuilder::applyCacheRegionDefinition);
    }

    final TypeContributorList typeContributorList = (TypeContributorList) buildTimeSettings
            .get(EntityManagerFactoryBuilderImpl.TYPE_CONTRIBUTORS);
    if (typeContributorList != null) {
        typeContributorList.getTypeContributors().forEach(metamodelBuilder::applyTypes);
    }
}
 
Example #2
Source File: PostgreSQLJsonBinaryTypeProgrammaticConfigurationSupplierTest.java    From hibernate-types with Apache License 2.0 6 votes vote down vote up
@Override
protected void additionalProperties(Properties properties) {
    ObjectMapper objectMapper = new ObjectMapper().findAndRegisterModules();
    objectMapper.setTimeZone(TimeZone.getTimeZone("GMT"));
    SimpleModule simpleModule = new SimpleModule("SimpleModule", new Version(1, 0, 0, null, null, null));
    simpleModule.addSerializer(new MoneySerializer());
    objectMapper.registerModule(simpleModule);

    JsonBinaryType jsonBinaryType = new JsonBinaryType(objectMapper, Location.class);

    properties.put("hibernate.type_contributors",
        (TypeContributorList) () -> Collections.singletonList(
            (typeContributions, serviceRegistry) ->
                typeContributions.contributeType(
                    jsonBinaryType, "location"
                )
        )
    );
}
 
Example #3
Source File: PostgreSQLJsonBinaryTypeProgrammaticConfigurationTest.java    From hibernate-types with Apache License 2.0 6 votes vote down vote up
@Override
protected void additionalProperties(Properties properties) {
    CustomObjectMapperSupplier customObjectMapperSupplier = new CustomObjectMapperSupplier();
    final JsonBinaryType jsonBinaryType = new JsonBinaryType(customObjectMapperSupplier.get(), Location.class);

    properties.put( "hibernate.type_contributors", new TypeContributorList() {
        @Override
        public List<TypeContributor> getTypeContributors() {
            List<TypeContributor> typeContributors = new ArrayList<TypeContributor>();
            typeContributors.add(new TypeContributor() {
                @Override
                public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
                    typeContributions.contributeType(
                        jsonBinaryType, "location"
                    );
                }
            });
            return typeContributors;
        }
    });
}
 
Example #4
Source File: EntityManagerFactoryBuilderImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected void populate(
		MetadataBuilder metamodelBuilder,
		MergedSettings mergedSettings,
		StandardServiceRegistry ssr,
		List<AttributeConverterDefinition> attributeConverterDefinitions) {
	( (MetadataBuilderImplementor) metamodelBuilder ).getBootstrapContext().markAsJpaBootstrap();

	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 ) {
		mergedSettings.cacheRegionDefinitions.forEach( metamodelBuilder::applyCacheRegionDefinition );
	}

	final TypeContributorList typeContributorList = (TypeContributorList) configurationValues.remove(
			TYPE_CONTRIBUTORS
	);
	if ( typeContributorList != null ) {
		typeContributorList.getTypeContributors().forEach( metamodelBuilder::applyTypes );
	}

	if ( attributeConverterDefinitions != null ) {
		attributeConverterDefinitions.forEach( metamodelBuilder::applyAttributeConverter );
	}
}
 
Example #5
Source File: PostgreSQLJsonBinaryTypeProgrammaticConfigurationTest.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
protected void additionalProperties(Properties properties) {
    CustomObjectMapperSupplier customObjectMapperSupplier = new CustomObjectMapperSupplier();
    JsonBinaryType jsonBinaryType = new JsonBinaryType(customObjectMapperSupplier.get(), Location.class);

    properties.put("hibernate.type_contributors",
        (TypeContributorList) () -> Collections.singletonList(
            (typeContributions, serviceRegistry) ->
                typeContributions.contributeType(
                    jsonBinaryType, "location"
                )
        )
    );
}
 
Example #6
Source File: PostgreSQLYearMonthIntegerTypeContributorTest.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
protected void additionalProperties(Properties properties) {
    properties.put("hibernate.type_contributors",
            (TypeContributorList) () -> Collections.singletonList(
                    (typeContributions, serviceRegistry) ->
                            typeContributions.contributeType(YearMonthIntegerType.INSTANCE)
            ));
}
 
Example #7
Source File: AbstractTest.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
protected EntityManagerFactory newEntityManagerFactory() {
    PersistenceUnitInfo persistenceUnitInfo = persistenceUnitInfo(getClass().getSimpleName());
    Map<String, Object> configuration = new HashMap<>();
    configuration.put(AvailableSettings.INTERCEPTOR, interceptor());
    Integrator integrator = integrator();
    if (integrator != null) {
        configuration.put("hibernate.integrator_provider", (IntegratorProvider) () -> Collections.singletonList(integrator));
    }

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        configuration.put("hibernate.type_contributors", (TypeContributorList) () -> {
            List<TypeContributor> typeContributors = new ArrayList<>();

            for (Type additionalType : additionalTypes) {
                if (additionalType instanceof BasicType) {
                    typeContributors.add((typeContributions, serviceRegistry) -> typeContributions.contributeType((BasicType) additionalType));


                } else if (additionalType instanceof UserType) {
                    typeContributors.add((typeContributions, serviceRegistry) -> typeContributions.contributeType((UserType) additionalType));
                } else if (additionalType instanceof CompositeUserType) {
                    typeContributors.add((typeContributions, serviceRegistry) -> typeContributions.contributeType((CompositeUserType) additionalType));
                }
            }
            return typeContributors;
        });
    }

    EntityManagerFactoryBuilderImpl entityManagerFactoryBuilder = new EntityManagerFactoryBuilderImpl(
            new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration
    );
    return entityManagerFactoryBuilder.build();
}
 
Example #8
Source File: MetadataContributorsJsonNodeBinaryTypeFetchTest.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Override
protected void additionalProperties(Properties properties) {
    TypeContributor typeContributor = new TypeContributor() {
        @Override
        public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
            typeContributions.contributeType(JsonNodeBinaryType.INSTANCE);
            typeContributions.contributeSqlTypeDescriptor(JsonNodeBinaryType.INSTANCE                       .getSqlTypeDescriptor());
        }
    };
    properties.put(
            "hibernate.type_contributors",
            (TypeContributorList) () -> Collections.singletonList(typeContributor)
    );
}