/* 64 */ this.log = Logger.getLogger(getClass().getName() + "." + manager.getMetaData().getName());
/* */ }
/* */
/* */ public Collection execute(JDBCCMRFieldBridge cmrField, Object pk)
/* */ {
/* 72 */ JDBCCMRFieldBridge relatedCMRField = (JDBCCMRFieldBridge)cmrField.getRelatedCMRField();
/* */
/* 75 */ ReadAheadCache readAheadCache = this.manager.getReadAheadCache();
/* 76 */ ReadAheadCache relatedReadAheadCache = cmrField.getRelatedManager().getReadAheadCache();
/* */
/* 79 */ ReadAheadCache.EntityReadAheadInfo info = readAheadCache.getEntityReadAheadInfo(pk);
/* 80 */ List loadKeys = info.getLoadKeys();
/* */
/* 82 */ Connection con = null;
/* 83 */ PreparedStatement ps = null;
/* 84 */ ResultSet rs = null;
/* */ try
/* */ {
/* 88 */ boolean[] preloadMask = getPreloadMask(cmrField);
/* 89 */ String sql = getSQL(cmrField, preloadMask, loadKeys.size());
/* */
/* 92 */ if (this.log.isDebugEnabled()) {
/* 93 */ this.log.debug("load relation SQL: " + sql);
/* */ }
/* */
/* 96 */ con = cmrField.getDataSource().getConnection();
/* 97 */ ps = con.prepareStatement(sql.toString());
/* */
/* 100 */ if (this.entity.getFetchSize() > 0)
/* */ {
/* 102 */ ps.setFetchSize(this.entity.getFetchSize());
/* */ }
/* */
/* 106 */ JDBCCMPFieldBridge[] myKeyFields = getMyKeyFields(cmrField);
/* 107 */ JDBCCMPFieldBridge[] relatedKeyFields = getRelatedKeyFields(cmrField);
/* */
/* 110 */ int paramIndex = 1;
/* 111 */ for (int i = 0; i < loadKeys.size(); i++)
/* */ {
/* 113 */ Object key = loadKeys.get(i);
/* 114 */ for (int j = 0; j < myKeyFields.length; j++) {
/* 115 */ paramIndex = myKeyFields[j].setPrimaryKeyParameters(ps, paramIndex, key);
/* */ }
/* */ }
/* */
/* 119 */ rs = ps.executeQuery();
/* */
/* 122 */ Map resultsMap = new HashMap(loadKeys.size());
/* 123 */ for (int i = 0; i < loadKeys.size(); i++)
/* */ {
/* 125 */ resultsMap.put(loadKeys.get(i), new ArrayList());
/* */ }
/* */
/* 129 */ Object[] ref = new Object[1];
/* 130 */ while (rs.next())
/* */ {
/* 133 */ int index = 1;
/* */
/* 136 */ ref[0] = null;
/* */
/* 139 */ Object loadedPk = pk;
/* 140 */ if (loadKeys.size() > 1)
/* */ {
/* 143 */ for (int i = 0; i < myKeyFields.length; i++)
/* */ {
/* 145 */ index = myKeyFields[i].loadPrimaryKeyResults(rs, index, ref);
/* 146 */ if (ref[0] == null)
/* */ {
/* */ break;
/* */ }
/* */ }
/* 151 */ loadedPk = ref[0];
/* */ }
/* */
/* 155 */ ref[0] = null;
/* 156 */ for (int i = 0; i < relatedKeyFields.length; i++)
/* */ {
/* 158 */ index = relatedKeyFields[i].loadPrimaryKeyResults(rs, index, ref);
/* 159 */ if (ref[0] == null)
/* */ {
/* */ break;
/* */ }
/* */ }
/* 164 */ Object loadedFk = ref[0];
/* */
/* 166 */ if (loadedFk != null)
/* */ {
/* 169 */ List results = (List)resultsMap.get(loadedPk);
/* 170 */ results.add(loadedFk);
/* */
/* 174 */ if (relatedCMRField.isSingleValued())
/* */ {
/* 176 */ relatedReadAheadCache.addPreloadData(loadedFk, relatedCMRField, Collections.singletonList(loadedPk));
/* */ }
/* */
/* 183 */ if (preloadMask != null)
/* */ {
/* 185 */ JDBCFieldBridge[] relatedFields = cmrField.getRelatedJDBCEntity().getTableFields();
/* 186 */ for (int i = 0; i < relatedFields.length; i++)
/* */ {
/* 188 */ if (preloadMask[i] == 0)
/* */ continue;
/* 190 */ JDBCFieldBridge field = relatedFields[i];
/* 191 */ ref[0] = null;
/* */
/* 194 */ index = field.loadArgumentResults(rs, index, ref);
/* 195 */ relatedReadAheadCache.addPreloadData(loadedFk, field, ref[0]);
/* */ }
/* */ }
/* */
/* */ }
/* */
/* */ }
/* */
/* 203 */ JDBCReadAheadMetaData readAhead = relatedCMRField.getReadAhead();
/* 204 */ for (iter = resultsMap.keySet().iterator(); iter.hasNext(); )
/* */ {
/* 206 */ Object key = iter.next();
/* */
/* 209 */ List results = (List)resultsMap.get(key);