private UnitOfWorkApplicationListener registerUnitOfWorkListenerIfAbsent(Environment environment) { for (Object singleton : environment.jersey().getResourceConfig().getSingletons()) { if (singleton instanceof UnitOfWorkApplicationListener) { return (UnitOfWorkApplicationListener) singleton; } } final UnitOfWorkApplicationListener listener = new UnitOfWorkApplicationListener(); environment.jersey().register(listener); return listener; }
/** * Construct an application event listener using the given name and session factory. * * <p/> * When using this constructor, the {@link UnitOfWorkApplicationListener} * should be added to a Jersey {@code ResourceConfig} as a singleton. * * @param name a name of a Hibernate bundle * @param sessionFactory a {@link SessionFactory} */ public UnitOfWorkApplicationListener(String name, SessionFactory sessionFactory) { registerSessionFactory(name, sessionFactory); }
@Override public final void run(T configuration, Environment environment) throws Exception { final PooledDataSourceFactory dbConfig = getDataSourceFactory(configuration); this.sessionFactory = requireNonNull(sessionFactoryFactory.build(this, environment, dbConfig, entities, name())); registerUnitOfWorkListenerIfAbsent(environment).registerSessionFactory(name(), sessionFactory); environment.healthChecks().register(name(), new SessionFactoryHealthCheck( environment.getHealthCheckExecutorService(), dbConfig.getValidationQueryTimeout().orElse(Duration.seconds(5)), sessionFactory, dbConfig.getValidationQuery())); }
private UnitOfWorkApplicationListener registerUnitOfWorkListerIfAbsent(Environment environment) { for (Object singleton : environment.jersey().getResourceConfig().getSingletons()) { if (singleton instanceof UnitOfWorkApplicationListener) { return (UnitOfWorkApplicationListener) singleton; } } UnitOfWorkApplicationListener listener = new UnitOfWorkApplicationListener(); environment.jersey().register(listener); return listener; } }
/** * Construct an application event listener using the given name and session factory. * * <p/> * When using this constructor, the {@link UnitOfWorkApplicationListener} * should be added to a Jersey {@code ResourceConfig} as a singleton. * * @param name a name of a Hibernate bundle * @param sessionFactory a {@link SessionFactory} */ public UnitOfWorkApplicationListener(String name, SessionFactory sessionFactory) { registerSessionFactory(name, sessionFactory); }
private UnitOfWorkApplicationListener registerUnitOfWorkListenerIfAbsent(Environment environment) { for (Object singleton : environment.jersey().getResourceConfig().getSingletons()) { if (singleton instanceof UnitOfWorkApplicationListener) { return (UnitOfWorkApplicationListener) singleton; } } final UnitOfWorkApplicationListener listener = new UnitOfWorkApplicationListener(); environment.jersey().register(listener); return listener; }
@Override public final void run(T configuration, Environment environment) throws Exception { final PooledDataSourceFactory dbConfig = getDataSourceFactory(configuration); this.sessionFactory = requireNonNull(sessionFactoryFactory.build(this, environment, dbConfig, entities, name())); registerUnitOfWorkListenerIfAbsent(environment).registerSessionFactory(name(), sessionFactory); environment.healthChecks().register(name(), new SessionFactoryHealthCheck( environment.getHealthCheckExecutorService(), dbConfig.getValidationQueryTimeout().orElse(Duration.seconds(5)), sessionFactory, dbConfig.getValidationQuery())); }
/** {@inheritDoc} */ public final void run(T configuration, Environment environment) throws ClassNotFoundException { PooledDataSourceFactory dbConfig = getDataSourceFactory(configuration); this.sessionFactory = sessionFactoryFactory.build(this, environment, dbConfig, hibernateXmlResourceName); // Register the annotations. registerUnitOfWorkWithDetachListerIfAbsent(environment).registerSessionFactory(DEFAULT_NAME, sessionFactory); registerUnitOfWorkListerIfAbsent(environment).registerSessionFactory(DEFAULT_NAME, sessionFactory); environment.healthChecks() .register(DEFAULT_NAME, new SessionFactoryHealthCheck(environment.getHealthCheckExecutorService(), dbConfig.getValidationQueryTimeout().or(Duration.seconds(5)), sessionFactory, dbConfig.getValidationQuery())); }