Example usage for org.hibernate.cache CacheException CacheException

List of usage examples for org.hibernate.cache CacheException CacheException

Introduction

In this page you can find the example usage for org.hibernate.cache CacheException CacheException.

Prototype

public CacheException(Throwable cause) 

Source Link

Document

Constructs a CacheException.

Usage

From source file:com.gemstone.gemfire.modules.hibernate.GemFireCache.java

License:Apache License

/**
 * Get an item from the cache/*w  w  w  . jav a 2  s .c  o m*/
 * 
 * @param key
 * @return the cached object or <tt>null</tt>
 * @throws CacheException
 */
public Object get(Object key) throws CacheException {
    GemFireCacheProvider.getLogger().debug("GemFireCache: get called for: " + key);
    try {
        Object value = region.get(key);
        GemFireCacheProvider.getLogger().debug("GemFireCache: retrieved: " + key + "-->" + value);
        return value;
    } catch (com.gemstone.gemfire.cache.CacheException e) {
        throw new CacheException(e);
    }
}

From source file:com.gemstone.gemfire.modules.hibernate.GemFireCache.java

License:Apache License

/**
 * Add an item to the cache//from  w w w . j  a v  a 2s .c o m
 * 
 * @param key
 * @param value
 * @throws CacheException
 */
public void put(Object key, Object value) throws CacheException {
    GemFireCacheProvider.getLogger().debug("GemFireCache: put called for key: " + key + "value: " + value);
    try {
        region.put(key, value);
        GemFireCacheProvider.getLogger().debug("GemFireCache: put " + key + "-->" + value);
    } catch (com.gemstone.gemfire.cache.CacheException e) {
        throw new CacheException(e);
    }
}

From source file:com.gemstone.gemfire.modules.hibernate.GemFireCache.java

License:Apache License

/**
 * Remove an item from the cache/*from   w w w  .  j  a  v  a2  s  . c o m*/
 */
public void remove(Object key) throws CacheException {
    GemFireCacheProvider.getLogger().debug("GemFireCache: remove called for: " + key);
    try {
        region.destroy(key);
        GemFireCacheProvider.getLogger().debug("GemFireCache: removed: " + key);
    } catch (EntryNotFoundException e) {
        // We can silently ignore this
    } catch (com.gemstone.gemfire.cache.CacheException e) {
        throw new CacheException(e);
    }
}

From source file:com.gemstone.gemfire.modules.hibernate.GemFireCacheProvider.java

License:Apache License

/**
 * Callback to perform any necessary initialization of the underlying cache
 * implementation during SessionFactory construction.
 * /* ww  w  .  j  ava  2 s  . c o m*/
 * @param properties
 *          current configuration settings.
 */
public void start(Properties properties) throws CacheException {
    logger.info("GemFireCacheProvider: Creating cache provider");

    // We have to strip out any unknown properties, do so here
    Properties gemfireOnlyProperties = new Properties();
    for (Object keyObj : properties.keySet()) {
        String key = (String) keyObj;
        if (key.contains("region-attributes")) {
            regionAttributes.put(key, properties.get(key));
        } else if (key.startsWith(DistributionConfig.GEMFIRE_PREFIX)) {
            gemfireOnlyProperties.setProperty(key.replace(DistributionConfig.GEMFIRE_PREFIX, ""),
                    properties.getProperty(key));
        }
    }

    // Create cache and d-lock service
    try {
        _cache = new CacheFactory(gemfireOnlyProperties).create();
        DistributedLockService existing = DistributedLockService.getServiceNamed(HIBERNATE_DLOCK_SERVICE_NAME);
        if (existing == null) {
            this.distributedLockService = DistributedLockService.create(HIBERNATE_DLOCK_SERVICE_NAME,
                    _cache.getDistributedSystem());
        } else {
            this.distributedLockService = existing;
        }
    } catch (com.gemstone.gemfire.cache.CacheException e) {
        throw new CacheException(e);
    }

    FunctionService.registerFunction(new CreateRegionFunction());

    logger.info("GemFireCacheProvider: Done creating cache provider");
}

From source file:com.hazelcast.hibernate.collection.HazelcastCollectionRegion.java

License:Open Source License

public CollectionRegionAccessStrategy buildAccessStrategy(final AccessType accessType) throws CacheException {
    if (null == accessType) {
        throw new CacheException(
                "Got null AccessType while attempting to build CollectionRegionAccessStrategy. This can't happen!");
    }//from   w ww .j a  v a2 s .  c o m
    if (AccessType.READ_ONLY.equals(accessType)) {
        return new ReadOnlyAccessStrategy(this, props);
    }
    if (AccessType.NONSTRICT_READ_WRITE.equals(accessType)) {
        return new NonStrictReadWriteAccessStrategy(this, props);
    }
    if (AccessType.READ_WRITE.equals(accessType)) {
        return new ReadWriteAccessStrategy(this, props);
    }
    if (AccessType.TRANSACTIONAL.equals(accessType)) {
        throw new CacheException("Transactional access is not currently supported by Hazelcast.");
    }
    throw new CacheException("Got unknown AccessType " + accessType
            + " while attempting to build CollectionRegionAccessStrategy.");
}

From source file:com.hazelcast.hibernate.entity.HazelcastEntityRegion.java

License:Open Source License

public EntityRegionAccessStrategy buildAccessStrategy(final AccessType accessType) throws CacheException {
    if (null == accessType) {
        throw new CacheException(
                "Got null AccessType while attempting to determine a proper EntityRegionAccessStrategy. This can't happen!");
    }/*from www  . ja  va2s.  c o  m*/
    if (AccessType.READ_ONLY.equals(accessType)) {
        return new ReadOnlyAccessStrategy(this, props);
    }
    if (AccessType.NONSTRICT_READ_WRITE.equals(accessType)) {
        return new NonStrictReadWriteAccessStrategy(this, props);
    }
    if (AccessType.READ_WRITE.equals(accessType)) {
        return new ReadWriteAccessStrategy(this, props);
    }
    if (AccessType.TRANSACTIONAL.equals(accessType)) {
        throw new CacheException("Transactional access is not currently supported by Hazelcast.");
    }
    throw new CacheException("Got unknown AccessType \"" + accessType
            + "\" while attempting to build EntityRegionAccessStrategy.");
}

From source file:com.hazelcast.hibernate.instance.DefaultHazelcastInstanceFactory.java

License:Open Source License

public IHazelcastInstanceLoader createInstanceLoader(final Properties props) throws CacheException {
    try {/*from   w w  w  .  ja v  a 2  s . com*/
        Class loaderClass = getInstanceLoaderClass(props);
        IHazelcastInstanceLoader instanceLoader = (IHazelcastInstanceLoader) loaderClass.newInstance();
        instanceLoader.configure(props);
        return instanceLoader;
    } catch (Exception e) {
        throw new CacheException(e);
    }
}

From source file:com.hazelcast.hibernate.instance.HazelcastClientLoader.java

License:Open Source License

public void unloadInstance() throws CacheException {
    if (client == null) {
        return;/*w w w  .j a va 2 s .  c  o m*/
    }
    try {
        client.getLifecycleService().shutdown();
        client = null;
    } catch (Exception e) {
        throw new CacheException(e);
    }
}

From source file:com.hazelcast.hibernate.instance.HazelcastInstanceFactory.java

License:Open Source License

public static IHazelcastInstanceLoader createInstanceLoader(Properties props) throws CacheException {
    try {//ww  w . j ava  2 s. com
        IHazelcastInstanceLoader instanceLoader = (IHazelcastInstanceLoader) props
                .get("com.hazelcast.hibernate.instance.loader");
        if (instanceLoader != null) {
            return instanceLoader;
        }
        Class loaderClass = getInstanceLoaderClass(props);
        instanceLoader = (IHazelcastInstanceLoader) loaderClass.newInstance();
        instanceLoader.configure(props);
        return instanceLoader;
    } catch (Exception e) {
        throw new CacheException(e);
    }
}

From source file:com.hazelcast.hibernate.instance.HazelcastInstanceLoader.java

License:Open Source License

public HazelcastInstance loadInstance() throws CacheException {
    if (instance != null && instance.getLifecycleService().isRunning()) {
        LOGGER.warning(//from   ww w  . j  av a  2s  .co m
                "Current HazelcastInstance is already loaded and running! " + "Returning current instance...");
        return instance;
    }
    String configResourcePath = null;
    instanceName = CacheEnvironment.getInstanceName(props);
    configResourcePath = CacheEnvironment.getConfigFilePath(props);
    if (!isEmpty(configResourcePath)) {
        try {
            config = ConfigLoader.load(configResourcePath);
        } catch (IOException e) {
            LOGGER.warning("IOException: " + e.getMessage());
        }
        if (config == null) {
            throw new CacheException("Could not find configuration file: " + configResourcePath);
        }
    }
    if (instanceName != null) {
        instance = Hazelcast.getHazelcastInstanceByName(instanceName);
        if (instance == null) {
            try {
                createOrGetInstance();
            } catch (DuplicateInstanceNameException ignored) {
                instance = Hazelcast.getHazelcastInstanceByName(instanceName);
            }
        }
    } else {
        createOrGetInstance();
    }
    return instance;
}