~ubuntu-branches/ubuntu/trusty/ehcache/trusty

« back to all changes in this revision

Viewing changes to src/main/java/net/sf/ehcache/transaction/xa/commands/AbstractStoreCommand.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-05-06 14:53:07 UTC
  • mfrom: (1.1.7) (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130506145307-v5bhw5yu70re00l3
Tags: 2.6.7-1
* Team upload.
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 *  Copyright 2003-2010 Terracotta, Inc.
 
2
 *  Copyright Terracotta, Inc.
3
3
 *
4
4
 *  Licensed under the Apache License, Version 2.0 (the "License");
5
5
 *  you may not use this file except in compliance with the License.
19
19
import net.sf.ehcache.store.ElementValueComparator;
20
20
import net.sf.ehcache.store.Store;
21
21
import net.sf.ehcache.transaction.SoftLock;
22
 
import net.sf.ehcache.transaction.SoftLockFactory;
 
22
import net.sf.ehcache.transaction.SoftLockManager;
 
23
import net.sf.ehcache.transaction.SoftLockID;
23
24
import net.sf.ehcache.transaction.xa.OptimisticLockFailureException;
24
25
import net.sf.ehcache.transaction.xa.XidTransactionID;
25
26
 
62
63
    /**
63
64
     * {@inheritDoc}
64
65
     */
65
 
    public boolean prepare(Store store, SoftLockFactory softLockFactory, XidTransactionID transactionId,
 
66
    public boolean prepare(Store store, SoftLockManager softLockManager, XidTransactionID transactionId,
66
67
                           ElementValueComparator comparator) {
67
68
        Object objectKey = getObjectKey();
68
69
        final boolean wasPinned = store.isPinned(objectKey);
69
70
 
70
 
        SoftLock softLock = softLockFactory.createSoftLock(transactionId, objectKey, newElement, oldElement, wasPinned);
71
 
        softLockedElement = createElement(objectKey, softLock, store, wasPinned);
 
71
        SoftLockID softLockId = softLockManager.createSoftLockID(transactionId, objectKey, newElement, oldElement, wasPinned);
 
72
        SoftLock softLock = softLockManager.findSoftLockById(softLockId);
 
73
        softLockedElement = createElement(objectKey, softLockId, store, wasPinned);
72
74
        softLock.lock();
73
75
        softLock.freeze();
74
76
 
96
98
    /**
97
99
     * {@inheritDoc}
98
100
     */
99
 
    public void rollback(Store store) {
 
101
    public void rollback(Store store, SoftLockManager softLockManager) {
100
102
        if (oldElement == null) {
101
103
            store.remove(getObjectKey());
102
104
        } else {
103
105
            store.put(oldElement);
104
106
        }
105
107
 
106
 
        SoftLock softLock = (SoftLock) softLockedElement.getObjectValue();
107
 
        if (!softLock.wasPinned()) {
108
 
            store.setPinned(softLock.getKey(), false);
 
108
        SoftLockID softLockId = (SoftLockID) softLockedElement.getObjectValue();
 
109
        SoftLock softLock = softLockManager.findSoftLockById(softLockId);
 
110
 
 
111
        if (!softLockId.wasPinned()) {
 
112
            store.setPinned(softLockId.getKey(), false);
109
113
        }
 
114
 
110
115
        softLock.unfreeze();
111
116
        softLock.unlock();
112
117
        softLockedElement = null;
113
118
    }
114
119
 
115
 
    private Element createElement(Object key, SoftLock softLock, Store store, boolean wasPinned) {
116
 
        Element element = new Element(key, softLock);
 
120
    private Element createElement(Object key, SoftLockID softLockId, Store store, boolean wasPinned) {
 
121
        Element element = new Element(key, softLockId);
117
122
        element.setEternal(true);
118
123
        if (!wasPinned) {
119
124
            store.setPinned(key, true);