下面列出了怎么用org.hibernate.cfg.Settings的API类实例代码及写法,或者点击链接到github查看源代码。
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;
}
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;
}
@Override
public void start(Settings settings, Properties properties) throws CacheException {
this.settings = settings;
if (this.channel == null) {
this.channel = J2Cache.getChannel();
}
}
@Override
public void start(SessionFactoryOptions settings, Properties properties) throws CacheException {
this.redisson = createRedissonClient(properties);
this.settings = new Settings(settings);
StrategySelector selector = settings.getServiceRegistry().getService(StrategySelector.class);
cacheKeysFactory = selector.resolveDefaultableStrategy(CacheKeysFactory.class,
properties.get(Environment.CACHE_KEYS_FACTORY), new RedissonCacheKeysFactory(redisson.getConfig().getCodec()));
}
@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 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;
}
@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;
}
@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);
}
@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;
}
/**
* 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 SchemaValidator(Configuration cfg, Settings settings) throws HibernateException {
this.configuration = cfg;
dialect = settings.getDialect();
connectionHelper = new SuppliedConnectionProviderConnectionHelper(
settings.getConnectionProvider()
);
}
@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);
}
/** {@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);
}
@Override
public QueryCache getQueryCache(
final String regionName,
final UpdateTimestampsCache updateTimestampsCache,
final Settings settings,
final Properties props) throws HibernateException {
return new IgniteStandardQueryCache(settings, props, updateTimestampsCache, regionName);
}
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 QueryCache getQueryCache(
final String regionName,
final UpdateTimestampsCache updateTimestampsCache,
final Settings settings,
final Properties props) throws HibernateException {
return new IgniteStandardQueryCache(settings, props, updateTimestampsCache, regionName);
}
public J2CacheCollectionRegion(J2CacheAccessStrategyFactory accessStrategyFactory, CacheRegion underlyingCache, Settings settings, CacheDataDescription metadata, Properties properties) {
super(accessStrategyFactory, underlyingCache, settings, metadata, properties);
}
public ReadWriteNaturalIdRegionAccessStrategy(Settings settings, GeneralDataRegion region,
RMapCache<Object, Object> mapCache) {
super(settings, region, mapCache);
}
public Settings getSettings() {
return settings;
}
public J2CacheNaturalIdRegion(J2CacheAccessStrategyFactory accessStrategyFactory, CacheRegion underlyingCache, Settings settings, CacheDataDescription metadata, Properties properties) {
super(accessStrategyFactory, underlyingCache, settings, metadata, properties);
}
public J2CacheEntityRegion(J2CacheAccessStrategyFactory accessStrategyFactory, CacheRegion underlyingCache, Settings settings, CacheDataDescription metadata, Properties properties) {
super(accessStrategyFactory,underlyingCache, settings, metadata, properties);
}
AbstractJ2CacheAccessStrategy(T region, Settings settings) {
this.region = region;
this.settings = settings;
}
protected Settings settings() {
return settings;
}
public ReadOnlyJ2CacheEntityRegionAccessStrategy(J2CacheEntityRegion region, Settings settings) {
super(region, settings);
}
public ReadWriteJ2CacheCollectionRegionAccessStrategy(J2CacheCollectionRegion region, Settings settings) {
super(region, settings);
}
public ReadOnlyJ2CacheNaturalIdRegionAccessStrategy(J2CacheNaturalIdRegion region, Settings settings) {
super(region, settings);
}
public Settings getSettings() {
return settings;
}
public NonStrictReadWriteJ2CacheEntityRegionAccessStrategy(J2CacheEntityRegion region, Settings settings) {
super(region, settings);
}
public TransactionalEntityRegionAccessStrategy(Settings settings, GeneralDataRegion region) {
super(settings, region);
}
public AbstractReadWriteJ2CacheAccessStrategy(T region, Settings settings) {
super(region, settings);
this.versionComparator = region.getCacheDataDescription().getVersionComparator();
}