package bank.server;
import imaginary.persist.Persistent;
public class AccountPeer extends imaginary.persist.DatabasePeer {
protected String getInsertSql(Persistent p) {
Account acct = (Account)p;
int account_id = acct.getId();
int cust_id = acct.getCustomerId();
String type = acct.getAccountType();
float balance = acct.getBalance();
return "INSERT INTO t_accounts (account_id, cust_id, " +
"account_type, balance) " +
"VALUES( " + account_id + ", " + cust_id + ", '" + type + "', " +
balance + ")";
}
public String getRemoveSql(Persistent p) {
int account_id = p.getId();
return "DELETE FROM t_accounts WHERE account_id = " + account_id;
}
public String getRestoreSql(Persistent p) {
return "SELECT * from t_accounts WHERE account_id = " +
p.getId();
}
public String getUpdateSql(Persistent p) {
Account acct = (Account)p;
int account_id = acct.getId();
int cust_id = acct.getCustomerId();
String type = acct.getAccountType();
float balance = acct.getBalance();
return "UPDATE t_accounts " +
"SET cust_id = " + cust_id + ", " +
"account_type = '" + type + "', " +
"balance = " + balance + " " +
"WHERE account_id = " + account_id;
}
}
|