transaction.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
  4. var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
  5. var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
  6. var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
  7. var _inherits2 = require('babel-runtime/helpers/inherits');
  8. var _inherits3 = _interopRequireDefault(_inherits2);
  9. var _bluebird = require('bluebird');
  10. var _bluebird2 = _interopRequireDefault(_bluebird);
  11. var _transaction = require('../../transaction');
  12. var _transaction2 = _interopRequireDefault(_transaction);
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14. var debugTx = require('debug')('knex:tx');
  15. var Oracle_Transaction = function (_Transaction) {
  16. (0, _inherits3.default)(Oracle_Transaction, _Transaction);
  17. function Oracle_Transaction() {
  18. (0, _classCallCheck3.default)(this, Oracle_Transaction);
  19. return (0, _possibleConstructorReturn3.default)(this, _Transaction.apply(this, arguments));
  20. }
  21. // disable autocommit to allow correct behavior (default is true)
  22. Oracle_Transaction.prototype.begin = function begin() {
  23. return _bluebird2.default.resolve();
  24. };
  25. Oracle_Transaction.prototype.commit = function commit(conn, value) {
  26. this._completed = true;
  27. return conn.commitAsync().return(value).then(this._resolver, this._rejecter);
  28. };
  29. Oracle_Transaction.prototype.release = function release(conn, value) {
  30. return this._resolver(value);
  31. };
  32. Oracle_Transaction.prototype.rollback = function rollback(conn, err) {
  33. this._completed = true;
  34. debugTx('%s: rolling back', this.txid);
  35. return conn.rollbackAsync().throw(err).catch(this._rejecter);
  36. };
  37. Oracle_Transaction.prototype.acquireConnection = function acquireConnection(config) {
  38. var t = this;
  39. return _bluebird2.default.try(function () {
  40. return config.connection || t.client.acquireConnection();
  41. }).tap(function (connection) {
  42. if (!t.outerTx) {
  43. connection.setAutoCommit(false);
  44. }
  45. }).disposer(function (connection) {
  46. debugTx('%s: releasing connection', t.txid);
  47. connection.setAutoCommit(true);
  48. if (!config.connection) {
  49. t.client.releaseConnection(connection);
  50. } else {
  51. debugTx('%s: not releasing external connection', t.txid);
  52. }
  53. });
  54. };
  55. return Oracle_Transaction;
  56. }(_transaction2.default);
  57. exports.default = Oracle_Transaction;
  58. module.exports = exports['default'];