FileDocCategorySizeDatePackage
ExceptionalTraps.javaAPI DocExample6917Sun Dec 14 22:47:36 GMT 2003oreilly.hcj.exceptions

ExceptionalTraps

public class ExceptionalTraps extends Object implements TableModel
A demonstration of traps associated with exceptions.
author
Robert Simmons jr. (kraythe)
version
$Revision: 1.5 $

Fields Summary
private static final Logger
LOGGER
logging object.
private ArrayList
data
Cache of the data fetched.
private ArrayList
processedOrders
an instance variable used for demo purposes.
private final oreilly.hcj.references.PropertyChangeSupport
propertyChangeSupport
Provides support for property change events.
private String
someProperty
Holds a demo property.
private String
sql
Holds the sql used to fetch the data.
Constructors Summary
Methods Summary
public voidaddTableModelListener(javax.swing.event.TableModelListener listener)

see
javax.swing.table.TableModel

	
public voidbillCreditCard(oreilly.hcj.bankdata.Customer customer)
demo method.

param
customer The customer to operate on.
throws
NullPointerException If the customer is null.

		if (customer == null) {
			throw new NullPointerException();
		}
		System.err.println(customer);
	
public voiddoOrderProcessing()
demo method.

	
public java.lang.ClassgetColumnClass(int column)

see
javax.swing.table.TableModel

		return null;
	
public intgetColumnCount()

see
javax.swing.table.TableModel

		return 0;
	
public java.lang.StringgetColumnName(int column)

see
javax.swing.table.TableModel

		return null;
	
public intgetRowCount()

see
javax.swing.table.TableModel

		return 0;
	
public java.lang.StringgetSomeProperty()
Getter for the property someProperty.

return
The current value of someProperty.

		return someProperty;
	
public java.lang.ObjectgetValueAt(int row, int column)

see
javax.swing.table.TableModel

		return null;
	
public booleanisCellEditable(int row, int column)

see
javax.swing.table.TableModel


	   	 
	        
		return false;
	
public intloadData(java.sql.Connection conn, java.lang.String sql)
Gets data from the the database and caches it for the table model.

param
conn The database connection to use.
param
sql The SQL to use.
return
The result value.
throws
SQLException If there is a SQL error.

		int result = 0;
		Statement stmt = null;
		ResultSet rs = null;
		Object[] record = null;
		this.data = new ArrayList();
		try {
			this.sql = sql;
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			int idx = 0;
			int columnCount = rs.getMetaData()
				                .getColumnCount();
			while (rs.next()) {
				record = new Object[columnCount];
				for (idx = 0; idx < columnCount; idx++) {
					record[idx] = rs.getObject(idx);
				}
				data.add(record);
			}
		} finally {
			if (rs != null) {
				rs.close();
			}
			if (stmt != null) {
				stmt.close();
			}
		}
		return result;
	
public intloadData2(java.sql.Connection conn, java.lang.String sql)
Gets data from the the database and caches it for the table model.

param
conn The database connection to use.
param
sql The SQL to use.
return
The result value.
throws
SQLException If there is a SQL error.

		int result = 0;
		Statement stmt = null;
		ResultSet rs = null;
		Object[] record = null;
		ArrayList temp = new ArrayList();
		try {
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			int idx = 0;
			int columnCount = rs.getMetaData()
				                .getColumnCount();
			while (rs.next()) {
				record = new Object[columnCount];
				for (idx = 0; idx < columnCount; idx++) {
					record[idx] = rs.getObject(idx);
				}
				temp.add(record);
			}
		} finally {
			if (rs != null) {
				rs.close();
			}
			if (stmt != null) {
				stmt.close();
			}
		}
		this.data = temp;
		this.sql = sql;
		return result;
	
public voidprocessOrder(java.lang.Object order, oreilly.hcj.bankdata.Customer customer)
Processes an order.

param
order The order to process.
param
customer The customer to operate on.

		this.processedOrders.add(order);
		doOrderProcessing();
		billCreditCard(customer);
	
public voidrefresh(java.sql.Connection conn)
Refreshes the data in the model using the existing SQL.

param
conn The connection to the database to use.
throws
SQLException If there is a database problem in the refresh.

		loadData(conn, this.sql);
	
public voidremoveTableModelListener(javax.swing.event.TableModelListener arg0)

see
javax.swing.table.TableModel

	
public voidsetSomeProperty(java.lang.String someProperty)
Setter for the property someProperty.

param
someProperty The new value for someProperty.

		final String oldSomeProperty = this.someProperty;
		this.someProperty = someProperty;
		propertyChangeSupport.firePropertyChange("someProperty", oldSomeProperty,
		                                         someProperty);
	
public voidsetSomeProperty2(java.lang.String someProperty)
Setter for the property someProperty.

param
someProperty The new value for someProperty.

		final String oldSomeProperty = this.someProperty;
		this.someProperty = someProperty;
		try {
			propertyChangeSupport.firePropertyChange("someProperty", oldSomeProperty,
			                                         someProperty);
		} catch (final Exception ex) {
			LOGGER.error("Exception in Listener", ex);
		}
	
public voidsetValueAt(java.lang.Object value, int row, int column)

see
javax.swing.table.TableModel