package flex.samples.crm.employee;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import flex.samples.ConnectionHelper;
import flex.samples.DAOException;
import flex.samples.crm.ConcurrencyException;
import flex.samples.crm.company.Company;
public class EmployeeDAO
{
public List getEmployees() throws DAOException
{
List list = new ArrayList();
Connection c = null;
try
{
c = ConnectionHelper.getConnection();
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM employee ORDER BY last_name");
Employee employee;
while (rs.next())
{
employee = new Employee();
employee.setEmployeeId(rs.getInt("employee_id"));
employee.setFirstName(rs.getString("first_name"));
employee.setLastName(rs.getString("last_name"));
employee.setTitle(rs.getString("title"));
employee.setEmail(rs.getString("email"));
employee.setPhone(rs.getString("phone"));
Company company = new Company();
company.setCompanyId(rs.getInt("company_id"));
employee.setCompany(company);
list.add(employee);
}
}
catch (SQLException e)
{
e.printStackTrace();
throw new DAOException(e);
}
finally
{
ConnectionHelper.close(c);
}
return list;
}
public List findEmployeesByCompany(Integer companyId) throws DAOException
{
List list = new ArrayList();
Connection c = null;
try
{
Company company = new Company();
company.setCompanyId(companyId.intValue());
c = ConnectionHelper.getConnection();
PreparedStatement ps = c.prepareStatement("SELECT * FROM employee WHERE company_id = ? ORDER BY last_name");
ps.setInt(1, companyId.intValue());
ResultSet rs = ps.executeQuery();
while (rs.next())
{
Employee employee = new Employee();
employee.setEmployeeId(rs.getInt("employee_id"));
employee.setFirstName(rs.getString("first_name"));
employee.setLastName(rs.getString("last_name"));
employee.setTitle(rs.getString("title"));
employee.setEmail(rs.getString("email"));
employee.setPhone(rs.getString("phone"));
employee.setCompany(company);
list.add(employee);
}
}
catch (SQLException e)
{
e.printStackTrace();
throw new DAOException(e);
}
finally
{
ConnectionHelper.close(c);
}
return list;
}
public List findEmployeesByName(String name) throws DAOException
{
List list = new ArrayList();
Connection c = null;
try
{
c = ConnectionHelper.getConnection();
PreparedStatement ps = c.prepareStatement("SELECT * FROM employee WHERE first_name LIKE ? OR last_name LIKE ? ORDER BY last_name");
ps.setString(1, "%" + name + "%");
ps.setString(2, "%" + name + "%");
ResultSet rs = ps.executeQuery();
Employee employee;
while (rs.next())
{
employee = new Employee();
employee.setEmployeeId(rs.getInt("employee_id"));
employee.setFirstName(rs.getString("first_name"));
employee.setLastName(rs.getString("last_name"));
employee.setTitle(rs.getString("title"));
employee.setEmail(rs.getString("email"));
employee.setPhone(rs.getString("phone"));
Company company = new Company();
company.setCompanyId(rs.getInt("company_id"));
list.add(employee);
}
}
catch (SQLException e)
{
e.printStackTrace();
throw new DAOException(e);
}
finally
{
ConnectionHelper.close(c);
}
return list;
}
public Employee getEmployee(int employeeId) throws DAOException
{
Employee employee = null;
Connection c = null;
try
{
c = ConnectionHelper.getConnection();
PreparedStatement ps = c.prepareStatement("SELECT * FROM employee WHERE employee_id= ?");
ps.setInt(1, employeeId);
ResultSet rs = ps.executeQuery();
if (rs.next())
{
employee = new Employee();
employee.setEmployeeId(rs.getInt("employee_id"));
employee.setFirstName(rs.getString("first_name"));
employee.setLastName(rs.getString("last_name"));
employee.setTitle(rs.getString("title"));
employee.setEmail(rs.getString("email"));
employee.setPhone(rs.getString("phone"));
}
}
catch (SQLException e)
{
e.printStackTrace();
throw new DAOException(e.getMessage());
}
finally
{
ConnectionHelper.close(c);
}
return employee;
}
public Employee createEmployee(Employee employee) throws DAOException
{
Connection c = null;
PreparedStatement ps = null;
try
{
c = ConnectionHelper.getConnection();
ps = c.prepareStatement("INSERT INTO employee (first_name, last_name, title, email, phone, company_id) VALUES (?, ?, ?, ?, ?, ?)");
ps.setString(1, employee.getFirstName());
ps.setString(2, employee.getLastName());
ps.setString(3, employee.getTitle());
ps.setString(4, employee.getEmail());
ps.setString(5, employee.getPhone());
if (employee.getCompany() != null)
ps.setInt(6, employee.getCompany().getCompanyId());
else
ps.setNull(6, Types.INTEGER);
ps.execute();
ps.close();
Statement s = c.createStatement();
// HSQLDB Syntax to get the identity (employee_id) of inserted row
ResultSet rs = s.executeQuery("CALL IDENTITY()");
rs.next();
// Update the id in the returned object. This is important as this
// value must get returned to the client.
employee.setEmployeeId(rs.getInt(1));
}
catch (SQLException e)
{
e.printStackTrace();
throw new DAOException(e);
}
finally
{
ConnectionHelper.close(c);
}
return employee;
}
public void updateEmployee(Employee newVersion, Employee previousVersion, List changes) throws DAOException, ConcurrencyException
{
Connection c = null;
try
{
c = ConnectionHelper.getConnection();
PreparedStatement ps = c.prepareStatement("UPDATE employee SET first_name=?, last_name=?, title=?, email=?, phone=?, company_id=? WHERE employee_id=? AND first_name=? AND last_name=? AND title=? AND email=? AND phone=? AND company_id=?");
ps.setString(1, newVersion.getFirstName());
ps.setString(2, newVersion.getLastName());
ps.setString(3, newVersion.getTitle());
ps.setString(4, newVersion.getEmail());
ps.setString(5, newVersion.getPhone());
if (newVersion.getCompany() != null)
ps.setInt(6, newVersion.getCompany().getCompanyId());
else
ps.setNull(6,Types.INTEGER);
ps.setInt(7, newVersion.getEmployeeId());
ps.setString(8, previousVersion.getFirstName());
ps.setString(9, previousVersion.getLastName());
ps.setString(10, previousVersion.getTitle());
ps.setString(11, previousVersion.getEmail());
ps.setString(12, previousVersion.getPhone());
if (previousVersion.getCompany() != null)
ps.setInt(13, previousVersion.getCompany().getCompanyId());
else
ps.setNull(13, Types.INTEGER);
if (ps.executeUpdate() == 0)
{
throw new ConcurrencyException("Item not found");
}
}
catch (SQLException e)
{
e.printStackTrace();
throw new DAOException(e.getMessage());
}
finally
{
ConnectionHelper.close(c);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
聊天室源码聊天室源码聊天室源码聊天室源码聊天室源码
共1175个文件
png:1021个
gif:33个
class:29个
需积分: 9 14 下载量 191 浏览量
2011-07-17
10:12:28
上传
评论
收藏 10.65MB RAR 举报
温馨提示
聊天室源码聊天室源码聊天室源码聊天室源码聊天室源码聊天室源码聊天室源码聊天室源码
资源推荐
资源详情
资源评论
收起资源包目录
聊天室源码聊天室源码聊天室源码聊天室源码聊天室源码 (1175个子文件)
bg.bmp 3.17MB
EmployeeDAO.class 7KB
ProductService.class 6KB
CompanyDAO.class 6KB
ProductService.class 5KB
ChatRoomService.class 4KB
Portfolio.class 3KB
Feed$FeedThread.class 3KB
Room.class 2KB
CustomDelayQueueProcessor.class 2KB
Product.class 2KB
Feed$FeedThread.class 2KB
Product.class 2KB
Stock.class 2KB
ChatRoomBiz.class 2KB
DatabaseCheckService.class 2KB
Employee.class 2KB
Company.class 2KB
FlexClientConfigService.class 2KB
EmployeeRuntimeRemotingDestination.class 1KB
ConnectionHelper.class 1KB
Person.class 1KB
FlexClientConfigService$Attribute.class 1KB
Feed.class 835B
RoomComparator.class 809B
ConcurrencyException.class 737B
DAOException.class 720B
DAOException.class 712B
Test.class 701B
Feed.class 646B
.classpath 2KB
history.css 371B
history.css 371B
Thumbs.db 1.08MB
Thumbs.db 3KB
treeAssets.fla 64KB
defaultTreeAssets.fla 32KB
4.gif 3KB
5.gif 3KB
6.gif 3KB
9.gif 3KB
12.gif 3KB
15.gif 3KB
19.gif 2KB
10.gif 2KB
3.gif 2KB
16.gif 2KB
1.gif 2KB
20.gif 2KB
8.gif 2KB
13.gif 2KB
7.gif 2KB
17.gif 2KB
18.gif 2KB
11.gif 2KB
14.gif 2KB
2.gif 2KB
refresh.gif 977B
page-first-disabled.gif 925B
page-first.gif 925B
page-last-disabled.gif 923B
page-last.gif 923B
page-prev-disabled.gif 879B
page-prev.gif 879B
page-next.gif 875B
page-next-disabled.gif 875B
grid-split.gif 817B
loading.gif 771B
warning.gif 331B
yahoo-icon.gif 192B
main.html 4KB
main.html 4KB
chat.html 4KB
chat.html 4KB
historyFrame.html 827B
historyFrame.html 827B
hsqldb.jar 684KB
flex-messaging-core.jar 674KB
commons-httpclient-3.1.jar 298KB
commons-httpclient-3.0.1.jar 273KB
fxgutils.jar 256KB
commons-io-1.4.jar 106KB
flex-messaging-common.jar 95KB
flex-messaging-proxy.jar 65KB
commons-logging-1.1.1.jar 59KB
flex-rds-server.jar 53KB
commons-fileupload-1.2.jar 52KB
commons-codec-1.3.jar 46KB
commons-logging.jar 37KB
flex-messaging-opt.jar 20KB
flex-messaging-remoting.jar 18KB
EmployeeDAO.java 9KB
ProductService.java 7KB
CompanyDAO.java 6KB
ProductService.java 5KB
CustomDelayQueueProcessor.java 4KB
ChatRoomService.java 4KB
Feed.java 2KB
Portfolio.java 2KB
Room.java 2KB
共 1175 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
shlingok
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功