From acd30eaad73bf1f50e727d65dc06b7c8ac456dab Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 28 Nov 2014 12:17:15 +0000
Subject: [PATCH] Code cleanup
---
opendj3-server-dev/src/server/org/opends/server/backends/jeb/ID2Entry.java | 33 +++++-----
opendj3-server-dev/src/server/org/opends/server/backends/jeb/DN2ID.java | 98 +++++++++-----------------------
2 files changed, 46 insertions(+), 85 deletions(-)
diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/DN2ID.java b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/DN2ID.java
index d98983e..5a02a04 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/DN2ID.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/DN2ID.java
@@ -26,12 +26,16 @@
*/
package org.opends.server.backends.jeb;
-import com.sleepycat.je.*;
+import java.util.Comparator;
import org.opends.server.types.DN;
-import org.forgerock.i18n.slf4j.LocalizedLogger;
-import java.util.Comparator;
+import com.sleepycat.je.*;
+
+import static com.sleepycat.je.LockMode.*;
+import static com.sleepycat.je.OperationStatus.*;
+
+import static org.opends.server.backends.jeb.JebFormat.*;
/**
* This class represents the DN database, or dn2id, which has one record
@@ -40,13 +44,8 @@
*/
public class DN2ID extends DatabaseContainer
{
- private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
-
- /**
- * The key comparator used for the DN database.
- */
+ /** The key comparator used for the DN database. */
private final Comparator<byte[]> comparator;
-
private final int prefixRDNComponents;
/**
@@ -90,8 +89,7 @@
//This line causes an unchecked cast error if the SuppressWarnings
//annotation is removed at the beginning of this method.
- this.dbConfig.setBtreeComparator((Class<? extends Comparator<byte[]>>)
- comparator.getClass());
+ this.dbConfig.setBtreeComparator((Class<? extends Comparator<byte[]>>) comparator.getClass());
}
@@ -107,21 +105,12 @@
* @throws DatabaseException If an error occurred while attempting to insert
* the new record.
*/
- public boolean insert(Transaction txn, DN dn, EntryID id)
- throws DatabaseException
+ public boolean insert(Transaction txn, DN dn, EntryID id) throws DatabaseException
{
- DatabaseEntry key = new DatabaseEntry(
- JebFormat.dnToDNKey(dn, prefixRDNComponents));
+ DatabaseEntry key = new DatabaseEntry(dnToDNKey(dn, prefixRDNComponents));
DatabaseEntry data = id.getDatabaseEntry();
- OperationStatus status;
-
- status = insert(txn, key, data);
- if (status != OperationStatus.SUCCESS)
- {
- return false;
- }
- return true;
+ return insert(txn, key, data) == SUCCESS;
}
/**
@@ -136,20 +125,12 @@
* @throws DatabaseException If an error occurred while attempting to write
* the record.
*/
- public boolean put(Transaction txn, DN dn, EntryID id)
- throws DatabaseException
+ public boolean put(Transaction txn, DN dn, EntryID id) throws DatabaseException
{
- DatabaseEntry key = new DatabaseEntry(
- JebFormat.dnToDNKey(dn, prefixRDNComponents));
+ DatabaseEntry key = new DatabaseEntry(dnToDNKey(dn, prefixRDNComponents));
DatabaseEntry data = id.getDatabaseEntry();
- OperationStatus status;
- status = put(txn, key, data);
- if (status != OperationStatus.SUCCESS)
- {
- return false;
- }
- return true;
+ return put(txn, key, data) == SUCCESS;
}
/**
@@ -163,9 +144,8 @@
* @throws DatabaseException If an error occurred while attempting to write
* the record.
*/
- public OperationStatus put(Transaction txn, DatabaseEntry key,
- DatabaseEntry data)
- throws DatabaseException
+ @Override
+ public OperationStatus put(Transaction txn, DatabaseEntry key, DatabaseEntry data) throws DatabaseException
{
return super.put(txn, key, data);
}
@@ -179,27 +159,16 @@
* @throws DatabaseException If an error occurred while attempting to remove
* the record.
*/
- public boolean remove(Transaction txn, DN dn)
- throws DatabaseException
+ public boolean remove(Transaction txn, DN dn) throws DatabaseException
{
- DatabaseEntry key = new DatabaseEntry(
- JebFormat.dnToDNKey(dn, prefixRDNComponents)
- );
+ DatabaseEntry key = new DatabaseEntry(dnToDNKey(dn, prefixRDNComponents));
- OperationStatus status = delete(txn, key);
- if (status != OperationStatus.SUCCESS)
- {
- return false;
- }
- return true;
+ return delete(txn, key) == SUCCESS;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
- protected OperationStatus delete(Transaction txn, DatabaseEntry key)
- throws DatabaseException
+ protected OperationStatus delete(Transaction txn, DatabaseEntry key) throws DatabaseException
{
return super.delete(txn, key);
}
@@ -213,30 +182,21 @@
* @return The entry ID, or null if the given DN is not in the DN database.
* @throws DatabaseException If an error occurs in the JE database.
*/
- public EntryID get(Transaction txn, DN dn, LockMode lockMode)
- throws DatabaseException
+ public EntryID get(Transaction txn, DN dn, LockMode lockMode) throws DatabaseException
{
- DatabaseEntry key = new DatabaseEntry(
- JebFormat.dnToDNKey(dn, prefixRDNComponents)
- );
+ DatabaseEntry key = new DatabaseEntry(dnToDNKey(dn, prefixRDNComponents));
DatabaseEntry data = new DatabaseEntry();
- OperationStatus status;
- status = read(txn, key, data, LockMode.DEFAULT);
- if (status != OperationStatus.SUCCESS)
+ if (read(txn, key, data, DEFAULT) == SUCCESS)
{
- return null;
+ return new EntryID(data);
}
- return new EntryID(data);
+ return null;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
@Override
- public OperationStatus read(Transaction txn,
- DatabaseEntry key, DatabaseEntry data,
- LockMode lockMode)
+ public OperationStatus read(Transaction txn, DatabaseEntry key, DatabaseEntry data, LockMode lockMode)
{
return super.read(txn, key, data, lockMode);
}
diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/ID2Entry.java b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/ID2Entry.java
index f2c1ccf..0d77860 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/ID2Entry.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/ID2Entry.java
@@ -26,6 +26,12 @@
*/
package org.opends.server.backends.jeb;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.zip.DataFormatException;
+import java.util.zip.DeflaterOutputStream;
+import java.util.zip.InflaterOutputStream;
+
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
@@ -34,6 +40,7 @@
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.forgerock.opendj.ldap.DecodeException;
import org.opends.server.api.CompressedSchema;
+import org.opends.server.backends.pluggable.KeyValueStore;
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
@@ -41,11 +48,7 @@
import com.sleepycat.je.*;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.zip.DataFormatException;
-import java.util.zip.DeflaterOutputStream;
-import java.util.zip.InflaterOutputStream;
+import static com.sleepycat.je.OperationStatus.*;
import static org.forgerock.util.Utils.*;
import static org.opends.messages.JebMessages.*;
@@ -55,7 +58,7 @@
* Represents the database containing the LDAP entries. The database key is
* the entry ID and the value is the entry contents.
*/
-public class ID2Entry extends DatabaseContainer
+public class ID2Entry extends DatabaseContainer implements KeyValueStore<EntryID, Entry, Transaction, LockMode>
{
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
@@ -345,6 +348,7 @@
* @throws DirectoryException If a problem occurs while attempting to encode
* the entry.
*/
+ @Override
public boolean insert(Transaction txn, EntryID id, Entry entry)
throws DatabaseException, DirectoryException
{
@@ -353,8 +357,7 @@
try
{
DatabaseEntry data = codec.encodeInternal(entry, dataConfig);
- OperationStatus status = insert(txn, key, data);
- return status == OperationStatus.SUCCESS;
+ return insert(txn, key, data) == SUCCESS;
}
finally
{
@@ -373,6 +376,7 @@
* @throws DirectoryException If a problem occurs while attempting to encode
* the entry.
*/
+ @Override
public boolean put(Transaction txn, EntryID id, Entry entry)
throws DatabaseException, DirectoryException
{
@@ -381,8 +385,7 @@
try
{
DatabaseEntry data = codec.encodeInternal(entry, dataConfig);
- OperationStatus status = put(txn, key, data);
- return status == OperationStatus.SUCCESS;
+ return put(txn, key, data) == SUCCESS;
}
finally
{
@@ -414,11 +417,11 @@
* @return true if the entry was removed, false if it was not.
* @throws DatabaseException If an error occurs in the JE database.
*/
+ @Override
public boolean remove(Transaction txn, EntryID id) throws DatabaseException
{
DatabaseEntry key = id.getDatabaseEntry();
- OperationStatus status = delete(txn, key);
- return status == OperationStatus.SUCCESS;
+ return delete(txn, key) == SUCCESS;
}
/**
@@ -431,16 +434,14 @@
* @throws DirectoryException If a problem occurs while getting the entry.
* @throws DatabaseException If an error occurs in the JE database.
*/
+ @Override
public Entry get(Transaction txn, EntryID id, LockMode lockMode)
throws DirectoryException, DatabaseException
{
DatabaseEntry key = id.getDatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
- OperationStatus status;
- status = read(txn, key, data, lockMode);
-
- if (status != OperationStatus.SUCCESS)
+ if (read(txn, key, data, lockMode) != SUCCESS)
{
return null;
}
--
Gitblit v1.10.0