You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/09/18 18:50:30 UTC

svn commit: r998495 - /directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java

Author: kayyagari
Date: Sat Sep 18 16:50:29 2010
New Revision: 998495

URL: http://svn.apache.org/viewvc?rev=998495&view=rev
Log:
o added a check to preven adding an existing entry (this check is useful only when a partition is not fronted by  interceptor chain, by default this check is disabled)

Modified:
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java?rev=998495&r1=998494&r2=998495&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java (original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java Sat Sep 18 16:50:29 2010
@@ -137,6 +137,13 @@ public abstract class AbstractStore<E, I
     /** the relative distinguished name index */
     protected Index<ParentIdAndRdn<ID>, E, ID> rdnIdx;
 
+    /**
+     * a flag to enable/disable hasEntry() check before adding the entry
+     * Note: This kind of check is already present in ExceptionInterceptor's
+     * add() method. This flag needs to be enabled only in cases where interceptor chain
+     * is not used or not yet effective at the time of adding entries into this store.
+     */
+    private boolean checkHasEntryDuringAdd = true;
 
     public void init( SchemaManager schemaManager ) throws Exception
     {
@@ -847,6 +854,19 @@ public abstract class AbstractStore<E, I
             throw new Exception( I18n.err( I18n.ERR_215 ) );
         }
 
+        DN entryDn = entry.getDn();
+
+        if ( checkHasEntryDuringAdd )
+        {
+            // check if the entry already exists
+            if ( getEntryId( entryDn ) != null )
+            {
+                LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException(
+                    I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, entryDn.getName() ) );
+                throw ne;
+            }
+        }
+
         ID parentId;
         ID id = master.getNextId( entry );
 
@@ -855,7 +875,6 @@ public abstract class AbstractStore<E, I
         // capped off using the zero value which no entry can have since
         // entry sequences start at 1.
         //
-        DN entryDn = entry.getDn();
         DN parentDn = null;
         ParentIdAndRdn<ID> key = null;
 
@@ -2142,4 +2161,24 @@ public abstract class AbstractStore<E, I
         entryCsnIdx.drop( id );
         entryCsnIdx.add( entry.get( SchemaConstants.ENTRY_CSN_AT ).getString(), id );
     }
+
+    
+    /**
+     * @return true if the hasEntry check is performed before adding a entry, false otherwise
+     */
+    public boolean isCheckHasEntryDuringAdd()
+    {
+        return checkHasEntryDuringAdd;
+    }
+
+    
+    /**
+     * set the flag to nable/disable checking of entry existence before actually adding it
+     * @param checkHasEntryDuringAdd
+     */
+    public void setCheckHasEntryDuringAdd( boolean checkHasEntryDuringAdd )
+    {
+        this.checkHasEntryDuringAdd = checkHasEntryDuringAdd;
+    }
+    
 }