001package org.apache.fulcrum.security.torque.om;
002
003import java.sql.ResultSet;
004import java.sql.SQLException;
005import java.util.List;
006
007import org.apache.commons.logging.Log;
008import org.apache.commons.logging.LogFactory;
009import org.apache.torque.Column;
010import org.apache.torque.TorqueException;
011import org.apache.torque.criteria.Criteria;
012import org.apache.torque.om.mapper.RecordMapper;
013
014
015/**
016 * Maps ResultSet rows into TorqueBasicUser objects.
017 *
018 * The skeleton for this class was autogenerated by Torque on:
019 *
020 * [Thu Nov 04 13:34:23 CET 2021]
021 *
022 */
023@SuppressWarnings("unused")
024public class BaseTorqueBasicUserRecordMapper implements RecordMapper<TorqueBasicUser>
025{
026    /** Serial version */
027    private static final long serialVersionUID = 1636029263709L;
028
029    /** The class log. */
030    private static Log log
031            = LogFactory.getLog(BaseTorqueBasicUserRecordMapper.class);
032
033    /**
034     * Constructs the object from the current row in the resultSet.
035     *
036     * @param resultSet the resultSet to operate on, already pointing
037     *        to the correct row. Not null.
038     * @param offset a possible offset in the columns to be considered
039     *        (if previous columns contain other objects),
040     *        or 0 for no offset.
041     * @param criteria The criteria which created the result set.
042     *        If set, the attributes to set in the data object
043     *        are determined from the select columns in the criteria;
044     *        if no matching column can be found, null is returned.
045     *        If not set, all of the table's columns are read from the
046     *        result set in the order defined in the table definition.
047     *
048     * @return the mapped object, not null.
049     *
050     * @throws TorqueException when reading fields from the RecordSet fails
051     *         or if a Criteria is passed which contains select columns other
052     *         than the columns in the FULCRUM_BASIC_USER table.
053     */
054    public TorqueBasicUser processRow(
055                ResultSet resultSet,
056                int offset,
057                Criteria criteria)
058            throws TorqueException
059    {
060        TorqueBasicUser torqueBasicUser = new TorqueBasicUser();
061
062        try 
063        {
064            torqueBasicUser.setLoading(true);
065            if (criteria == null)
066            {
067                torqueBasicUser.setEntityId(
068                        getEntityId(resultSet, offset + 1));
069                torqueBasicUser.setEntityName(
070                        getEntityName(resultSet, offset + 2));
071                torqueBasicUser.setPassword(
072                        getPassword(resultSet, offset + 3));
073            }
074            else
075            {
076                // try to get columns to be mapped
077                // from criteria's select columns
078                boolean columnMapped = false;
079                int totalOffset = offset + 1;
080                List<Column> selectColumns = criteria.getSelectColumns();
081                List<Column> columnsWithoutOffset = selectColumns.subList(
082                        offset, 
083                        selectColumns.size());
084                for (Column column : columnsWithoutOffset)
085                {
086                    if (BaseTorqueBasicUserPeer.USER_ID.getSqlExpression().equals(
087                            column.getSqlExpression()))
088                    {
089                        torqueBasicUser.setEntityId(
090                            getEntityId(resultSet, totalOffset));
091                        columnMapped = true;
092                    }
093                    else if (BaseTorqueBasicUserPeer.LOGIN_NAME.getSqlExpression().equals(
094                            column.getSqlExpression()))
095                    {
096                        torqueBasicUser.setEntityName(
097                            getEntityName(resultSet, totalOffset));
098                        columnMapped = true;
099                    }
100                    else if (BaseTorqueBasicUserPeer.PASSWORD_VALUE.getSqlExpression().equals(
101                            column.getSqlExpression()))
102                    {
103                        torqueBasicUser.setPassword(
104                            getPassword(resultSet, totalOffset));
105                        columnMapped = true;
106                    }
107                    totalOffset++;
108                }
109                if (!columnMapped)
110                {
111                    log.debug("no columns to map found in criteria, "
112                        + "returning null");
113                    return null;
114                }
115            }
116            torqueBasicUser.setNew(false);
117            torqueBasicUser.setModified(false);
118        }
119        finally
120        {
121            torqueBasicUser.setLoading(false);
122        }
123        return torqueBasicUser;
124    }
125
126    /**
127     * Reads the value of the <code>columnIndex</code>'th column
128     * in the <code>resultSet</code> so that it can be used to set
129     * the field entityId in TorqueBasicUser.
130     *
131     * @param resultSet the ResultSet to read from, not null.
132     * @param columnIndex the index in the resultSet which should be read.
133     *
134     * @return the content of the column.
135     *
136     * @throws SQLException if a problem occurs when reading
137     *         from the resultSet.
138     */
139    protected Integer getEntityId(
140                ResultSet resultSet,
141                int columnIndex)
142            throws TorqueException
143    {
144        try
145        {
146            Integer value = resultSet.getInt(columnIndex);
147            if (resultSet.wasNull())
148            {
149                value = null;
150            }
151            return value;
152        }
153        catch (SQLException e)
154        {
155            throw new TorqueException(e);
156        }
157    }
158    /**
159     * Reads the value of the <code>columnIndex</code>'th column
160     * in the <code>resultSet</code> so that it can be used to set
161     * the field entityName in TorqueBasicUser.
162     *
163     * @param resultSet the ResultSet to read from, not null.
164     * @param columnIndex the index in the resultSet which should be read.
165     *
166     * @return the content of the column.
167     *
168     * @throws SQLException if a problem occurs when reading
169     *         from the resultSet.
170     */
171    protected String getEntityName(
172                ResultSet resultSet,
173                int columnIndex)
174            throws TorqueException
175    {
176        try
177        {
178            return resultSet.getString(columnIndex);
179        }
180        catch (SQLException e)
181        {
182            throw new TorqueException(e);
183        }
184    }
185    /**
186     * Reads the value of the <code>columnIndex</code>'th column
187     * in the <code>resultSet</code> so that it can be used to set
188     * the field password in TorqueBasicUser.
189     *
190     * @param resultSet the ResultSet to read from, not null.
191     * @param columnIndex the index in the resultSet which should be read.
192     *
193     * @return the content of the column.
194     *
195     * @throws SQLException if a problem occurs when reading
196     *         from the resultSet.
197     */
198    protected String getPassword(
199                ResultSet resultSet,
200                int columnIndex)
201            throws TorqueException
202    {
203        try
204        {
205            return resultSet.getString(columnIndex);
206        }
207        catch (SQLException e)
208        {
209            throw new TorqueException(e);
210        }
211    }
212
213}