CSE1301 Computer Programming: Lecture 28 Transaction Processing.

36
CSE1301 Computer Programming: Lecture 28 Transaction Processing
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    221
  • download

    0

Transcript of CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Page 1: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

CSE1301 Computer Programming:

Lecture 28Transaction Processing

Page 2: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Topics

• Dataflow Diagrams

• Data structures (structs, arrays)

• Transaction Processing Example – Dataflow Diagram– Structs as parameters

• Reading: Brookshear, 6.4

Page 3: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Structure chart with labels showing data coupling

inviteToParty ( name , date , venue ){ ringUp ( name ) askToParty (date , venue ) sayGoodbye ( name )}

askToParty sayGoodbyeringUp

inviteToParty

name

date

venue

namename

date

venue

control coupling

data coupling

Recall:

Page 4: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Dataflow Diagrams (DFD)

• Pictorial representation of data paths:

– origin (source)

– destination (sink, storage)

– processing points (location of data manipulation, modules)

Page 5: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Dataflow diagram showing data paths

inviteToParty

Mom

Ad

dre

ss B

oo

k

date & venue

name

Invitatio

n List

ringUp

name

phone

Friendgreeting

askToParty

date & venue

date & venue

sayGoodbye

name

salu

tatio

n

Page 6: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Friend

sayGoodbye

ringUp

inviteToParty

askToParty

Mom

Ad

dre

ss B

oo

k

date & venue

name

Invitatio

n List

name

phone

greeting

date & venue

date & venue

name

salu

tatio

n

Arrows: Data Paths

Page 7: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Friend

sayGoodbye

ringUp

inviteToParty

askToParty

Mom

Ad

dre

ss B

oo

k

date & venue

name

Invitatio

n List

name

phone

greeting

date & venue

date & venue

name

salu

tatio

n

Boxes: Data Sources and Sinks

Page 8: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Friend

sayGoodbye

ringUp

inviteToParty

askToParty

Mom

Ad

dre

ss B

oo

k

date & venue

name

Invitatio

n List

name

phone

greeting

date & venue

date & venue

name

salu

tatio

n

Circles (Bubbles): Processing Points

Page 9: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Friend

sayGoodbye

ringUp

inviteToParty

askToParty

Mom

Ad

dre

ss B

oo

k

date & venue

name

Invitatio

n List

name

phone

greeting

date & venue

date & venue

name

salu

tatio

n

Heavy Straight Lines: Data Storage

Page 10: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Friend

sayGoodbye

ringUp

inviteToParty

askToParty

Mom

Ad

dre

ss B

oo

k

date & venue

name

Invitatio

n List

name

phone

greeting

date & venue

date & venue

name

salu

tatio

n

Note: You are not included in the diagram!

Page 11: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Dataflow diagrams (DFD)

• Emphasise the data (information) to flow through system.

(rather than procedures to be executed)

• By following data paths, discover where data units merge, split, are altered.

Page 12: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Transaction Processing: Dataflow Diagram

• What are the actions / data manipulation?

• What are the data sources / sinks?

• What data is stored?

• Example: ATM Transaction

Page 13: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Example: Transactions

• Actions / Data Processing:– withdraw cash

– transfer funds

– determine balance

– deposit money (??)

– authenticate customer

Page 14: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Authenticate: Algorithm

read card number from ATM cardask the Customer for PIN numbersearch the Customer Database for that card numberif card number is found{ retrieve Customer’s PIN on record if PIN on record matches the PIN keyed in { return card number and PIN Okay }}

return BAD card number and PIN

Page 15: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Authenticate: Dataflow Diagram

Authenticate

Customer

PIN

Cu

sto

mer

Dat

abas

e

PIN on record

card number

ATM Card

card number

Transfer

Withdraw

result

& card number

resu

lt

& ca

rd n

umbe

r

Page 16: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Authenticate: Data

struct CustomerIDRec{ long cardNumber; int pin;};

typedef struct CustomerIDRec CustomerID;

• card number– an integer of many digits

• PIN– a 4-digit number

Page 17: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Withdraw: Dataflow Diagram

Withdraw

Customer

account type and amount

Cu

sto

mer

Dat

abas

e

balance

card number and account type result and

card number Authenticate

new balance

cash

Page 18: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Customer Record

• How would you represent a record in the customer database?

struct CustomerRec{ char name[NAMELEN]; long cardNumber; int pin; long chequeAccountNumber; float chequeAccountBalance; long savingsAccountNumber; float savingsAccountBalance;};

typedef struct CustomerRec Customer;

Page 19: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Customer Record

struct CustomerRec{ char name[NAMELEN]; long cardNumber; int pin; long chequeAccountNumber; float chequeAccountBalance; long savingsAccountNumber; float savingsAccountBalance;};

typedef struct CustomerRec Customer;

Already defined as: CustomerID

Page 20: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Customer Record

struct CustomerRec{ char name[NAMELEN]; CustomerID id; long chequeAccountNumber; float chequeAccountBalance; long savingsAccountNumber; float savingsAccountBalance;};

typedef struct CustomerRec Customer;

Page 21: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

struct CustomerRec{ char name[NAMELEN]; CustomerID id; long chequeAccountNumber; float chequeAccountBalance; long savingsAccountNumber; float savingsAccountBalance;};

typedef struct CustomerRec Customer;

Customer RecordProblems:• Cumbersome• How do we know which ones are open?

Page 22: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

struct CustomerRec{ char name[NAMELEN]; CustomerID id; Account accounts[2];};

typedef struct CustomerRec Customer;

Customer Recordstruct AccountRec{ int open; /* boolean */ long number; float balance;};

typedef struct AccountRec Account;

Page 23: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

struct CustomerRec{ char name[NAMELEN]; CustomerID id; Account accounts[2];};

typedef struct CustomerRec Customer;

Customer Recordstruct AccountRec{ int open; /* boolean */ long number; float balance;};

typedef struct AccountRec Account;

Index determines account type:accounts[0]: cheque accountaccounts[1]: savings account

More scalable!

Page 24: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Example 1: printBalance

void printBalance ( Customer cust ){ int type;

printf(“Customer name: %s\n”, cust.name); for (type=0; type < 2; type++) { if (cust.accounts[type].open) { printf(“Account number: “); printf(“%ld\n”, cust.accounts[type].number); printf(“Balance: “); printf(“%.2f\n”, cust.accounts[type].balance); } } printf(“\n”);}

Page 25: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Customer Database

struct DatabaseInfo{ int count; /* Number of records. */ Customer customers[MAXRECORDS];};

typedef struct DatabaseInfo Database;

Page 26: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

void printAllbalance ( Database db ){ int i;

for (i=0; i < db.count; i++) { printBalance ( db.customer[i] ); }}

Example 2: printAllBalance

Page 27: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Transaction Data

ATM BANK’SMAINFRAME

card number and request for PIN

PIN on record

card number and request for balance

balance

card number and balance update

confirmation

• Potential problems with this setup: security, link break-up, traffic.

Page 28: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

ATM BANK’SMAINFRAME

request

response

Transaction Data

Page 29: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Transaction Data

struct requestRec{ int type; /* 0=balance, 1=withdraw, etc */ CustomerID id; /* card no. and PIN keyed in */ int accountFrom; /* account type */ int accountTo; /* account type */ float amount;};

typdef struct requestRec Request;

• Disadvantages: Large record, some fields unused.• Advantages: Security, processed in mainframe,

shorter response, less traffic.

Page 30: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Transaction Data

struct responseRec{ int code; /* 0=ok, 1=wrong pin, 2=no funds, .. */ float amount;};

typdef struct responseRec Response;

Page 31: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Transaction Processing

Response processRequest ( Request req ){ Response response;

if (req.type == 0) response = doBalance(req); else if (req.type == 1) response = doWithdraw(req); else if (req.type == 2) response = doTransfer(req); else

/* ...and so on... */

return (response); }

Page 32: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Updating StructsCustomer updateCustomer ( Customer cust ){ printf(“Customer name: %s\n, cust.name); printf(“Enter new card number: “); scanf(“%ld”, &(cust.id.cardNumber)); printf(“Enter new PIN: “); scanf(“%d”, &(cust.id.pin));

return cust;}

...

cust = updateCustomer(cust);

...

Can we avoidlong identifies?

Page 33: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

new id

Hierarchy and Data Coupling

updateID updateAccountupdateName

updateCustomer

customer

customer

old account old name

old id

new name new account

The size of the data coupling corresponds roughly to the level of the module in the hierarchy.

Page 34: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Hierarchy and Data CouplingCustomer updateCustomer ( Customer cust ){ updateName ( cust.name ); cust.id = updateID ( cust.id ); cust.account[0] = updateAccount ( cust.account[0] ); cust.account[1] = updateAccount ( cust.account[1] );

return cust;}

Page 35: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Exercise: Dataflow diagram

Draw a dataflow diagram depicting the flow of information between a lecturer, a student, and a textbook. Include the fact that an end of semester examination is given.

• Data sources? – Lecturer, textbook

• Data storage? – Student memory, notebooks

• Data manipulation? – Read textbook, compile information, answer questions

Page 36: CSE1301 Computer Programming: Lecture 28 Transaction Processing.

Summary

• Dataflow diagrams are an alternative representation of a system.

• Transaction processing: focus on dataflow and data structures.

• Combination of: – top down and bottom up;– design tools and techniques.

• Readings: Brookshear. 6.4, Fig 6-6