ADO.NET (and more LINQ) Entity Framework (and more LINQ) Verification (CodeContracts) TPL (Task Parallel Library) Other.NET/C# topics.

Slides:



Advertisements
Similar presentations
17. Data Access ADO.Net Architecture New Features of ADO.NET
Advertisements

Transactions generalities 1 Transactions - generalities.
Transactions - Concurrent access & System failures - Properties of Transactions - Isolation Levels 4/13/2015Databases21.
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
Accessing data Transactions. Agenda Questions from last class? Transactions concurrency Locking rollback.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
ACS-4902 R McFadyen 1 Chapter 17 Introduction to Transaction Processing Concepts and Theory 17.1, 17.2, 17.3, 17.5, 17.6.
End of SQL: Triggers, Impedance Mismatch and Transactions February 6 th, 2004.
Transaction Management and Concurrency Control
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Transaction Management
Database Management Systems I Alex Coman, Winter 2006
1 Introduction to Web Application Introduction to Data Base.
Cs3431 Transactions, Logging and Security. cs3431 Transactions: What and Why? A set of operations on a database must appear as one “unit”. Example: Consider.
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
COMP 5138 Relational Database Management Systems Semester 2, 2007 Lecture 8A Transaction Concept.
Managing Concurrency in Web Applications. DBI 2007 HUJI-CS 2 Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses.
Transaction Management and Concurrency Control
Transaction. A transaction is an event which occurs on the database. Generally a transaction reads a value from the database or writes a value to the.
INTRODUCTION TO TRANSACTION PROCESSING CHAPTER 21 (6/E) CHAPTER 17 (5/E)
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
1 UCN Technology: Computer Science: Autumn 2012 ADO.NET 2.0 Architecture DataReader DataSet Connection factory Config file.
FEN Data connection DataReader DataSet Bonus info: Concurrency and Database Transactions Embedded SQL.
Database Management System Module 5 DeSiaMorewww.desiamore.com/ifm1.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
Transactions Sylvia Huang CS 157B. Transaction A transaction is a unit of program execution that accesses and possibly updates various data items. A transaction.
Transactions1 Unit of work on a database. Transactions2 Transactions, concept Logical unit of work on the database –Examples Transfer money from bank.
TRANSACTIONS. Objectives Transaction Concept Transaction State Concurrent Executions Serializability Recoverability Implementation of Isolation Transaction.
1 What is database 2? What is normalization? What is SQL? What is transaction?
1cs Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses by multiple users Concurrent accesses intersect.
Transaction Processing Concepts. 1. Introduction To transaction Processing 1.1 Single User VS Multi User Systems One criteria to classify Database is.
Transaction processing Book, chapter 6.6. Problem: With a single user…. you run a query, you get the results, you run the next, etc. But database life.
TRANSACTION MANAGEMENT R.SARAVANAKUAMR. S.NAVEEN..
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 136 Database Systems I SQL Modifications and Transactions.
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Transactions and Locks A Quick Reference and Summary BIT 275.
Chapter 16 Concurrency. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.16-2 Topics in this Chapter Three Concurrency Problems Locking Deadlock.
XA Transactions.
Introduction.  Administration  Simple DBMS  CMPT 454 Topics John Edgar2.
15.1 Transaction Concept A transaction is a unit of program execution that accesses and possibly updates various data items. E.g. transaction to transfer.
CM Name : p.rajesh Year/Semester : VI Semester Subject : Advanced database system Subject Code : CM-603 Topic : Advanced database concepts Duration.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_JDBC_MySQL 1 Transations.
1 Intro stored procedures Declaring parameters Using in a sproc Intro to transactions Concurrency control & recovery States of transactions Desirable.
1 Advanced Database Concepts Transaction Management and Concurrency Control.
NOEA/IT - FEN: Databases/Transactions1 Transactions ACID Concurrency Control.
©Bob Godfrey, 2002, 2005 Lecture 17: Transaction Integrity and Concurrency BSA206 Database Management Systems.
10 1 Chapter 10 - A Transaction Management Database Systems: Design, Implementation, and Management, Rob and Coronel.
Module 2: Using ADO.NET to Access Data. Overview ADO.NET Architecture Creating an Application That Uses ADO.NET to Access Data Changing Database Records.
18 September 2008CIS 340 # 1 Last Covered (almost)(almost) Variety of middleware mechanisms Gain? Enable n-tier architectures while not necessarily using.
In this session, you will learn to: Implement triggers Implement transactions Objectives.
Data Access. ADO.NET ADO.NET is the primary library for building database solutions within the.NET Framework. ADO.NET does not replace ADO. ADO and OLEDB.
SQL Basics Review Reviewing what we’ve learned so far…….
Chapter 13 Managing Transactions and Concurrency Database Principles: Fundamentals of Design, Implementation, and Management Tenth Edition.
ADO.NET Framework.
LAB: Web-scale Data Management on a Cloud
Isolation Levels Understanding Transaction Temper Tantrums
Transaction Properties
Ch 21: Transaction Processing
On transactions, and Atomic Operations
Batches, Transactions, & Errors
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
On transactions, and Atomic Operations
Batches, Transactions, & Errors
Chapter 10 ADO.
Transactions and Concurrency
-Transactions in SQL -Constraints and Triggers
Advanced Topics: Indexes & Transactions
Presentation transcript:

ADO.NET (and more LINQ) Entity Framework (and more LINQ) Verification (CodeContracts) TPL (Task Parallel Library) Other.NET/C# topics

ADO.NET To måder at tilgå DB på: Connected Åbn connection Læse-/Skrivetilgang (select, insert, update og delete) via Command-objekt Ved læsetilgang (select) returneres et DataReader-objekt Luk Connection Disconnected Fyld et DataSet-objekt (kopi af dele af db) vha. en DataAdapter DataAdapter indpakker SQL-statement(s) DataSet-objekt indeholder DataTable-objekter DataTable-objekter indeholder collections af rækker og kolonner

Connection vs. Connectionless Connection: Open Connection Udfør db-operationer Luk Connection Der arbejdes på aktuelle data Andre applikationer lukkes evt. ude

Connectionless: –Tag en kopi af et databaseudsnit –Udfør db-operationer på kopien –Andre applikationer kan ændre data –Der arbejdes evt. på en uaktuel kopi af data Connection vs. Connectionless Data ændres i den lokale kopi: –ved update checkes om andre har ændret dataene i kopien –i så fald afvises opdateringen (ConcurrencyException)

Hvis DB skal opdateres Tilføj et commandobjekt til dataadapteren InsertCommand UpdateCommand DeleteCommand Gøres vha. parametriserede queries, fx: da.InsertCommand = new OleDbCommand("INSERT INTO ” + Ansat (løn, navn, stilling) VALUES (?, ?, ?)",dbconn); da.Update(ds, ”Ansat”); 1. parameter: sql 2. parameter: connection Her opdateres DB. Kan fejle (ConcurrencyException)

Transaction - Definition A transaction is an operation on data in the database. A transaction may be composed of several database operations, but is viewed as a logical unit of work A transaction must be done completely or not done at all A transaction must have the ACID properties: A: Either it is done in total or it is not done at all (Atomicity) C: The database moves from one consistent state to an other consistent state (Consistency) I: If more operations are accessing the same data, they are not to disturb each other – they must execute as if they executed alone (Isolation) D: When a transaction completes, its changes to the database are permanent (Durability)

Transactions – example: T1 and T2 are executing concurrently T1: Transfers N DKKs from account X to account Y: read_item(X); X:= X-N; write_item(X); read_item(Y); Y:= Y+N; write_item(Y); T2: Deposits M DKK on account Y: read_item(Y); Y:= Y+M; write_item(Y); Any possible problems? time

Transactions – Problems We want several transactions to execute concurrently (Why?) Three types of problems: lost update uncommitted dependency (temporary update) inconsistent analysis (incorrect summary) Crash during execution of a transaction must be handled

Lost Update

Uncommitted Dependency

Inconsistent Analysis

SQL Support for Transactions By default any SQL statement is considered to be atomic, that is: a transaction. Transactions involving more than one SQL statement must be opened by BeginTransaction() and terminated by either Commit() or Rollback(). It is possible to specify the isolation level of a transaction: Read Uncommitted Read Committed (Default on MS SQL Server) Repeatable Read Serializable

Isolation Levels READ UNCOMMITTED In this isolation level, dirty reads are allowed. One transaction may see uncommitted changes made by some other transaction. READ COMMITTED Data records retrieved by a query are not prevented from modification by some other transaction. Non-repeatable reads may occur, meaning data retrieved in a SELECT statement may be modified by some other transaction when it commits. In this isolation level, read locks are acquired on selected data but they are released immediately whereas write locks are released at the end of the transaction.

Isolation Levels REPEATABLE READ All data records read by a SELECT statement cannot be changed; however, if the SELECT statement contains any ranged WHERE clauses, phantom reads can occur. In this isolation level, the transaction acquires read locks on all retrieved data, but does not acquire range locks. SERIALIZABLE This isolation level specifies that all transactions occur in a completely isolated fashion; i.e., as if all transactions in the system had executed serially, one after the other. The DBMS may execute two or more transactions at the same time only if the illusion of serial execution can be maintained. At this isolation level, phantom reads cannot occur.

Entity Framework Data menu >> Add New Data Source… select Database, Entity Data Model, … VS generates persistent model ― entities, collections, etc. var query = from doctor in _db.Doctors orderby doctor.LastName, doctor.FirstName select doctor; foreach (Doctor d in query) { string name = string.Format("{0}, {1}", d.LastName, d.FirstName); lstDoctors.Items.Add(name); } var query = from doctor in _db.Doctors orderby doctor.LastName, doctor.FirstName select doctor; foreach (Doctor d in query) { string name = string.Format("{0}, {1}", d.LastName, d.FirstName); lstDoctors.Items.Add(name); } SchedulingEntities _db = new SchedulingEntities(); From Joe Hummel

Specifikationer: Code Contracts Metoder specificeres vha. pre- og postbetingelser: Prebetingelse: Et udsagn om programmets tilstand (værdier af variable) som skal være sandt inden metoden må kaldes. Postbetingelse: Et udsagn om programmets tilstand (værdier af variable) som skal være sandt når metoden returnerer. Invarianter specificerer krav, som går på tværs af metoder.

Eksempel: Dictionary (Map – værdibaseret container, lagrer par af (key, value)) public interface Dictionary { invariant // Basic queries public int count(); ensures (count()==0) ==> public boolean has(Object key); requires public Object valueFor(Object key); // Derived queries ensures \result == public boolean isEmpty(); // Commands requires ensures ensures ensures public void put(Object key, Object value); requires ensures ensures public void remove(Object key); } Her specifikation som kommentarer Understøttes i.NET af CodeContracts

TPL: Task Parallel Library Vi får næppe bedre performance pga. øget clock- frekvens (More’s lov holder ikke længere). Derimod får vi flere processorer – fire er allerede ved at være standard på almindelige lap-tops. Derfor bliver parallelprogrammering mere og mere interessant. TPL er.NET 4’s bud en API til parallelprogrammering.

Task using System.Threading.Tasks; Task T = new Task( code ); T.Start(); if… while… using System.Threading.Tasks; Task T = new Task( code ); T.Start(); if… while… tells.NET that task *can* start, then returns immediately tells.NET that task *can* start, then returns immediately original code task "code" Program “forks” and now 2 code streams are executing concurrently ― original, and T. computation to perform… From Joe Hummel

Language support TPL takes advantage of.NET language features Lambda expressions Closures Parallel.For(0, N, (i) => { C[i] = A[i] + B[i]; } ); Parallel.For(0, N, (i) => { C[i] = A[i] + B[i]; } ); int[] A, B, C;. for(i=0; i<N; i++) { C[i] = A[i] + B[i]; } int[] A, B, C;. for(i=0; i<N; i++) { C[i] = A[i] + B[i]; } lambda expression close over data (by ref!) From Joe Hummel