opendj3-server-dev/src/server/org/opends/server/backends/jeb/DN2ID.java
@@ -64,36 +64,12 @@ comparator = new AttributeIndex.KeyComparator(); prefixRDNComponents = entryContainer.getBaseDN().size(); DatabaseConfig dn2idConfig = new DatabaseConfig(); if(env.getConfig().getReadOnly()) { dn2idConfig.setReadOnly(true); dn2idConfig.setAllowCreate(false); dn2idConfig.setTransactional(false); } else if(!env.getConfig().getTransactional()) { dn2idConfig.setAllowCreate(true); dn2idConfig.setTransactional(false); dn2idConfig.setDeferredWrite(true); } else { dn2idConfig.setAllowCreate(true); dn2idConfig.setTransactional(true); } this.dbConfig = dn2idConfig; this.dbConfig = JEBUtils.toDatabaseConfigNoDuplicates(env); this.dbConfig.setKeyPrefixing(true); //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()); } /** * Insert a new record into the DN database. * @param txn A JE database transaction to be used for the database operation, opendj3-server-dev/src/server/org/opends/server/backends/jeb/DN2URI.java
@@ -103,31 +103,8 @@ dn2uriComparator = new AttributeIndex.KeyComparator(); prefixRDNComponents = entryContainer.getBaseDN().size(); DatabaseConfig dn2uriConfig = new DatabaseConfig(); if(env.getConfig().getReadOnly()) { dn2uriConfig.setReadOnly(true); dn2uriConfig.setSortedDuplicates(true); dn2uriConfig.setAllowCreate(false); dn2uriConfig.setTransactional(false); } else if(!env.getConfig().getTransactional()) { dn2uriConfig.setSortedDuplicates(true); dn2uriConfig.setAllowCreate(true); dn2uriConfig.setTransactional(false); dn2uriConfig.setDeferredWrite(true); } else { dn2uriConfig.setSortedDuplicates(true); dn2uriConfig.setAllowCreate(true); dn2uriConfig.setTransactional(true); } this.dbConfig = dn2uriConfig; //This line causes an unchecked cast error if the SuppressWarnings //annotation is removed at the beginning of this method. this.dbConfig = JEBUtils.toDatabaseConfigAllowDuplicates(env); this.dbConfig.setBtreeComparator((Class<? extends Comparator<byte[]>>) dn2uriComparator.getClass()); } opendj3-server-dev/src/server/org/opends/server/backends/jeb/ID2Entry.java
@@ -235,28 +235,7 @@ { super(name, env, entryContainer); this.dataConfig = dataConfig; DatabaseConfig dbNodupsConfig = new DatabaseConfig(); if(env.getConfig().getReadOnly()) { dbNodupsConfig.setReadOnly(true); dbNodupsConfig.setAllowCreate(false); dbNodupsConfig.setTransactional(false); } else if(!env.getConfig().getTransactional()) { dbNodupsConfig.setAllowCreate(true); dbNodupsConfig.setTransactional(false); dbNodupsConfig.setDeferredWrite(true); } else { dbNodupsConfig.setAllowCreate(true); dbNodupsConfig.setTransactional(true); } this.dbConfig = dbNodupsConfig; this.dbConfig = JEBUtils.toDatabaseConfigNoDuplicates(env); } /** opendj3-server-dev/src/server/org/opends/server/backends/jeb/Index.java
@@ -144,26 +144,7 @@ this.newImportIDSet = new ImportIDSet(indexEntryLimit, indexEntryLimit, maintainCount); final DatabaseConfig dbNodupsConfig = new DatabaseConfig(); if(env.getConfig().getReadOnly()) { dbNodupsConfig.setReadOnly(true); dbNodupsConfig.setAllowCreate(false); dbNodupsConfig.setTransactional(false); } else if(!env.getConfig().getTransactional()) { dbNodupsConfig.setAllowCreate(true); dbNodupsConfig.setTransactional(false); dbNodupsConfig.setDeferredWrite(true); } else { dbNodupsConfig.setAllowCreate(true); dbNodupsConfig.setTransactional(true); } this.dbConfig = dbNodupsConfig; this.dbConfig = JEBUtils.toDatabaseConfigNoDuplicates(env); this.dbConfig.setOverrideBtreeComparator(true); this.dbConfig.setBtreeComparator((Class<? extends Comparator<byte[]>>) comparator.getClass()); opendj3-server-dev/src/server/org/opends/server/backends/jeb/JEBUtils.java
New file @@ -0,0 +1,104 @@ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt * or http://forgerock.org/license/CDDLv1.0.html. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at legal-notices/CDDLv1_0.txt. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * Copyright 2014 ForgeRock AS */ package org.opends.server.backends.jeb; import com.sleepycat.je.DatabaseConfig; import com.sleepycat.je.Environment; /** * JE Backend utility methods. */ final class JEBUtils { private JEBUtils() { // Private for utility classes } /** * Converts the provided JE environment to a {@link DatabaseConfig} object * that disallows duplicates. * * @param env * the environment object to convert * @return a new {@link DatabaseConfig} object */ static DatabaseConfig toDatabaseConfigNoDuplicates(Environment env) { final DatabaseConfig result = new DatabaseConfig(); if (env.getConfig().getReadOnly()) { result.setReadOnly(true); result.setAllowCreate(false); result.setTransactional(false); } else if (!env.getConfig().getTransactional()) { result.setAllowCreate(true); result.setTransactional(false); result.setDeferredWrite(true); } else { result.setAllowCreate(true); result.setTransactional(true); } return result; } /** * Converts the provided JE environment to a {@link DatabaseConfig} object * that allows duplicates. * * @param env * the environment object to convert * @return a new {@link DatabaseConfig} object */ static DatabaseConfig toDatabaseConfigAllowDuplicates(Environment env) { final DatabaseConfig result = new DatabaseConfig(); if (env.getConfig().getReadOnly()) { result.setReadOnly(true); result.setSortedDuplicates(true); result.setAllowCreate(false); result.setTransactional(false); } else if (!env.getConfig().getTransactional()) { result.setSortedDuplicates(true); result.setAllowCreate(true); result.setTransactional(false); result.setDeferredWrite(true); } else { result.setSortedDuplicates(true); result.setAllowCreate(true); result.setTransactional(true); } return result; } } opendj3-server-dev/src/server/org/opends/server/backends/jeb/JECompressedSchema.java
@@ -196,25 +196,7 @@ */ private void load() throws DatabaseException, InitializationException { final DatabaseConfig dbConfig = new DatabaseConfig(); if (environment.getConfig().getReadOnly()) { dbConfig.setReadOnly(true); dbConfig.setAllowCreate(false); dbConfig.setTransactional(false); } else if (!environment.getConfig().getTransactional()) { dbConfig.setAllowCreate(true); dbConfig.setTransactional(false); dbConfig.setDeferredWrite(true); } else { dbConfig.setAllowCreate(true); dbConfig.setTransactional(true); } final DatabaseConfig dbConfig = JEBUtils.toDatabaseConfigNoDuplicates(environment); adDatabase = environment.openDatabase(null, DB_NAME_AD, dbConfig); ocDatabase = environment.openDatabase(null, DB_NAME_OC, dbConfig); opendj3-server-dev/src/server/org/opends/server/backends/jeb/State.java
@@ -58,28 +58,7 @@ throws DatabaseException { super(name, env, entryContainer); DatabaseConfig dbNodupsConfig = new DatabaseConfig(); if(env.getConfig().getReadOnly()) { dbNodupsConfig.setReadOnly(true); dbNodupsConfig.setAllowCreate(false); dbNodupsConfig.setTransactional(false); } else if(!env.getConfig().getTransactional()) { dbNodupsConfig.setAllowCreate(true); dbNodupsConfig.setTransactional(false); dbNodupsConfig.setDeferredWrite(true); } else { dbNodupsConfig.setAllowCreate(true); dbNodupsConfig.setTransactional(true); } this.dbConfig = dbNodupsConfig; this.dbConfig = JEBUtils.toDatabaseConfigNoDuplicates(env); } /** opendj3-server-dev/src/server/org/opends/server/backends/jeb/VLVIndex.java
@@ -187,27 +187,7 @@ this.sortOrder = new SortOrder(sortKeys); this.comparator = new VLVKeyComparator(orderingRules, ascending); DatabaseConfig dbNodupsConfig = new DatabaseConfig(); if(env.getConfig().getReadOnly()) { dbNodupsConfig.setReadOnly(true); dbNodupsConfig.setAllowCreate(false); dbNodupsConfig.setTransactional(false); } else if(!env.getConfig().getTransactional()) { dbNodupsConfig.setAllowCreate(true); dbNodupsConfig.setTransactional(false); dbNodupsConfig.setDeferredWrite(true); } else { dbNodupsConfig.setAllowCreate(true); dbNodupsConfig.setTransactional(true); } this.dbConfig = dbNodupsConfig; this.dbConfig = JEBUtils.toDatabaseConfigNoDuplicates(env); this.dbConfig.setOverrideBtreeComparator(true); this.dbConfig.setBtreeComparator(this.comparator);