/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 * In particular this file is part of the iWear Database Access Library.
 *
 * The iWear Framework is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the
 * Free Software Foundation as in version 2 of the License.

 * 
 * The iWear Framework 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 General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __IWEAR_DB_DBSTORABLE_H
#define __IWEAR_DB_DBSTORABLE_H

#include "iwear/db/db.h"
#include <string>

using namespace std;

namespace iwear {
    namespace db {
/**
 * This class defines a basic interface for classes that want to be storable to
 * a database. Those objects must itself generate the necessary SQL statements,
 * and control how and when they are executed.
 *
 * You may not use transactions during this process, since any upper class
 * storing those objects must take care of it. So an upper class can do a
 * transact, then store an arbitrary number of objects, and then commit. This
 * is needed to take care of database integrity.
 */
class dbstorable
{
public:    
    virtual bool SaveToDatabase( const string& tablename, db& dbref ) = 0;
    virtual bool LoadFromDatabase( uint32_t ID, const string& tablename, db& dbref ) = 0;
    virtual bool UpdateToDatabase( const string& tablename, db& dbref ) = 0;
    dbstorable( ) : dbID(0) { }
    virtual ~dbstorable() {}
   /**
    * @return the database ID of this object.
    */
    inline uint32_t get_dbid( void ) const { return dbID; }
protected:
   /**
    */
    uint32_t dbID;
};

} // namespace iwear
}
#endif
