/** * Utility method to peek a node and throw an exception if the version isn't what is expected. * * @param ctx context to use * @return node peeked, null if nonexistent * @throws org.jboss.cache.optimistic.DataVersioningException * if there is a version mismatch */ protected NodeSPI peekVersioned(InvocationContext ctx) { NodeSPI n = ctx.lookUpNode(fqn); if (n != null && isVersioned() && n.getVersion().newerThan(dataVersion)) { String errMsg = new StringBuilder("Node found, but version is not equal to or less than the expected [").append(dataVersion).append("]. Is [").append(n.getVersion()).append("] instead!").toString(); throw new DataVersioningException(errMsg); } return n; } }
/** * Constructs with a node and workspace. */ public WorkspaceNodeImpl(NodeSPI<K, V> node, TransactionWorkspace workspace, NodeFactory<K, V> nodeFactory) { NodeInvocationDelegate delegate = (NodeInvocationDelegate) node; if (!(delegate.getDelegationTarget() instanceof VersionedNode)) { throw new IllegalArgumentException("node " + delegate.getDelegationTarget() + " not VersionedNode"); } this.node = node; this.workspace = workspace; Map<K, V> nodeData = node.getDataDirect(); if (!nodeData.isEmpty()) optimisticDataMap = new HashMap<K, V>(nodeData); this.version = node.getVersion(); if (version == null) { throw new IllegalStateException("VersionedNode version null"); } initFlags(); this.nodeFactory = nodeFactory; }
else if (node.getVersion() == null) if (dataVersion != null && node.getVersion().newerThan(dataVersion)) // dataVersion *could* be null if the invalidate was triggered by removing a node that did not exist in the first place. String errMsg = new StringBuilder("Node found, but version is not equal to or less than the expected [").append(dataVersion).append("]. Is [").append(node.getVersion()).append("] instead!").toString(); log.warn(errMsg); throw new DataVersioningException(errMsg);
private void performVersionUpdate(NodeSPI underlyingNode, WorkspaceNode workspaceNode) { if (workspaceNode.isVersioningImplicit()) { if (trace) log.trace("Versioning is implicit; incrementing."); underlyingNode.setVersion(((DefaultDataVersion) workspaceNode.getVersion()).increment()); } else { if (trace) log.trace("Versioning is explicit; not attempting an increment."); underlyingNode.setVersion(workspaceNode.getVersion()); } if (trace) log.trace("Setting version of node " + underlyingNode.getFqn() + " from " + workspaceNode.getVersion() + " to " + underlyingNode.getVersion()); }
if (underlyingNode.getVersion().newerThan(workspaceNode.getVersion())) throw new DataVersioningException("Version mismatch for node " + fqn + ": underlying node with version " + workspaceNode.getNode().getVersion() + " is newer than workspace node, with version " + workspaceNode.getVersion()); else if (underlyingNode.getVersion().newerThan(workspaceNode.getVersion())) throw new DataVersioningException("Version mismatch for node " + fqn + ": underlying node with version " + workspaceNode.getNode().getVersion() + " is newer than workspace node, with version " + workspaceNode.getVersion());
if ( !( ( ( NodeSPI ) regionRoot ).getVersion() instanceof NonLockingDataVersion ) ) { ((NodeSPI) regionRoot).setVersion(NonLockingDataVersion.INSTANCE);
if ( !( ( ( NodeSPI ) regionRoot ).getVersion() instanceof NonLockingDataVersion ) ) { ((NodeSPI) regionRoot).setVersion(NonLockingDataVersion.INSTANCE);
if ( !( ( ( NodeSPI ) newRoot ).getVersion() instanceof NonLockingDataVersion ) ) { ((NodeSPI) newRoot).setVersion(NonLockingDataVersion.INSTANCE);
if ( !( ( ( NodeSPI ) newRoot ).getVersion() instanceof NonLockingDataVersion ) ) { ((NodeSPI) newRoot).setVersion(NonLockingDataVersion.INSTANCE);