SmartPersistencelayer 2.0 transaction processing articles
conventional
In our usual business, transaction operation is an essential content. The SPL is very functional in transaction processing:
1. A multi-database operation function:
Add a transaction child in a transaction, each transaction subkey can correspond to different databases, and transactions will be updated in their own database.
2. Multi-types of transaction children:
You can add physical operations in your transaction [Entity], update standard [Updatecriteria], delete standard [deletecriteria]
Transaction t = new transaction (); // instantiate a transaction
T.addsaveObject (student): // To add or modify the entity
T.adddeleteObject (student); // To delete the entity
T.adddeletecriteria (DC); // Add a deletecriteria
T.addupdatecriteria (UC); // Add a Updatecriteria
T.addsqlstring (SQLSTRING, DBNAME); / / Add a SQL execution statement
T.Process (); // Execute this transaction
Through the above manner, a wide variety of operations can be processed in a transaction.
Add / Modify Entity AddsaveObject
In the SPL transaction, allowing a new / modified entity, as follows:
NEW TRANSACTION ();
StudENTentity Student = new studENTENTITY (); // This is an entity to add
STUDENT.ID = 2;
Student.name = "abu";
T.addsaveObject (student); // Add to add entities to the transaction
StudENTENTITY Student2 = New StudENTENTENTITY ();
Student2.id = 1;
Student2.Retrieve ();
IF (student2.ispersistence)
{
Student2.name = "TintownUpdate";
T.addsaveObject (student2); // Add the entity to be modified into the transaction
}
T.Process (); // transaction execution
The above code can achieve a new Student entity and update Student2 entity.
AddsaveObject () will add and modify it according to the entity itself, which is similar to the SAVE method of the entity itself.
In new and updated transactions, you can also capture primary key conflicts and cascaded update constraints, and you can use the entity Entity section.
If the entity is IssaveTomeMory = True, the memory is automatically updated after the transaction is performed.
Delete entity AddDeleteObject
In the SPL transaction, allowing a delete entity, as follows:
NEW TRANSACTION ();
StudENTENTENTITYTENT = New StudENTENTENTITY ();
STUDENT.ID = 1;
Student.Retrieve ();
at (student.ispersistence)
{
T.adddeleteObject (student);
Try
{
T.Process ();
} catch (plexception exp)
{
IF (exp.errorType == ErrorTypes. Restricter)
Response.write ();
Else
Throw Exp;
}
In transaction, you can also capture the "cascaded handle constraint" exception, and perform friendly tips.
If the entity's IssaveTomeMory = true, the memory will be automatically updated after deletion.
Delete standard AddDeletecriteria
In SPL transactions, you can add delete standards, as follows:
NEW TRANSACTION ();
Deletecriteria DC = New DeleteCriteria (TypeEntent);
Dc.getnewcondition (). addententity.name, "tintown");
T.AdddeleteCriteria (DC);
T.Process ();
It can also capture the level of the Class Delete and the deletion of Deletecriteira.
If the entity's IssaveTomEMEMORY, it will be automatically updated to memory.
Update standard AddupdateCriteria
Update standards can be added in SPL transactions, as follows:
NEW TRANSACTION ();
Updatecriteria uc = new updatecriteria (TypeEntent);
Uc.addattributeforupdate (Studententity.Name, "BBB");
Uc.getnewcondition (). AddEqualto (StudenTenity.Name, "Tintown");
T. ADUPDATECRITERIA (UC);
T.Process ();
You can also capture cascaded update constraints, refer to Updatecriteira's processing
If the entity's IssaveTomeMory = true, it will be automatically updated to memory.
SQL statement transaction
In SPL, it is impossible to overwrite all database operations. In order to expand, the transaction processing of SQL statements is provided, as follows:
NEW TRANSACTION ();
String Sqlstring = "Update Student Set Name = 'Tintown' where id = 1";
String dbname = "db2"
t. addsqlstring (Sqlstring, DBNAME);
.
T.Process ();
Through this transaction processing of this SQL statement, the DBNAME is the data source name in the SPL can be resolved. Note: If the entity is IssaveTomeMory, then after using SQL updates this entity, it will not be able to affect the data in the memory, so for memory stored tables, use SPL operations.
other
Transaction's CLEAR () method can clear all transaction objects
Count attributes can get the number of current transaction objects
Listen to
November 2004
MSN: TINTOWN_LIU@hotmail.com