001    
002    /*
003     * Copyright (C) 2012 Archie L. Cobbs. All rights reserved.
004     *
005     * $Id: PersistentObjectVersionException.java 226 2012-01-18 16:30:35Z archie.cobbs $
006     */
007    
008    package org.dellroad.stuff.pobj;
009    
010    /**
011     * Optimistic locking exception thrown by {@link PersistentObject#setRoot PersistentObject.setRoot()}
012     * when the expected version number does not agree.
013     */
014    @SuppressWarnings("serial")
015    public class PersistentObjectVersionException extends PersistentObjectException {
016    
017        private final long actualVersion;
018        private final long expectedVersion;
019    
020        public PersistentObjectVersionException(long actualVersion, long expectedVersion) {
021            this.actualVersion = actualVersion;
022            this.expectedVersion = expectedVersion;
023        }
024    
025        /**
026         * Get the actual, unexpected version number.
027         */
028        public long getActualVersion() {
029            return this.actualVersion;
030        }
031    
032        /**
033         * Get the version number that was expected.
034         */
035        public long getExpectedVersion() {
036            return this.expectedVersion;
037        }
038    }
039