~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
  -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:

  *  Definitions required for Configuration Variables plugin

  *  Copyright (C) 2008 Mark Atwood
  *
  *  This program 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; version 2 of the License.
  *
  *  This program 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 this program; if not, write to the Free Software
  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */

#ifndef DRIZZLED_PLUGIN_REPLICATOR_H
#define DRIZZLED_PLUGIN_REPLICATOR_H

/**
 * @file
 *
 * Defines the API for Replication
 */

/**
 * Base class for replication implementations.
 *
 *    if a method returns bool true, that means it failed.
 */
class Replicator
{
private:
  bool enabled;
protected:
  virtual bool session_init_hook(Session *) { return false; }
  virtual bool row_insert_hook(Session *, Table *) { return false; }
  virtual bool row_update_hook(Session *, Table *,
                               const unsigned char *,
                               const unsigned char *) { return false; }
  virtual bool row_delete_hook(Session *, Table *) { return false; }
  virtual bool end_transaction_hook(Session *, bool, bool) { return false; }
  virtual bool statement_hook(Session *, const char *, size_t) { return false; }
public:

  Replicator() : enabled(true) {}

  virtual ~Replicator() {}
  /**
   * Initialize session for replication
   */
  bool session_init(Session *session)
  {
    return session_init_hook(session);
  }

  /**
   * Row insert
   *
   * @param current Session
   * @param Table inserted
   */
  bool row_insert(Session *session, Table *table)
  {
    return row_insert_hook(session, table);
  }

  /**
   * Row update
   *
   * @param current Session
   * @param Table updated
   * @param before values
   * @param after values
   */
  bool row_update(Session *session, Table *table,
                          const unsigned char *before,
                          const unsigned char *after)
  {
    return row_update_hook(session, table, before, after);
  }

  /**
   * Row Delete
   *
   * @param current session
   * @param Table deleted from
   */
  bool row_delete(Session *session, Table *table)
  {
    return row_delete_hook(session, table);
  }

  /**
   * End Transaction
   *
   * @param current Session
   * @param is autocommit on?
   * @param did the transaction commit?
   */
  bool end_transaction(Session *session, bool autocommit, bool commit)
  {
    return end_transaction_hook(session, autocommit, commit);
  }

  /**
   * Raw statement
   *
   * @param current Session
   * @param query string
   * @param length of query string in bytes
   */
  bool statement(Session *session, const char *query, size_t query_length)
  {
    return statement_hook(session, query, query_length);
  }
};

#endif /* DRIZZLED_PLUGIN_REPLICATOR_H */