本文整理匯總了Java中org.hibernate.boot.registry.StandardServiceRegistryBuilder.build方法的典型用法代碼示例。如果您正苦於以下問題:Java StandardServiceRegistryBuilder.build方法的具體用法?Java StandardServiceRegistryBuilder.build怎麽用?Java StandardServiceRegistryBuilder.build使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hibernate.boot.registry.StandardServiceRegistryBuilder
的用法示例。
在下文中一共展示了StandardServiceRegistryBuilder.build方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
public static SessionFactory getSessionFactory() {
if (sessionFactory == null || sessionFactory.isClosed()) {
try {
Configuration configuration = new Configuration().configure();
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
serviceRegistryBuilder.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
// sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {
ex.printStackTrace();
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
return sessionFactory;
}
示例2: 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();
}
示例3: buildSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
private static SessionFactory buildSessionFactory() {
try {
Configuration configuration=new Configuration().configure();
StandardServiceRegistryBuilder serviceRegistryBuilder =
new StandardServiceRegistryBuilder();
serviceRegistryBuilder.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
return configuration.buildSessionFactory(serviceRegistry);
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
示例4: 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);
}
示例5: DBServiceImpl
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
public DBServiceImpl() {
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
Map<String, Object> settings = new HashMap<>();
settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect");
settings.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver");
settings.put(Environment.URL, "jdbc:mysql://localhost:3306/db_example");
settings.put(Environment.USER, "tully");
settings.put(Environment.PASS, "tully");
settings.put(Environment.HBM2DDL_AUTO, "create");
settings.put(Environment.SHOW_SQL, true);
settings.put(Environment.ENABLE_LAZY_LOAD_NO_TRANS, true);
// c3p0 configuration
settings.put(Environment.C3P0_MIN_SIZE, 5); //Minimum size of pool
settings.put(Environment.C3P0_MAX_SIZE, 20); //Maximum size of pool
settings.put(Environment.C3P0_ACQUIRE_INCREMENT, 1);//Number of connections acquired at a time when pool is exhausted
settings.put(Environment.C3P0_TIMEOUT, 1800); //Connection idle time
registryBuilder.applySettings(settings);
ServiceRegistry registry = registryBuilder.build();
MetadataSources sources = new MetadataSources(registry)
.addAnnotatedClass(PhoneDataSet.class)
.addAnnotatedClass(UserDataSet.class)
.addAnnotatedClass(AddressDataSet.class);
Metadata metadata = sources.getMetadataBuilder().build();
sessionFactory = metadata.getSessionFactoryBuilder().build();
}
示例6: DBServiceImpl
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
public DBServiceImpl() {
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
Map<String, Object> settings = new HashMap<>();
settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect");
settings.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver");
settings.put(Environment.URL, "jdbc:mysql://localhost:3306/db_example");
settings.put(Environment.USER, "tully");
settings.put(Environment.PASS, "tully");
settings.put(Environment.HBM2DDL_AUTO, "create");
settings.put(Environment.SHOW_SQL, true);
settings.put(Environment.ENABLE_LAZY_LOAD_NO_TRANS, true);
// c3p0 configuration
settings.put(Environment.C3P0_MIN_SIZE, 5); //Minimum size of pool
settings.put(Environment.C3P0_MAX_SIZE, 20); //Maximum size of pool
settings.put(Environment.C3P0_ACQUIRE_INCREMENT, 1);//Number of connections acquired at a time when pool is exhausted
settings.put(Environment.C3P0_TIMEOUT, 1800); //Connection idle time
registryBuilder.applySettings(settings);
ServiceRegistry registry = registryBuilder.build();
MetadataSources sources = new MetadataSources(registry)
.addAnnotatedClass(PhoneDataSet.class)
.addAnnotatedClass(UserDataSet.class);
Metadata metadata = sources.getMetadataBuilder().build();
sessionFactory = metadata.getSessionFactoryBuilder().build();
}
示例7: 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();
}
示例8: 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();
}
示例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: 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;
}
示例11: buildSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
/**
*
*
* @return
*/
private static SessionFactory buildSessionFactory() {
try {
Cfg prop = Cfg.inst();
Configuration hibernate = new Configuration().configure("hibernate.cfg.xml");
hibernate.setProperty("hibernate.bytecode.use_reflection_optimizer", "false");
hibernate.setProperty("hibernate.search.autoregister_listeners", "false");
hibernate.setProperty("hibernate.current_session_context_class", "thread");
hibernate.setProperty("hibernate.connection.driver_class", "org.mariadb.jdbc.Driver");
hibernate.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect");
hibernate.setProperty("hibernate.connection.url", "jdbc:mariadb://"
+ prop.getProp(PropertiesFile.MAIN_CONFIG, PropString.MASTER_DBHOST) + ":"
+ prop.getProp(PropertiesFile.MAIN_CONFIG, PropString.MASTER_DBPORT)
+ "?autoReconnect=true");
hibernate.setProperty("hibernate.default_catalog", prop.getProp(PropertiesFile.MAIN_CONFIG,
PropString.MASTER_DBNAME));
hibernate.setProperty("hibernate.connection.username", prop.getProp(
PropertiesFile.MAIN_CONFIG, PropString.MASTER_DBUSER));
hibernate.setProperty("hibernate.connection.password", prop.getProp(
PropertiesFile.MAIN_CONFIG, PropString.MASTER_DBPASS));
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
serviceRegistryBuilder.applySettings(hibernate.getProperties());
ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
SessionFactory sessionFactory = hibernate.buildSessionFactory(serviceRegistry);
return sessionFactory;
} catch (Exception ex) {
if (LOGGER != null) {
LOGGER.error("Initial SessionFactory creation failed.", ex);
}
throw new ExceptionInInitializerError(ex);
}
}
示例12: createSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
@Provides
public SessionFactory createSessionFactory() {
if (this.sessionFactory == null) {
Configuration configuration = new Configuration();
configuration.configure("hibernate.cfg.xml");
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
serviceRegistryBuilder.applySettings(configuration.getProperties());
StandardServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
this.sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
return this.sessionFactory;
}
示例13: buildSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
private static SessionFactory buildSessionFactory() throws HibernateException {
Configuration configuration = new Configuration().configure();
// configures settings from hibernate.cfg.xml
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
// If you miss the below line then it will complain about a missing dialect setting
serviceRegistryBuilder.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
return configuration.buildSessionFactory(serviceRegistry);
}
示例14: createSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
private static SessionFactory createSessionFactory(Configuration configuration) {
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
builder.applySettings(configuration.getProperties());
ServiceRegistry serviceRegistry = builder.build();
return configuration.buildSessionFactory(serviceRegistry);
}
示例15: DBServiceImpl
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; //導入方法依賴的package包/類
public DBServiceImpl() {
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
Map<String, Object> settings = new HashMap<>();
configureHibernate(settings);
configurePool(settings);
configureCache(settings);
//statistics of L2 cache
//settings.put(Environment.GENERATE_STATISTICS, "true");
registryBuilder.applySettings(settings);
ServiceRegistry registry = registryBuilder.build();
MetadataSources sources = new MetadataSources(registry)
.addAnnotatedClass(PhoneDataSet.class)
.addAnnotatedClass(UserDataSet.class);
Metadata metadata = sources.getMetadataBuilder().build();
sessionFactory = metadata.getSessionFactoryBuilder().build();
registerCacheMBean();
}