Looking up "dao data consistency" or "data access layer data consistency" on Google returns nothing useful
Suppose I have to write DAOs that use a SQL db as datasource and let's say that my schema enforces most (but not all) of the business data (?) rules like not null username etc.. but not those that, for the sake of this example, are virtually impossible to check with DDL checks or other SQL mechanisms.
Does this mean that my DAOs have to ensure data consistency, or do they have to be "stupid" and expect the caller to do the appropriate checks?
Practical example with SQL: this schema has 2 tables
create table bank_accounts
(
accid int primary key,
balance int not null default 0,
check(balance >= 0)
);
create table transfer
(
tid int primary key,
senderaccid int not null,
receiveraccid int not null,
sendercurrentbalance int not null,
receivercurrentbalance int not null,
amount int not null,
check(amount > 0),
foreign key (senderaccid) references bank_accounts(accid),
foreign key (receiveraccid) references bank_accounts(accid)
);
and a typical transaction in SQL would update 2 account balances based on the amount and create a record in transfer
for mere presentation only (e.g. list all money transfers in a web app); should I have DAOs that e.g. let me insert a record in transfer
without having to do the actual account balance update or should I only have DAOs that act like transactions (by using connection.setAutoCommit(false) of java.sql API etc.) and perhaps even do what the db can't to ensure data consistency as specified by the application requirements?
p.s. if it seems like I'm trying to use a mallet as a wrench it's because it's part of a university project that requires us students to do it the good ol' way without using any fancy new framework or API