Websharp use Instructions (4)

Source: Internet
Author: User
Tags definition
How Web data is accessed

The purpose of data access is to persist the saved object. In Websharp, the PersistenceManager interface is defined to implement this function. PersistenceManager definition can be seen: attached 1:websharp main interface definition--persistencemanager



We can persist an object by using the following methods:

Product Product=new product (TRUE);

...//Processing product

PersistenceManager pm = persistencemanagerfactory.instance ().

Createpersistencemanager ();

Pm. Persistnewobject (P);

Pm. Close ();




The code is very concise and intuitive, not a lot of database manipulation code, it is not easy to error.

You can also initialize a persistencemanager by passing a persistenceproperty parameter to Persistencemanagerfactory, such as:

Persistenceproperty pp=new Persistenceproperty ();

pp......//Set properties of PP

PersistenceManager pm = persistencemanagerfactory.instance (). Createpersistencemanager (PP);


For a description of Persistenceproperty, see the following system Persistence configuration information section.



Transaction processing

In many cases, when dealing with object preservation, we need to use transaction processing, especially when dealing with a One-to-many structure object similar to a warehouse receipt in the previous example. In Websharp, we can accomplish this function through the transaction interface. Transaction interface definition can be seen: attached 1:websharp main interface definition--transaction

Here is an example of using transaction processing:

Product Product=new product (TRUE);

...//Processing product

PersistenceManager pm = persistencemanagerfactory.instance ().

Createpersistencemanager ();

Transaction trans=pm. Currenttransaction;

Trans. Begin ();

Try

{

Pm. Persistnewobject (P);

Trans.commit ();

}

catch (Excption e)

{

Trans. Rollback ();

}

Finally

{

Pm. Close ();

}



Related Article

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.