~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/replicator.h

  • Committer: Brian Aker
  • Date: 2009-03-22 21:27:04 UTC
  • mfrom: (960.2.22 mordred)
  • Revision ID: brian@tangent.org-20090322212704-ysn4mkkjg2u9kv22
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#ifndef DRIZZLED_PLUGIN_REPLICATOR_H
24
24
#define DRIZZLED_PLUGIN_REPLICATOR_H
25
25
 
26
 
typedef struct replicator_st
 
26
/**
 
27
 * @file
 
28
 *
 
29
 * Defines the API for Replication
 
30
 */
 
31
 
 
32
/**
 
33
 * Base class for replication implementations.
 
34
 *
 
35
 *    if a method returns bool true, that means it failed.
 
36
 */
 
37
class Replicator
27
38
{
 
39
private:
28
40
  bool enabled;
29
 
  /* todo, define this api */
30
 
  /* this is the API that a replicator plugin must implement.
31
 
     it should implement each of these function pointers.
32
 
     if a function returns bool true, that means it failed.
33
 
     if a function pointer is NULL, that's ok.
34
 
  */
35
 
 
36
 
  bool (*session_init)(Session *session);
37
 
  bool (*row_insert)(Session *session, Table *table);
38
 
  bool (*row_update)(Session *session, Table *table,
39
 
                     const unsigned char *before,
40
 
                     const unsigned char *after);
41
 
  bool (*row_delete)(Session *session, Table *table);
42
 
  bool (*end_transaction)(Session *session, bool autocommit, bool commit);
43
 
  bool (*statement)(Session *session, const char *query, size_t query_length);
44
 
} replicator_t;
 
41
protected:
 
42
  virtual bool session_init_hook(Session *) { return false; }
 
43
  virtual bool row_insert_hook(Session *, Table *) { return false; }
 
44
  virtual bool row_update_hook(Session *, Table *,
 
45
                               const unsigned char *,
 
46
                               const unsigned char *) { return false; }
 
47
  virtual bool row_delete_hook(Session *, Table *) { return false; }
 
48
  virtual bool end_transaction_hook(Session *, bool, bool) { return false; }
 
49
  virtual bool statement_hook(Session *, const char *, size_t) { return false; }
 
50
public:
 
51
 
 
52
  Replicator() : enabled(true) {}
 
53
 
 
54
  virtual ~Replicator() {}
 
55
  /**
 
56
   * Initialize session for replication
 
57
   */
 
58
  bool session_init(Session *session)
 
59
  {
 
60
    return session_init_hook(session);
 
61
  }
 
62
 
 
63
  /**
 
64
   * Row insert
 
65
   *
 
66
   * @param current Session
 
67
   * @param Table inserted
 
68
   */
 
69
  bool row_insert(Session *session, Table *table)
 
70
  {
 
71
    return row_insert_hook(session, table);
 
72
  }
 
73
 
 
74
  /**
 
75
   * Row update
 
76
   *
 
77
   * @param current Session
 
78
   * @param Table updated
 
79
   * @param before values
 
80
   * @param after values
 
81
   */
 
82
  bool row_update(Session *session, Table *table,
 
83
                          const unsigned char *before,
 
84
                          const unsigned char *after)
 
85
  {
 
86
    return row_update_hook(session, table, before, after);
 
87
  }
 
88
 
 
89
  /**
 
90
   * Row Delete
 
91
   *
 
92
   * @param current session
 
93
   * @param Table deleted from
 
94
   */
 
95
  bool row_delete(Session *session, Table *table)
 
96
  {
 
97
    return row_delete_hook(session, table);
 
98
  }
 
99
 
 
100
  /**
 
101
   * End Transaction
 
102
   *
 
103
   * @param current Session
 
104
   * @param is autocommit on?
 
105
   * @param did the transaction commit?
 
106
   */
 
107
  bool end_transaction(Session *session, bool autocommit, bool commit)
 
108
  {
 
109
    return end_transaction_hook(session, autocommit, commit);
 
110
  }
 
111
 
 
112
  /**
 
113
   * Raw statement
 
114
   *
 
115
   * @param current Session
 
116
   * @param query string
 
117
   * @param length of query string in bytes
 
118
   */
 
119
  bool statement(Session *session, const char *query, size_t query_length)
 
120
  {
 
121
    return statement_hook(session, query, query_length);
 
122
  }
 
123
};
45
124
 
46
125
#endif /* DRIZZLED_PLUGIN_REPLICATOR_H */