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 TorqueBasicGroup 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 BaseTorqueBasicGroupRecordMapper implements RecordMapper<TorqueBasicGroup> 025{ 026 /** Serial version */ 027 private static final long serialVersionUID = 1636029263703L; 028 029 /** The class log. */ 030 private static Log log 031 = LogFactory.getLog(BaseTorqueBasicGroupRecordMapper.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_GROUP table. 053 */ 054 public TorqueBasicGroup processRow( 055 ResultSet resultSet, 056 int offset, 057 Criteria criteria) 058 throws TorqueException 059 { 060 TorqueBasicGroup torqueBasicGroup = new TorqueBasicGroup(); 061 062 try 063 { 064 torqueBasicGroup.setLoading(true); 065 if (criteria == null) 066 { 067 torqueBasicGroup.setEntityId( 068 getEntityId(resultSet, offset + 1)); 069 torqueBasicGroup.setEntityName( 070 getEntityName(resultSet, offset + 2)); 071 } 072 else 073 { 074 // try to get columns to be mapped 075 // from criteria's select columns 076 boolean columnMapped = false; 077 int totalOffset = offset + 1; 078 List<Column> selectColumns = criteria.getSelectColumns(); 079 List<Column> columnsWithoutOffset = selectColumns.subList( 080 offset, 081 selectColumns.size()); 082 for (Column column : columnsWithoutOffset) 083 { 084 if (BaseTorqueBasicGroupPeer.GROUP_ID.getSqlExpression().equals( 085 column.getSqlExpression())) 086 { 087 torqueBasicGroup.setEntityId( 088 getEntityId(resultSet, totalOffset)); 089 columnMapped = true; 090 } 091 else if (BaseTorqueBasicGroupPeer.GROUP_NAME.getSqlExpression().equals( 092 column.getSqlExpression())) 093 { 094 torqueBasicGroup.setEntityName( 095 getEntityName(resultSet, totalOffset)); 096 columnMapped = true; 097 } 098 totalOffset++; 099 } 100 if (!columnMapped) 101 { 102 log.debug("no columns to map found in criteria, " 103 + "returning null"); 104 return null; 105 } 106 } 107 torqueBasicGroup.setNew(false); 108 torqueBasicGroup.setModified(false); 109 } 110 finally 111 { 112 torqueBasicGroup.setLoading(false); 113 } 114 return torqueBasicGroup; 115 } 116 117 /** 118 * Reads the value of the <code>columnIndex</code>'th column 119 * in the <code>resultSet</code> so that it can be used to set 120 * the field entityId in TorqueBasicGroup. 121 * 122 * @param resultSet the ResultSet to read from, not null. 123 * @param columnIndex the index in the resultSet which should be read. 124 * 125 * @return the content of the column. 126 * 127 * @throws SQLException if a problem occurs when reading 128 * from the resultSet. 129 */ 130 protected Integer getEntityId( 131 ResultSet resultSet, 132 int columnIndex) 133 throws TorqueException 134 { 135 try 136 { 137 Integer value = resultSet.getInt(columnIndex); 138 if (resultSet.wasNull()) 139 { 140 value = null; 141 } 142 return value; 143 } 144 catch (SQLException e) 145 { 146 throw new TorqueException(e); 147 } 148 } 149 /** 150 * Reads the value of the <code>columnIndex</code>'th column 151 * in the <code>resultSet</code> so that it can be used to set 152 * the field entityName in TorqueBasicGroup. 153 * 154 * @param resultSet the ResultSet to read from, not null. 155 * @param columnIndex the index in the resultSet which should be read. 156 * 157 * @return the content of the column. 158 * 159 * @throws SQLException if a problem occurs when reading 160 * from the resultSet. 161 */ 162 protected String getEntityName( 163 ResultSet resultSet, 164 int columnIndex) 165 throws TorqueException 166 { 167 try 168 { 169 return resultSet.getString(columnIndex); 170 } 171 catch (SQLException e) 172 { 173 throw new TorqueException(e); 174 } 175 } 176 177}