transactions

Test script for transaction concurrency for postgresql

喜夏-厌秋 提交于 2020-01-01 19:04:27
问题 I would like to test some variants of transaction concurrency in PostgreSQL and for that I need a script which would force two transaction to start at exactly the same time. Something that does not requires manual intervention ;) Any ideas? 回答1: You can homebrew this by taking a LOCK on a table, setting up your transactions, then releasing the lock by rolling back the transaction that got the lock. See this prior answer and its links for details on this approach. While I demonstrated it using

How to save and delete in same transaction

萝らか妹 提交于 2020-01-01 16:38:29
问题 I need to save some cms pages and delete others in a single transaction. So, how to I make this: $page1->save(); $page2->delete(); A single transaction? For reference, both $page1 and $page2 come from Mage::getModel('cms/page'). Also, I found an excellent answer here that tells me how to do two saves in a transaction, but not how to do both a save and delete. How can it be done? 回答1: If you must do this in a single transaction, just call isDeleted(true) on those items which you wish to be

how to share a transaction in two dbContext with EF6?

两盒软妹~` 提交于 2020-01-01 14:35:48
问题 I am using EF6 and I know that has two methods to use a transaction, BeginTransaction and UseTransaction. I use to use only one dbContext, but in my case, I need to use an auxiliar dbContext and I need that this second dbContext use the same transaction that the main one. I try to use this code: using(Entities miDbContext = new Entities()) { using (DbContextTransaction miTransaccion = miDbContext.Database.BeginTransaction()) { Entities miDbContext2 = new Entities(); miDbContext2.DataBase

How to kill db transaction that timed out from jboss

二次信任 提交于 2020-01-01 14:29:26
问题 I use jboss 4.2.3. It has setting "TransactionTimeout" (in jboss-service.xml), that specifies how long Transaction is allowed to execute. Unfortunately, when the timeout passes, the execution isn't aborted right now, if the transaction is doing something, only it is marked to be rolled back later. The effect is - when I have long lasting transaction and thread is wainting on preparedStatement.execute for example, and when the TransactionTimeout passes, nothing happend, client still hang, only

MySQL transaction conundrum

六月ゝ 毕业季﹏ 提交于 2020-01-01 12:15:15
问题 I need to perform several inserts in a single atomic transaction. For example: start transaction; insert ... insert ... commit; However when MySQL encounters an error it aborts only the particular statement that caused the error. For example, if there is an error in the second insert statement the commit will still take place and the first insert statement will be recorded. Thus, when errors occur a MySQL transaction is not really a transaction. To overcome this problem I have used an error

Rails 3 ActiveRecord Transactions

喜欢而已 提交于 2020-01-01 12:05:36
问题 I have a model method that I'd like to call from various controllers. It looks something like this: def Post < ActiveRecord::Base def read! self.read_at = Time.now self.save self.thread.status = Status.find_by_name("read") self.thread.save end end In my controller, if I call @post.read! , will this rollback on any errors? 回答1: In your current setup, if read_at gives an error, it will still continue onto the code that executes thread.status for example. You want to use ActiveRecord

Can I rollback Dynamic SQL in SQL Server / TSQL

北战南征 提交于 2020-01-01 11:58:15
问题 Can I run a dynamic sql in a transaction and roll back using EXEC: exec('SELECT * FROM TableA; SELECT * FROM TableB;'); Put this in a Transaction and use the @@error after the exec statement to do rollbacks. eg. Code BEGIN TRANSACTION exec('SELECT * FROM TableA; SELECT * FROM TableB;'); IF @@ERROR != 0 BEGIN ROLLBACK TRANSACTION RETURN END ELSE COMMIT TRANSACTION If there are n dynamic sql statements and the error occurs in n/2 will the first 1 to ((n/2) - 1) statements be rolled back

how do I perform transactions with ruby mysql2

天大地大妈咪最大 提交于 2020-01-01 11:46:34
问题 I've started using mysql2 gem. I'm trying to figure out a few basic things - one of them is how to explicitly perform transactions (for batch operations, like multiple INSERT/UPDATE queries). In the old ruby-mysql , this was my approach: client = Mysql.real_connect(...) inserts = [ "INSERT INTO ...", "UPDATE .. WHERE id=..", # etc ] client.autocommit(false) inserts.each do |ins| begin client.query(ins) rescue # handle errors or abort entirely end end client.commit I couldn't find much in the

Transaction required exception JPA / Spring

﹥>﹥吖頭↗ 提交于 2020-01-01 11:20:09
问题 I have a method in the repository class marked as @Transactional , the aspect is being executed as seen in the stacktrace, but the exception being thrown is "Transaction required exception" I changed the @Repository annotation to @Component (and it seemd like it fixed this problem in some situations), but it is still happening on the web role. Here is the stacktrace: 2015-04-13 08:00:56,497 [http-nio-8080-exec-9] WARN es.mycompany.util.filters.MyFilter - Error storing : /admin/online/update

CakePHP 2.3.x database transaction

末鹿安然 提交于 2020-01-01 10:49:27
问题 I need your help using transactions in CakePHP. I have a Product model, with clause hasMany to Price and Property models (key product_id). In my Product model, I add function begin() { $db =& ConnectionManager::getDataSource($this->useDbConfig); $db->begin($this); } function commit() { $db =& ConnectionManager::getDataSource($this->useDbConfig); $db->commit($this); } function rollback() { $db =& ConnectionManager::getDataSource($this->useDbConfig); $db->rollback($this); } And in