package entity;

import boundary.*;
import java.sql.*;
import java.util.*;
public class StockPortfolioInfo {
	private int userId;
	private HashMap<String, Integer> stockList;
	private ResultSet portfolio;
	
	public StockPortfolioInfo(int userId) {
		this.userId = userId;
		stockList = new HashMap<String, Integer>();
		portfolio = null;
	}
	
	public void fetchPortfolio() {
		String query = "SELECT * FROM portfolio WHERE user_id = " + this.userId;
		portfolio = DatabaseCommunicator.query(query);
		try {
			if (portfolio.first()) {
				stockList.put(portfolio.getString("symbol"), Integer.valueOf(portfolio.getString("amount")));
			}
			while (portfolio.next()) {
				stockList.put(portfolio.getString("symbol"), Integer.valueOf(portfolio.getString("amount")));
			}
		}
		catch (Exception e) {
			System.err.println(e.toString());
		}
	}
}
