本文整理匯總了Java中org.hibernate.service.ServiceRegistry類的典型用法代碼示例。如果您正苦於以下問題:Java ServiceRegistry類的具體用法?Java ServiceRegistry怎麽用?Java ServiceRegistry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ServiceRegistry類屬於org.hibernate.service包,在下文中一共展示了ServiceRegistry類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSessionFactory
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
public static SessionFactory getSessionFactory() {
if (null != sessionFactory)
return sessionFactory;
Configuration configuration = new Configuration();
String jdbcUrl = "jdbc:mysql://"
+ System.getenv("RDS_HOSTNAME")
+ "/"
+ System.getenv("RDS_DB_NAME");
configuration.setProperty("hibernate.connection.url", jdbcUrl);
configuration.setProperty("hibernate.connection.username", System.getenv("RDS_USERNAME"));
configuration.setProperty("hibernate.connection.password", System.getenv("RDS_PASSWORD"));
configuration.configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
try {
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} catch (HibernateException e) {
System.err.println("Initial SessionFactory creation failed." + e);
throw new ExceptionInInitializerError(e);
}
return sessionFactory;
}
示例2: buildSessionFactory
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
/**
* Create a {@link SessionFactory} using the properties and mappings in this configuration. The
* {@link SessionFactory} will be immutable, so changes made to {@code this} {@link Configuration} after
* building the {@link 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.debugf( "Preparing to build session factory with filters : %s", filterDefinitions );
buildTypeRegistrations( serviceRegistry );
secondPassCompile();
if ( !metadataSourceQueue.isEmpty() ) {
LOG.incompleteMappingMetadataCacheProcessing();
}
validate();
Environment.verifyProperties( properties );
Properties copy = new Properties();
copy.putAll( properties );
ConfigurationHelper.resolvePlaceHolders( copy );
Settings settings = buildSettings( copy, serviceRegistry );
return new SessionFactoryImpl(
this,
mapping,
serviceRegistry,
settings,
sessionFactoryObserver
);
}
示例3: MetadataSources
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
public MetadataSources(ServiceRegistry serviceRegistry, EntityResolver entityResolver, NamingStrategy namingStrategy) {
this.serviceRegistry = serviceRegistry;
this.entityResolver = entityResolver;
this.namingStrategy = namingStrategy;
this.jaxbHelper = new JaxbHelper( this );
this.metadataBuilder = new MetadataBuilderImpl( this );
// service registry really should be either BootstrapServiceRegistry or StandardServiceRegistry type...
if ( ! isExpectedServiceRegistryType( serviceRegistry ) ) {
LOG.debugf(
"Unexpected ServiceRegistry type [%s] encountered during building of MetadataSources; may cause " +
"problems later attempting to construct MetadataBuilder",
serviceRegistry.getClass().getName()
);
}
}
示例4: getStandardServiceRegistry
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
private static StandardServiceRegistry getStandardServiceRegistry(ServiceRegistry serviceRegistry) {
if ( serviceRegistry == null ) {
throw new HibernateException( "ServiceRegistry passed to MetadataBuilder cannot be null" );
}
if ( StandardServiceRegistry.class.isInstance( serviceRegistry ) ) {
return ( StandardServiceRegistry ) serviceRegistry;
}
else if ( BootstrapServiceRegistry.class.isInstance( serviceRegistry ) ) {
log.debugf(
"ServiceRegistry passed to MetadataBuilder was a BootstrapServiceRegistry; this likely wont end well" +
"if attempt is made to build SessionFactory"
);
return new StandardServiceRegistryBuilder( (BootstrapServiceRegistry) serviceRegistry ).build();
}
else {
throw new HibernateException(
String.format(
"Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder",
serviceRegistry.getClass().getName()
)
);
}
}
示例5: SchemaExport
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
public SchemaExport(ServiceRegistry serviceRegistry, Configuration configuration) {
this.connectionHelper = new SuppliedConnectionProviderConnectionHelper(
serviceRegistry.getService( ConnectionProvider.class )
);
this.sqlStatementLogger = serviceRegistry.getService( JdbcServices.class ).getSqlStatementLogger();
this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter();
this.sqlExceptionHelper = serviceRegistry.getService( JdbcServices.class ).getSqlExceptionHelper();
this.importFiles = ConfigurationHelper.getString(
AvailableSettings.HBM2DDL_IMPORT_FILES,
configuration.getProperties(),
DEFAULT_IMPORT_FILE
);
final Dialect dialect = serviceRegistry.getService( JdbcServices.class ).getDialect();
this.dropSQL = configuration.generateDropSchemaScript( dialect );
this.createSQL = configuration.generateSchemaCreationScript( dialect );
}
示例6: createEntityCopyObserver
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
private EntityCopyObserver createEntityCopyObserver(SessionFactoryImplementor sessionFactory) {
final ServiceRegistry serviceRegistry = sessionFactory.getServiceRegistry();
if ( entityCopyObserverStrategy == null ) {
final ConfigurationService configurationService
= serviceRegistry.getService( ConfigurationService.class );
entityCopyObserverStrategy = configurationService.getSetting(
"hibernate.event.merge.entity_copy_observer",
new ConfigurationService.Converter<String>() {
@Override
public String convert(Object value) {
return value.toString();
}
},
EntityCopyNotAllowedObserver.SHORT_NAME
);
LOG.debugf( "EntityCopyObserver strategy: %s", entityCopyObserverStrategy );
}
final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
return strategySelector.resolveStrategy( EntityCopyObserver.class, entityCopyObserverStrategy );
}
示例7: contribute
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
@Override
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
JsonType jtype;
JavaTypeDescriptor jdesc;
try {
jtype = JsonType.INSTANCE;
jdesc = JsonJavaTypeDescriptor.INSTANCE;
}
catch (Throwable t) {
// Avoid logging system for a project so small
System.err.println("JSON type contribution failed! Message: " + t.getMessage());
t.printStackTrace(System.err);
return;
}
JavaTypeDescriptorRegistry.INSTANCE.addDescriptor(jdesc);
typeContributions.contributeType(jtype);
}
示例8: getSessionFactory
import org.hibernate.service.ServiceRegistry; //導入依賴的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;
}
示例9: configureRunsBeforeSessionFactoryCreation
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
@Test
public void configureRunsBeforeSessionFactoryCreation(){
final SessionFactoryFactory customFactory = new SessionFactoryFactory() {
@Override
protected void configure(final Configuration configuration, final ServiceRegistry registry) {
super.configure(configuration, registry);
configuration.setInterceptor(EmptyInterceptor.INSTANCE);
}
};
this.sessionFactory = customFactory.build(this.bundle,
this.environment,
this.config,
ImmutableList.<Class<?>>of(Person.class),
RemoteCredentialHibernateBundle.DEFAULT_NAME);
assertThat(this.sessionFactory.getSessionFactoryOptions().getInterceptor()).isSameAs(EmptyInterceptor.INSTANCE);
}
開發者ID:mtakaki,項目名稱:CredentialStorageService-dw-hibernate,代碼行數:18,代碼來源:SessionFactoryFactoryTest.java
示例10: buildSessionFactory
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
public static SessionFactory buildSessionFactory() {
try {
Configuration configuration = new Configuration();
// Create properties file
Properties properties = new Properties();
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("Hibernate.properties"));
configuration.setProperties(properties);
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
configuration.addAnnotatedClass(Wordlist.class);
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} catch (Throwable ex) {
ex.printStackTrace();
}
return sessionFactory;
}
示例11: buildSessionFactory
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
private static SessionFactory buildSessionFactory() {
try {
Configuration configuration = new Configuration();
Properties props = new Properties();
props.put("hibernate.current_session_context_class", "thread");
configuration.setProperties(props);
for (Class<?> clazz : entityClasses) {
configuration.addAnnotatedClass(clazz);
}
PluginHandler.get().getPlugin().addAnnotatedClass(configuration);
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties())
.addService(ConnectionProvider.class, new NomadConnectionProvider()).build();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
} catch (Throwable ex) {
logger.error("Failed to build session factory.", ex);
throw new ExceptionInInitializerError(ex);
}
}
示例12: bootstrapping
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
@Test
public void bootstrapping() {
log.info("... bootstrapping ...");
ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().configure().build();
SessionFactory sessionFactory = new MetadataSources(standardRegistry)
.addAnnotatedClass(Author.class).buildMetadata()
.buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
Author a = new Author();
a.setFirstName("Thorben");
a.setLastName("Janssen");
session.persist(a);
session.getTransaction().commit();
session.close();
}
示例13: addRegex
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
public boolean addRegex(Regex regex) {
Transaction tx = null;
Configuration config = new Configuration().configure();
config.addClass(Regex.class);
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
.build();
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.getCurrentSession();
try{
tx = session.beginTransaction();
session.save(regex);
tx.commit();
return true;
}catch (Exception ex){
ex.printStackTrace();
tx.commit();
return false;
}finally {
if(tx != null){
tx = null;
}
sessionFactory.close();
}
}
示例14: updateRegex
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
public boolean updateRegex(Regex regex) {
Transaction tx = null;
Configuration config = new Configuration().configure();
config.addClass(Regex.class);
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
.build();
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.getCurrentSession();
try{
tx = session.beginTransaction();
session.update(regex);
tx.commit();
return true;
}catch (Exception ex){
ex.printStackTrace();
tx.commit();
return false;
}finally {
if(tx != null){
tx = null;
}
sessionFactory.close();
}
}
示例15: addData
import org.hibernate.service.ServiceRegistry; //導入依賴的package包/類
public boolean addData(Data data) {
Transaction tx = null;
Configuration config = new Configuration().configure();
config.addClass(Data.class);
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(config.getProperties())
.build();
SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
Session session = sessionFactory.getCurrentSession();
try{
tx = session.beginTransaction();
session.save(data);
tx.commit();
return true;
}catch (Exception ex){
ex.printStackTrace();
tx.commit();
return false;
}finally {
if(tx != null){
tx = null;
}
sessionFactory.close();
}
}