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    
015    package org.apache.tapestry.contrib.table.model.sql;
016    
017    import org.apache.commons.logging.Log;
018    import org.apache.commons.logging.LogFactory;
019    import org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn;
020    
021    import java.sql.ResultSet;
022    import java.sql.SQLException;
023    
024    /**
025     * @author mindbridge
026     */
027    public class SqlTableColumn extends SimpleTableColumn
028    {
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         * 
036         * @param strSqlField
037         *            the identifying name of the column and the SQL field it refers
038         *            to
039         * @param strDisplayName
040         *            the display name of the column
041         */
042        public SqlTableColumn(String strSqlField, String strDisplayName)
043        {
044            super(strSqlField, strDisplayName);
045        }
046    
047        /**
048         * Creates an SqlTableColumn.
049         * 
050         * @param strSqlField
051         *            the identifying name of the column and the SQL field it refers
052         *            to
053         * @param strDisplayName
054         *            the display name of the column
055         * @param bSortable
056         *            whether the column is sortable
057         */
058        public SqlTableColumn(String strSqlField, String strDisplayName,
059                boolean bSortable)
060        {
061            super(strSqlField, strDisplayName, bSortable);
062        }
063    
064        /**
065         * @see org.apache.tapestry.contrib.table.model.simple.SimpleTableColumn#getColumnValue(Object)
066         */
067        public Object getColumnValue(Object objRow)
068        {
069            try
070            {
071                ResultSet objRS = (ResultSet) objRow;
072                String strColumnName = getColumnName();
073                Object objValue = objRS.getObject(strColumnName);
074    
075                if (objValue == null)
076                    objValue = "";
077                
078                return objValue;
079            }
080            catch (SQLException e)
081            {
082                LOG.error("Cannot get the value for column: " + getColumnName(), e);
083                return "";
084            }
085        }
086    
087    }