Search in sources :

Example 21 with ChangeLogEntry

use of com.unboundid.ldap.sdk.ChangeLogEntry in project ldapsdk by pingidentity.

the class InMemoryRequestHandler method addChangeLogEntry.

/**
 * Adds the provided changelog entry to the data set, removing an old entry if
 * necessary to remain within the maximum allowed number of changes.  This
 * must only be called from a synchronized method, and the change number for
 * the changelog entry must have been obtained by calling
 * {@code lastChangeNumber.incrementAndGet()}.
 *
 * @param  e        The changelog entry to add to the data set.
 * @param  authzDN  The authorization DN for the change.
 */
private void addChangeLogEntry(@NotNull final ChangeLogEntry e, @NotNull final DN authzDN) {
    // Construct the DN object to use for the entry and put it in the map.
    final long changeNumber = e.getChangeNumber();
    final Schema schema = schemaRef.get();
    final DN dn = new DN(new RDN("changeNumber", String.valueOf(changeNumber), schema), changeLogBaseDN);
    final Entry entry = e.duplicate();
    if (generateOperationalAttributes) {
        final Date d = new Date();
        entry.addAttribute(new Attribute("entryDN", DistinguishedNameMatchingRule.getInstance(), dn.toNormalizedString()));
        entry.addAttribute(new Attribute("entryUUID", CryptoHelper.getRandomUUID().toString()));
        entry.addAttribute(new Attribute("subschemaSubentry", DistinguishedNameMatchingRule.getInstance(), subschemaSubentryDN.toString()));
        entry.addAttribute(new Attribute("creatorsName", DistinguishedNameMatchingRule.getInstance(), authzDN.toString()));
        entry.addAttribute(new Attribute("createTimestamp", GeneralizedTimeMatchingRule.getInstance(), StaticUtils.encodeGeneralizedTime(d)));
        entry.addAttribute(new Attribute("modifiersName", DistinguishedNameMatchingRule.getInstance(), authzDN.toString()));
        entry.addAttribute(new Attribute("modifyTimestamp", GeneralizedTimeMatchingRule.getInstance(), StaticUtils.encodeGeneralizedTime(d)));
    }
    entryMap.put(dn, new ReadOnlyEntry(entry));
    indexAdd(entry);
    // Update the first change number and/or trim the changelog if necessary.
    final long firstNumber = firstChangeNumber.get();
    if (changeNumber == 1L) {
        // It's the first change, so we need to set the first change number.
        firstChangeNumber.set(1);
    } else {
        // See if we need to trim an entry.
        final long numChangeLogEntries = changeNumber - firstNumber + 1;
        if (numChangeLogEntries > maxChangelogEntries) {
            // We need to delete the first changelog entry and increment the
            // first change number.
            firstChangeNumber.incrementAndGet();
            final Entry deletedEntry = entryMap.remove(new DN(new RDN("changeNumber", String.valueOf(firstNumber), schema), changeLogBaseDN));
            indexDelete(deletedEntry);
        }
    }
}
Also used : ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) ChangeLogEntry(com.unboundid.ldap.sdk.ChangeLogEntry) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry) Entry(com.unboundid.ldap.sdk.Entry) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) Attribute(com.unboundid.ldap.sdk.Attribute) Schema(com.unboundid.ldap.sdk.schema.Schema) RDN(com.unboundid.ldap.sdk.RDN) DN(com.unboundid.ldap.sdk.DN) RDN(com.unboundid.ldap.sdk.RDN) Date(java.util.Date)

Aggregations

ChangeLogEntry (com.unboundid.ldap.sdk.ChangeLogEntry)21 Entry (com.unboundid.ldap.sdk.Entry)20 Test (org.testng.annotations.Test)19 DN (com.unboundid.ldap.sdk.DN)13 RDN (com.unboundid.ldap.sdk.RDN)13 Attribute (com.unboundid.ldap.sdk.Attribute)11 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)7 Control (com.unboundid.ldap.sdk.Control)6 Modification (com.unboundid.ldap.sdk.Modification)6 LDIFModifyChangeRecord (com.unboundid.ldif.LDIFModifyChangeRecord)5 LDIFDeleteChangeRecord (com.unboundid.ldif.LDIFDeleteChangeRecord)3 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)2 ReadOnlyEntry (com.unboundid.ldap.sdk.ReadOnlyEntry)2 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)2 UnboundIDChangeLogEntry (com.unboundid.ldap.sdk.unboundidds.UnboundIDChangeLogEntry)2 LDIFAddChangeRecord (com.unboundid.ldif.LDIFAddChangeRecord)2 LDIFModifyDNChangeRecord (com.unboundid.ldif.LDIFModifyDNChangeRecord)2 DeleteRequest (com.unboundid.ldap.sdk.DeleteRequest)1 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1