/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. package com.hazelcast.hibernate.access;
  17. import com.hazelcast.hibernate.region.HazelcastRegion;
  18. import org.hibernate.cache.CacheException;
  19. import org.hibernate.cache.access.SoftLock;
  20. import java.util.Properties;
  21. import java.util.logging.Level;
  22. /**
  23. * @author Leo Kim (lkim@limewire.com)
  24. */
  25. public class ReadOnlyAccessDelegate<T extends HazelcastRegion> extends NonStrictReadWriteAccessDelegate<T> {
  26. public ReadOnlyAccessDelegate(T hazelcastRegion, final Properties props) {
  27. super(hazelcastRegion, props);
  28. }
  29. /**
  30. * @throws UnsupportedOperationException
  31. */
  32. @Override
  33. public boolean afterUpdate(final Object key, final Object value, final Object currentVersion,
  34. final Object previousVersion, final SoftLock lock) throws CacheException {
  35. throw new UnsupportedOperationException("Cannot update an item in a read-only cache: "
  36. + getHazelcastRegion().getName());
  37. }
  38. /**
  39. * @throws UnsupportedOperationException
  40. */
  41. @Override
  42. public SoftLock lockItem(final Object key, final Object version) throws CacheException {
  43. throw new UnsupportedOperationException("Attempting to lock an item in a read-only cache region: "
  44. + getHazelcastRegion().getName());
  45. }
  46. /**
  47. * @throws UnsupportedOperationException
  48. */
  49. @Override
  50. public SoftLock lockRegion() throws CacheException {
  51. throw new UnsupportedOperationException("Attempting to lock a read-only cache region: "
  52. + getHazelcastRegion().getName());
  53. }
  54. /**
  55. * This will issue a log warning stating that an attempt was made to unlock an item from a read-only cache region.
  56. */
  57. @Override
  58. public void unlockItem(final Object key, final SoftLock lock) throws CacheException {
  59. LOG.log(Level.WARNING, "Attempting to unlock an item from a read-only cache region");
  60. }
  61. /**
  62. * This will issue a log warning stating that an attempt was made to unlock a read-only cache region.
  63. */
  64. @Override
  65. public void unlockRegion(final SoftLock lock) throws CacheException {
  66. LOG.log(Level.WARNING, "Attempting to unlock a read-only cache region");
  67. }
  68. /**
  69. * @throws UnsupportedOperationException
  70. */
  71. @Override
  72. public boolean update(final Object key, final Object value, final Object currentVersion,
  73. final Object previousVersion) throws CacheException {
  74. throw new UnsupportedOperationException("Attempting to update an item in a read-only cache: "
  75. + getHazelcastRegion().getName());
  76. }
  77. }