use of org.hibernate.boot.MetadataBuilder in project hibernate-orm by hibernate.
the class SchemaValidator method buildMetadata.
private static MetadataImplementor buildMetadata(CommandLineArgs parsedArgs, StandardServiceRegistry serviceRegistry) throws Exception {
final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
for (String filename : parsedArgs.hbmXmlFiles) {
metadataSources.addFile(filename);
}
for (String filename : parsedArgs.jarFiles) {
metadataSources.addJar(new File(filename));
}
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
final StrategySelector strategySelector = serviceRegistry.getService(StrategySelector.class);
if (parsedArgs.implicitNamingStrategy != null) {
metadataBuilder.applyImplicitNamingStrategy(strategySelector.resolveStrategy(ImplicitNamingStrategy.class, parsedArgs.implicitNamingStrategy));
}
if (parsedArgs.physicalNamingStrategy != null) {
metadataBuilder.applyPhysicalNamingStrategy(strategySelector.resolveStrategy(PhysicalNamingStrategy.class, parsedArgs.physicalNamingStrategy));
}
return (MetadataImplementor) metadataBuilder.build();
}
use of org.hibernate.boot.MetadataBuilder in project hibernate-orm by hibernate.
the class BootstrapTest method test_basic_custom_type_register_BasicType_example.
//end::bootstrap-native-PersistenceUnitInfoImpl-example[]
@Test
public void test_basic_custom_type_register_BasicType_example() {
try {
//tag::basic-custom-type-register-BasicType-example[]
ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build();
MetadataSources sources = new MetadataSources(standardRegistry);
MetadataBuilder metadataBuilder = sources.getMetadataBuilder();
metadataBuilder.applyBasicType(BitSetType.INSTANCE);
//end::basic-custom-type-register-BasicType-example[]
} catch (Exception ignore) {
}
}
use of org.hibernate.boot.MetadataBuilder in project hibernate-orm by hibernate.
the class Configuration method buildSessionFactory.
/**
* Create a {@link SessionFactory} using the properties and mappings in this configuration. The
* SessionFactory will be immutable, so changes made to this Configuration afterQuery building the
* SessionFactory will not affect it.
*
* @param serviceRegistry The registry of services to be used in creating this session factory.
*
* @return The built {@link SessionFactory}
*
* @throws HibernateException usually indicates an invalid configuration or invalid mapping information
*/
public SessionFactory buildSessionFactory(ServiceRegistry serviceRegistry) throws HibernateException {
log.debug("Building session factory using provided StandardServiceRegistry");
final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder((StandardServiceRegistry) serviceRegistry);
if (implicitNamingStrategy != null) {
metadataBuilder.applyImplicitNamingStrategy(implicitNamingStrategy);
}
if (physicalNamingStrategy != null) {
metadataBuilder.applyPhysicalNamingStrategy(physicalNamingStrategy);
}
if (sharedCacheMode != null) {
metadataBuilder.applySharedCacheMode(sharedCacheMode);
}
if (!typeContributorRegistrations.isEmpty()) {
for (TypeContributor typeContributor : typeContributorRegistrations) {
metadataBuilder.applyTypes(typeContributor);
}
}
if (!basicTypes.isEmpty()) {
for (BasicType basicType : basicTypes) {
metadataBuilder.applyBasicType(basicType);
}
}
if (sqlFunctions != null) {
for (Map.Entry<String, SQLFunction> entry : sqlFunctions.entrySet()) {
metadataBuilder.applySqlFunction(entry.getKey(), entry.getValue());
}
}
if (auxiliaryDatabaseObjectList != null) {
for (AuxiliaryDatabaseObject auxiliaryDatabaseObject : auxiliaryDatabaseObjectList) {
metadataBuilder.applyAuxiliaryDatabaseObject(auxiliaryDatabaseObject);
}
}
if (attributeConverterDefinitionsByClass != null) {
for (AttributeConverterDefinition attributeConverterDefinition : attributeConverterDefinitionsByClass.values()) {
metadataBuilder.applyAttributeConverter(attributeConverterDefinition);
}
}
final Metadata metadata = metadataBuilder.build();
final SessionFactoryBuilder sessionFactoryBuilder = metadata.getSessionFactoryBuilder();
if (interceptor != null && interceptor != EmptyInterceptor.INSTANCE) {
sessionFactoryBuilder.applyInterceptor(interceptor);
}
if (getSessionFactoryObserver() != null) {
sessionFactoryBuilder.addSessionFactoryObservers(getSessionFactoryObserver());
}
if (getEntityNotFoundDelegate() != null) {
sessionFactoryBuilder.applyEntityNotFoundDelegate(getEntityNotFoundDelegate());
}
if (getEntityTuplizerFactory() != null) {
sessionFactoryBuilder.applyEntityTuplizerFactory(getEntityTuplizerFactory());
}
if (getCurrentTenantIdentifierResolver() != null) {
sessionFactoryBuilder.applyCurrentTenantIdentifierResolver(getCurrentTenantIdentifierResolver());
}
return sessionFactoryBuilder.build();
}
Aggregations