我是2011年鉴我是2011年鉴
package service;
import dao.AccountDAO;
import dao.StockDAO;
import entity.Account;
import entity.Stock;
import util.TransactionManager;
import java.sql.Connection;
/**
* Created by Administrator on 14-3-27.
*/
public class StockService {
public double buy(String AccountNo,String StockNo,double amt) throws Exception{
double rs=-2;
TransactionManager.beginTransaction();
try{
AccountDAO accountDao = new AccountDAO();
Account account = accountDao.find(AccountNo);
if (amt>account.getBalance()){
return -1;
}
account.setBalance(account.getBalance()-amt);
accountDao.modify(account);
StockDAO stockDao = new StockDAO();
Stock stock = stockDao.find(StockNo);
stock.setQty(stock.getQty()+amt);
stockDao.modify(stock);
TransactionManager.commit();
return amt/10;
}catch (Exception e){
e.printStackTrace();
TransactionManager.rollback();
}
return rs;
}
}
package service;
import dao.AccountDAO;
import dao.StockDAO;
import entity.Account;
import entity.Stock;
import util.TransactionManager;
import java.sql.Connection;
/**
* Created by Administrator on 14-3-27.
*/
public class StockService {
public double buy(String AccountNo,String StockNo,double amt) throws Exception{
double rs=-2;
TransactionManager.beginTransaction();
try{
AccountDAO accountDao = new AccountDAO();
Account account = accountDao.find(AccountNo);
if (amt>account.getBalance()){
return -1;
}
account.setBalance(account.getBalance()-amt);
accountDao.modify(account);
StockDAO stockDao = new StockDAO();
Stock stock = stockDao.find(StockNo);
stock.setQty(stock.getQty()+amt);
stockDao.modify(stock);
TransactionManager.commit();
return amt/10;
}catch (Exception e){
e.printStackTrace();
TransactionManager.rollback();
}
return rs;
}
}
package service;
import dao.AccountDAO;
import dao.StockDAO;
import entity.Account;
import entity.Stock;
import util.TransactionManager;
import java.sql.Connection;
/**
* Created by Administrator on 14-3-27.
*/
public class StockService {
public double buy(String AccountNo,String StockNo,double amt) throws Exception{
double rs=-2;
TransactionManager.beginTransaction();
try{
AccountDAO accountDao = new AccountDAO();
Account account = accountDao.find(AccountNo);
if (amt>account.getBalance()){
return -1;
}
account.setBalance(account.getBalance()-amt);
accountDao.modify(account);
StockDAO stockDao = new StockDAO();
Stock stock = stockDao.find(StockNo);
stock.setQty(stock.getQty()+amt);
stockDao.modify(stock);
TransactionManager.commit();
return amt/10;
}catch (Exception e){
e.printStackTrace();
TransactionManager.rollback();
}
return rs;
}
}
package service;
import dao.AccountDAO;
import dao.StockDAO;
import entity.Account;
import entity.Stock;
import util.TransactionManager;
import java.sql.Connection;
/**
* Created by Administrator on 14-3-27.
*/
public class StockService {
public double buy(String AccountNo,String StockNo,double amt) throws Exception{
double rs=-2;
TransactionManager.beginTransaction();
try{
AccountDAO accountDao = new AccountDAO();
Account account = accountDao.find(AccountNo);
if (amt>account.getBalance()){
return -1;
}
account.setBalance(account.getBalance()-amt);
accountDao.modify(account);
StockDAO stockDao = new StockDAO();
Stock stock = stockDao.find(StockNo);
stock.setQty(stock.getQty()+amt);
stockDao.modify(stock);
TransactionManager.commit();
return amt/10;
}catch (Exception e){
e.printStackTrace();
TransactionManager.rollback();
}
return rs;
}
}
|
|
|
|
|
吴中区道教协会2010年鉴吴中区道教协会2011年鉴吴中区道教协会2011年鉴吴中区道教协会2011年鉴
|