~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/transaction_services.cc

  • Committer: Olaf van der Spek
  • Date: 2011-06-23 10:47:03 UTC
  • mto: This revision was merged to the branch mainline in revision 2348.
  • Revision ID: olafvdspek@gmail.com-20110623104703-hw93svu0vfgcqt9p
Refactor

Show diffs side-by-side

added added

removed removed

Lines of Context:
304
304
 * is always committed at the end of all statements.
305
305
 */
306
306
 
307
 
static plugin::XaStorageEngine *xa_storage_engine;
308
 
 
309
 
TransactionServices::TransactionServices()
 
307
static plugin::XaStorageEngine& xa_storage_engine()
310
308
{
311
 
  xa_storage_engine= static_cast<plugin::XaStorageEngine*>(plugin::StorageEngine::findByName("InnoDB"));
 
309
  static plugin::XaStorageEngine& engine= static_cast<plugin::XaStorageEngine&>(*plugin::StorageEngine::findByName("InnoDB"));
 
310
  return engine;
312
311
}
313
312
 
314
313
void TransactionServices::registerResourceForStatement(Session& session,
327
326
    registerResourceForTransaction(session, monitored, engine);
328
327
  }
329
328
 
330
 
  TransactionContext *trans= &session.transaction.stmt;
 
329
  TransactionContext& trans= session.transaction.stmt;
331
330
  ResourceContext& resource_context= session.getResourceContext(*monitored, 0);
332
331
 
333
332
  if (resource_context.isStarted())
338
337
 
339
338
  resource_context.setMonitored(monitored);
340
339
  resource_context.setTransactionalStorageEngine(engine);
341
 
  trans->registerResource(&resource_context);
342
 
 
343
 
  trans->no_2pc= true;
 
340
  trans.registerResource(&resource_context);
 
341
  trans.no_2pc= true;
344
342
}
345
343
 
346
344
void TransactionServices::registerResourceForStatement(Session& session,
360
358
    registerResourceForTransaction(session, monitored, engine, resource_manager);
361
359
  }
362
360
 
363
 
  TransactionContext *trans= &session.transaction.stmt;
 
361
  TransactionContext& trans= session.transaction.stmt;
364
362
  ResourceContext& resource_context= session.getResourceContext(*monitored, 0);
365
363
 
366
364
  if (resource_context.isStarted())
372
370
  resource_context.setMonitored(monitored);
373
371
  resource_context.setTransactionalStorageEngine(engine);
374
372
  resource_context.setXaResourceManager(resource_manager);
375
 
  trans->registerResource(&resource_context);
 
373
  trans.registerResource(&resource_context);
376
374
}
377
375
 
378
376
void TransactionServices::registerResourceForTransaction(Session& session,
379
377
                                                         plugin::MonitoredInTransaction *monitored,
380
378
                                                         plugin::TransactionalStorageEngine *engine)
381
379
{
382
 
  TransactionContext *trans= &session.transaction.all;
 
380
  TransactionContext& trans= session.transaction.all;
383
381
  ResourceContext& resource_context= session.getResourceContext(*monitored, 1);
384
382
 
385
383
  if (resource_context.isStarted())
387
385
 
388
386
  session.server_status|= SERVER_STATUS_IN_TRANS;
389
387
 
390
 
  trans->registerResource(&resource_context);
 
388
  trans.registerResource(&resource_context);
391
389
 
392
390
  assert(monitored->participatesInSqlTransaction());
393
391
  assert(not monitored->participatesInXaTransaction());
394
392
 
395
393
  resource_context.setMonitored(monitored);
396
394
  resource_context.setTransactionalStorageEngine(engine);
397
 
  trans->no_2pc= true;
 
395
  trans.no_2pc= true;
398
396
 
399
397
  if (session.transaction.xid_state.xid.is_null())
400
398
    session.transaction.xid_state.xid.set(session.getQueryId());
445
443
  }
446
444
 
447
445
  Session *my_session= current_session;
448
 
  uint64_t xa_id= xa_storage_engine->getNewTransactionId(my_session);
 
446
  uint64_t xa_id= xa_storage_engine().getNewTransactionId(my_session);
449
447
  my_session->setXaId(xa_id);
450
448
}
451
449
 
453
451
{
454
452
  if (session.getXaId() == 0)
455
453
  {
456
 
    session.setXaId(xa_storage_engine->getNewTransactionId(&session)); 
 
454
    session.setXaId(xa_storage_engine().getNewTransactionId(&session)); 
457
455
  }
458
456
 
459
457
  return session.getXaId();