org.hibernate.boot.MetadataBuilder Java Examples

The following examples show how to use org.hibernate.boot.MetadataBuilder. 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: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MetadataBuilder applyAttributeConverter(AttributeConverter attributeConverter, boolean autoApply) {
	this.bootstrapContext.addAttributeConverterInfo(
			new AttributeConverterInfo() {
				@Override
				public Class<? extends AttributeConverter> getConverterClass() {
					return attributeConverter.getClass();
				}

				@Override
				public ConverterDescriptor toConverterDescriptor(MetadataBuildingContext context) {
					return new InstanceBasedConverterDescriptor(
							attributeConverter,
							autoApply,
							context.getBootstrapContext().getClassmateContext()
					);
				}
			}
	);
	return this;
}
 
Example #2
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 #3
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MetadataBuilder applyAttributeConverter(AttributeConverter attributeConverter) {
	this.bootstrapContext.addAttributeConverterInfo(
			new AttributeConverterInfo() {
				@Override
				public Class<? extends AttributeConverter> getConverterClass() {
					return attributeConverter.getClass();
				}

				@Override
				public ConverterDescriptor toConverterDescriptor(MetadataBuildingContext context) {
					return new InstanceBasedConverterDescriptor(
							attributeConverter,
							null,
							context.getBootstrapContext().getClassmateContext()
					);
				}
			}
	);
	return this;
}
 
Example #4
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MetadataBuilder applyAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass, boolean autoApply) {
	this.bootstrapContext.addAttributeConverterInfo(
			new AttributeConverterInfo() {
				@Override
				public Class<? extends AttributeConverter> getConverterClass() {
					return attributeConverterClass;
				}

				@Override
				public ConverterDescriptor toConverterDescriptor(MetadataBuildingContext context) {
					return new ClassBasedConverterDescriptor(
							attributeConverterClass,
							autoApply,
							context.getBootstrapContext().getClassmateContext()
					);
				}
			}
	);
	return this;
}
 
Example #5
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MetadataBuilder applyAttributeConverter(Class<? extends AttributeConverter> attributeConverterClass) {
	this.bootstrapContext.addAttributeConverterInfo(
			new AttributeConverterInfo() {
				@Override
				public Class<? extends AttributeConverter> getConverterClass() {
					return attributeConverterClass;
				}

				@Override
				public ConverterDescriptor toConverterDescriptor(MetadataBuildingContext context) {
					return new ClassBasedConverterDescriptor(
							attributeConverterClass,
							null,
							context.getBootstrapContext().getClassmateContext()
					);
				}
			}
	);
	return this;
}
 
Example #6
Source File: DateTruncTimeZoneFunctionTest.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Override
public void contribute(MetadataBuilder metadataBuilder) {
    metadataBuilder.applySqlFunction(
            "date_trunc",
            new SQLFunctionTemplate(
                    StandardBasicTypes.TIMESTAMP,
                    "date_trunc('day', (?1 AT TIME ZONE ?2))"
            )
    );
}
 
Example #7
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 #8
Source File: SchemaValidatorTask.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void configure(MetadataBuilder metadataBuilder, StandardServiceRegistry serviceRegistry) {
	final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
	if ( implicitNamingStrategy != null ) {
		metadataBuilder.applyImplicitNamingStrategy(
				strategySelector.resolveStrategy( ImplicitNamingStrategy.class, implicitNamingStrategy )
		);
	}
	if ( physicalNamingStrategy != null ) {
		metadataBuilder.applyPhysicalNamingStrategy(
				strategySelector.resolveStrategy( PhysicalNamingStrategy.class, physicalNamingStrategy )
		);
	}
}
 
Example #9
Source File: DefaultPersistManager.java    From onedev with MIT License 5 votes vote down vote up
protected Metadata buildMetadata() {
	MetadataSources metadataSources = new MetadataSources(serviceRegistry);
	for (Class<? extends AbstractEntity> each: ClassUtils.findImplementations(AbstractEntity.class, AbstractEntity.class)) {
		metadataSources.addAnnotatedClass(each);
	}
	
	MetadataBuilder builder = metadataSources.getMetadataBuilder();
	builder.applyPhysicalNamingStrategy(physicalNamingStrategy);
	return builder.build();
}
 
Example #10
Source File: SQLiteMetadataBuilderInitializer.java    From md_blockchain with Apache License 2.0 5 votes vote down vote up
@Override
public void contribute(MetadataBuilder metadataBuilder, StandardServiceRegistry serviceRegistry) {
    DialectResolver dialectResolver = serviceRegistry.getService(DialectResolver.class);

    if (!(dialectResolver instanceof DialectResolverSet)) {
        logger.warnf("DialectResolver '%s' is not an instance of DialectResolverSet, not registering SQLiteDialect",
                dialectResolver);
        return;
    }

    ((DialectResolverSet) dialectResolver).addResolver(resolver);
}
 
Example #11
Source File: Hbm2ddl.java    From wallride with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	String locationPattern = "classpath:/org/wallride/domain/*";

	final BootstrapServiceRegistry registry = new BootstrapServiceRegistryBuilder().build();
	final MetadataSources metadataSources = new MetadataSources(registry);
	final StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder(registry);

	registryBuilder.applySetting(AvailableSettings.DIALECT, ExtendedMySQL5InnoDBDialect.class.getCanonicalName());
	registryBuilder.applySetting(AvailableSettings.GLOBALLY_QUOTED_IDENTIFIERS, true);
	registryBuilder.applySetting(AvailableSettings.PHYSICAL_NAMING_STRATEGY, PhysicalNamingStrategySnakeCaseImpl.class);

	final PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
	final Resource[] resources = resourcePatternResolver.getResources(locationPattern);
	final SimpleMetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
	for (Resource resource : resources) {
		MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
		AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
		if (metadata.hasAnnotation(Entity.class.getName())) {
			metadataSources.addAnnotatedClass(Class.forName(metadata.getClassName()));
		}
	}

	final StandardServiceRegistryImpl registryImpl = (StandardServiceRegistryImpl) registryBuilder.build();
	final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder(registryImpl);

	new SchemaExport()
			.setHaltOnError(true)
			.setDelimiter(";")
			.create(EnumSet.of(TargetType.STDOUT), metadataBuilder.build());
}
 
Example #12
Source File: GroupConcatFunctionMetadataBuilderContributorRegisterTest.java    From high-performance-java-persistence with Apache License 2.0 5 votes vote down vote up
@Override
public void contribute(MetadataBuilder metadataBuilder) {
    metadataBuilder.applySqlFunction(
        "group_concat",
        new StandardSQLFunction("group_concat", StandardBasicTypes.STRING)
    );
}
 
Example #13
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MetadataBuilder enableNewIdentifierGeneratorSupport(boolean enabled) {
	if ( enabled ) {
		this.options.idGenerationTypeInterpreter.disableLegacyFallback();
	}
	else {
		this.options.idGenerationTypeInterpreter.enableLegacyFallback();
	}
	return this;
}
 
Example #14
Source File: EmbeddableImplicitOverrideTest.java    From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void initialize(MetadataBuilder metadataBuilder) {
	super.initialize( metadataBuilder );
	//tag::embeddable-multiple-ImplicitNamingStrategyComponentPathImpl[]
	metadataBuilder.applyImplicitNamingStrategy(
		ImplicitNamingStrategyComponentPathImpl.INSTANCE
	);
	//end::embeddable-multiple-ImplicitNamingStrategyComponentPathImpl[]
}
 
Example #15
Source File: AbstractTest.java    From high-performance-java-persistence with Apache License 2.0 4 votes vote down vote up
private SessionFactory newSessionFactory() {
    final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder()
        .enableAutoClose();

    Integrator integrator = integrator();
    if (integrator != null) {
        bsrb.applyIntegrator( integrator );
    }

    final BootstrapServiceRegistry bsr = bsrb.build();

    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bsr)
        .applySettings(properties())
        .build();

    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);

    for (Class annotatedClass : entities()) {
        metadataSources.addAnnotatedClass(annotatedClass);
    }

    String[] packages = packages();
    if (packages != null) {
        for (String annotatedPackage : packages) {
            metadataSources.addPackage(annotatedPackage);
        }
    }

    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            metadataSources.addResource(resource);
        }
    }

    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder()
    .enableNewIdentifierGeneratorSupport(true)
    .applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE);

    final List<Type> additionalTypes = additionalTypes();
    if (additionalTypes != null) {
        additionalTypes.stream().forEach(type -> {
            metadataBuilder.applyTypes((typeContributions, sr) -> {
                if(type instanceof BasicType) {
                    typeContributions.contributeType((BasicType) type);
                } else if (type instanceof UserType ){
                    typeContributions.contributeType((UserType) type);
                } else if (type instanceof CompositeUserType) {
                    typeContributions.contributeType((CompositeUserType) type);
                }
            });
        });
    }

    additionalMetadata(metadataBuilder);

    MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();

    final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
    Interceptor interceptor = interceptor();
    if(interceptor != null) {
        sfb.applyInterceptor(interceptor);
    }

    return sfb.build();
}
 
Example #16
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder applyIndexView(IndexView jandexView) {
	this.bootstrapContext.injectJandexView( jandexView );
	return this;
}
 
Example #17
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder applyScanner(Scanner scanner) {
	this.bootstrapContext.injectScanner( scanner );
	return this;
}
 
Example #18
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder applyScanEnvironment(ScanEnvironment scanEnvironment) {
	this.bootstrapContext.injectScanEnvironment( scanEnvironment );
	return this;
}
 
Example #19
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder applyTypes(TypeContributor typeContributor) {
	typeContributor.contribute( this, options.serviceRegistry );
	return this;
}
 
Example #20
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder applySharedCacheMode(SharedCacheMode sharedCacheMode) {
	this.options.sharedCacheMode = sharedCacheMode;
	return this;
}
 
Example #21
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder applyPhysicalNamingStrategy(PhysicalNamingStrategy namingStrategy) {
	this.options.physicalNamingStrategy = namingStrategy;
	return this;
}
 
Example #22
Source File: AbstractDelegatingMetadataBuilderImplementor.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder applyImplicitCatalogName(String implicitCatalogName) {
	delegate.applyImplicitCatalogName( implicitCatalogName );
	return getThis();
}
 
Example #23
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder applyAccessType(AccessType implicitCacheAccessType) {
	this.options.mappingDefaults.implicitCacheAccessType = implicitCacheAccessType;
	return this;
}
 
Example #24
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder applyArchiveDescriptorFactory(ArchiveDescriptorFactory factory) {
	this.bootstrapContext.injectArchiveDescriptorFactory( factory );
	return this;
}
 
Example #25
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder applyScanOptions(ScanOptions scanOptions) {
	this.bootstrapContext.injectScanOptions( scanOptions );
	return this;
}
 
Example #26
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder enableImplicitDiscriminatorsForJoinedSubclassSupport(boolean supported) {
	options.implicitDiscriminatorsForJoinedInheritanceSupported = supported;
	return this;
}
 
Example #27
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder enableImplicitForcingOfDiscriminatorsInSelect(boolean supported) {
	options.implicitlyForceDiscriminatorInSelect = supported;
	return this;
}
 
Example #28
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder enableGlobalNationalizedCharacterDataSupport(boolean enabled) {
	options.useNationalizedCharacterData = enabled;
	return this;
}
 
Example #29
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder applyBasicType(BasicType type) {
	options.basicTypeRegistrations.add( new BasicTypeRegistration( type ) );
	return this;
}
 
Example #30
Source File: MetadataBuilderImpl.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MetadataBuilder applyBasicType(BasicType type, String... keys) {
	options.basicTypeRegistrations.add( new BasicTypeRegistration( type, keys ) );
	return this;
}