forked from demo/example
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.1 KiB
63 lines
2.1 KiB
7 years ago
|
package com.fr.data;
|
||
6 years ago
|
import javax.naming.*;
|
||
|
import java.util.*;
|
||
|
import examples.ejb.ejb20.basic.beanManaged.*;
|
||
7 years ago
|
public class DataModelDemo extends AbstractTableData {
|
||
|
private String[] columnNames;
|
||
|
private ArrayList valueList = null;
|
||
|
public DataModelDemo() {
|
||
6 years ago
|
String[] columnNames = { "Name", "Score" };
|
||
7 years ago
|
this.columnNames = columnNames;
|
||
|
}
|
||
|
// 实现其他四个方法
|
||
|
public int getColumnCount() {
|
||
|
return columnNames.length;
|
||
|
}
|
||
|
public String getColumnName(int columnIndex) {
|
||
|
return columnNames[columnIndex];
|
||
|
}
|
||
|
public int getRowCount() {
|
||
|
init();
|
||
|
return valueList.size();
|
||
|
}
|
||
|
public Object getValueAt(int rowIndex, int columnIndex) {
|
||
|
init();
|
||
|
return ((Object[]) valueList.get(rowIndex))[columnIndex];
|
||
|
}
|
||
|
// 准备数据
|
||
|
public void init() {
|
||
|
// 确保只被执行一次
|
||
|
if (valueList != null) {
|
||
|
return;
|
||
|
}
|
||
|
// 保存得到的结果集
|
||
|
valueList = new ArrayList();
|
||
|
Context ctx = null;
|
||
|
Account ac = null;
|
||
|
AccountHome home = null;
|
||
|
try {
|
||
|
// Contact the AccountBean container (the "AccountHome") through
|
||
|
// JNDI.
|
||
|
ctx = new InitialContext();
|
||
|
home = (AccountHome) ctx
|
||
|
.lookup("java:/comp/env/BeanManagedAccountEJB");
|
||
|
double balanceGreaterThan = 100;
|
||
|
Collection col = home.findBigAccounts(balanceGreaterThan);
|
||
|
if (col != null) {
|
||
|
// 用对象保存数据
|
||
|
Object[] objArray = null;
|
||
|
Iterator iter = col.iterator();
|
||
|
while (iter.hasNext()) {
|
||
|
Account bigAccount = (Account) iter.next();
|
||
|
objArray = new Object[2];
|
||
|
objArray[0] = bigAccount.getPrimaryKey();
|
||
6 years ago
|
objArray[1] = new Double(bigAccount.balance());
|
||
7 years ago
|
// 在valueList中加入这一行数据
|
||
|
valueList.add(objArray);
|
||
|
}
|
||
|
}
|
||
|
} catch (Exception ex) {
|
||
|
ex.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
}
|