001    /*
002     @license.text@
003      */
004    package biz.hammurapi.sql;
005    
006    import java.sql.ResultSet;
007    import java.sql.SQLException;
008    
009    import biz.hammurapi.convert.CompositeConverter;
010    import biz.hammurapi.convert.Converter;
011    
012    /**
013     * Base class for SQLC generated projectors.
014     * @author Pavel Vlasov
015     *
016     * @version $Revision: 1.3 $
017     */
018    public class FirstColumnSmartProjector implements Projector {
019        private Converter converter;
020            private Class targetClass;
021    
022            public Object project(ResultSet rs) throws SQLException {
023                    Object ret;
024                    if (targetClass==null) {
025                            ret = rs.getObject(1);
026                    } else {
027                            ret=CompositeConverter.getDefaultConverter().convert(rs.getObject(1), targetClass, false);
028                    }
029                    
030                    if (converter==null) {
031                            return ret;
032                    }
033                    
034                    return converter.convert(ret);
035        }
036        
037        public FirstColumnSmartProjector(Class targetClass, Converter converter) {
038            this.converter=converter;
039            this.targetClass=targetClass;
040        }       
041    }