Enterprise-level agile software development platform based on DOTNET component technology-agileeas. Net-Unified Data Access

Source: Internet
Author: User

Unified Data Access (UDA) is used to isolate systems and data platforms, so that the system can be freely transplanted on various database platforms. The database access interface requires that standard SQL statements be submitted to the database access module through this interface, not just statements that are valid for the current database.

Unified data access and data layer separation are two concepts and practices that complement each other. Unified Data Access provides the database access environment and interface independence for data layer separation, interface-driven, and data layer architecture. consistency is guaranteed.

Uniform Data Access is automatically packaged inside ADO. net. The specific database used is defined by the system administrator in the configuration file. The unified data access interface provides internal management of database connection objects, Data command objects, transaction objects, etc. Therefore, the client does not need to manage these objects on its own, but only needs to submit database commands.

The main data structure in UDA is "result data ". Result data is the packaging of database operation results. For a query command, an idatareader object, a DataSet object, a able object, an idictionary object, an ilist object, and a data object (the data structure defined in Data Object Management) may be returned) or a simple result. Of course, the user can request to return data in XML format.

Agileeas. NET provides the idataaccessor and idataconntion interfaces:

Idataaccessor provides two basic operations for data: query results and SQL statement execution. It also provides SQL batch processing, proxy query, and transaction delegate operations, idataconnetion provides a database execution environment for idataaccessor.

The following describes two interfaces in detail:

Idataaccessor:

 Idataaccessor  /// <Summary>  /// Data access provider/Data accesser.  /// </Summary>  Public   Interface Idataaccessor { /// <Summary>          /// Obtain or set the data access environment.          /// </Summary> Idataconnection dataconnection {Get ; Set ;} /// <Summary>          /// Execute the specified non-query command.          /// </Summary>          /// <Param name = "commandstring"> command statement to be executed. This statement must be a standard database statement. </Param>          /// <Returns> returns the number of lines affected by the command. </Returns>          Int Execute ( String Commandstring ); /// <Summary>          /// Execute the specified non-query command.          /// </Summary>         /// <Param name = "commandstring"> command statement to be executed. This statement must be a standard database statement. </Param>          /// <Param name = "Parameters"> set of parameters of the command to be executed. </Param>          /// <Returns> returns the number of lines affected by the command. </Returns>          Int Execute ( String Commandstring, parametercollection parameters ); /// <Summary>          /// Execute the specified non-query command.          /// </Summary>          /// <Param name = "commandstring"> command statement to be executed. This statement must be a standard database statement. </Param>          /// <Param name = "commandtype"> command type to be executed. </Param>         /// <Returns> returns the number of lines affected by the command. </Returns>          Int Execute ( String Commandstring, system. Data. commandtype ); /// <Summary>          /// Execute the specified non-query command.          /// </Summary>          /// <Param name = "commandstring"> command statement to be executed. This statement must be a standard database statement. </Param>          /// <Param name = "commandtype"> command type to be executed. </Param>          /// <Param name = "Parameters"> set of parameters of the command to be executed. </Param>          /// <Returns> returns the number of lines affected by the command. </Returns>          Int Execute ( String Commandstring, system. Data. commandtype, parametercollection parameters ); /// <Summary>          /// Execute the specified non-query command.          /// </Summary>          /// <Param name = "command"> database access command to be executed. This command must be an encapsulation of valid database access parameters. </Param>          /// <Returns> returns the number of lines affected by the command. </Returns>          Int Execute (dbcommand command ); /// <Summary>          /// Execute the given database query command.          /// </Summary>         /// <Param name = "commandstring"> the command statement to be executed may be a SELECT statement or a stored procedure name. </Param>          /// <Returns> returns the queried data result. </Returns>          Object Query ( String Commandstring ); /// <Summary>          /// Execute the given database query command.          /// </Summary>          /// <Param name = "commandstring"> the command statement to be executed may be a SELECT statement or a stored procedure name. </Param>          /// <Param name = "resulttype"> type of the returned result requested by the caller. </Param>         /// <Param name = "fillparameters"> oledbdataadapter fill parameter when the result type is dataset, able, or XML. Other resulttypes ignore this parameter. </Param>          /// <Returns> returns the queried data result. </Returns>          Object Query ( String Commandstring, EAS. Data. Access. resulttype, Params   Object [] Fillparameters ); /// <Summary>          /// Execute the given database query command.          /// </Summary>          /// <Param name = "commandstring"> the command statement to be executed may be a SELECT statement or a stored procedure name. </Param>         /// <Param name = "Parameters"> parameters required for command execution. </Param>          /// <Returns> returns the queried data result. </Returns>          Object Query ( String Commandstring, parametercollection parameters ); /// <Summary>          /// Execute the given database query command.          /// </Summary>          /// <Param name = "commandstring"> the command statement to be executed may be a SELECT statement or a stored procedure name. </Param>          /// <Param name = "Parameters"> parameters required for command execution. </Param>          /// <Param name = "resulttype"> type of the returned result requested by the caller. </Param>         /// <Returns> returns the queried data result. </Returns>          Object Query ( String Commandstring, parametercollection parameters, EAS. Data. Access. resulttype ); /// <Summary>          /// Execute the given database query command.          /// </Summary>          /// <Param name = "commandstring"> the command statement to be executed may be a SELECT statement or a stored procedure name. </Param>          /// <Param name = "commandtype"> type of the command to be executed. </Param>          /// <Param name = "Parameters"> parameters required for command execution. </Param>         /// <Param name = "resulttype"> type of the returned result requested by the caller. </Param>          /// <Param name = "fillparameters"> oledbdataadapter fill parameter when the result type is dataset, able, or XML. Other resulttypes ignore this parameter. </Param>          /// <Returns> returns the queried data result. </Returns>          Object Query ( String Commandstring, system. Data. commandtype, parametercollection parameters, EAS. Data. Access. resulttype, Params   Object [] Fillparameters ); /// <Summary>          /// Execute the given database query command.         /// </Summary>          /// <Param name = "command"> database access command to be executed. This command must be a valid database access parameter encapsulation, which may be a SELECT statement or a stored procedure name. </Param>          /// <Returns> returns the queried data result. </Returns>          Object Query (dbcommand command ); /// <Summary>          /// Execute the specified non-query command (batch processing command ).          /// </Summary>          /// <Param name = "commands"> set of database access commands to be executed. This command set must be a valid database access parameter encapsulation. </Param>          /// <Returns> returns the number of lines affected by the command. </Returns>          Int Bachexecute (dbcommandcollection commands );/// <Summary>          /// Execute the given database query command set (batch query command ).          /// </Summary>          /// <Param name = "commands"> set of database access commands to be executed. This command must be a valid database access parameter encapsulation, which may be a SELECT statement or a stored procedure name. </Param>          /// <Returns> returns the queried data result set. </Returns>          /// </Remarks> EAS. Data. Access. dbresultcollection backquery (dbcommandcollection commands ); /// <Summary>          /// Execute the given EAS. Data. Access. transactionhandler in the transaction environment. The EAS. Data. Access. transactionhandler contains all database operations to be performed in the transaction.          /// </Summary>         /// <Param name = "handler"> the EAS. Data. Access. transactionhandler object to be executed. </Param>          /// <Returns> returns the number of affected rows. The value is returned by EAS. Data. Access. transactionhandler. The default value is 0. </Returns>          Int Transactionexecute (EAS. Data. Access. transactionhandler handler ); /// <Summary>          /// Delegate query. When the caller needs to return the datareader, if the query is used, the environment must be enabled and disabled, and the datareader must be disabled.          /// The caller can process the datareader resultCodePackaged in the datareaderhandler delegate, the delegatequery method represents the caller's call for data processingProgramAnd manage the data access environment and the lifecycle of datareader in the delegatequery.          /// </Summary>         /// <Param name = "handler"> the EAS. Data. Access. datareaderhandler delegate object to be called by the delegatequery method. The method in handler can disable the datareader object or not. </Param>          /// <Param name = "commandstring"> query command text to be executed. </Param>          Void Delegatequery (EAS. Data. Access. datareaderhandler handler, String Commandstring ); /// <Summary>          /// Delegate query. When the caller needs to return the datareader, if the query is used, the environment must be enabled and disabled, and the datareader must be disabled.          /// The caller can wrap the code that processes the datareader result in the datareaderhandler delegate. The delegatequery method indicates that the caller calls the data processing program, manage the data access environment and the lifecycle of datareader in delegatequery.          /// </Summary>         /// <Param name = "handler"> the EAS. Data. Access. datareaderhandler delegate object to be called by the delegatequery method. The method in handler can disable the datareader object or not. </Param>          /// <Param name = "commandstring"> query command text to be executed. </Param>          /// <Param name = "commandtype"> query command type. </Param>          /// <Param name = "Parameters"> command parameters. </Param>          Void Delegatequery (EAS. Data. Access. datareaderhandler handler, String Commandstring, system. Data. commandtype, parametercollection parameters );}

Idataconnetion:

Idataconnection      /// <Summary>      /// Data Access Connection/environment.      /// </Summary>      /// <Remarks>      /// This interface is a basic interface for data access, used to build a data access connection/environment.      /// </Remarks>      Public   Interface Idataconnection: EAs. Sessions. isessionresource { /// <Summary>          /// Create a data accessor on this connection.          /// </Summary>         /// <Returns> the data accessors created successfully. </Returns> Idataaccessor createdataaccessor (); /// <Summary>          /// Create a data accessor on this connection.          /// </Summary>          /// <Returns> the data accessors created successfully. </Returns> [Obsolete (" The method has expired. Use the createdataaccessor method. ")] Idataaccessor createaccessor (); /// <Summary>          /// Open the data connection.          /// </Summary>          Void Open (); /// <Summary>         /// Close the data connection.          /// </Summary>          Void Close ();}}

 

Idataaccessor is an interface for unified data access. It exists in the idataaccessor database environment, the client only needs to use the methods provided by the accessor and provide appropriate parameters for these methods for database operations. The accessors automatically create database commands on the current database connection and encapsulate the returned results.

Currently, when the accessor returns the query results, it adds a one-step packing operation to return a unified type of data (object). You need to unpack the data and obtain the specific data result.

The idataaccessor does not change the idataconnetion status at will. We know that you need to enable and disable database operations when accessing the database. Therefore, when idataaccessor executes the SQL command, first, check whether idataconnetion is enabled. If not, execute idataconnetion. open () and perform idataconnetion after the SQL statement is executed. close ().

BoolOpen =This. Connection. isopen;If(! Open)This. Connection. open ();Try{// Execute SQL}Finally{If(! Open)This. Connection. Close ();}

When executing the query command, there is a returned result idatareader, which requires the database to remain open. Therefore, we added a delegate method delegatequery, which is defined as follows:

/// <Summary>/// Define the data access delegate when the result is returned using datareader./// </Summary>/// <Remarks>/// The instance of the delegate can be called internally by the accessor. delegatequery method. Therefore, you do not need to consider disabling datareader for the delegate instance./// </Remarks>Public Delegate VoidDatareaderhandler (system. Data. idatareader datareader );

In the database transaction section, apart from opening and closing the transaction normally, I recommend a transaction delegate and method for execution. idataaccessor provides the transactionexecute method, definition of its delegate transactionhandler:

/// <Summary>/// Define the transaction processing delegate for database operations. This delegate will execute database transactions on behalf of the customer, so that the user does not need to consider the start and end of the transaction./// </Summary>Public Delegate IntTransactionhandler (idataaccessor accessor );

Currently, SQL databases (sqlserverconnection and sqlserveraccessor), oledbconnection, and oledbaccessor, and ODBC databases (odbcconnection and odbcaccessor) are implemented. Oracle databases are implemented by accessing service assembly from individual databases.

The specific data access routine will be shown below:

The following describes the ORM in agileeas. net.

 

QQ: 15118502

 

Link: agileeas. NET application development platform Introduction

Agile parallel development method of agileeas. net

 

Agile Software Engineering Lab

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.