/*!
  @header FTDefaultObjectToIdMapper
  @abstract Maps objects (usually strings) to identifier.
 
  @availability OS X, GNUstep
  @copyright 2004, 2005, 2006 Free Software Foundation, Inc.
  
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA

  <pre>
  -------------------------------------------------------------------------
  Modification history

  09.02.2005 ola     initial version
  23.08.2006 ola     license changed
  -------------------------------------------------------------------------
  </pre>
*/

#if !defined(__FTDefaultObjectToIdMapper_H)
#define __FTDefaultObjectToIdMapper_H

#include <Foundation/Foundation.h>
#include <FT/FTObject.h>
#include <FT/FTObjectToIdMapper.h>
#include <BDB/BDB.h>

@class FTServerImpl;

/*!
 * @class FTDefaultObjectToIdMapper
 * @abstract Used to map objects (usually strings) to identifier
 * @discussionion This mapper returns the same identifier for objects whose
 *   serialized data equal (see {@link NSCoding}).
 */
@interface FTDefaultObjectToIdMapper : FTObject <FTObjectToIdMapper> {
  @private
    BDBDatabase *database;
	
	/**
	 * Contains fully qualified database name
	 */
	NSString *databaseName;
	
	
	/**
	 * This lock is used to synchronize the insert operation
	 */
	NSLock *insertLock;
	
	FTServerImpl *server;
}

/*!
 * @method initWithDatabase
 * @abstract Initialize and hand-off the underlying db to be used
 * @discussion This method neither opens nor creates the underlying
 *   database. For this purpose {@link #setup} or {@link #mountDatabase}
 *   may be called.
 * @param aDatabaseName fully qualified database name
 * @result self
 */
- initWithDatabaseName: (NSString *) aDatabaseName 
  forServer: (FTServerImpl *) aServer;
- (void) dealloc;


/*!
 * @method dbConfig
 * @abstract create the database configuration instance for the
 *   underlying database
 * @result database configuration
 */
- (BDBDatabaseConfig *) dbConfig;


/*!
 * @method lookup
 * @abstract lookup the given object. 
 * @result Return the related id if found, nil otherwise
 * @throws ECIllegalStateException if database has not been mounted before
 */
- (id <FTId>) lookupObject: (id) toLookup;


/*!
 * @method mapObject
 * @abstract maps a string object to the corresponding identifier
 * @param strObject to map. May not equal nil or be empty.
 * @result identifier
 * @throws ECIllegalStateException if database has not been mounted before
 */
- (id <FTId>) mapObject: (NSString *) strObject;


/*!
 * @method mountDatabase
 * @abstract mounts the underlying database
 * @result self
 * @throws ECIllegalStateException if the underlying database file does not
 *   exist.
 */
- mountDatabase;


/*!
 * @method setupDatabase
 * @abstract creates the database
 * @discussion The caller of this method is responsible for potential
 *   thread synchronization
 * @result self
 * @throws ECIllegalStateException if a file name equal to the database
 *   name already exists.
 */
- setupDatabase;


/*!
 * @method unmountDatabase
 * @abstract closes the database
 * @result self
 */
- unmountDatabase;
@end

#endif
