View Javadoc

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.transaction.xa.commands;
18  
19  import net.sf.ehcache.CacheEntry;
20  import net.sf.ehcache.Element;
21  
22  /***
23   * Represents a {@link net.sf.ehcache.store.Store#remove(Object) remove} operation to be executed on a {@link net.sf.ehcache.store.Store}.
24   *
25   * @author Alex Snaps
26   */
27  public class StoreRemoveCommand extends AbstractStoreCommand {
28  
29      private Object key;
30  
31      /***
32       * Create a StoreRemoveCommand
33       *
34       * @param key the key of the element to remove
35       * @param oldElement the element in the underlying store at the time this command is created
36       */
37      public StoreRemoveCommand(final Object key, final Element oldElement) {
38          super(oldElement, null);
39          this.key = key;
40      }
41  
42      /***
43       * {@inheritDoc}
44       */
45      public boolean isPut(Object key) {
46          return false;
47      }
48  
49      /***
50       * {@inheritDoc}
51       */
52      public boolean isRemove(Object key) {
53          return getObjectKey().equals(key);
54      }
55  
56  
57      /***
58       * {@inheritDoc}
59       */
60      public Object getObjectKey() {
61          return key;
62      }
63  
64      /***
65       * Getter to the cache entry to be removed
66       *
67       * @return the cache entry
68       */
69      public CacheEntry getEntry() {
70          return new CacheEntry(key, getOldElement());
71      }
72  }