-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2957 from harawata/gh/2956
Registered type handler should be used for anonymous enum
- Loading branch information
Showing
9 changed files
with
139 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/test/java/org/apache/ibatis/submitted/enum_with_method/Mood.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2009-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.ibatis.submitted.enum_with_method; | ||
|
||
public enum Mood { | ||
GOOD(1) { | ||
@Override | ||
public String getMessage() { | ||
return "Yeehaw"; | ||
} | ||
}, | ||
BAD(2) { | ||
@Override | ||
public String getMessage() { | ||
return "whatevs"; | ||
} | ||
}; | ||
|
||
private int value; | ||
|
||
private Mood(int value) { | ||
this.value = value; | ||
} | ||
|
||
public int getValue() { | ||
return value; | ||
} | ||
|
||
public static Mood fromValue(int i) { | ||
for (Mood t : values()) { | ||
if (t.value == i) { | ||
return t; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown value for Mood: " + i); | ||
} | ||
|
||
public abstract String getMessage(); | ||
} |
49 changes: 49 additions & 0 deletions
49
src/test/java/org/apache/ibatis/submitted/enum_with_method/MoodTypeTypeHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2009-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.ibatis.submitted.enum_with_method; | ||
|
||
import java.sql.CallableStatement; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
import org.apache.ibatis.type.BaseTypeHandler; | ||
import org.apache.ibatis.type.JdbcType; | ||
|
||
public class MoodTypeTypeHandler extends BaseTypeHandler<Mood> { | ||
|
||
@Override | ||
public void setNonNullParameter(PreparedStatement ps, int i, Mood parameter, JdbcType jdbcType) throws SQLException { | ||
ps.setInt(i, parameter.getValue()); | ||
} | ||
|
||
@Override | ||
public Mood getNullableResult(ResultSet rs, String columnName) throws SQLException { | ||
return Mood.fromValue(rs.getInt(columnName)); | ||
} | ||
|
||
@Override | ||
public Mood getNullableResult(ResultSet rs, int columnIndex) throws SQLException { | ||
return Mood.fromValue(rs.getInt(columnIndex)); | ||
} | ||
|
||
@Override | ||
public Mood getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { | ||
return Mood.fromValue(cs.getInt(columnIndex)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters