// -*- C++ -*- //

/* metastore.h
 *
 * Copyright 2006 libgdamm Development Team
 *
 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <libgdamm/connection.h>
#include <libgdamm/metastruct.h>

_DEFS(libgdamm,libgda)
_PINCLUDE(glibmm/private/object_p.h)

namespace Gnome
{

namespace Gda
{

_WRAP_GERROR(MetaStoreError, GdaMetaStoreError, GDA_META_STORE_ERROR)
_WRAP_ENUM(SqlIdentifierStyle, GdaSqlIdentifierStyle)

/** Dictionary object.
 *
 * Previous versions of Libgda relied on an XML based file to store dictionary 
 * information, such as the database's schema (tables, views, etc) and various 
 * other information. The problems were that it was difficult for an application
 * to integrate its own data into the dictionary and that there were some 
 * performances problems as the XML file needed to be parsed (and converted into 
 * its own in-memory structure) before any data could be read out of it.
 *
 * The new dictionary now relies on a database structure to store its data 
 * (see the database schema section for a detailled description). The actual 
 * database can be a single file (using an SQLite database), an entirely in 
 * memory database (also using an SQLite database), or a more conventional backend 
 * such as a PostgreSQL database for a shared dictionary on a server. 
 *
 * @ingroup Connection
 */
class MetaStore : public Glib::Object
{
  typedef GdaMetaContext MetaContext;
  
  _CLASS_GOBJECT(MetaStore, GdaMetaStore, GDA_META_STORE, Glib::Object, GObject)
protected:
  _WRAP_CTOR(MetaStore(const Glib::ustring& cnc_string), gda_meta_store_new)
  // TODO: cannot be overloaded, no filename property  
  //_WRAP_CTOR(MetaStore(const std::string& filename), gda_meta_store_new_with_file)

public:
  _WRAP_CREATE(const Glib::ustring& cnc_string)
  
  _WRAP_METHOD(int get_version() const, gda_meta_store_get_version)
  _WRAP_METHOD_DOCS_ONLY (gda_meta_store_extract)

  Glib::RefPtr<DataModel> extract(const Glib::ustring& sql);

  _WRAP_METHOD_DOCS_ONLY (gda_meta_store_modify)
  bool modify(const Glib::ustring& sql, const Glib::RefPtr<DataModel>& data_model, const Glib::ustring& condition);

  _WRAP_METHOD(bool modify_with_context (MetaContext* context, const Glib::RefPtr<DataModel>& new_data), gda_meta_store_modify_with_context, errthrow)

  _WRAP_METHOD(Glib::RefPtr<DataModel> create_modify_data_model(const Glib::ustring& table_name), gda_meta_store_create_modify_data_model)
  _WRAP_METHOD(void set_identifiers_style(SqlIdentifierStyle style), gda_meta_store_set_identifiers_style)
  _WRAP_METHOD(Glib::RefPtr<MetaStruct> schema_get_structure(), gda_meta_store_schema_get_structure, errthrow)
  
#m4 _CONVERSION(`GSList*',`std::vector<Glib::ustring>', `Glib::SListHandler<Glib::ustring>::slist_to_vector($3, Glib::OWNERSHIP_SHALLOW)')
  _WRAP_METHOD(std::vector<Glib::ustring> schema_get_all_tables(), gda_meta_store_schema_get_all_tables)
  _WRAP_METHOD(std::vector<Glib::ustring> schema_get_depend_tables(const Glib::ustring& table_name), gda_meta_store_schema_get_depend_tables)  

  _WRAP_METHOD_DOCS_ONLY(gda_meta_store_get_attribute_value)
   bool get_attribute_value(const Glib::ustring& att_name, Glib::ustring& att_value);

  _WRAP_METHOD(bool set_attribute_value(const Glib::ustring& att_name, const Glib::ustring& att_value), gda_meta_store_set_attribute_value, errthrow)
  _WRAP_METHOD(bool schema_add_custom_object(const Glib::ustring& xml_description), gda_meta_store_schema_add_custom_object, errthrow)
  _WRAP_METHOD(bool schema_remove_custom_object(const Glib::ustring& obj_name), gda_meta_store_schema_remove_custom_object, errthrow)

  _WRAP_METHOD(Glib::RefPtr<Connection> get_internal_connection(), gda_meta_store_get_internal_connection)
  _WRAP_METHOD(Glib::RefPtr<const Connection> get_internal_connection() const, gda_meta_store_get_internal_connection)

  _IGNORE(gda_meta_store_set_reserved_keywords_func)
  
  // The rest of the properties are Write / Construct-only
  _WRAP_PROPERTY("cnc", Glib::RefPtr<Connection>)  

  _WRAP_SIGNAL(void meta_reset(), "meta-reset")

  // TODO: do we need these?
  //_WRAP_SIGNAL(GError* suggest_update(MetaContext*  suggest), "suggest-update", no_default_handler)
  //_WRAP_SIGNAL(void meta_changed(std::vector<>))
};

} // namespace Gda
} // namespace Gnome

