View Javadoc
1   /*
2    *    Copyright 2009-2024 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.apache.ibatis.executor.resultset;
17  
18  import java.util.Objects;
19  
20  import org.apache.ibatis.mapping.ResultMapping;
21  
22  /**
23   * A unique identifier for a pending constructor creation, prefix is used to distinguish between equal result maps for
24   * different columns
25   *
26   * @author Willie Scholtz
27   */
28  final class PendingCreationKey {
29    private final String resultMapId;
30    private final String constructorColumnPrefix;
31  
32    PendingCreationKey(ResultMapping constructorMapping) {
33      this.resultMapId = constructorMapping.getNestedResultMapId();
34      this.constructorColumnPrefix = constructorMapping.getColumnPrefix();
35    }
36  
37    String getConstructorColumnPrefix() {
38      return constructorColumnPrefix;
39    }
40  
41    String getResultMapId() {
42      return resultMapId;
43    }
44  
45    @Override
46    public boolean equals(Object o) {
47      if (this == o)
48        return true;
49      if (o == null || getClass() != o.getClass())
50        return false;
51  
52      PendingCreationKey that = (PendingCreationKey) o;
53      return Objects.equals(resultMapId, that.resultMapId)
54          && Objects.equals(constructorColumnPrefix, that.constructorColumnPrefix);
55    }
56  
57    @Override
58    public int hashCode() {
59      return Objects.hash(resultMapId, constructorColumnPrefix);
60    }
61  
62    @Override
63    public String toString() {
64      return "PendingCreationKey{" + "resultMapId='" + resultMapId + '\'' + ", constructorColumnPrefix='"
65          + constructorColumnPrefix + '\'' + '}';
66    }
67  }