本文整理匯總了Java中org.hibernate.boot.MetadataSources.addPackage方法的典型用法代碼示例。如果您正苦於以下問題:Java MetadataSources.addPackage方法的具體用法?Java MetadataSources.addPackage怎麽用?Java MetadataSources.addPackage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hibernate.boot.MetadataSources
的用法示例。
在下文中一共展示了MetadataSources.addPackage方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: validateSchema
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
/**
* Schema validation
*/
private void validateSchema() {
try {
StandardServiceRegistry registry = localSessionFactory.getConfiguration()
.getStandardServiceRegistryBuilder().build();
MetadataSources sources = new MetadataSources(registry);
sources.addPackage("org.unitedinternet.cosmo.model.hibernate");
Metadata metadata = sources.buildMetadata(registry);
new SchemaValidator().validate(metadata);
LOG.info("schema validation passed");
} catch (HibernateException e) {
LOG.error("error validating schema", e);
throw e;
}
}
示例2: createSQLSchema
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
private void createSQLSchema(String fileName, String dialect) {
File file = new File(fileName);
if (file.exists()) {
file.delete();
}
MetadataSources metadata = new MetadataSources(
new StandardServiceRegistryBuilder()
.applySetting("hibernate.implicit_naming_strategy", new MidPointImplicitNamingStrategy())
.applySetting("hibernate.physical_naming_strategy", new MidPointPhysicalNamingStrategy())
.applySetting("hibernate.dialect", dialect)
.build());
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.container", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.any", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.embedded", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.enums", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.id", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.other", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.common.type", metadata);
addAnnotatedClasses("com.evolveum.midpoint.repo.sql.data.audit", metadata);
metadata.addPackage("com.evolveum.midpoint.repo.sql.type");
SchemaExport export = new SchemaExport();
export.setOutputFile(fileName);
export.setDelimiter(";");
// export.setFormat(true);
export.execute(EnumSet.of(TargetType.SCRIPT), SchemaExport.Action.CREATE, metadata.buildMetadata());
}
示例3: newSessionFactory
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
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();
metadataBuilder.enableNewIdentifierGeneratorSupport(true);
metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE);
MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
Interceptor interceptor = interceptor();
if (interceptor != null) {
sfb.applyInterceptor(interceptor);
}
return sfb.build();
}
示例4: newSessionFactory
import org.hibernate.boot.MetadataSources; //導入方法依賴的package包/類
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();
metadataBuilder.enableNewIdentifierGeneratorSupport(true);
metadataBuilder.applyImplicitNamingStrategy(ImplicitNamingStrategyLegacyJpaImpl.INSTANCE);
final List<Type> additionalTypes = additionalTypes();
if (additionalTypes != null) {
additionalTypes.stream().forEach(type -> {
metadataBuilder.applyTypes((typeContributions, serviceRegistry1) -> {
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);
}
});
});
}
MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
Interceptor interceptor = interceptor();
if(interceptor != null) {
sfb.applyInterceptor(interceptor);
}
return sfb.build();
}