mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-11-21 16:45:02 -05:00
Fix jdbcmapper enums when being compiled in same run as generated code
This commit is contained in:
parent
391fbc6b97
commit
4c8c848a1f
@ -35,7 +35,7 @@ import static com.moparisthebest.jdbc.codegen.JdbcMapperProcessor.typeMirrorToCl
|
||||
public class CompileTimeResultSetMapper {
|
||||
|
||||
public final Types types;
|
||||
public final TypeMirror collectionType, mapType, mapCollectionType, iteratorType, listIteratorType, finishableType, resultSetType, resultSetIterableType, byteArrayType;
|
||||
public final TypeMirror collectionType, mapType, mapCollectionType, iteratorType, listIteratorType, finishableType, resultSetType, resultSetIterableType, byteArrayType, enumType;
|
||||
//IFJAVA8_START
|
||||
public final TypeMirror streamType;
|
||||
//IFJAVA8_END
|
||||
@ -58,6 +58,8 @@ public class CompileTimeResultSetMapper {
|
||||
|
||||
byteArrayType = types.getArrayType(types.getPrimitiveType(TypeKind.BYTE));
|
||||
|
||||
enumType = types.getDeclaredType(elements.getTypeElement(Enum.class.getCanonicalName()), types.getWildcardType(null, null));
|
||||
|
||||
//IFJAVA8_START
|
||||
streamType = types.getDeclaredType(elements.getTypeElement(Stream.class.getCanonicalName()), types.getWildcardType(null, null));
|
||||
//IFJAVA8_END
|
||||
|
@ -438,12 +438,11 @@ public class CompileTimeRowToObjectMapper {
|
||||
java.append("ret.finish(rs);\n");
|
||||
}
|
||||
|
||||
public static int getTypeId(TypeMirror classType) {
|
||||
public int getTypeId(TypeMirror classType) {
|
||||
try {
|
||||
return _tmf.getTypeId(typeMirrorToClass(classType));
|
||||
} catch (ClassNotFoundException e) {
|
||||
// todo: what about enums?
|
||||
return TypeMappingsFactory.TYPE_UNKNOWN;
|
||||
return rsm.types.isAssignable(classType, rsm.enumType) ? TypeMappingsFactory.TYPE_ENUM : TypeMappingsFactory.TYPE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,6 +211,21 @@ public interface PersonDAO extends JdbcMapper {
|
||||
@JdbcMapper.SQL("SELECT first_name AS M_PERSON_FIRST_NAME FROM person WHERE person_no = {personNo}")
|
||||
CaseSensitivePerson getCaseSensitivePerson(long personNo);
|
||||
|
||||
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE person_no = {personNo}")
|
||||
SameClassPathEnumPerson getSameClassPathEnumPerson(long personNo) throws SQLException;
|
||||
|
||||
@JdbcMapper.SQL("SELECT first_name FROM person WHERE person_no = {personNo}")
|
||||
SameClassPathEnumPerson getSameClassPathEnumPersonConstructor(long personNo) throws SQLException;
|
||||
|
||||
@JdbcMapper.SQL("SELECT first_name FROM person WHERE person_no = {personNo}")
|
||||
SameClassPathEnumPerson.FirstName getSameClassPathFirstNameEnum(long personNo) throws SQLException;
|
||||
|
||||
@JdbcMapper.SQL("SELECT str_val as first_name, str_val as last_name FROM val WHERE val_no = 4")
|
||||
SameClassPathEnumPerson getSameClassPathEnumPersonNull() throws SQLException;
|
||||
|
||||
@JdbcMapper.SQL("SELECT str_val FROM val WHERE val_no = 4")
|
||||
SameClassPathEnumPerson.FirstName getSameClassPathEnumNull() throws SQLException;
|
||||
|
||||
//IFJAVA8_START
|
||||
|
||||
@JdbcMapper.SQL("SELECT birth_date FROM person WHERE person_no = {personNo}")
|
||||
|
@ -0,0 +1,67 @@
|
||||
package com.moparisthebest.jdbc.codegen;
|
||||
|
||||
import com.moparisthebest.jdbc.dto.Person;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class SameClassPathEnumPerson implements Person {
|
||||
|
||||
public enum FirstName {
|
||||
First,
|
||||
Second,
|
||||
Third,
|
||||
}
|
||||
|
||||
public FirstName firstName;
|
||||
public String lastName;
|
||||
|
||||
public SameClassPathEnumPerson() {
|
||||
}
|
||||
|
||||
public SameClassPathEnumPerson(final FirstName firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPersonNo() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getBirthDate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstName() {
|
||||
return firstName.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setFirstName(final FirstName firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public void setLastName(final String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof SameClassPathEnumPerson)) return false;
|
||||
|
||||
final SameClassPathEnumPerson that = (SameClassPathEnumPerson) o;
|
||||
|
||||
return firstName == that.firstName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return firstName != null ? firstName.hashCode() : 0;
|
||||
}
|
||||
}
|
@ -211,6 +211,21 @@ public interface PrestoPersonDAO extends PersonDAO {
|
||||
@JdbcMapper.SQL("SELECT first_name AS M_PERSON_FIRST_NAME FROM person WHERE person_no = {personNo}")
|
||||
CaseSensitivePerson getCaseSensitivePerson(long personNo);
|
||||
|
||||
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE person_no = {personNo}")
|
||||
SameClassPathEnumPerson getSameClassPathEnumPerson(long personNo) throws SQLException;
|
||||
|
||||
@JdbcMapper.SQL("SELECT first_name FROM person WHERE person_no = {personNo}")
|
||||
SameClassPathEnumPerson getSameClassPathEnumPersonConstructor(long personNo) throws SQLException;
|
||||
|
||||
@JdbcMapper.SQL("SELECT first_name FROM person WHERE person_no = {personNo}")
|
||||
SameClassPathEnumPerson.FirstName getSameClassPathFirstNameEnum(long personNo) throws SQLException;
|
||||
|
||||
@JdbcMapper.SQL("SELECT str_val as first_name, str_val as last_name FROM val WHERE val_no = 4")
|
||||
SameClassPathEnumPerson getSameClassPathEnumPersonNull() throws SQLException;
|
||||
|
||||
@JdbcMapper.SQL("SELECT str_val FROM val WHERE val_no = 4")
|
||||
SameClassPathEnumPerson.FirstName getSameClassPathEnumNull() throws SQLException;
|
||||
|
||||
//IFJAVA8_START
|
||||
|
||||
@JdbcMapper.SQL("SELECT birth_date FROM person WHERE person_no = {personNo}")
|
||||
|
Loading…
Reference in New Issue
Block a user