Database Objects 1/12/2019 See scm-intranet
Objective To examine the implementation of objects that use data sources To develop an understanding of the relationship between a client system and a database server 1/12/2019 See scm-intranet
Objects in Database Development An object model, which describes data and processes cannot be converted into a relational schema. However, the development tools used to produce application software which employ a relational database use object oriented ideas-particularly with regard to the user interface. 1/12/2019 See scm-intranet
Question? How can an object based application interact with a non-object based data source e.g a relational database. Answer- By ‘encapsulating’ the data source ‘inside’ an object. Sometimes called ‘wrapping’ the data source. This makes the data source ‘look like’ and ‘behave like’ any other type of object 1/12/2019 See scm-intranet
ADO Object Model ActiveX Data Objects- used in Microsoft environments to manipulate database systems. Capable of manipulating most databases inc. non-Microsoft products. Connects client applications to database servers. Three most important objects are Connection RecordSet Command 1/12/2019 See scm-intranet
Provides a common interface to sources of data. If data source changes e.g. SQL SERVER to ORACLE all application systems remain the same. Assuming systems designed properly i.e. to exploit this capability. An OLE DB provider is required for every potential data source. ADO interfaces to data via a OLE DB provider. 1/12/2019 See scm-intranet
Connection Object A Connection object, that uses a data link, is required to make and manage the communication between the application and the database management system (DBMS) This may be the same physical machine on which the application executes or a remote server 1/12/2019 See scm-intranet
Objects are Instantiated (created) from Classes. Classes may be pre-defined e.g. by a software supplier, or produced from scratch (programmed). Objects can have An identity Properties Methods Events (for which handling functions can be written) Collections These may be private (not ‘visible’ for use) or public (available for use-the interface between the object and external world) Internal workings of an object private (encapsulation) 1/12/2019 See scm-intranet
Example SQL*Server can be used by running the Query Analyser. The QueryAnalyser is created from objects. When the QueryAnalyser is selected at the PC a dialogue appears which creates an instantiated Connection Object The user has to supply a database server name, a user id, and a password. This information is used to make a Connection String (part of data link) which is then used by the connection object to connect the QueryAnalyser to the database. 1/12/2019 See scm-intranet
1/12/2019 See scm-intranet
1/12/2019 See scm-intranet
Connection String A connection string is a property of a connection object. Object Properties can be ‘set’. This means giving them values. The connection string property is set with basic connection information e.g. user id , password, etc.. 1/12/2019 See scm-intranet
Example Connection Object Properties ConnectionString: defines the database to use, user id and other necessary data. IsolationLevel: defines the degree of locking required on database objects (tables, rows, columns, records) 1/12/2019 See scm-intranet
Example Methods of a Connection Object BeginTrans: Begin a transaction Close: closes a connection with the database Open: opens a connection to database. RollBackTrans: Undo transaction updates. (You can get access to methods by double-clicking a connection object in a Data Environment.) 1/12/2019 See scm-intranet
Example Events of a Connection Object Disconnect: used for operations to be carried out after connection broken ExecuteComplete: used for operations to be carried out after SQL query executed. 1/12/2019 See scm-intranet
RecordSet Object This object holds data that has been requested from a connected database via the OLE DB provider. The object also holds information on that data (meta-data) such as the names of tables and columns, data types and similar. As an object, there are properties, methods and collections which can be accessed and programmed. 1/12/2019 See scm-intranet
Example Properties of Recordset BOF: true if before 1st record CursorLocation:record pointer location EOF:true if after last record MaxRecords:to return from query Source:source of data 1/12/2019 See scm-intranet
Example Methods of RecordSet Close:recordset Delete:current record Movefirst, movelast, Movenext, moveprevious Open:a cursor Update:commit changes 1/12/2019 See scm-intranet
Example Events of RecordSet EndofRecordset:have reached end WillChangeRecordset: something in Recordset will change 1/12/2019 See scm-intranet
Command Object Used for passing queries or data manipulation commands to a connected database. 1/12/2019 See scm-intranet
Example Properties of Command Object ActiveConnection:associated connection object CommandText:command itself 1/12/2019 See scm-intranet
Example Methods of Command Object Cancel:to stop execution Execute:opens a recordset object 1/12/2019 See scm-intranet
ActiveX Data Object (ADO) The ADO is a class/object which can be used to connect to a DBMS and retrieve data An ADO includes a connection, command and recordset object An ADO object is capable of basic data retrieval and manipulation operations 1/12/2019 See scm-intranet
Association/Aggregation Classes/Objects can be used by other classes/objects. The ways of relating them together are known as abstractions. Association/Aggregation is an abstraction used in object oriented models. In this case, the ADO relates a recordset, command, and connection object. Then adding further functionality (e.g. record browsing) to add value to existing objects. 1/12/2019 See scm-intranet
Instantiation Objects are instantiated from classes This involves setting properties and modifying the parameters of methods This process enables the reusability of components whilst allowing them to be customised to the needs of a specific application So, ADO’s can be instantiated from the ADO class which in turn causes instantiations of command, recordset and connection objects from their respective classes. Hence ADO’s connections, recordsets, and commands are reusable components. 1/12/2019 See scm-intranet
Programming an ADO E.g. Connection objects can be created, opened and closed in a application program It is possible to see Instantiation, method calls and the setting of object properties using a simple example. 1/12/2019 See scm-intranet
Example Application Code-VBasic Private adoConnect as Connection {declaring an object from pre-defined class} Private sub xxx() Set adoConnect=New Connection {Instantiation} AdoConnect.Open “a connection string” {method call} …..database and procedural operations….. AdoConnect.Close {method call} Set adoConnect=Nothing {setting the value of an object property-to remove from memory} End sub 1/12/2019 See scm-intranet
ADO.NET ADO.NET uses some ADO objects, such as the Connection and Command objects, and also introduces new objects. Key ADO.NET objects include Command Connection DataReader DataAdapter DataSet 1/12/2019 See scm-intranet
DataReaders The DataReader object is a read-only/forward-only cursor over data. A DataReader object is returned after executing a command against a database. The format of the returned DataReader object is different from a recordset. For example, you might use the DataReader to show the results of a search list in a web page. 1/12/2019 See scm-intranet
The Dataset is separate and distinct from any data stores. The DataSet functions as a standalone entity. It is an ‘always disconnected’ recordset that knows nothing about the source or destination of the data it contains. Inside a DataSet there are tables, columns, relationships, constraints, views………. The DataSet has the ability to produce and consume XML data 1/12/2019 See scm-intranet
DataAdapter is the object that connects to the database to fill the DataSet. It connects back to the database to update the data, based on operations performed on the DataSet. Provides a bridge to retrieve and save data between a DataSet and its source data store. It accomplishes this by means of SQL commands made against the data store. 1/12/2019 See scm-intranet
Application program Data Reader Data Set Data Adapter OLE DB Database(s) 1/12/2019 See scm-intranet
OLE DB and SQL Server .NET Data Providers The OLE DB and SQL Server .NET Data Providers System.Data.OleDb System.Data.SqlClient are part of the .Net Framework and provide the basic objects 1/12/2019 See scm-intranet
Persistence Objects are made persistent when the application program is saved. Programs are not saved into the database. Programs are saved into program files within the VB environment 1/12/2019 See scm-intranet
The class/object definitions and instantiations are normally stored in the program development environment using project files. This places them outside the management control of the database management system, unless the program development environment is an integral part of the DBMS (making it an ODBMS?). 1/12/2019 See scm-intranet
Summary An object oriented view can be taken with regard to client applications Application components are instantiated from pre-defined packaged classes Many data sources are not object-oriented so there is an apparent fundamental incompatibility between clients programs and data sources. 1/12/2019 See scm-intranet
Microsoft uses ADO.NET to achieve this. Data sources are encapsulated as objects to be directly compatible with client program objects. Microsoft uses ADO.NET to achieve this. ADO’s consist of an aggregation of objects which manage all connections and interactions with data sources. 1/12/2019 See scm-intranet
(e.g.sharing components in a distributed environment) The application (and components) are made persistent by ‘saving’ into application project files. This method of persistence puts the application components outside the control of the DBMS Putting the components under the control of the DBMS would enhance reusability and configuration management. Software development tools could then use data management tools and techniques to manage components (e.g.sharing components in a distributed environment) 1/12/2019 See scm-intranet