com.hazelcast.hibernate.provider.HazelcastCacheProvider Maven / Gradle / Ivy
/*
* Copyright (c) 2008-2010, Hazel Ltd. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.hazelcast.hibernate.provider;
import java.util.Properties;
import java.util.logging.Level;
import org.hibernate.cache.Cache;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.CacheProvider;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.hibernate.HazelcastCacheRegionFactory;
import com.hazelcast.hibernate.HazelcastInstanceFactory;
import com.hazelcast.hibernate.HazelcastTimestamper;
import com.hazelcast.logging.ILogger;
import com.hazelcast.logging.Logger;
/**
* Implementation of (deprecated) Hibernate CacheProvider
interface for compatibility with pre-Hibernate
* 3.3.x code.
*
* To enable, hibernate.cache.provider_class=com.hazelcast.hibernate.provider.HazelcastCacheProvider
. This
* cache provider relies on hazelcast.xml
for cache configuration.
*
* @author Leo Kim ([email protected])
* @see HazelcastCache
* @see HazelcastCacheRegionFactory
*/
public final class HazelcastCacheProvider implements CacheProvider {
private static final ILogger LOG = Logger.getLogger(HazelcastCacheProvider.class.getName());
private HazelcastInstance instance;
public HazelcastCacheProvider() {
}
/**
* We ignore the Properties
passed in here in favor of the hazelcast.xml
file.
*/
public Cache buildCache(final String name, final Properties properties) throws CacheException {
return new HazelcastCache(instance, name);
}
/**
* @return true - for a large cluster, unnecessary puts will most likely slow things down.
*/
public boolean isMinimalPutsEnabledByDefault() {
return true;
}
public long nextTimestamp() {
return HazelcastTimestamper.nextTimestamp(instance);
}
public void start(final Properties props) throws CacheException {
LOG.log(Level.INFO, "Starting up HazelcastCacheProvider...");
instance = HazelcastInstanceFactory.createInstance(props);
}
/**
* Calls {@link Hazelcast#shutdown()}
.
*/
public void stop() {
LOG.log(Level.INFO, "Shutting down HazelcastCacheProvider...");
instance.shutdown();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy