软考-特殊名词-数据库程序在线访问方式

软考-特殊名词-数据库程序在线访问方式

软考当中,可能会遇到一个特殊名词“程序在线访问”,题目如最后。很多同学都比较奇怪这个说法,什么是“程序在线访问”?这个是微软.NET平台中的http://Ado.net技术特有的一种说法。指的使用http://Ado.net技术中的Connection, Command, DataReader, Transaction, ParameterCollection, 和 Parameter类,以只读的方式,联机实时查询数据库的特定业务数据,而不是把数据库的数据采用脱机的方式,将数据库表的数据直接获取后放入DataSet, DataTable中,在C#或者.NET其他语言中进行下一步的计算。

该软件企业很快决定基于.NET平台和SQL Server数据库进行开发,但在数据库访问方式上出现了争议。王工认为应该采用程序在线访问的方式访问数据库;而李工认为本企业内部程序员缺乏数据库开发经验,而且应用筒单,应该采用ORM (对象关系映射)方式。

题目意思:

  1. 王工认为可以采用http://ado.net技术中的Connection, Command, DataReader, Transaction, ParameterCollection, 和 Parameter类,直接联机的方式,只读的形式,通过事先写好的sql语句,传输给sql server,让sql server执行预先定义的sql脚本,获取相关业务数据。
  2. 李工则认为应该采用ORM框架,比如Entity Framework, NHibernate等,实现领域对象(Object)与数据库关系表(Relation)的自动映射,减少sql脚本工作量。

 

在开始设计.NET体系架构时,微软就决定重新设计数据访问模型,以便能够完全的基于XML和离线计算模型。两者的区别主要有:
(1)ADO以Recordset存储,而http://ADO.NET则以DataSet存储。Recordset看起来更像单表,如果让Recordset以多表的方式表示就必须在SQL中进行多表连接。反之,DataSet可以是多个表的集合。
(2)ADO的运作是一种在线方式,这意味着不论是浏览或更新数据都必须是实时的。http://ADO.NET则使用离线方式,在访问数据的时候http://ADO.NET会利用XML制作数据的一份副本,http://ADO.NET的数据库连接也只有在这段时间需要在线。
(3)由于ADO使用COM技术,这就要求所使用的数据类型必须符合COM规范,而http://ADO.NET基于XML格式,数据类型更为丰富并且不需要再做COM编排导致的数据类型转换,从而提高了整体性能。
图2描绘了http://ADO.NET体系。图3给出了http://ADO.NET基于XML进行数据传递的原理图。

 

Connected and Disconnected Data
As mentioned earlier, http://ADO.NET supports two different programming environments: connected and disconnected.
The connected environment provides forward-only, read-only access to data in the data source and the ability to execute commands against the data source. The connected classes provide a common way to work with connected data regardless of the underlying data source. They include 
ConnectionCommandDataReaderTransactionParameterCollection, and Parameter classes.
The disconnected environment allows data retrieved from the data source to be manipulated and later reconciled with the data source. The disconnected classes provide a common way to work with disconnected data regardless of the underlying data source. They include the 
DataSetDataTableDataColumnDataRowConstraintDataRelationship, and DataView classes.
Finally, http://ADO.NET introduces the connected 
DataAdapter class to bridge the data source and disconnected classes by way of the connected classes. The DataAdapter is an abstraction of the connected classes that simplifies filling the disconnected DataSetor DataTable classes with data from the data source and updating the data source to reflect any changes made to the disconnected data. Figure 1-1 shows the relationship between the connected and disconnected classes in ADO.NET.


Figure 1-1. The connected and disconnected http://ADO.NET classes

Connected Classes
The following classes are used by http://ADO.NET to communicate directly with the data source:

ConnectionMaintains information required to connect to the data source through a connection string. The connection string contains information such as the name of the data source and its location, and authorization credentials and settings. The Connection class has methods to open and close the connection, for transactions to be initiated on the connection, as well as control other properties of the connection.CommandExecutes SQL statements or stored procedures against the data source. The command class has a ParameterCollection object containing Parameterobjects that allow parameterized SQL statements and stored procedures to be used against the data source.DataReaderProvides connected forward-only, read-only access to the data source. It is optimized for speed. The DataReader is instantiated through a Command object.ParameterAllows parameters for both parameterized queries and stored procedures to be defined and set to appropriate values. The Parameter class is accessed through the ParametersCollection object within a Command object. It supports input and output parameters as well as return values from stored procedures.TransactionAllows transactions to be created on a connection so that multiple changes to data in a data source are treated as a single unit of work and either all committed or cancelled.DataAdapterBridges the data source and the disconnected DataSet or DataTable classes. The DataAdapter wraps the connected classes to provide this functionality. It provides a method to retrieve data into a disconnected object and a method to reconcile modified data in the disconnected object with the data source. The CommandBuilder class can generate the logic to reconcile changes in simple situations; custom logic can be supplied to deal with complex situations and optimize performance.
Disconnected Classes
The following http://ADO.NET classes allow data to be retrieved from the data set, examined and modified offline, and reconciled with the data source through the 
DataAdapter:
DataSetProvides a consistent way to deal with disconnected data completely independently of the data source. The DataSet is essentially an in-memory relational database, serving as a container for the DataTableDataColumnDataRowConstraint, and DataRelation objects.
The XML format serializes and transports a 
DataSet. A DataSet can be accessed and manipulated either as XML or through the methods and properties of the DataSetinterchangeably; the XmlDataDocument class represents and synchronizes the relational data within a DataSet object with the XML Document Object Model (DOM).DataTableAllows disconnected data to be examined and modified through a collection of DataColumn and DataRow classes. The DataTable allows constraints such as foreign keys and unique constraints to be defined using the Constraintclass.DataColumnCorresponds to a column in a table. The DataColumn class stores metadata about the structure of the column that, together with constraints, defines the schema of the table. The DataColumn can also create expression columns based on other columns in the table.DataRowCorresponds to a row in a table and can examine and update data in the DataTable. The DataTable exposes DataRow objects through the DataRowCollection object it contains. The DataRow caches changes made to data contained in its columns, storing both original and current values. This allows changes to be cancelled or to be later reconciled with the data source.ConstraintAllows constraints to be placed on data stored within a DataTable. Unique and foreign key constraints can be created to maintain data integrity.DataRelationProvides a way to indicate a relationship between different DataTable objects within a DataSet. The DataRelation relates columns in the parent and child tables allowing navigation between the parent and child tables and referential integrity to be enforced through cascading updates and deletes.DataViewAllows data, once retrieved into a DataSet or DataTable, to be viewed in different ways. It allows data to be sorted based on column values and for a subset of the data to be filtered so that only rows matching specified criteria are displayed.
Chapter 2 examines .NET data providers in more detail and describes the way in which they provide connected functionality and serve as a bridge to disconnected functionality.

 

某制造企业为拓展网上销售业务,委托某软件企业开发一套电子商务网站。初期仅解决基本的网上销售、订单等功能需求。该软件企业很快决定基于.NET平台和SQL Server数据库进行开发,但在数据库访问方式上出现了争议。王工认为应该采用程序在线访问的方式访问数据库;而李工认为本企业内部程序员缺乏数据库开发经验,而且应用筒单,应该采用ORM (对象关系映射)方式。最终经过综合考虑,该软件企业采用了李工的建议。
随着业务的发展,该电子商务网站逐渐发展成一个通用的电子商务平台,销售多家制造企业的产品,电子商务平台的功能也日益复杂。目前急需对该电子商务网站进行改造,以支持对多种异构数据库平台的数据访问,同时满足复杂的数据管理需求。该软件企业针对上述需求,对电子商务网站的架构进行了重新设计,新增加了数据访问层,同时采用工厂设计模式解决异构数据库访问的问题。新设计的系统架构如图4-1所示。

问题:4.1 (9分)
请用300字以内的文字分别说明数据库程序在线访问方式和ORM方式的优缺点,说明该软件企业采用ORM的原因。问题:4.2 (9分)
请用100字以内的文字说明新体系架构中增加数据访问层的原因。请根据图4-1所示,填写图中空白处(1) - (3)。问题:4.3 (7分)
应用程序设计中,数据库访问需要良好的封装性和可维护性,因此经常使用工厂设计模式来实现对数据库访问的封装。请解释工厂设计模式,并说明其优点和应用场景;请解释说明工厂模式在数据访问层中的应用。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章