One of the new matters: transactions in DOTNET and COM
Small gas god 2002-4-16
Article Type: In-Depth Difficult Level: 6/9 Version: 2.32
CLR neutralization attribute class
Attribute class
effect
AutoCompleteAttribute
Automatic completion of the statement within the function
ConstructionenableDattribute
Add a construct string
JustintimeActivationAttribute
Instantly activation
ObjectPoolingAttribute
Object pool
TransactionAttribute
Statement
Method and attributes related to transactions in CLR
Properties and methods
Interface and method
DisableCommit
IObjectControl :: DisableCommit
EnableCommit
IObjectControl :: EnableCommit
Setabort
IOBJECTCONTROL :: setabort
SetComplete
IOBJECTCONTROL :: SetComplete
Isintransaction
IObjectContextInfo :: isintransaction
MyTransactionvote
IconTextState :: get / setMytransactionvote
DeactivateonReturn
IconTextState :: get / stateactivateonreturn
TRANSACTION
IObjectContextInfo :: getTransaction
TransactionID
IObjectContextInfo :: gettransactionid contextid
IObjectContextInfo :: getContextid
Of course, in the above class, we can also control any attributes, but simply inherited a class from ServicedComponent, then when we use RegSVCS to register our components, there is still some default values, or We use the properties but not clearly specify the value of the property. These are done by System.EnterpriseServices.RegistrationHelper, in fact, REGSVCS calls it after calling REGASM and TLBEXP registration it is completed in COM Catalogs.
The following table is the property after compilation of CLR (configuration and no configuration)
Attributes
Scope of application
Value in COM when no configuration properties
Use properties configuration but no value indicating attribute in COM
ApplicationActiVation
AskSEMBLY
Library
No Default
ApplicationID
AskSEMBLY
Generated Guid
No Default
ApplicationName
AskSEMBLY
AskEMBLY NAME
No Default
AutoComplete
Method
False
True
Constructionenabled
Class
False
True
JustImeActivation
Class
False
True
MustrunInClientContext
Class
False
True
ObjectPooling
Class
False
True
SYNCHRONIZATION
Class
False
SynchronizationOption.Required
TRANSACTION
Class
False
TransactionOption.Required
TransactionissionLevel.Serializable
Timeout = Infinite sees the property programming from above to the convenient and simple feelings, which is much more convenient than the COM programming in the previous COM mode, no need to quote, do not need to consider the synchronization of the thread, or even register to COM It is also very easy in the environment. But can only say that if you work well in COM, now you can work well under this CLR, COM and transaction programming models still have no change, from actual needs and applications to analyze and construct a transaction The model is still the main task of each developer, but now you can have more time and energy to deal with this problem.
Configurable Transaction Isolation Level in Windows XP and Windows.NET
Under Windows XP and Widnows.net COM Environment Allows us to specify transaction isolation levels.
This is indeed a long-awaited new feature. In COM 1.0, we can only use the default, the most stringent transaction isolation level: serializable. COM in Windows XP and Windows.net allows us to specify the transaction isolation level of the component, which can be used by developers and practical applications to use the isolation level. Not all RM (Resource Manager) supports current defined four isolation levels, and a policy is that when RM does not support current isolation settings, use a higher isolation level, Serializable is the most stringent isolation level, while It is also the most ordinary isolation level, that is, almost all RM supports this isolation level setting (current COM supporting four isolation levels are also MS SQL Server support and implementation is also four of SQL-92 definitions). It is also not all developers to understand the roles and meaning of these options. Some common explanations and information will be given in the future development process.
Multiple users may generate data inconsistency on database operations, and the isolation level is to say that transactions can accept inconsistency data, which is an extent of transaction with other transactions. The lower isolation level can increase concurrency, but the cost is to reduce the correctness of the data. Instead, higher isolation levels ensure the correctness of data, but may have a negative impact on concurrency. Our isolation level required in COM determines the behavior of RM use locks. Different isolation grades may bring different problems, such as:
Problem description example dirty
Dirty Read is also called not submitted or not confirmed. A transaction modifies the database but not submits or confirmed, and the other transaction reads this value and takes the operation. The original Xiaoming account has 1 yuan, and a is responsible for depositing, b is responsible for the release, then A first deposit 20 yuan but not submit, at this time B read this 20 yuan, then go to 5 yuan, A failed rollback transaction, B The 15 yuan will be stored in the database to complete the transaction. Xiao Ming is happy.
Not read
NonRepeATable read also is also called not always read or can not read. A transaction reads a value, when it changes next time, and the modification is not the dominant, it is obviously that other transactions have been operated this time, in the first time I get 20 yuan. After that, I will subtract my own 5 yuan, then I didn't update the database immediately, and I checked a database, and the original 20 turned 50, after three seconds, B discovery is already 10, so B is very wondering: I am not responsible Draw up?
phantom
Phantom refers to a set of new data in two readings of the same database. The difference from non-reread is that it is not rereaded to modify or coverage for existing data. It does not increase or decrease data. The phantom is inserted into previous data or deletes the original existing data. B is also responsible for reporting his latest deposit situation to Xiaoming. Although I didn't sleep well yesterday, but B still made statistics. He found that 5 records of the first statistics, there were 10 records, the second query confirmation A Added 3 copies of the total of 9 in the beginning of the month, B wants to take a break and count again, although there is a little strange, but if the result is a total of A. That Xiao Ming's deposit is still confident that the following table is to set different quarantine options to accept the problem of concurrency, seeing Serializable the most stringent, three possible errors will not happen. COM sequentially considers them from low to high isolation values from low to high, read uncommitted, and Serializable is the largest.
Isolation level
Dirty reading
Do not read
Phantom
Read uncommitted
YES
YES
YES
Read committed
NO
YES
YES
REPEATABLE READ
NO
NO
YES
Serializable
NO
NO
NO
(Fail)
especially:
This article 9CBS signature start, reprint, or adaptation, please indicate the author and the source. If there is a problem, please send an email to new2001@msn.com
The above text and pictures involve other people's privacy and personal rights, all texts and pictures are only used for internal communication and do not make any news published and commercial purposes.