本文整理匯總了Java中org.hibernate.boot.registry.StandardServiceRegistryBuilder.applySetting方法的典型用法代碼示例。如果您正苦於以下問題:Java StandardServiceRegistryBuilder.applySetting方法的具體用法?Java StandardServiceRegistryBuilder.applySetting怎麽用?Java StandardServiceRegistryBuilder.applySetting使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hibernate.boot.registry.StandardServiceRegistryBuilder
的用法示例。
在下文中一共展示了StandardServiceRegistryBuilder.applySetting方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startHibernate
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
/**
* @param nodeName Name of the grid providing caches.
* @return Session factory.
*/
SessionFactory startHibernate(String nodeName) {
log.info("Start hibernate on node: " + nodeName);
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
for (Map.Entry<String, String> e : hibernateProperties(nodeName, NONSTRICT_READ_WRITE.name()).entrySet())
builder.applySetting(e.getKey(), e.getValue());
builder.applySetting("hibernate.connection.url", CONNECTION_URL);
builder.applySetting(DFLT_CACHE_NAME_PROPERTY, CACHE_NAME);
MetadataSources metadataSources = new MetadataSources(builder.build());
metadataSources.addAnnotatedClass(Entity1.class);
metadataSources.addAnnotatedClass(Entity2.class);
metadataSources.addAnnotatedClass(Entity3.class);
return metadataSources.buildMetadata().buildSessionFactory();
}
示例2: generate
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
/**
* Method that actually creates the file.
*
* @param dbDialect to use
*/
private void generate(Dialect dialect) {
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
ssrb.applySetting("hibernate.dialect", dialect.getDialectClass());
StandardServiceRegistry standardServiceRegistry = ssrb.build();
MetadataSources metadataSources = new MetadataSources(standardServiceRegistry);
for (Class clzz : jpaClasses) {
metadataSources.addAnnotatedClass(clzz);
}
Metadata metadata = metadataSources.buildMetadata();
SchemaExport export = new SchemaExport();
export.setDelimiter(";");
export.setOutputFile(dialect.name().toLowerCase() + ".ddl");
//export.execute(true, false, false, true);
export.execute(EnumSet.of(TargetType.SCRIPT), Action.BOTH, metadata);
}
示例3: configureSettingsFromSystemProperties
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
/**
* Loads all <code>dbbootstrap.[user-space-cfg-name-here].[hibernate-property-name-here]</code> properties from system
* properties. <br>
* <br>
* Any existing hibernate properties with the same name (<code>[hibernate-property-name-here]</code> in above example) will
* be replaced by the matching system property. <br>
* <br>
*
* @param configuration - the runtime hibernate configuration object
*/
private void configureSettingsFromSystemProperties(String prefix, StandardServiceRegistryBuilder configuration) {
String propertyPrefix = String.format("%s.%s", DBBOOTSTRAP_SYSTEM_PROPERTY_PREFIX, prefix);
DbBootstrapLogger.ROOT_LOGGER.tracef(
"Searching for system properties with prefix %s to set and/or override hibernate configuration properties",
propertyPrefix);
for (Map.Entry<Object, Object> entrySet : (System.getProperties().entrySet())) {
if (entrySet.getKey().toString().startsWith(propertyPrefix)) {
String hibernatePropertyName = entrySet.getKey().toString().replace(String.format("%s.", propertyPrefix), "");
String newHibernatePropertyValue = entrySet.getValue().toString();
DbBootstrapLogger.ROOT_LOGGER.tracef("Setting hibernate property: %s=%s", hibernatePropertyName,
newHibernatePropertyValue);
configuration.applySetting(hibernatePropertyName, newHibernatePropertyValue);
}
}
}
示例4: initializeFactory
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
/**
* 初始化 hibernate 工廠
*
* @param driver
* 驅動
* @param url
* 連接地址
* @param user
* 用戶名
* @param password
* 密碼
*
*/
static void initializeFactory(String driver, String url, String user, String password, int fixedConnectionSize) {
// 引導 hibernate 日誌配置 see
System.setProperty("org.jboss.logging.provider", "slf4j");
// A StandardServiceRegistryBuilder
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder().configure(); // configures
// settings
// from
// hibernate.cfg.xml
// overwrite some config
registryBuilder.applySetting("hibernate.connection.driver_class", driver);
registryBuilder.applySetting("hibernate.connection.url", url);
registryBuilder.applySetting("hibernate.connection.username", user);
registryBuilder.applySetting("hibernate.connection.password", password);
// overwrite dialect
String usingDialect = "";
if (driver.toLowerCase().contains("mysql")) usingDialect = "org.hibernate.dialect.MySQLDialect";
else if (driver.toLowerCase().contains("oracle")) usingDialect = "org.hibernate.dialect.Oracle10gDialect";
registryBuilder.applySetting("hibernate.dialect", usingDialect);
log.info("[DataSource]::hibernate using dialect {}.", usingDialect);
// config with proxool
ProxoolHelper.addProxoolConfig(registryBuilder);
ProxoolHelper.configProxoolAlias(user, password, url, driver, fixedConnectionSize);
// A SessionFactory is set up once for an application!
final StandardServiceRegistry registry = registryBuilder.build();
MetadataSources metadataSources = new MetadataSources(registry);
// attach other mappings
for (Class<?> cls : otherMappingsClasses)
metadataSources.addAnnotatedClass(cls);
// build session factory
sessionFactory = metadataSources.buildMetadata().buildSessionFactory();
}
示例5: addProxoolConfig
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
public static void addProxoolConfig(StandardServiceRegistryBuilder registryBuilder) {
registryBuilder.applySetting("hibernate.connection.provider_class", ConnectionProviderClass);
registryBuilder.applySetting("hibernate.proxool.pool_alias", ProxoolAliasname);
registryBuilder.applySetting("hibernate.proxool.existing_pool", "true");
log.info("[ProxoolHelper] using [{}] .", ConnectionProviderClass);
log.info("[ProxoolHelper] using alias [{}] .", ProxoolAliasname);
}
示例6: startHibernate
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
/**
* @param igniteInstanceName Name of the grid providing caches.
* @return Session factory.
*/
private SessionFactory startHibernate(String igniteInstanceName) {
Configuration cfg = hibernateConfiguration(igniteInstanceName);
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
builder.applySetting("hibernate.connection.url", CONNECTION_URL);
builder.applySetting("hibernate.show_sql", false);
builder.applySettings(cfg.getProperties());
return cfg.buildSessionFactory(builder.build());
}
示例7: startHibernate
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
/**
* @param accessType Cache access typr.
* @param igniteInstanceName Name of the grid providing caches.
* @return Session factory.
*/
private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
builder.applySetting("hibernate.connection.url", CONNECTION_URL);
for (Map.Entry<String, String> e : HibernateL2CacheSelfTest.hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
builder.applySetting(e.getKey(), e.getValue());
builder.applySetting(USE_STRUCTURED_CACHE, "true");
builder.applySetting(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1");
builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2");
builder.applySetting(REGION_CACHE_PROPERTY + TIMESTAMP_CACHE, TIMESTAMP_CACHE);
builder.applySetting(REGION_CACHE_PROPERTY + QUERY_CACHE, QUERY_CACHE);
MetadataSources metadataSources = new MetadataSources(builder.build());
metadataSources.addAnnotatedClass(Entity1.class);
metadataSources.addAnnotatedClass(Entity2.class);
metadataSources.addAnnotatedClass(Entity3.class);
metadataSources.addAnnotatedClass(Entity4.class);
Metadata metadata = metadataSources.buildMetadata();
for (PersistentClass entityBinding : metadata.getEntityBindings()) {
if (!entityBinding.isInherited())
((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
}
return metadata.buildSessionFactory();
}
示例8: registryBuilder
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
/**
* @return Hibernate registry builder.
*/
protected StandardServiceRegistryBuilder registryBuilder() {
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
builder.applySetting("hibernate.connection.url", CONNECTION_URL);
return builder;
}
示例9: startHibernate
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
/**
* Starts Hibernate.
*
* @param accessType Cache access type.
* @param igniteInstanceName Ignite instance name.
* @return Session factory.
*/
private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) {
StandardServiceRegistryBuilder builder = registryBuilder();
for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
builder.applySetting(e.getKey(), e.getValue());
// Use the same cache for Entity and Entity2.
builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);
StandardServiceRegistry srvcRegistry = builder.build();
MetadataSources metadataSources = new MetadataSources(srvcRegistry);
for (Class entityClass : getAnnotatedClasses())
metadataSources.addAnnotatedClass(entityClass);
Metadata metadata = metadataSources.buildMetadata();
for (PersistentClass entityBinding : metadata.getEntityBindings()) {
if (!entityBinding.isInherited())
((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
}
for (org.hibernate.mapping.Collection collectionBinding : metadata.getCollectionBindings())
collectionBinding.setCacheConcurrencyStrategy(accessType.getExternalName() );
return metadata.buildSessionFactory();
}
示例10: createHibernateSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
/**
* Creates a new Hibernate {@link SessionFactory} using a programmatic
* configuration.
*
* @param hibernateCfg Hibernate configuration file.
* @return New Hibernate {@link SessionFactory}.
*/
private static SessionFactory createHibernateSessionFactory(URL hibernateCfg) {
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
builder.applySetting("hibernate.connection.url", JDBC_URL);
builder.applySetting("hibernate.show_sql", true);
builder.configure(hibernateCfg);
return new MetadataSources(builder.build()).buildMetadata().buildSessionFactory();
}
示例11: generateMetadata
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
protected MetadataSources generateMetadata(Class<? extends Dialect> dialect, String defaultSchema, Collection<String> classNames) throws ClassNotFoundException {
Assert.notNull(dialect, "dialect is invalid [null]");
StandardServiceRegistryBuilder registryBuilder =
new StandardServiceRegistryBuilder()
.applySetting(Environment.DIALECT, dialect.getName())
.applySetting(Environment.HBM2DDL_AUTO, "create-drop")
.applySetting(Environment.SHOW_SQL, "true")
.applySetting(Environment.FORMAT_SQL, "true")
.applySetting(Environment.USE_SQL_COMMENTS, "true")
.applySetting(Environment.ORDER_INSERTS, "true")
.applySetting(Environment.ORDER_UPDATES, "true");
if (StringUtils.hasText(defaultSchema)) {
registryBuilder.applySetting(Environment.DEFAULT_SCHEMA, defaultSchema);
}
MetadataSources metadata = new MetadataSources(registryBuilder.build());
if (classNames != null) {
for (String className : classNames) {
metadata.addAnnotatedClass(Class.forName(className));
}
}
return metadata;
}
示例12: configure
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
DataSource ds = env.get(dskey)
.orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder();
bsrb.applyIntegrator(new JpaIntegrator());
this.bsrb.accept(bsrb, conf);
String ddl_auto = env.name().equals("dev") ? "update" : "none";
BootstrapServiceRegistry bsr = bsrb.build();
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder(bsr);
ssrb.applySetting(AvailableSettings.HBM2DDL_AUTO, ddl_auto);
ssrb.applySettings(settings(env, conf));
this.ssrb.accept(ssrb, conf);
ssrb.applySetting(AvailableSettings.DATASOURCE, ds);
ssrb.applySetting(org.hibernate.jpa.AvailableSettings.DELAY_CDI_ACCESS, true);
StandardServiceRegistry serviceRegistry = ssrb.build();
MetadataSources sources = new MetadataSources(serviceRegistry);
this.sources.forEach(src -> src.accept(sources, conf));
this.metaSources.accept(sources, conf);
/** scan package? */
List<URL> packages = sources.getAnnotatedPackages()
.stream()
.map(pkg -> getClass().getResource("/" + pkg.replace('.', '/')))
.collect(Collectors.toList());
Metadata metadata = sources.getMetadataBuilder()
.applyImplicitNamingStrategy(ImplicitNamingStrategyJpaCompliantImpl.INSTANCE)
.applyScanEnvironment(new ScanEnvImpl(packages))
.build();
SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
this.sfb.accept(sfb, conf);
sfb.applyName(name);
CompletableFuture<Registry> registry = new CompletableFuture<>();
sfb.applyBeanManager(GuiceBeanManager.beanManager(registry));
SessionFactory sessionFactory = sfb.build();
this.sf.accept(sessionFactory, conf);
Provider<Session> session = new SessionProvider(sessionFactory);
ServiceKey serviceKey = env.serviceKey();
serviceKey.generate(SessionFactory.class, name,
k -> binder.bind(k).toInstance(sessionFactory));
serviceKey.generate(EntityManagerFactory.class, name,
k -> binder.bind(k).toInstance(sessionFactory));
/** Session/Entity Manager . */
serviceKey.generate(Session.class, name,
k -> binder.bind(k).toProvider(session));
serviceKey.generate(EntityManager.class, name,
k -> binder.bind(k).toProvider(session));
/** Unit of work . */
Provider<UnitOfWork> uow = new UnitOfWorkProvider(sessionFactory);
serviceKey.generate(UnitOfWork.class, name,
k -> binder.bind(k).toProvider(uow));
bindings.forEach(it -> it.accept(binder));
env.onStart(r -> {
registry.complete(r);
listeners.forEach(it -> it.accept((SessionFactoryImplementor) sessionFactory, r));
});
env.onStop(sessionFactory::close);
}
示例13: registryBuilder
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Nullable @Override protected StandardServiceRegistryBuilder registryBuilder() {
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
DatasourceConnectionProviderImpl connProvider = new DatasourceConnectionProviderImpl();
BasicManagedDataSource dataSrc = new BasicManagedDataSource(); // JTA-aware data source.
dataSrc.setTransactionManager(jotm.getTransactionManager());
dataSrc.setDefaultAutoCommit(false);
JdbcDataSource h2DataSrc = new JdbcDataSource();
h2DataSrc.setURL(CONNECTION_URL);
dataSrc.setXaDataSourceInstance(h2DataSrc);
connProvider.setDataSource(dataSrc);
connProvider.configure(Collections.emptyMap());
builder.addService(ConnectionProvider.class, connProvider);
builder.addService(JtaPlatform.class, new TestJtaPlatform());
builder.applySetting(Environment.TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class.getName());
return builder;
}