Use of facic Transaction Management Facility

Source: Internet
Author: User

TheProgramSet:

    • Castle. Facilities. automatictransactionmanagement
    • Castle. Services. Transactions
    • Castle. dynamicproxy
    • Castle. Core

1. Configuration

Windsorcontainer container =   New Windsorcontainer (store );
Container. addfacility ( " Auto. Transaction " , New Transactionfacility ());

Or

< Facilities >
< Facility ID = "Transaction" Type = "Castle. Facilities. automatictransactionmanagement. transactionfacility, Castle. Facilities. automatictransactionmanagement"   />

</ Facilities >

2. Code Use automatic transaction management Using System;
Using System. collections;
Using System. Collections. Generic;
Using System. text;

Using FeS. persistence;
Using FeS. domain. Common;
Using FeS. Service. interface;

Using Castle. Facilities. ibatisnetintegration;
Using Castle. Services. transaction;
Using Castle. Facilities. automatictransactionmanagement;

Namespace FeS. Service. Implement
{
[Transactional]
[Usesautomaticsessioncreation]
Public   Class Commonservice: icommonservice
{
Private Commonsqlmapdao _ common;
Public Commonservice (commonsqlmapdao common)
{
_ Common=Common;
}

[Transaction (transactionmode. Requires)]
Public   Bool Login ( String Empcode, String Password, Ref Employees EMP)
{
EMP = _ Common. getemployeedetailbypassword (empcode, password );
If (EMP =   Null )
{
Return False;
}
Else
{
Return True;
}
}


[Transaction (transactionmode. Requires)]
Public   Void Insertemppages (emppages pages)
{
_ Common. deleteemppages (pages. Eid );
_ Common. addemppages (pages );
}

[Transaction (transactionmode. Requires)]
Public   Void Insertemppages (arraylist Al, Int EID)
{
_ Common. deleteemppages (EID );
For ( Int I =   0 ; I < Al. Count; I ++ )
{
Emppages pages=(Emppages) al [I];
_ Common. addemppages (pages );
}
}
}
}

Note: If the component you use for automatic transaction management in container registration is not registered as an interface, the method for automatic transaction management must be declared as virtual.

You can also use automatic transaction management in the configuration file of the container registration component:

< Configuration >

< Components >
< Component
ID = "Common"
Service = "FES. Service. interface. icommonservice, FeS. Service"
Type = "FES. Service. Implement. commonservice, FeS. Service" Istransactional = "True" >
< Transaction >
< Method Name = "Login"   />
< Method Name = "Insertemppages"   />
</ Transaction >
</ Component >
</ Components >

</ Configuration >

 

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.