//## begin module.cp preserve=no

//    ANNA K5 METACORE

//    This material is the property of www.ProximaCentauri.org.

//    All rights reserved.

//

//    Author        : Alexander Ioan Mihail

//    Incept date   : 12 April 2010

//    Last modified : 28 April 2010

//    Description   : Bridge from DB engines to ANNA's persistnce core

//## end module.cp

 

//## Module: anna_db; Package specification

//## Subsystem: MORPH::SQL

//## Source file: X:\Sources.DEV\SATURN.OS\MORPH\SQL\annaDb.h

 

#ifndef annaDb_h

#define annaDb_h 1

 

//## begin module.additionalIncludes preserve=no

//## end module.additionalIncludes

 

//## begin module.includes preserve=yes

/*

 * $Log: /Core/Saturn.OS/MORPH/SQL/annaDb.h $

 *

 * 1     4/29/10 5:51a Alexander Mihail

 * The ANNA_DB storage engine for MySQL and the ANNA/SQL/dbBridge.DLL

 * module:

 *

 * 1. AnnaDbApi.DLL is a flat C API to create/delete/rename/alter tables

 * and to seek/read/write/update/delete table rows. The module is built

 * with Borland tools and requires a conversion to a Visual Studio -

 * usable import library. The command to do that in the shell of Windows

 * SDK 32Bit build environment is:

 *       SQL>lib /DEF:AnnaDbApi.def /MACHINE:X86

 *

 * 2. Copy the AnnaDbApi.LIB over to MySQL's example storage engine

 * directory along with the annaDb.H and annaDb.CPP source files for the

 * engine with  a command such as:

 *       copy AnnaDbApi.lib X:\Sources.DEV\mysql-5.1.42\storage\example\

 * and have the AnnaDbApi.DLL module available on the path of the MySQL

 * service.

 *

 * 3. AnnaDb.H/CPP is an instance of the example storage engine. The main

 * area of difficulty in this module is to convolve/de-convolve the record

 * buffer for a transaction and build a neutral representation that can be

 * passed to ANNA for marshalling.

 *

 * 4.The ANNA database engine implements all the fundamental MySQL types

 * and the bridge aliases them to ANNA's own data types in the ABSTRACT

 * category through USES relations. Anna's internal Type Viewer would be

 * able to operate on the tables using its own interpretation of the

 * column types.

 *

 * 5. Our ANNA storage engine does not implement any keys at the present

 * time. Our database clients use a construct we call BOND to correlate

 * objects.

 *

 * 6. The bridge turns the external threads into internally managed

 * threads for as long as they stay in the cytoplasm of ANNA. This is

 * "controlled invasion". Once the client is in, its thread would be

 * treated as any of the inbound threads of ANNA, participating in

 * interlocking of threads and resources until it retracts from the cell.

 *

 * 7. The AnaDbApi.DLL bridge filters the requests to create tables and

 * opens-up the Enterprise Frame whenever a CREATE TABLE anna_k5_gui

 * (dummy INT) query is issued.

 *

 * 8. The new system of launching the GUI on demand is useful when loading

 * ANNA as a service.

 */

//## end module.includes

 

//## begin module.declarations preserve=no

//## end module.declarations

 

//## begin module.additionalDeclarations preserve=yes

#ifdef USE_PRAGMA_INTERFACE

#pragma interface             /* gcc class implementation */

#endif

 

typedef struct st_example_share

{

  char *table_name;

  uint table_name_length,use_count;

  pthread_mutex_t mutex;

  THR_LOCK lock;

} EXAMPLE_SHARE;

//## end module.additionalDeclarations

 

 

//## Class: ANNA_DB

//    Bridge to ANNA K5 Morphology Server.

//## Category: MORPH::SQL

//## Subsystem: MORPH::SQL

//## Persistence: Transient

//## Cardinality/Multiplicity: n

 

class ANNA_DB : public handler  //## Inherits: <unnamed>

{

  //## begin ANNA_DB.initialDeclarations preserve=yes

  THR_LOCK_DATA lock;      ///< MySQL lock

  EXAMPLE_SHARE *share;    ///< Shared lock info

  //## end ANNA_DB.initialDeclarations

 

  public:

    //## Constructors (specified)

      //## Operation: ANNA_DB%1669365937; C++

      ANNA_DB (handlerton* hton, TABLE_SHARE* table_arg);

 

    //## Destructor (specified)

      //## Operation: ~ANNA_DB%2045699594; C++

      ~ANNA_DB ();

 

 

    //## Other Operations (specified)

      //## Operation: table_type%-781774322; C++

      const char* table_type () const;

 

      //## Operation: index_type%-394372188; C++

      const char* index_type (unsigned int inx);

 

      //## Operation: bas_ext%856304436; C++

      //    This is a list of flags that indicate what functionality the

      //    storage engine implements. The current table flags are documented

      //    in handler.h

      const char** bas_ext () const;

 

      //## Operation: table_flags%102979909; C++

      //    We are saying that this engine is just row capable to have an

      //    engine that can only handle row-based logging. This is used in

      //    testing.

      ulonglong table_flags () const;

 

      //## Operation: index_flags%1839522061; C++

      unsigned long index_flags (unsigned int inx, unsigned int part, bool all_parts) const;

 

      //## Operation: max_supported_record_length%1323790678; C++

      unsigned int max_supported_record_length () const;

 

      //## Operation: max_supported_keys%-296952971; C++

      unsigned int max_supported_keys () const;

 

      //## Operation: max_supported_key_parts%-1454425379; C++

      unsigned int max_supported_key_parts () const;

 

      //## Operation: max_supported_key_length%-709273228; C++

      unsigned int max_supported_key_length () const;

 

      //## Operation: scan_time%-1343526196; C++

      virtual double scan_time ();

 

      //## Operation: read_time%-1402178710; C++

      virtual double read_time (ha_rows rows);

 

      //## Operation: open%-896650194; C++

      int open (const char* name, int mode, unsigned int test_if_locked);

 

      //## Operation: close%171976220; C++

      int close (void );

 

      //## Operation: transfer_row%1272014773; C++

      int transfer_row (const unsigned char* old_data, unsigned char* new_data);

 

      //## Operation: write_row%741133983; C++

      int write_row (unsigned char* buf);

 

      //## Operation: update_row%612424118; C++

      int update_row (const unsigned char* old_data, unsigned char* new_data);

 

      //## Operation: delete_row%1560135012; C++

      int delete_row (const unsigned char* buf);

 

      //## Operation: index_read_map%474207500; C++

      int index_read_map (unsigned char* buf, const unsigned char* key, key_part_map keypart_map, ha_rkey_function find_flag);

 

      //## Operation: index_next%529634069; C++

      int index_next (unsigned char* buf);

 

      //## Operation: index_prev%-1676896581; C++

      int index_prev (unsigned char* buf);

 

      //## Operation: index_first%-1253854237; C++

      int index_first (unsigned char* buf);

 

      //## Operation: index_last%-1879937318; C++

      //    Unlike index_init(), rnd_init() can be called two consecutive

      //    times without rnd_end() in between (it only makes sense if

      //    scan=1). In this case, the second call should prepare for the new

      //    table scan (e.g if rnd_init() allocates the cursor, the second

      //    call should position the cursor to the start of the table; no need

      //    to deallocate and allocate

      //    it again. This is a required method.

      int index_last (unsigned char* buf);

 

      //## Operation: rnd_init%-1171833730; C++

      int rnd_init (bool scan);

 

      //## Operation: rnd_end%982421517; C++

      int rnd_end ();

 

      //## Operation: rnd_next%-157622378; C++

      int rnd_next (unsigned char* buf);

 

      //## Operation: rnd_pos%1383484823; C++

      int rnd_pos (unsigned char* buf, unsigned char* pos);

 

      //## Operation: position%-168638123; C++

      void position (const unsigned char* record);

 

      //## Operation: info%-289929065; C++

      int info (unsigned int );

 

      //## Operation: extra%1353886229; C++

      int extra (ha_extra_function operation);

 

      //## Operation: external_lock%-2111736477; C++

      int external_lock (THD* thd, int lock_type);

 

      //## Operation: delete_all_rows%1088118382; C++

      int delete_all_rows (void );

 

      //## Operation: records_in_range%-1361632576; C++

      ha_rows records_in_range (unsigned int inx, key_range* min_key, key_range* max_key);

 

      //## Operation: delete_table%-847543193; C++

      int delete_table (const char* from);

 

      //## Operation: rename_table%-776503407; C++

      int rename_table (const char* from, const char* to);

 

      //## Operation: create%576095706; C++

      int create (const char* name, TABLE* table_arg, HA_CREATE_INFO* create_info);

 

      //## Operation: store_lock%423278311; C++

      THR_LOCK_DATA** store_lock (THD* thd, THR_LOCK_DATA** to, thr_lock_type lock_type);

 

    // Additional Public Declarations

      //## begin ANNA_DB.public preserve=yes

      //## end ANNA_DB.public

 

  protected:

    // Additional Protected Declarations

      //## begin ANNA_DB.protected preserve=yes

      //## end ANNA_DB.protected

 

  private:

    // Additional Private Declarations

      //## begin ANNA_DB.private preserve=yes

      //## end ANNA_DB.private

 

  private//## implementation

    // Additional Implementation Declarations

      //## begin ANNA_DB.implementation preserve=yes

      //## end ANNA_DB.implementation

 

};

 

//## begin ANNA_DB.postscript preserve=yes

//## end ANNA_DB.postscript

 

 

 

// Class ANNA_DB

 

inline ANNA_DB::~ANNA_DB ()

{

  //## begin ANNA_DB::~ANNA_DB%2045699594.body preserve=yes

  //## end ANNA_DB::~ANNA_DB%2045699594.body

}

 

 

 

//## Other Operations (inline)

inline const char* ANNA_DB::table_type () const

{

  //## begin ANNA_DB::table_type%-781774322.body preserve=yes

  return "ANNADB";

  //## end ANNA_DB::table_type%-781774322.body

}

 

inline const char* ANNA_DB::index_type (unsigned int inx)

{

  //## begin ANNA_DB::index_type%-394372188.body preserve=yes

  return "HASH";

  //## end ANNA_DB::index_type%-394372188.body

}

 

inline ulonglong ANNA_DB::table_flags () const

{

  //## begin ANNA_DB::table_flags%102979909.body preserve=yes

  return HA_BINLOG_ROW_CAPABLE;

  //## end ANNA_DB::table_flags%102979909.body

}

 

inline unsigned long ANNA_DB::index_flags (unsigned int inx, unsigned int part, bool all_parts) const

{

  //## begin ANNA_DB::index_flags%1839522061.body preserve=yes

  return 0;

  //## end ANNA_DB::index_flags%1839522061.body

}

 

inline unsigned int ANNA_DB::max_supported_record_length () const

{

  //## begin ANNA_DB::max_supported_record_length%1323790678.body preserve=yes

  return HA_MAX_REC_LENGTH;

  //## end ANNA_DB::max_supported_record_length%1323790678.body

}

 

inline unsigned int ANNA_DB::max_supported_keys () const

{

  //## begin ANNA_DB::max_supported_keys%-296952971.body preserve=yes

  return 0;

  //## end ANNA_DB::max_supported_keys%-296952971.body

}

 

inline unsigned int ANNA_DB::max_supported_key_parts () const

{

  //## begin ANNA_DB::max_supported_key_parts%-1454425379.body preserve=yes

  return 0;

  //## end ANNA_DB::max_supported_key_parts%-1454425379.body

}

 

inline unsigned int ANNA_DB::max_supported_key_length () const

{

  //## begin ANNA_DB::max_supported_key_length%-709273228.body preserve=yes

  return 0;

  //## end ANNA_DB::max_supported_key_length%-709273228.body

}

 

inline double ANNA_DB::scan_time ()

{

  //## begin ANNA_DB::scan_time%-1343526196.body preserve=yes

  return (double) (stats.records+stats.deleted) / 20.0+10;

  //## end ANNA_DB::scan_time%-1343526196.body

}

 

inline double ANNA_DB::read_time (ha_rows rows)

{

  //## begin ANNA_DB::read_time%-1402178710.body preserve=yes

  return (double) rows /  20.0+1;

  //## end ANNA_DB::read_time%-1402178710.body

}

 

 

 

 

 

//## begin module.epilog preserve=yes

//## end module.epilog

#endif