帆软帮助文档代码合集。
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

7 years ago
package com.fr.data;
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() {
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();
objArray[1] = new Double(bigAccount.balance());
7 years ago
// 在valueList中加入这一行数据
valueList.add(objArray);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}