import java.rmi.RemoteException;=0A=
=0A=
import javax.ejb.SessionBean;=0A=
import javax.ejb.SessionContext;=0A=
=0A=
import javax.sql.DataSource;=0A=
=0A=
import javax.naming.InitialContext;=0A=
import javax.naming.NamingException;=0A=
=0A=
import java.sql.Connection;=0A=
import java.sql.PreparedStatement;=0A=
import java.sql.ResultSet;=0A=
import java.sql.SQLException;=0A=
=0A=
import java.util.Vector;=0A=
=0A=
import java.security.Principal;=0A=
=0A=
public class InventoryBean implements SessionBean=0A=
{=0A=
	private SessionContext context;=0A=
=0A=
	public String principalCallback() throws RemoteException=0A=
	{=0A=
		Principal principal;=0A=
=0A=
		principal =3D context.getCallerPrincipal();=0A=
=0A=
		return "X";=0A=
	}=0A=
=0A=
	public String[] listItems() throws RemoteException=0A=
	{=0A=
		String[] returnValue =3D null;=0A=
		Connection connection =3D null;=0A=
		PreparedStatement statement =3D null;=0A=
=0A=
		try=0A=
		{=0A=
			if (context !=3D null)=0A=
			{=0A=
				Object o;=0A=
	=0A=
				o =3D new InitialContext().lookup("jdbc/OracleDS");=0A=
=0A=
				if (o instanceof DataSource)=0A=
				{=0A=
					DataSource dataSource;=0A=
					ResultSet resultSet;=0A=
					Vector v;=0A=
=0A=
					v =3D new Vector();=0A=
=0A=
					dataSource =3D (DataSource) o;=0A=
=0A=
					connection =3D dataSource.getConnection();=0A=
=0A=
					statement =3D=0A=
						connection.prepareStatement("select item_code from item");=0A=
=0A=
//					statement.setString(1,"W1");=0A=
=0A=
					resultSet =3D statement.executeQuery();=0A=
=0A=
					while (resultSet.next())=0A=
					{=0A=
						v.addElement(resultSet.getString(1));=0A=
					}=0A=
=0A=
					returnValue =3D new String[v.size()];=0A=
					for (int i =3D 0;i < v.size();i++)=0A=
					{=0A=
						returnValue[i] =3D (String) v.elementAt(i);=0A=
					}=0A=
=0A=
				}=0A=
			}=0A=
		}=0A=
		catch (NamingException ex)=0A=
		{=0A=
			throw new RemoteException("lost NamingException " + ex.getMessage());=0A=
		}=0A=
		catch (SQLException ex)=0A=
		{=0A=
			throw new RemoteException("lost SQLException " + ex.getMessage());=0A=
		}=0A=
=0A=
		finally=0A=
		{=0A=
			try=0A=
			{=0A=
				if (statement !=3D null)=0A=
				{=0A=
					statement.close();=0A=
					statement =3D null;=0A=
				}=0A=
				if (connection !=3D null)=0A=
				{=0A=
					connection.close();=0A=
					connection =3D null;=0A=
				}=0A=
			}=0A=
			catch (SQLException ex)=0A=
			{=0A=
				throw new RemoteException("lost SQLException " + ex.getMessage());=0A=
			}=0A=
		}=0A=
=0A=
		return returnValue;=0A=
	}=0A=
=0A=
	public void removeItems() throws RemoteException=0A=
	{=0A=
		Connection connection =3D null;=0A=
		PreparedStatement statement =3D null;=0A=
=0A=
		try=0A=
		{=0A=
			if (context !=3D null)=0A=
			{=0A=
				Object o;=0A=
	=0A=
				o =3D new InitialContext().lookup("jdbc/OracleDS");=0A=
=0A=
				if (o instanceof DataSource)=0A=
				{=0A=
					DataSource dataSource;=0A=
=0A=
					dataSource =3D (DataSource) o;=0A=
=0A=
					connection =3D dataSource.getConnection();=0A=
=0A=
					statement =3D=0A=
						connection.prepareStatement("delete from item");=0A=
=0A=
					statement.executeUpdate();=0A=
				}=0A=
			}=0A=
		}=0A=
		catch (NamingException ex)=0A=
		{=0A=
			throw new RemoteException("lost NamingException " + ex.getMessage());=0A=
		}=0A=
		catch (SQLException ex)=0A=
		{=0A=
			throw new RemoteException("lost SQLException " + ex.getMessage());=0A=
		}=0A=
=0A=
		finally=0A=
		{=0A=
			try=0A=
			{=0A=
				if (statement !=3D null)=0A=
				{=0A=
					statement.close();=0A=
					statement =3D null;=0A=
				}=0A=
				if (connection !=3D null)=0A=
				{=0A=
					connection.close();=0A=
					connection =3D null;=0A=
				}=0A=
			}=0A=
			catch (SQLException ex)=0A=
			{=0A=
				throw new RemoteException("lost SQLException " + ex.getMessage());=0A=
			}=0A=
		}=0A=
	}=0A=
=0A=
	public void createItems() throws RemoteException=0A=
	{=0A=
		Connection connection =3D null;=0A=
		PreparedStatement statement =3D null;=0A=
		ResultSet resultSet =3D null;=0A=
=0A=
		try=0A=
		{=0A=
			if (context !=3D null)=0A=
			{=0A=
				Object o;=0A=
	=0A=
				o =3D new InitialContext().lookup("jdbc/OracleDS");=0A=
=0A=
				if (o instanceof DataSource)=0A=
				{=0A=
					DataSource dataSource;=0A=
=0A=
					dataSource =3D (DataSource) o;=0A=
=0A=
					connection =3D dataSource.getConnection();=0A=
=0A=
					statement =3D=0A=
						connection.prepareStatement(=0A=
							"insert into item (item_code,description) values (?,?)");=0A=
=0A=
					statement.setString(1,"ex");=0A=
					statement.setString(2,"Molson Ex");=0A=
					statement.executeUpdate();=0A=
=0A=
					statement.setString(1,"blue");=0A=
					statement.setString(2,"Labatts Blue");=0A=
					statement.executeUpdate();=0A=
=0A=
					statement.setString(1,"vinegar");=0A=
					statement.setString(2,"White Vinegar");=0A=
					statement.executeUpdate();=0A=
=0A=
					statement.setString(1,"smirnoff");=0A=
					statement.setString(2,"Smirnoff Vodka");=0A=
					statement.executeUpdate();=0A=
=0A=
					statement.setString(1,"cc");=0A=
					statement.setString(2,"Canadian Club");=0A=
					statement.executeUpdate();=0A=
=0A=
					statement.setString(1,"bacardi");=0A=
					statement.setString(2,"Bacardi Rum");=0A=
					statement.executeUpdate();=0A=
=0A=
					statement.setString(1,"kahlua");=0A=
					statement.setString(2,"Kahlua");=0A=
					statement.executeUpdate();=0A=
=0A=
					statement.close();=0A=
					connection.close();=0A=
				}=0A=
			}=0A=
		}=0A=
		catch (NamingException ex)=0A=
		{=0A=
			throw new RemoteException("lost NamingException " + ex.getMessage());=0A=
		}=0A=
		catch (SQLException ex)=0A=
		{=0A=
			throw new RemoteException("lost SQLException " + ex.getMessage());=0A=
		}=0A=
		finally=0A=
		{=0A=
			try=0A=
			{=0A=
				if (resultSet !=3D null)=0A=
				{=0A=
					resultSet.close();=0A=
					resultSet =3D null;=0A=
				}=0A=
				if (statement !=3D null)=0A=
				{=0A=
					statement.close();=0A=
					statement =3D null;=0A=
				}=0A=
				if (connection !=3D null)=0A=
				{=0A=
					connection.close();=0A=
					connection =3D null;=0A=
				}=0A=
			}=0A=
			catch (SQLException ex)=0A=
			{=0A=
				throw new RemoteException("lost SQLException " + ex.getMessage());=0A=
			}=0A=
		}=0A=
	}=0A=
=0A=
	public void createItemsError() throws RemoteException=0A=
	{=0A=
		Connection connection =3D null;=0A=
		PreparedStatement statement =3D null;=0A=
		ResultSet resultSet =3D null;=0A=
=0A=
		try=0A=
		{=0A=
			if (context !=3D null)=0A=
			{=0A=
				Object o;=0A=
	=0A=
				o =3D new InitialContext().lookup("jdbc/OracleDS");=0A=
=0A=
				if (o instanceof DataSource)=0A=
				{=0A=
					DataSource dataSource;=0A=
=0A=
					dataSource =3D (DataSource) o;=0A=
=0A=
					connection =3D dataSource.getConnection();=0A=
=0A=
					statement =3D=0A=
						connection.prepareStatement(=0A=
							"insert into item (item_code,description) values (?,?)");=0A=
=0A=
					statement.setString(1,"ex");=0A=
					statement.setString(2,"Molson Ex");=0A=
					statement.executeUpdate();=0A=
=0A=
					statement.setString(1,"blue");=0A=
					statement.setString(2,"Labatts Blue");=0A=
					statement.executeUpdate();=0A=
=0A=
					statement.setString(1,"vinegar");=0A=
					statement.setString(2,"White Vinegar");=0A=
					statement.executeUpdate();=0A=
=0A=
					statement.setString(1,"smirnoff");=0A=
					statement.setString(2,"Smirnoff Vodka");=0A=
					statement.executeUpdate();=0A=
=0A=
					if (statement !=3D null)=0A=
					{=0A=
						throw new RemoteException("forced exception");=0A=
					}=0A=
=0A=
					statement.setString(1,"cc");=0A=
					statement.setString(2,"Canadian Club");=0A=
					statement.executeUpdate();=0A=
=0A=
					statement.setString(1,"bacardi");=0A=
					statement.setString(2,"Bacardi Rum");=0A=
					statement.executeUpdate();=0A=
=0A=
					statement.setString(1,"kahlua");=0A=
					statement.setString(2,"Kahlua");=0A=
					statement.executeUpdate();=0A=
=0A=
					statement.close();=0A=
					connection.close();=0A=
				}=0A=
			}=0A=
		}=0A=
		catch (NamingException ex)=0A=
		{=0A=
			throw new RemoteException("lost NamingException " + ex.getMessage());=0A=
		}=0A=
		catch (SQLException ex)=0A=
		{=0A=
			throw new RemoteException("lost SQLException " + ex.getMessage());=0A=
		}=0A=
		finally=0A=
		{=0A=
			try=0A=
			{=0A=
				if (resultSet !=3D null)=0A=
				{=0A=
					resultSet.close();=0A=
					resultSet =3D null;=0A=
				}=0A=
				if (statement !=3D null)=0A=
				{=0A=
					statement.close();=0A=
					statement =3D null;=0A=
				}=0A=
				if (connection !=3D null)=0A=
				{=0A=
					connection.close();=0A=
					connection =3D null;=0A=
				}=0A=
			}=0A=
			catch (SQLException ex)=0A=
			{=0A=
				throw new RemoteException("lost SQLException " + ex.getMessage());=0A=
			}=0A=
		}=0A=
	}=0A=
=0A=
	public void ejbCreate()=0A=
	{=0A=
	}=0A=
=0A=
	public void ejbRemove()=0A=
	{=0A=
	}=0A=
	public void ejbActivate()=0A=
	{=0A=
	}=0A=
	public void ejbPassivate()=0A=
	{=0A=
	}=0A=
	public void setSessionContext(SessionContext context)=0A=
	{=0A=
		this.context =3D context;=0A=
	}=0A=
}=0A=
