[Leaneap. Net] lean enterprise application platform design -- Data Access class library EAP. Data

Source: Internet
Author: User

 

[EAP. Data] The main task is to solve database access and data verification. Ease-no complicated injection configuration; flexibility-use an object to organize arbitrary SQL commands; security-implement SQL command compilation detection and provide secure type conversion; high Efficiency-lightweight operations to reduce performance loss.

 

 

First, we will summarize the factors and design ideas to be taken into account in the design of database access class libraries:

  1. Supports common databases such as Oracle, MSSQL, and MySQL. Access to different databases is implemented through various database providers. SQLite, PostgreSQL, and DB2 have not been used yet, But extensions can be retained.
  2. Basic functions: add, delete, modify, and query, stored procedures, custom SQL statements, subqueries, paging queries, and common functions.
  3. Design a set of objects to represent the database structure. Through this set of object Assembly SQL commands, the SQL keywords correspond to the corresponding C # method, replacing the direct spelling string. Ensure flexibility and avoid errors that cannot be detected by string commands during compilation.
  4. The naming rules and Data Types of various databases are different. We need to respect the rules of various databases and use the item_category number (9) Field in Oracle) or the int itemcategory attribute from itemcategory int mapping to C # in MSSQL.
  5. Provides basic data verification methods. When verification fails, executes the exception interrupt method and provides verification failure information.
  6. Attribute is used to establish a corresponding relationship between the DTO field and the object representing the database object structure, and load the data to DTO through reflection.

 

Dataaccessor, dbprovider, and queryportal for database access

Create a dataaccessor class to execute dbcommand. Dataaccessor uses dbprovider to create queryportal. queryportal is an abstract class for creating dbcommand. It also includes some C # methods corresponding to common database functions.

In dataaccessor, the FN attribute is of the function type, including the method for calling database functions. When the tracesql attribute is set to true, EAP is called. logger. log. the trace method records the executed dbcommandtext in the log. Customsql can execute string SQL statements, and strodprocedure is used to execute stored procedures. Begintransaction will return EAP. Data. dbtransaction, which is an encapsulation of system. Data. Common. dbtransaction. Select, update, delete, and insert are the methods corresponding to SQL keywords. They are used together with dbtable, which represents the database structure.

 

 

The providers of various databases inherit the abstract dbprovider.

 

 

Create dbcommand for different databases by implementing the methods in queryportal.

 

 

 

Dbtable, dbcolumn, and dbstoredprocedure of the database structure

  Dbtable corresponds to the database table or view, mainly including the table name and alias. Dbcolumn corresponds to fields in the database and inherits from the expression class. It can be used for various operator operations, including dbtype, columnname, and other attributes. Dbstroedprocedure includes the name attribute, which corresponds to the stored procedure of the database.

In expression, AVG, Count, Max, Min, sum, +,-, *,/, %, and other methods or operations return the expression object, between, fuzzy, In, notin, isnull, isnotnull, like ,!, = ,! =,>, <, >=, <=, And other methods or wherestatement objects returned by an operation.

 

 

Validator used for verification

  Validator provides basic data verification methods. Information about verification failures will be added to errorinfocollection. Errorinfo includes the field name, row number, and errors attribute of errortextcollection type. Errortext is an object used for localization, including a reskey that represents the resource key. If no resource is provided, the default text is displayed.

 

 

 

Ing of Objects

The columninfoattribute feature associates object fields with the dbcolumn representing the database structure. Columnmapping stores the reflected information in the static dictionary to avoid repeated reflection operations.

 

 

 

[Leaneap. Net] lean enterprise application platform-series directory

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.