1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.mitosis.operation;
21
22
23 import org.apache.directory.mitosis.common.CSN;
24 import org.apache.directory.mitosis.operation.support.EntryUtil;
25 import org.apache.directory.mitosis.store.ReplicationStore;
26 import org.apache.directory.server.core.CoreSession;
27 import org.apache.directory.server.core.entry.ClonedServerEntry;
28 import org.apache.directory.server.core.entry.ServerEntry;
29 import org.apache.directory.server.core.filtering.EntryFilteringCursor;
30 import org.apache.directory.server.core.interceptor.context.AddOperationContext;
31 import org.apache.directory.server.core.interceptor.context.DeleteOperationContext;
32 import org.apache.directory.server.core.interceptor.context.ListOperationContext;
33 import org.apache.directory.server.core.interceptor.context.LookupOperationContext;
34 import org.apache.directory.server.core.partition.PartitionNexus;
35 import org.apache.directory.server.schema.registries.Registries;
36 import org.apache.directory.shared.ldap.entry.Entry;
37 import org.apache.directory.shared.ldap.name.LdapDN;
38
39
40
41
42
43
44
45 public class AddEntryOperation extends Operation
46 {
47
48
49
50
51
52
53
54 private static final long serialVersionUID = 2294492811671880570L;
55
56
57 private Entry entry;
58
59
60
61
62
63
64
65
66
67 public AddEntryOperation( Registries registries )
68 {
69 super( registries, OperationType.ADD_ENTRY );
70 }
71
72
73
74
75
76
77
78 public AddEntryOperation( Registries registries, CSN csn, ServerEntry entry )
79 {
80 super( registries, OperationType.ADD_ENTRY, csn );
81
82 assert entry != null;
83
84 this.entry = entry;
85 }
86
87
88
89
90
91
92
93
94
95 protected void execute0( PartitionNexus nexus, ReplicationStore store, CoreSession coreSession )
96 throws Exception
97 {
98 if ( ! EntryUtil.isEntryUpdatable( coreSession, entry.getDn(), getCSN() ) )
99 {
100 return;
101 }
102
103 EntryUtil.createGlueEntries( coreSession, entry.getDn(), false );
104
105
106 if ( nexus.lookup( new LookupOperationContext( coreSession, entry.getDn() ) ) != null )
107 {
108 recursiveDelete( nexus, entry.getDn(), coreSession );
109 }
110
111 nexus.add( new AddOperationContext( coreSession, (ServerEntry)entry ) );
112 }
113
114
115
116
117
118
119
120
121
122
123
124 @SuppressWarnings("unchecked")
125 private void recursiveDelete( PartitionNexus nexus, LdapDN normalizedName, CoreSession coreSession )
126 throws Exception
127 {
128 EntryFilteringCursor cursor = nexus.list( new ListOperationContext( coreSession, normalizedName ) );
129
130 if ( !cursor.available() )
131 {
132 nexus.delete( new DeleteOperationContext( coreSession, normalizedName ) );
133 return;
134 }
135
136 Registries registries = coreSession.getDirectoryService().getRegistries();
137 while ( cursor.next() )
138 {
139 ClonedServerEntry sr = cursor.get();
140 LdapDN dn = sr.getDn();
141 dn.normalize( registries.getAttributeTypeRegistry().getNormalizerMapping() );
142 recursiveDelete( nexus, dn, coreSession );
143 }
144
145 nexus.delete( new DeleteOperationContext( coreSession, normalizedName ) );
146 }
147
148
149
150
151
152
153
154 public void setEntry( Entry entry )
155 {
156 this.entry = entry;
157 }
158
159
160
161
162
163 public Entry getEntry()
164 {
165 return entry;
166 }
167
168
169
170
171
172 public String toString()
173 {
174 return super.toString() + ": [" + entry.getDn() + "].new( " + entry + " )";
175 }
176 }