Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 80C389DE5 for ; Thu, 5 Jan 2012 16:25:14 +0000 (UTC) Received: (qmail 91936 invoked by uid 500); 5 Jan 2012 16:25:14 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 91902 invoked by uid 500); 5 Jan 2012 16:25:13 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 91895 invoked by uid 99); 5 Jan 2012 16:25:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jan 2012 16:25:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jan 2012 16:25:11 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5A9052388A32 for ; Thu, 5 Jan 2012 16:24:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1227681 - in /directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn: DefaultTxnLogManager.java DefaultTxnManager.java DnSet.java IndexWrapper.java Date: Thu, 05 Jan 2012 16:24:51 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120105162451.5A9052388A32@eris.apache.org> Author: elecharny Date: Thu Jan 5 16:24:50 2012 New Revision: 1227681 URL: http://svn.apache.org/viewvc?rev=1227681&view=rev Log: o Some java code refactoring (coding style) o Using for () construct instead of while() o Added some Javadoc, toString() method, etc o Slight code improvement Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DnSet.java directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexWrapper.java Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java?rev=1227681&r1=1227680&r2=1227681&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnLogManager.java Thu Jan 5 16:24:50 2012 @@ -294,20 +294,12 @@ public class DefaultTxnLogManager implem { Transaction curTxn = txnManager.getCurTxn(); - if ( ( curTxn == null ) ) + // No txn, or read only txn, return without doing anything. + if ( ( curTxn == null ) || ( curTxn instanceof ReadOnlyTxn ) ) { - // NO txn, return without doing anything. return; } - // No need to do anything for read only txns - if ( !( curTxn instanceof ReadWriteTxn ) ) - { - - return; - - } - DnSet dnSet = new DnSet( baseDn, scope ); ReadWriteTxn txn = ( ReadWriteTxn ) curTxn; Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java?rev=1227681&r1=1227680&r2=1227681&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DefaultTxnManager.java Thu Jan 5 16:24:50 2012 @@ -665,14 +665,10 @@ class DefaultTxnManager implements TxnMa verifyLock.lock(); //Verify txn and throw conflict exception if necessary - Iterator it = committedQueue.iterator(); - ReadWriteTxn toCheckTxn; long startTime = txn.getStartTime(); - while ( it.hasNext() ) + for ( ReadWriteTxn toCheckTxn : committedQueue ) { - toCheckTxn = it.next(); - // Check txns that committed after we started if ( toCheckTxn.getCommitTime() < startTime ) { @@ -831,7 +827,6 @@ class DefaultTxnManager implements TxnMa class LogSyncer extends Thread { - @Override public void run() { @@ -844,7 +839,6 @@ class DefaultTxnManager implements TxnMa flushCondition.await( flushInterval, TimeUnit.MILLISECONDS ); flushTxns(); } - } catch ( InterruptedException e ) { @@ -861,5 +855,4 @@ class DefaultTxnManager implements TxnMa } } } - } Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DnSet.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DnSet.java?rev=1227681&r1=1227680&r2=1227681&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DnSet.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/DnSet.java Thu Jan 5 16:24:50 2012 @@ -20,8 +20,10 @@ package org.apache.directory.server.core.shared.txn; -import org.apache.directory.shared.ldap.model.name.Dn; + import org.apache.directory.shared.ldap.model.message.SearchScope; +import org.apache.directory.shared.ldap.model.name.Dn; + /** * A class representing the set of Dns a read operation depends or the set of Dns a write @@ -38,6 +40,12 @@ public class DnSet SearchScope dnScope; + /** + * Create a new instance of DnSet. + * + * @param base The base DN + * @param scope The scope + */ public DnSet( Dn base, SearchScope scope ) { baseDn = base; @@ -45,14 +53,29 @@ public class DnSet } + /** + * @return The base DN + */ public Dn getBaseDn() { return baseDn; } + /** + * @return The scope + */ public SearchScope getScope() { return dnScope; } + + + /** + * @see Object#toString() + */ + public String toString() + { + return "DnSet[" + baseDn + '/' + dnScope + ']'; + } } Modified: directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexWrapper.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexWrapper.java?rev=1227681&r1=1227680&r2=1227681&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexWrapper.java (original) +++ directory/apacheds/branches/apacheds-txns/core-shared/src/main/java/org/apache/directory/server/core/shared/txn/IndexWrapper.java Thu Jan 5 16:24:50 2012 @@ -30,26 +30,27 @@ import org.apache.directory.server.core. import org.apache.directory.server.core.api.partition.index.ReverseIndexComparator; import org.apache.directory.server.core.api.partition.index.ReverseIndexEntry; import org.apache.directory.server.core.api.txn.TxnLogManager; - import org.apache.directory.shared.ldap.model.cursor.Cursor; import org.apache.directory.shared.ldap.model.name.Dn; import org.apache.directory.shared.ldap.model.schema.AttributeType; + /** * * @author Apache Directory Project */ public class IndexWrapper implements Index { - /** wrapped index */ + /** wrapped index */ Index wrappedIndex; - + /** partition the table belongs to */ private Dn partitionDn; - + /** Txn log manager */ - private TxnLogManager txnLogManager; - + private TxnLogManager txnLogManager; + + public IndexWrapper( TxnManagerFactory txnManagerFactory, Dn partitionDn, Index wrappedIndex ) { this.partitionDn = partitionDn; @@ -57,7 +58,7 @@ public class IndexWrapper implements Ind txnLogManager = txnManagerFactory.txnLogManagerInstance(); } - + /** * {@inheritDoc} */ @@ -93,6 +94,7 @@ public class IndexWrapper implements Ind wrappedIndex.setCacheSize( cacheSize ); } + /** * {@inheritDoc} */ @@ -119,6 +121,7 @@ public class IndexWrapper implements Ind return wrappedIndex.getAttribute(); } + /** * {@inheritDoc} */ @@ -163,33 +166,34 @@ public class IndexWrapper implements Ind return wrappedIndex.lessThanCount( attrVal ); } - + /** * {@inheritDoc} */ public UUID forwardLookup( Object attrVal ) throws Exception { -// IndexCursor cursor = forwardCursor( attrVal ); -// -// try -// { -// -// if ( cursor.next() ) -// { -// return cursor.get().getId(); -// } -// -// return null; -// } -// finally -// { -// cursor.close(); -// } - + // IndexCursor cursor = forwardCursor( attrVal ); + // + // try + // { + // + // if ( cursor.next() ) + // { + // return cursor.get().getId(); + // } + // + // return null; + // } + // finally + // { + // cursor.close(); + // } + // Find the UUID from the underlying index UUID curId = wrappedIndex.forwardLookup( attrVal ); - - curId = txnLogManager.mergeForwardLookup( partitionDn, wrappedIndex.getAttribute().getOid(), attrVal, curId, wrappedIndex.getForwardIndexEntryComparator().getValueComparator() ); - + + curId = txnLogManager.mergeForwardLookup( partitionDn, wrappedIndex.getAttributeId(), attrVal, curId, + wrappedIndex.getForwardIndexEntryComparator().getValueComparator() ); + return curId; } @@ -199,27 +203,27 @@ public class IndexWrapper implements Ind */ public Object reverseLookup( UUID id ) throws Exception { -// IndexCursor cursor = reverseCursor( id ); -// -// try -// { -// -// if ( cursor.next() ) -// { -// return cursor.get().getValue(); -// } -// -// return null; -// } -// finally -// { -// cursor.close(); -// } - + // IndexCursor cursor = reverseCursor( id ); + // + // try + // { + // + // if ( cursor.next() ) + // { + // return cursor.get().getValue(); + // } + // + // return null; + // } + // finally + // { + // cursor.close(); + // } + Object curVal = wrappedIndex.reverseLookup( id ); - + curVal = txnLogManager.mergeReversLookup( partitionDn, wrappedIndex.getAttribute().getOid(), id, curVal ); - + return curVal; } @@ -258,18 +262,19 @@ public class IndexWrapper implements Ind { IndexCursor wrappedCursor; IndexCursor cursor = wrappedIndex.reverseCursor(); - + try { - wrappedCursor = ( IndexCursor) txnLogManager.wrap( partitionDn, cursor, wrappedIndex.getReverseIndexEntryComparator(), + wrappedCursor = ( IndexCursor ) txnLogManager.wrap( partitionDn, cursor, + wrappedIndex.getReverseIndexEntryComparator(), wrappedIndex.getAttribute().getOid(), false, null, null ); - } - catch (Exception e) + } + catch ( Exception e ) { cursor.close( e ); throw e; } - + return wrappedCursor; } @@ -281,21 +286,22 @@ public class IndexWrapper implements Ind { IndexCursor wrappedCursor; IndexCursor cursor = wrappedIndex.forwardCursor(); - + try { - wrappedCursor = ( IndexCursor)txnLogManager.wrap( partitionDn, cursor, wrappedIndex.getForwardIndexEntryComparator(), + wrappedCursor = ( IndexCursor ) txnLogManager.wrap( partitionDn, cursor, + wrappedIndex.getForwardIndexEntryComparator(), wrappedIndex.getAttribute().getOid(), true, null, null ); - } - catch (Exception e) + } + catch ( Exception e ) { cursor.close( e ); throw e; } - + return wrappedCursor; } - + /** * {@inheritDoc} @@ -304,21 +310,22 @@ public class IndexWrapper implements Ind { IndexCursor wrappedCursor; IndexCursor cursor = wrappedIndex.reverseCursor( id ); - + try { - wrappedCursor = ( IndexCursor)txnLogManager.wrap( partitionDn, cursor, wrappedIndex.getReverseIndexEntryComparator(), + wrappedCursor = ( IndexCursor ) txnLogManager.wrap( partitionDn, cursor, + wrappedIndex.getReverseIndexEntryComparator(), wrappedIndex.getAttribute().getOid(), false, null, id ); - } - catch (Exception e) + } + catch ( Exception e ) { cursor.close( e ); throw e; } - + return wrappedCursor; } - + /** * {@inheritDoc} @@ -327,21 +334,22 @@ public class IndexWrapper implements Ind { IndexCursor wrappedCursor; IndexCursor cursor = wrappedIndex.forwardCursor( key ); - + try { - wrappedCursor = ( IndexCursor)txnLogManager.wrap( partitionDn, cursor, wrappedIndex.getForwardIndexEntryComparator(), + wrappedCursor = ( IndexCursor ) txnLogManager.wrap( partitionDn, cursor, + wrappedIndex.getForwardIndexEntryComparator(), wrappedIndex.getAttribute().getOid(), true, key, null ); - } - catch (Exception e) + } + catch ( Exception e ) { cursor.close( e ); throw e; } - + return wrappedCursor; } - + /** * {@inheritDoc} @@ -350,7 +358,7 @@ public class IndexWrapper implements Ind { throw new UnsupportedOperationException(); } - + /** * {@inheritDoc} @@ -359,7 +367,7 @@ public class IndexWrapper implements Ind { throw new UnsupportedOperationException(); } - + /** * {@inheritDoc} @@ -367,14 +375,14 @@ public class IndexWrapper implements Ind public boolean forward( Object attrVal ) throws Exception { IndexCursor cursor = forwardCursor( attrVal ); - + try { if ( cursor.next() ) { return true; } - + return false; } finally @@ -382,7 +390,7 @@ public class IndexWrapper implements Ind cursor.close(); } } - + /** * {@inheritDoc} @@ -390,13 +398,14 @@ public class IndexWrapper implements Ind public boolean forward( Object attrVal, UUID id ) throws Exception { boolean currentlyExists = wrappedIndex.forward( attrVal, id ); - + ForwardIndexEntry indexEntry = new ForwardIndexEntry(); indexEntry.setId( id ); indexEntry.setValue( attrVal ); - return txnLogManager.mergeExistence( partitionDn, wrappedIndex.getAttribute().getOid(), indexEntry, currentlyExists ); + return txnLogManager.mergeExistence( partitionDn, wrappedIndex.getAttribute().getOid(), indexEntry, + currentlyExists ); } - + /** * {@inheritDoc} @@ -404,14 +413,14 @@ public class IndexWrapper implements Ind public boolean reverse( UUID id ) throws Exception { IndexCursor cursor = reverseCursor( id ); - + try { if ( cursor.next() ) { return true; } - + return false; } finally @@ -420,20 +429,21 @@ public class IndexWrapper implements Ind } } - + /** * {@inheritDoc} */ public boolean reverse( UUID id, Object attrVal ) throws Exception { boolean currentlyExists = wrappedIndex.reverse( id, attrVal ); - + ReverseIndexEntry indexEntry = new ReverseIndexEntry(); indexEntry.setId( id ); indexEntry.setValue( attrVal ); - return txnLogManager.mergeExistence( partitionDn, wrappedIndex.getAttribute().getOid(), indexEntry, currentlyExists ); + return txnLogManager.mergeExistence( partitionDn, wrappedIndex.getAttribute().getOid(), indexEntry, + currentlyExists ); } - + /** * {@inheritDoc} @@ -441,16 +451,16 @@ public class IndexWrapper implements Ind public boolean forwardGreaterOrEq( Object attrVal ) throws Exception { IndexCursor cursor = forwardCursor(); - + try { cursor.beforeValue( null, attrVal ); - + if ( cursor.next() ) { return true; } - + return false; } finally @@ -458,7 +468,7 @@ public class IndexWrapper implements Ind cursor.close(); } } - + /** * {@inheritDoc} @@ -467,16 +477,16 @@ public class IndexWrapper implements Ind { // Lock down the index by the key IndexCursor cursor = forwardCursor( attrVal ); - + try { cursor.beforeValue( id, attrVal ); - + if ( cursor.next() ) { return true; } - + return false; } finally @@ -484,7 +494,7 @@ public class IndexWrapper implements Ind cursor.close(); } } - + /** * {@inheritDoc} @@ -492,16 +502,16 @@ public class IndexWrapper implements Ind public boolean reverseGreaterOrEq( UUID id ) throws Exception { IndexCursor cursor = reverseCursor(); - + try { cursor.beforeValue( id, null ); - + if ( cursor.next() ) { return true; } - + return false; } finally @@ -509,7 +519,7 @@ public class IndexWrapper implements Ind cursor.close(); } } - + /** * {@inheritDoc} @@ -518,16 +528,16 @@ public class IndexWrapper implements Ind { // lock down the index by the key IndexCursor cursor = reverseCursor( id ); - + try { cursor.beforeValue( id, attrVal ); - + if ( cursor.next() ) { return true; } - + return false; } finally @@ -535,7 +545,7 @@ public class IndexWrapper implements Ind cursor.close(); } } - + /** * {@inheritDoc} @@ -543,16 +553,16 @@ public class IndexWrapper implements Ind public boolean forwardLessOrEq( Object attrVal ) throws Exception { IndexCursor cursor = forwardCursor(); - + try { cursor.afterValue( null, attrVal ); - + if ( cursor.previous() ) { return true; } - + return false; } finally @@ -560,7 +570,7 @@ public class IndexWrapper implements Ind cursor.close(); } } - + /** * {@inheritDoc} @@ -568,16 +578,16 @@ public class IndexWrapper implements Ind public boolean forwardLessOrEq( Object attrVal, UUID id ) throws Exception { IndexCursor cursor = forwardCursor( attrVal ); - + try { cursor.afterValue( id, attrVal ); - + if ( cursor.previous() ) { return true; } - + return false; } finally @@ -585,7 +595,7 @@ public class IndexWrapper implements Ind cursor.close(); } } - + /** * {@inheritDoc} @@ -593,16 +603,16 @@ public class IndexWrapper implements Ind public boolean reverseLessOrEq( UUID id ) throws Exception { IndexCursor cursor = reverseCursor(); - + try { cursor.afterValue( id, null ); - + if ( cursor.previous() ) { return true; } - + return false; } finally @@ -610,7 +620,7 @@ public class IndexWrapper implements Ind cursor.close(); } } - + /** * {@inheritDoc} @@ -618,16 +628,16 @@ public class IndexWrapper implements Ind public boolean reverseLessOrEq( UUID id, Object attrVal ) throws Exception { IndexCursor cursor = reverseCursor( id ); - + try { cursor.afterValue( id, attrVal ); - + if ( cursor.previous() ) { return true; } - + return false; } finally @@ -635,8 +645,8 @@ public class IndexWrapper implements Ind cursor.close(); } } - - + + /** * {@inheritDoc} */ @@ -645,7 +655,7 @@ public class IndexWrapper implements Ind return wrappedIndex.getForwardIndexEntryComparator(); } - + /** * {@inheritDoc} */ @@ -654,7 +664,7 @@ public class IndexWrapper implements Ind return wrappedIndex.getReverseIndexEntryComparator(); } - + /** * {@inheritDoc} */ @@ -672,7 +682,7 @@ public class IndexWrapper implements Ind wrappedIndex.sync(); } - + /** * {@inheritDoc} */