001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2014-2015 ForgeRock AS 025 */ 026package org.opends.server.backends.pluggable.spi; 027 028import java.io.Closeable; 029 030import org.forgerock.opendj.ldap.ByteSequence; 031import org.forgerock.opendj.ldap.ByteString; 032 033/** 034 * Allows to run an import. For performance reasons, imports are run without transactions. 035 * <p> 036 * Since import is multi threaded, implementations must be thread-safe. 037 * <p> 038 * 039 * @ThreadSafe 040 */ 041public interface Importer extends Closeable 042{ 043 /** 044 * Clear the tree whose name is provided. Ensure that an empty tree with the given name exists. If the tree already 045 * exists, all the data it contains will be deleted. If not, an empty tree will be created. 046 * 047 * @param treeName name of the tree to clear 048 */ 049 void clearTree(TreeName treeName); 050 051 /** 052 * Creates a record with the provided key and value in the tree identified by the provided name. At the end of this 053 * method, the record is visible by {@link read(TreeName, ByteSequence)} and {@link openCursor(TreeName)} methods of 054 * this instance. The record is guaranteed to be persisted only after {@link #close()}. 055 * 056 * @param treeName 057 * the tree name 058 * @param key 059 * the new record's key 060 * @param value 061 * the new record's value 062 */ 063 void put(TreeName treeName, ByteSequence key, ByteSequence value); 064 065 /** 066 * Reads the record's value associated to the provided key, in the tree whose name is provided. 067 * 068 * @param treeName 069 * the tree name 070 * @param key 071 * the record's key 072 * @return the record's value, or {@code null} if none exists 073 */ 074 ByteString read(TreeName treeName, ByteSequence key); 075 076 /** 077 * Opens a cursor on the tree whose name is provided. Cursors are predictable only if there is no pending 078 * {@link put(TreeName, ByteSequence, ByteSequence)} operations. Indeed, once opened, cursors might not reflect 079 * changes. 080 * 081 * @param treeName 082 * the tree name 083 * @return a new cursor 084 */ 085 SequentialCursor<ByteString, ByteString> openCursor(TreeName treeName); 086 087 @Override 088 void close(); 089}