PageRenderTime 16ms CodeModel.GetById 10ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/hazelcast-hibernate/src/main/java/com/hazelcast/hibernate/access/ReadOnlyAccessDelegate.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 89 lines | 41 code | 12 blank | 36 comment | 0 complexity | 64965b8373b84ac681d9f0894cc0f38e MD5 | raw file
 1/*
 2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 * http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.hazelcast.hibernate.access;
18
19import com.hazelcast.hibernate.region.HazelcastRegion;
20import org.hibernate.cache.CacheException;
21import org.hibernate.cache.access.SoftLock;
22
23import java.util.Properties;
24import java.util.logging.Level;
25
26/**
27 * @author Leo Kim (lkim@limewire.com)
28 */
29
30public class ReadOnlyAccessDelegate<T extends HazelcastRegion> extends NonStrictReadWriteAccessDelegate<T> {
31
32    public ReadOnlyAccessDelegate(T hazelcastRegion, final Properties props) {
33        super(hazelcastRegion, props);
34    }
35
36    /**
37     * @throws UnsupportedOperationException
38     */
39    @Override
40    public boolean afterUpdate(final Object key, final Object value, final Object currentVersion,
41                               final Object previousVersion, final SoftLock lock) throws CacheException {
42        throw new UnsupportedOperationException("Cannot update an item in a read-only cache: "
43                + getHazelcastRegion().getName());
44    }
45
46    /**
47     * @throws UnsupportedOperationException
48     */
49    @Override
50    public SoftLock lockItem(final Object key, final Object version) throws CacheException {
51        throw new UnsupportedOperationException("Attempting to lock an item in a read-only cache region: "
52                + getHazelcastRegion().getName());
53    }
54
55    /**
56     * @throws UnsupportedOperationException
57     */
58    @Override
59    public SoftLock lockRegion() throws CacheException {
60        throw new UnsupportedOperationException("Attempting to lock a read-only cache region: "
61                + getHazelcastRegion().getName());
62    }
63
64    /**
65     * This will issue a log warning stating that an attempt was made to unlock an item from a read-only cache region.
66     */
67    @Override
68    public void unlockItem(final Object key, final SoftLock lock) throws CacheException {
69        LOG.log(Level.WARNING, "Attempting to unlock an item from a read-only cache region");
70    }
71
72    /**
73     * This will issue a log warning stating that an attempt was made to unlock a read-only cache region.
74     */
75    @Override
76    public void unlockRegion(final SoftLock lock) throws CacheException {
77        LOG.log(Level.WARNING, "Attempting to unlock a read-only cache region");
78    }
79
80    /**
81     * @throws UnsupportedOperationException
82     */
83    @Override
84    public boolean update(final Object key, final Object value, final Object currentVersion,
85                          final Object previousVersion) throws CacheException {
86        throw new UnsupportedOperationException("Attempting to update an item in a read-only cache: "
87                + getHazelcastRegion().getName());
88    }
89}