SessionBuilderImpl(SessionFactoryImpl sessionFactory) { this.sessionFactory = sessionFactory; this.sessionOwner = null; final Settings settings = sessionFactory.settings; // set up default builder values... this.interceptor = sessionFactory.getInterceptor(); this.connectionReleaseMode = settings.getConnectionReleaseMode(); this.autoClose = settings.isAutoCloseSessionEnabled(); this.flushBeforeCompletion = settings.isFlushBeforeCompletionEnabled(); if ( sessionFactory.getCurrentTenantIdentifierResolver() != null ) { tenantIdentifier = sessionFactory.getCurrentTenantIdentifierResolver().resolveCurrentTenantIdentifier(); } listeners = settings.getBaselineSessionEventsListenerBuilder().buildBaselineList(); }
/** * Constructs a StandardQueryCache instance * * @param settings The SessionFactory settings. * @param props Any properties * @param updateTimestampsCache The update-timestamps cache to use. * @param regionName The base query cache region name */ public StandardQueryCache( final Settings settings, final Properties props, final UpdateTimestampsCache updateTimestampsCache, final String regionName) { String regionNameToUse = regionName; if ( regionNameToUse == null ) { regionNameToUse = StandardQueryCache.class.getName(); } final String prefix = settings.getCacheRegionPrefix(); if ( prefix != null ) { regionNameToUse = prefix + '.' + regionNameToUse; } LOG.startingQueryCache( regionNameToUse ); this.cacheRegion = settings.getRegionFactory().buildQueryResultsRegion( regionNameToUse, props ); this.updateTimestampsCache = updateTimestampsCache; }
public StandardQueryCache( final Settings settings, final Properties props, final UpdateTimestampsCache updateTimestampsCache, String regionName) throws HibernateException { if ( regionName == null ) { regionName = StandardQueryCache.class.getName(); } String prefix = settings.getCacheRegionPrefix(); if ( prefix != null ) { regionName = prefix + '.' + regionName; } log.info( "starting query cache at region: " + regionName ); this.queryCache = settings.getCacheProvider().buildCache(regionName, props); this.updateTimestampsCache = updateTimestampsCache; this.regionName = regionName; }
public HazelcastInstance getHazelcastInstance(Settings settings) { Object providerObject = null; try { Method getCacheProviderMethod = Settings.class.getMethod(METHOD_GET_CACHE_PROVIDER); providerObject = getCacheProviderMethod.invoke(settings); } catch (Exception e) { logger.log(Level.SEVERE, e.getMessage(), e); return null; } if (providerObject == null) { logger.log(Level.SEVERE, "Hibernate 2nd level cache has not been enabled!"); return null; } final CacheProvider provider = (CacheProvider) providerObject; if (provider instanceof HazelcastCacheProvider) { return ((HazelcastCacheProvider) provider).getHazelcastInstance(); } logger.log(Level.WARNING, "Current 2nd level cache implementation is not HazelcastCacheProvider!"); return null; }
public HazelcastInstance getHazelcastInstance(Settings settings) { final RegionFactory rf = settings.getRegionFactory(); if (rf == null) { logger.log(Level.SEVERE, "Hibernate 2nd level cache has not been enabled!"); return null; } if (rf instanceof RegionFactoryCacheProviderBridge) { final CacheProvider provider = ((RegionFactoryCacheProviderBridge) rf).getCacheProvider(); if (provider instanceof HazelcastCacheProvider) { return ((HazelcastCacheProvider) provider).getHazelcastInstance(); } logger.log(Level.WARNING, "Current 2nd level cache implementation is not HazelcastCacheProvider!"); } else if (rf instanceof HazelcastCacheRegionFactory) { return ((HazelcastCacheRegionFactory) rf).getHazelcastInstance(); } else { logger.log(Level.WARNING, "Current 2nd level cache implementation is not HazelcastCacheRegionFactory!"); } return null; }
SessionBuilderImpl(SessionFactoryImpl sessionFactory) { this.sessionFactory = sessionFactory; this.sessionOwner = null; final Settings settings = sessionFactory.settings; // set up default builder values... this.interceptor = sessionFactory.getInterceptor(); this.connectionReleaseMode = settings.getConnectionReleaseMode(); this.autoClose = settings.isAutoCloseSessionEnabled(); this.flushBeforeCompletion = settings .isFlushBeforeCompletionEnabled(); if (sessionFactory.getCurrentTenantIdentifierResolver() != null) { tenantIdentifier = sessionFactory .getCurrentTenantIdentifierResolver() .resolveCurrentTenantIdentifier(); } }
HibernateCacheTimestamper populateTimestamper(Settings settings, OverridableReadOnlyProperties properties) { String timestamperClazzName = properties.getProperty(TIMESTAMPER_PROPERTY_KEY, DEFAULT_TIMESTAMPER_CLASS.getName()); HibernateCacheTimestamper timestamper; try { Class<?> clazz = Class.forName(timestamperClazzName); timestamper = (HibernateCacheTimestamper) clazz.newInstance(); } catch (Exception e) { throw new IllegalStateException(e.getMessage(), e); } timestamper.setSettings(settings); timestamper.setProperties(properties); timestamper.setMemcachedAdapter(memcachedAdapter); timestamper.init(); return timestamper; }
public HazelcastInstance getHazelcastInstance(Settings settings) { final RegionFactory rf = settings.getRegionFactory(); if (rf == null) { logger.log(Level.SEVERE, "Hibernate 2nd level cache has not been enabled!"); return null; } if (rf instanceof RegionFactoryCacheProviderBridge) { final CacheProvider provider = ((RegionFactoryCacheProviderBridge) rf).getCacheProvider(); if (provider instanceof HazelcastCacheProvider) { return ((HazelcastCacheProvider) provider).getHazelcastInstance(); } logger.log(Level.WARNING, "Current 2nd level cache implementation is not HazelcastCacheProvider!"); } else if (rf instanceof AbstractHazelcastCacheRegionFactory) { return ((AbstractHazelcastCacheRegionFactory) rf).getHazelcastInstance(); } else { logger.log(Level.WARNING, "Current 2nd level cache implementation is not HazelcastCacheRegionFactory!"); } return null; }
@Override public Settings buildSettings(Properties props, ServiceRegistry serviceRegistry) throws HibernateException { Settings settings = super.buildSettings(props, serviceRegistry); if (this.cacheRegionFactory != null) { try { Method setRegionFactory = Settings.class.getDeclaredMethod("setRegionFactory", RegionFactory.class); setRegionFactory.setAccessible(true); setRegionFactory.invoke(settings, this.cacheRegionFactory); } catch (Exception ex) { throw new IllegalStateException("Failed to invoke Hibernate's setRegionFactory method", ex); } } return settings; }
/** * Constructs an UpdateTimestampsCache. * * @param settings The SessionFactory settings * @param props Any properties * @param factory The SessionFactory */ public UpdateTimestampsCache(Settings settings, Properties props, final SessionFactoryImplementor factory) { this.factory = factory; final String prefix = settings.getCacheRegionPrefix(); final String regionName = prefix == null ? REGION_NAME : prefix + '.' + REGION_NAME; LOG.startingUpdateTimestampsCache( regionName ); this.region = settings.getRegionFactory().buildTimestampsRegion( regionName, props ); }
@Override public QueryCache getQueryCache( final String regionName, final UpdateTimestampsCache updateTimestampsCache, final Settings settings, final Properties props) throws HibernateException { return new StandardQueryCache(settings, props, updateTimestampsCache, regionName); }
public void start(Settings settings, Properties properties) throws CacheException { // Do nothing the hazelcast hazelcastInstance is injected log.info("Starting up {}", getClass().getSimpleName()); if (hazelcastInstance == null) { throw new IllegalArgumentException("Hazelcast hazelcastInstance must not be null"); } cleanupService = new CleanupService(hazelcastInstance.getName()); }
public void start(final Settings settings, final Properties properties) throws CacheException { log.info("Starting up " + getClass().getSimpleName()); if (instance == null || !instance.getLifecycleService().isRunning()) { instanceLoader = HazelcastInstanceFactory.createInstanceLoader(properties); instance = instanceLoader.loadInstance(); } cleanupService = new CleanupService(instance.getName()); }
/** * Tries to extract <code>HazelcastInstance</code> from <code>SessionFactoryImplementor</code>. * * @param sessionFactory Hibernate <code>SessionFactory</code> to extract settings from * @return currently used <code>HazelcastInstance</code> or null if an error occurs. */ public static HazelcastInstance getHazelcastInstance(final SessionFactoryImplementor sessionFactory) { final Settings settings = sessionFactory.getSettings(); final RegionFactory rf = settings.getRegionFactory(); if (rf instanceof AbstractHazelcastCacheRegionFactory) { return ((AbstractHazelcastCacheRegionFactory) rf).getHazelcastInstance(); } else { LOGGER.warning("Current 2nd level cache implementation is not HazelcastCacheRegionFactory!"); } return null; }
@Override public void start(final Settings settings, final Properties properties) throws CacheException { logger.info("Starting up " + getClass().getSimpleName()); if (instance == null || !instance.getLifecycleService().isRunning()) { instanceLoader = HazelcastInstanceFactory.createInstanceLoader(properties); instance = instanceLoader.loadInstance(); } cleanupService = new CleanupService(instance.getName()); }
/** * Create a schema exporter for the given Configuration * and given settings */ public SchemaExport(Configuration cfg, Settings settings) throws HibernateException { dialect = settings.getDialect(); connectionHelper = new SuppliedConnectionProviderConnectionHelper( settings.getConnectionProvider() ); dropSQL = cfg.generateDropSchemaScript( dialect ); createSQL = cfg.generateSchemaCreationScript( dialect ); format = settings.isFormatSqlEnabled(); }
public SchemaUpdate(Configuration cfg, Settings settings) throws HibernateException { this.configuration = cfg; dialect = settings.getDialect(); connectionHelper = new SuppliedConnectionProviderConnectionHelper( settings.getConnectionProvider() ); exceptions = new ArrayList(); }
public SchemaValidator(Configuration cfg, Settings settings) throws HibernateException { this.configuration = cfg; dialect = settings.getDialect(); connectionHelper = new SuppliedConnectionProviderConnectionHelper( settings.getConnectionProvider() ); }
public QueryCache getQueryCache( final String regionName, final UpdateTimestampsCache updateTimestampsCache, final Settings settings, final Properties props) throws HibernateException { return new StandardQueryCache(settings, props, updateTimestampsCache, regionName); }
/** {@inheritDoc} */ @Override public void start(Settings settings, Properties props) throws CacheException { String accessType = props.getProperty(DFLT_ACCESS_TYPE_PROPERTY, NONSTRICT_READ_WRITE.name()); dfltAccessType = AccessType.valueOf(accessType); accessStgyFactory.start(props); }
public void start(final Settings settings, final Properties properties) throws CacheException { // Do nothing the hazelcast hazelcastInstance is injected log.info("Starting up {}", getClass().getSimpleName()); if (hazelcastInstance == null) { throw new IllegalArgumentException("Hazelcast hazelcastInstance must not be null"); } cleanupService = new CleanupService(hazelcastInstance.getName()); }
public void start(final Settings settings, final Properties properties) throws CacheException { LOG.log(Level.INFO, "Starting up HazelcastCacheRegionFactory..."); if (instance == null || !instance.getLifecycleService().isRunning()) { instanceLoader = HazelcastInstanceFactory.createInstanceLoader(properties); instance = instanceLoader.loadInstance(); } }
public MemcachedRegion(CacheNamespace cacheNamespace, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) { this.cacheNamespace = cacheNamespace; this.properties = properties; this.metadata = metadata; this.settings = settings; this.memcachedAdapter = memcachedAdapter; this.hibernateCacheTimestamper = hibernateCacheTimestamper; }
public NaturalIdMemcachedRegion(String regionName, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) { super(new CacheNamespace(regionName, true), properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper); }
@Override public void start(Settings settings, Properties properties) throws CacheException { log.debug("# start Hibernate4MemcachedRegionFactory."); this.settings = settings; cacheProviderConfigProperties = populateCacheProviderConfigProperties(properties); OverridableReadOnlyProperties mergedConfigProperties = new OverridableReadOnlyPropertiesImpl(properties, cacheProviderConfigProperties); memcachedAdapter = populateMemcachedProvider(mergedConfigProperties); hibernateCacheTimestamper = populateTimestamper(settings, mergedConfigProperties); }
@Test public void populateTimestamper_default() throws Exception { Properties properties = new Properties(); Settings settings = new TestingSettingsBuilder().build(); HibernateCacheTimestamper timestamper = regionFactory.populateTimestamper(settings, new OverridableReadOnlyPropertiesImpl(properties)); assertThat(timestamper).isExactlyInstanceOf(Hibernate4MemcachedRegionFactory.DEFAULT_TIMESTAMPER_CLASS); }
@Test public void populateTimestamper() throws Exception { Properties properties = new Properties(); properties.setProperty(Hibernate4MemcachedRegionFactory.TIMESTAMPER_PROPERTY_KEY, FakeHibernateCacheTimestamper.class.getName()); Settings settings = new TestingSettingsBuilder().build(); HibernateCacheTimestamper timestamper = regionFactory.populateTimestamper(settings, new OverridableReadOnlyPropertiesImpl(properties)); assertThat(timestamper).isExactlyInstanceOf(FakeHibernateCacheTimestamper.class); assertThat(((FakeHibernateCacheTimestamper) timestamper).isInitCalled()).isTrue(); }
@Test public void putFromLoad_without_minimalPutOverride() throws Exception { Settings settings = new TestingSettingsBuilder().setField("minimalPutsEnabled", true).build(); when(generalDataMemcachedRegion.getSettings()).thenReturn(settings); memcachedRegionAccessStrategy.putFromLoad("books#1", "book 1", 1L, "version object"); verify(memcachedRegionAccessStrategy).putFromLoad("books#1", "book 1", 1L, "version object", true); }
@Test public void isMinimalPutsEnabled_true() throws Exception { Settings settings = new TestingSettingsBuilder().setField("minimalPutsEnabled", true).build(); when(generalDataMemcachedRegion.getSettings()).thenReturn(settings); assertThat(memcachedRegionAccessStrategy.isMinimalPutsEnabled()).isTrue(); }
@Test public void isMinimalPutsEnabled_false() throws Exception { Settings settings = new TestingSettingsBuilder().setField("minimalPutsEnabled", false).build(); when(generalDataMemcachedRegion.getSettings()).thenReturn(settings); assertThat(memcachedRegionAccessStrategy.isMinimalPutsEnabled()).isFalse(); }
public RefineKeyOverridedGeneralDataMemcachedRegion(CacheNamespace cacheNamespace, OverridableReadOnlyProperties properties, CacheDataDescription metadata, Settings settings, MemcachedAdapter memcachedAdapter, HibernateCacheTimestamper hibernateCacheTimestamper) { super(cacheNamespace, properties, metadata, settings, memcachedAdapter, hibernateCacheTimestamper); }
public RDBMSJDBCBinder(RDBMSConfiguration rdbmsConfiguration, Settings settings, Mappings mappings, ReverseEngineeringStrategy revEngStrategy) { super(rdbmsConfiguration,settings,mappings,revEngStrategy); this.cfg = rdbmsConfiguration; this.settings = settings; this.mappings = mappings; this.revEngStrategy = revEngStrategy; }
private String getHbm2ddlAuto() { Session session = entityManager.unwrap(Session.class); SessionFactoryImpl sessionImpl = (SessionFactoryImpl)session.getSessionFactory(); Settings setting = sessionImpl.getSettings(); String hbm2ddlAuto = setting.isAutoCreateSchema() ? "create" : "update"; return hbm2ddlAuto; }
public Settings getSettings() { return sessionFactoryImplementor.getSettings(); }
@Override public void start(Settings settings, Properties properties) throws CacheException { this.regionFactory.start(settings, properties); }