Jfinal things rollback, @Before (Tx.class) and Db.tx (new Iatom () {})

Source: Internet
Author: User
Tags rollback

First, note @Before (tx.class) Add things rollback

@Before (tx.class) public
	void Pay () throws Exception {
		//throws Exception;
	}

The method body cannot catch exceptions, all exceptions are thrown, and things will roll back when an exception occurs

Advantages: Simple violence, do not need to deal with each exception, directly thrown can be;

Disadvantage: Can not be detailed to distinguish the return data, views, can only be generalized to report exceptions


Second, Db.tx (new Iatom () {})

public void Pay () {
		final map<string,string> Map = new hashmap<string, string> ();
		Boolean bl = Db.tx (new Iatom () {
			@Override public
			Boolean run () throws SQLException {
				
				if (...) {
					//...
					return false;
				} else {
					...
					return true;
				}
				
				return true;
			}
		});
		
		This.rendjson (BL, Null,map.get ("Return_words"), null);
	}

return False or an exception thrown will rollback the transaction, return True to commit the transaction, the Db.tx method is a return value True/false, can be changed to return the value of the business return, if you want the run method to pass the variable to the outer layer, you can define a final Modified container class object or definition map, two more comprehensive, processing more delicate, recommended to use two.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.