xaversionmanager.java
来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 614 行 · 第 1/2 页
JAVA
614 行
* <p/> * Not needed. */ public void addListener(ItemStateListener listener) { } /** * {@inheritDoc} * <p/> * Not needed. */ public void removeListener(ItemStateListener listener) { } //-----------------------------------------------< AbstractVersionManager > /** * {@inheritDoc} */ protected InternalVersionItem getItem(NodeId id) throws RepositoryException { InternalVersionItem item = null; if (xaItems != null) { item = (InternalVersionItem) xaItems.get(id); } if (item == null) { item = vMgr.getItem(id); } return item; } /** * {@inheritDoc} */ protected boolean hasItem(NodeId id) { if (xaItems != null && xaItems.containsKey(id)) { return true; } return vMgr.hasItem(id); } /** * {@inheritDoc} */ protected List getItemReferences(InternalVersionItem item) { return vMgr.getItemReferences(item); } /** * {@inheritDoc} * <p/> * Before modifying version history given, make a local copy of it. */ protected InternalVersion checkin(InternalVersionHistoryImpl history, NodeImpl node) throws RepositoryException { if (history.getVersionManager() != this) { history = makeLocalCopy(history); xaItems.put(history.getId(), history); } return super.checkin(history, node); } /** * {@inheritDoc} * <p/> * Before modifying version history given, make a local copy of it. */ protected void removeVersion(InternalVersionHistoryImpl history, QName name) throws VersionException, RepositoryException { if (history.getVersionManager() != this) { history = makeLocalCopy(history); xaItems.put(history.getId(), history); // also put 'successor' and 'predecessor' version items to xaItem sets InternalVersion v = history.getVersion(name); InternalVersion[] vs = v.getSuccessors(); for (int i=0; i<vs.length; i++) { xaItems.put(vs[i].getId(), vs[i]); } vs = v.getPredecessors(); for (int i=0; i<vs.length; i++) { xaItems.put(vs[i].getId(), vs[i]); } } super.removeVersion(history, name); } /** * {@inheritDoc} * <p/> * Before modifying version history given, make a local copy of it. */ protected InternalVersion setVersionLabel(InternalVersionHistoryImpl history, QName version, QName label, boolean move) throws RepositoryException { if (history.getVersionManager() != this) { history = makeLocalCopy(history); xaItems.put(history.getId(), history); } return super.setVersionLabel(history, version, label, move); } /** * {@inheritDoc} * <p/> * Put the version object into our cache. */ protected void versionCreated(InternalVersion version) { xaItems.put(version.getId(), version); } /** * {@inheritDoc} * <p/> * Remove the version object from our cache. */ protected void versionDestroyed(InternalVersion version) { xaItems.remove(version.getId()); } //-------------------------------------------------------------------< XA > /** * {@inheritDoc} */ public void associate(TransactionContext tx) { ((XAItemStateManager) stateMgr).associate(tx); Map xaItems = null; if (tx != null) { xaItems = (Map) tx.getAttribute(ITEMS_ATTRIBUTE_NAME); if (xaItems == null) { xaItems = new HashMap(); tx.setAttribute(ITEMS_ATTRIBUTE_NAME, xaItems); } } this.xaItems = xaItems; } /** * {@inheritDoc} * <p/> * Delegate the call to our XA item state manager. */ public void beforeOperation(TransactionContext tx) { ((XAItemStateManager) stateMgr).beforeOperation(tx); } /** * {@inheritDoc} * <p/> * Delegate the call to our XA item state manager. */ public void prepare(TransactionContext tx) throws TransactionException { ((XAItemStateManager) stateMgr).prepare(tx); } /** * {@inheritDoc} * <p/> * Delegate the call to our XA item state manager. If successful, inform * global repository manager to update its caches. */ public void commit(TransactionContext tx) throws TransactionException { ((XAItemStateManager) stateMgr).commit(tx); Map xaItems = (Map) tx.getAttribute(ITEMS_ATTRIBUTE_NAME); vMgr.itemsUpdated(xaItems.values()); } /** * {@inheritDoc} * <p/> * Delegate the call to our XA item state manager. */ public void rollback(TransactionContext tx) { ((XAItemStateManager) stateMgr).rollback(tx); } /** * {@inheritDoc} * <p/> * Delegate the call to our XA item state manager. */ public void afterOperation(TransactionContext tx) { ((XAItemStateManager) stateMgr).afterOperation(tx); } /** * Returns an {@link InternalXAResource} that acquires a write lock on the * version manager in {@link InternalXAResource#prepare(TransactionContext)} * if there are any version related items involved in this transaction. * * @return an internal XA resource. */ public InternalXAResource getXAResourceBegin() { return new InternalXAResource() { public void associate(TransactionContext tx) { } public void beforeOperation(TransactionContext tx) { } public void prepare(TransactionContext tx) { Map vItems = (Map) tx.getAttribute(ITEMS_ATTRIBUTE_NAME); if (!vItems.isEmpty()) { vMgr.acquireWriteLock(); vMgr.getSharedStateMgr().setNoLockHack(true); vmgrLocked = true; } } public void commit(TransactionContext tx) { } public void rollback(TransactionContext tx) { } public void afterOperation(TransactionContext tx) { } }; } /** * Returns an {@link InternalXAResource} that releases the write lock on the * version manager in {@link InternalXAResource#commit(TransactionContext)} * or {@link InternalXAResource#rollback(TransactionContext)}. * * @return an internal XA resource. */ public InternalXAResource getXAResourceEnd() { return new InternalXAResource() { public void associate(TransactionContext tx) { } public void beforeOperation(TransactionContext tx) { } public void prepare(TransactionContext tx) { } public void commit(TransactionContext tx) { internalReleaseWriteLock(); } public void rollback(TransactionContext tx) { internalReleaseWriteLock(); } public void afterOperation(TransactionContext tx) { } private void internalReleaseWriteLock() { if (vmgrLocked) { vMgr.getSharedStateMgr().setNoLockHack(false); vMgr.releaseWriteLock(); vmgrLocked = false; } } }; } //-------------------------------------------------------< implementation > /** * Return a flag indicating whether this version manager is currently * associated with an XA transaction. */ private boolean isInXA() { return xaItems != null; } /** * Make a local copy of an internal version item. This will recreate the * (global) version item with state information from our own state * manager. */ private InternalVersionHistoryImpl makeLocalCopy(InternalVersionHistoryImpl history) throws RepositoryException { acquireReadLock(); try { NodeState state = (NodeState) stateMgr.getItemState(history.getId()); NodeStateEx stateEx = new NodeStateEx(stateMgr, ntReg, state, null); return new InternalVersionHistoryImpl(this, stateEx); } catch (ItemStateException e) { throw new RepositoryException("Unable to make local copy", e); } finally { releaseReadLock(); } } /** * Return a flag indicating whether an internal version item belongs to * a different XA environment. */ boolean differentXAEnv(InternalVersionItemImpl item) { if (item.getVersionManager() == this) { if (xaItems == null || !xaItems.containsKey(item.getId())) { return true; } } return false; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?