00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00025 #pragma once
00026
00027 #include <drizzled/atomics.h>
00028 #include <drizzled/message/transaction.pb.h>
00029 #include <drizzled/identifier.h>
00030 #include <drizzled/message/schema.h>
00031 #include <drizzled/message/table.h>
00032 #include <drizzled/session.h>
00033
00034 #include <drizzled/visibility.h>
00035
00036 namespace drizzled {
00037
00042 class DRIZZLED_API TransactionServices
00043 {
00044 public:
00045 static const size_t DEFAULT_RECORD_SIZE= 100;
00046
00051 static bool shouldConstructMessages();
00052
00060 static void finalizeStatementMessage(message::Statement&, Session&);
00061
00072 static bool insertRecord(Session&, Table &in_table);
00073
00083 static void updateRecord(Session&,
00084 Table&,
00085 const unsigned char *old_record,
00086 const unsigned char *new_record);
00087
00096 static void deleteRecord(Session&, Table&, bool use_update_record= false);
00097
00106 static void createSchema(Session&, const message::Schema &schema);
00107
00116 static void dropSchema(Session&,
00117 const identifier::Schema& identifier,
00118 message::schema::const_reference schema);
00119
00129 static void alterSchema(Session&,
00130 const message::Schema &old_schema,
00131 const message::Schema &new_schema);
00132
00141 static void createTable(Session&, const message::Table&);
00142
00152 static void dropTable(Session&,
00153 const identifier::Table& identifier,
00154 message::table::const_reference table,
00155 bool if_exists);
00156
00165 static void truncateTable(Session&, Table&);
00166
00180 static void rawStatement(Session&, const std::string &query, const std::string &schema);
00181
00182 static void rawStatement(Session& session, const std::string& query)
00183 {
00184 rawStatement(session, query, "");
00185 }
00186
00187
00188 static int rollbackTransaction(Session&, bool all);
00189
00203 static int commitTransaction(Session&, bool all);
00204
00216 static int autocommitOrRollback(Session&, int error);
00217
00218
00219 static int rollbackToSavepoint(Session&, NamedSavepoint &sv);
00220 static int setSavepoint(Session&, NamedSavepoint &sv);
00221 static int releaseSavepoint(Session&, NamedSavepoint &sv);
00222
00241 static void registerResourceForStatement(Session&, plugin::MonitoredInTransaction*, plugin::TransactionalStorageEngine*);
00242
00262 static void registerResourceForStatement(Session&,
00263 plugin::MonitoredInTransaction *monitored,
00264 plugin::TransactionalStorageEngine *engine,
00265 plugin::XaResourceManager *resource_manager);
00266
00291 static void registerResourceForTransaction(Session&, plugin::MonitoredInTransaction*, plugin::TransactionalStorageEngine*);
00292
00293 static void registerResourceForTransaction(Session&, plugin::MonitoredInTransaction*, plugin::TransactionalStorageEngine*, plugin::XaResourceManager*);
00294
00295 static void allocateNewTransactionId();
00296
00297
00298
00299
00300
00309 static bool sendStartupEvent(Session&);
00310
00319 static bool sendShutdownEvent(Session&);
00320
00321 private:
00322
00334 static message::Transaction *getActiveTransactionMessage(Session&, bool should_inc_trx_id= true);
00335
00346 static void initTransactionMessage(message::Transaction&, Session&, bool should_inc_trx_id);
00347
00355 static void initStatementMessage(message::Statement&, message::Statement::Type type, const Session&);
00356
00364 static void finalizeTransactionMessage(message::Transaction&, const Session&);
00365
00370 static void cleanupTransactionMessage(message::Transaction *transaction, Session&);
00371
00379 static message::Statement &getInsertStatement(Session&, Table&, uint32_t *next_segment_id);
00380
00389 static void setInsertHeader(message::Statement&,
00390 const Session&,
00391 Table&);
00402 static message::Statement &getUpdateStatement(Session&,
00403 Table&,
00404 const unsigned char *old_record,
00405 const unsigned char *new_record,
00406 uint32_t *next_segment_id);
00417 static void setUpdateHeader(message::Statement&,
00418 const Session&,
00419 Table&,
00420 const unsigned char *old_record,
00421 const unsigned char *new_record);
00422
00431 static message::Statement &getDeleteStatement(Session&, Table&, uint32_t *next_segment_id);
00432
00441 static void setDeleteHeader(message::Statement&, const Session&, Table&);
00442
00449 static int commitTransactionMessage(Session&);
00450
00457 static void rollbackTransactionMessage(Session&);
00458
00468 static void rollbackStatementMessage(Session&);
00469
00478 static bool isFieldUpdated(Field *current_field,
00479 Table&,
00480 const unsigned char *old_record,
00481 const unsigned char *new_record);
00482
00497 static int sendEvent(Session&, const message::Event &event);
00498
00511 static message::Transaction *segmentTransactionMessage(Session&, message::Transaction*);
00512
00513 static int commitPhaseOne(Session&, bool all);
00514
00515 static uint64_t getCurrentTransactionId(Session&);
00516 };
00517
00518 }
00519