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 TurbineUserGroupRole 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 BaseTurbineUserGroupRoleRecordMapper implements RecordMapper<TurbineUserGroupRole>
025{
026    /** Serial version */
027    private static final long serialVersionUID = 1636029263809L;
028
029    /** The class log. */
030    private static Log log
031            = LogFactory.getLog(BaseTurbineUserGroupRoleRecordMapper.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 TURBINE_USER_GROUP_ROLE table.
053     */
054    public TurbineUserGroupRole processRow(
055                ResultSet resultSet,
056                int offset,
057                Criteria criteria)
058            throws TorqueException
059    {
060        TurbineUserGroupRole turbineUserGroupRole = new TurbineUserGroupRole();
061
062        try 
063        {
064            turbineUserGroupRole.setLoading(true);
065            if (criteria == null)
066            {
067                turbineUserGroupRole.setUserId(
068                        getUserId(resultSet, offset + 1));
069                turbineUserGroupRole.setGroupId(
070                        getGroupId(resultSet, offset + 2));
071                turbineUserGroupRole.setRoleId(
072                        getRoleId(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 (BaseTurbineUserGroupRolePeer.USER_ID.getSqlExpression().equals(
087                            column.getSqlExpression()))
088                    {
089                        turbineUserGroupRole.setUserId(
090                            getUserId(resultSet, totalOffset));
091                        columnMapped = true;
092                    }
093                    else if (BaseTurbineUserGroupRolePeer.GROUP_ID.getSqlExpression().equals(
094                            column.getSqlExpression()))
095                    {
096                        turbineUserGroupRole.setGroupId(
097                            getGroupId(resultSet, totalOffset));
098                        columnMapped = true;
099                    }
100                    else if (BaseTurbineUserGroupRolePeer.ROLE_ID.getSqlExpression().equals(
101                            column.getSqlExpression()))
102                    {
103                        turbineUserGroupRole.setRoleId(
104                            getRoleId(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            turbineUserGroupRole.setNew(false);
117            turbineUserGroupRole.setModified(false);
118        }
119        finally
120        {
121            turbineUserGroupRole.setLoading(false);
122        }
123        return turbineUserGroupRole;
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 userId in TurbineUserGroupRole.
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 getUserId(
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 groupId in TurbineUserGroupRole.
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 Integer getGroupId(
172                ResultSet resultSet,
173                int columnIndex)
174            throws TorqueException
175    {
176        try
177        {
178            Integer value = resultSet.getInt(columnIndex);
179            if (resultSet.wasNull())
180            {
181                value = null;
182            }
183            return value;
184        }
185        catch (SQLException e)
186        {
187            throw new TorqueException(e);
188        }
189    }
190    /**
191     * Reads the value of the <code>columnIndex</code>'th column
192     * in the <code>resultSet</code> so that it can be used to set
193     * the field roleId in TurbineUserGroupRole.
194     *
195     * @param resultSet the ResultSet to read from, not null.
196     * @param columnIndex the index in the resultSet which should be read.
197     *
198     * @return the content of the column.
199     *
200     * @throws SQLException if a problem occurs when reading
201     *         from the resultSet.
202     */
203    protected Integer getRoleId(
204                ResultSet resultSet,
205                int columnIndex)
206            throws TorqueException
207    {
208        try
209        {
210            Integer value = resultSet.getInt(columnIndex);
211            if (resultSet.wasNull())
212            {
213                value = null;
214            }
215            return value;
216        }
217        catch (SQLException e)
218        {
219            throw new TorqueException(e);
220        }
221    }
222
223}