001// Copyright 2004, 2005 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.tapestry.contrib.table.model.sql; 016 017import java.sql.ResultSet; 018import java.sql.SQLException; 019 020import org.apache.commons.logging.Log; 021import org.apache.commons.logging.LogFactory; 022import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn; 023 024/** 025 * 026 * @author mindbridge 027 */ 028public class SqlTableColumn extends SimpleTableColumn 029{ 030 private static final long serialVersionUID = 1L; 031 private static final Log LOG = LogFactory.getLog(SqlTableColumn.class); 032 033 /** 034 * Creates an SqlTableColumn 035 * @param strSqlField the identifying name of the column and the SQL field it refers to 036 * @param strDisplayName the display name of the column 037 */ 038 public SqlTableColumn(String strSqlField, String strDisplayName) 039 { 040 super(strSqlField, strDisplayName); 041 } 042 043 /** 044 * Creates an SqlTableColumn 045 * @param strSqlField the identifying name of the column and the SQL field it refers to 046 * @param strDisplayName the display name of the column 047 * @param bSortable whether the column is sortable 048 */ 049 public SqlTableColumn( 050 String strSqlField, 051 String strDisplayName, 052 boolean bSortable) 053 { 054 super(strSqlField, strDisplayName, bSortable); 055 } 056 057 /** 058 * @see org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn#getColumnValue(Object) 059 */ 060 public Object getColumnValue(Object objRow) 061 { 062 try 063 { 064 ResultSet objRS = (ResultSet) objRow; 065 String strColumnName = getColumnName(); 066 Object objValue = objRS.getObject(strColumnName); 067 if (objValue == null) 068 objValue = ""; 069 return objValue; 070 } 071 catch (SQLException e) 072 { 073 LOG.error("Cannot get the value for column: " + getColumnName(), e); 074 return ""; 075 } 076 } 077 078}