1 /***
2 * Copyright 2003-2010 Terracotta, Inc.
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
17 package net.sf.ehcache.store;
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.List;
22 import java.util.Map;
23
24 import net.sf.ehcache.CacheException;
25 import net.sf.ehcache.Element;
26 import net.sf.ehcache.config.InvalidConfigurationException;
27 import net.sf.ehcache.search.Attribute;
28 import net.sf.ehcache.search.Results;
29 import net.sf.ehcache.search.attribute.AttributeExtractor;
30 import net.sf.ehcache.terracotta.TerracottaNotRunningException;
31
32 /***
33 * @author gkeim
34 *
35 */
36 public abstract class AbstractStore implements Store {
37 /***
38 * listener list
39 */
40 private transient List<StoreListener> listenerList;
41
42 /***
43 * onLoad initializer
44 */
45 protected synchronized List<StoreListener> getEventListenerList() {
46 if (listenerList == null) {
47 listenerList = new ArrayList<StoreListener>();
48 }
49 return listenerList;
50 }
51
52 /***
53 * {@inheritDoc}
54 *
55 * @see net.sf.ehcache.store.Store#isCacheCoherent()
56 */
57 public boolean isCacheCoherent() {
58 return false;
59 }
60
61 /***
62 * {@inheritDoc}
63 *
64 * @see net.sf.ehcache.store.Store#isClusterCoherent()
65 */
66 public boolean isClusterCoherent() {
67 return false;
68 }
69
70 /***
71 * {@inheritDoc}
72 *
73 * @see net.sf.ehcache.store.Store#isNodeCoherent()
74 */
75 public boolean isNodeCoherent() {
76 throw new UnsupportedOperationException();
77 }
78
79 /***
80 * {@inheritDoc}
81 *
82 * @see net.sf.ehcache.store.Store#setNodeCoherent(boolean)
83 */
84 public void setNodeCoherent(boolean coherent) throws UnsupportedOperationException {
85 throw new UnsupportedOperationException();
86 }
87
88 /***
89 * {@inheritDoc}
90 * @throws InterruptedException
91 * @throws TerracottaNotRunningException
92 *
93 * @see net.sf.ehcache.store.Store#waitUntilClusterCoherent()
94 */
95 public void waitUntilClusterCoherent() throws UnsupportedOperationException, TerracottaNotRunningException, InterruptedException {
96 throw new UnsupportedOperationException();
97 }
98
99 /***
100 * {@inheritDoc}
101 *
102 * @see net.sf.ehcache.store.Store#addStoreListener(net.sf.ehcache.store.StoreListener)
103 */
104 public synchronized void addStoreListener(StoreListener listener) {
105 removeStoreListener(listener);
106 getEventListenerList().add(listener);
107 }
108
109 /***
110 * {@inheritDoc}
111 *
112 * @see net.sf.ehcache.store.Store#removeStoreListener(net.sf.ehcache.store.StoreListener)
113 */
114 public synchronized void removeStoreListener(StoreListener listener) {
115 getEventListenerList().remove(listener);
116 }
117
118 /***
119 * {@inheritDoc}
120 */
121 public void setAttributeExtractors(Map<String, AttributeExtractor> extractors) {
122 if (!extractors.isEmpty()) {
123 throw new InvalidConfigurationException("Search attributes not supported by this store type: " + getClass().getName());
124 }
125 }
126
127 /***
128 * {@inheritDoc}
129 */
130 public Results executeQuery(StoreQuery query) {
131 throw new UnsupportedOperationException("Query execution not supported by this store type: " + getClass().getName());
132 }
133
134
135 /***
136 * {@inheritDoc}
137 */
138 public <T> Attribute<T> getSearchAttribute(String attributeName) throws CacheException {
139 return null;
140 }
141
142 /***
143 * {@inheritDoc}
144 */
145 public void putAll(Collection<Element> elements) throws CacheException {
146 for (Element element : elements) {
147 put(element);
148 }
149 }
150
151 /***
152 * {@inheritDoc}
153 */
154 public void removeAll(Collection<Object> keys) {
155 for (Object key : keys) {
156 remove(key);
157 }
158 }
159 }