Use expected defaults for primitive types in jdbcmapper

This commit is contained in:
Travis Burtrum 2017-06-28 16:00:32 -04:00
parent 8079ae6aa7
commit c1b8cfcf3b
3 changed files with 13 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package com.moparisthebest.jdbc.codegen;
import com.moparisthebest.jdbc.Finishable; import com.moparisthebest.jdbc.Finishable;
import com.moparisthebest.jdbc.ResultSetMapper; import com.moparisthebest.jdbc.ResultSetMapper;
import com.moparisthebest.jdbc.TypeMappingsFactory;
import com.moparisthebest.jdbc.util.ResultSetIterable; import com.moparisthebest.jdbc.util.ResultSetIterable;
import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.ProcessingEnvironment;
@ -171,7 +172,12 @@ public class CompileTimeResultSetMapper {
writeObject(w, keys, returnTypeMirror, cal, reflectionFields); writeObject(w, keys, returnTypeMirror, cal, reflectionFields);
w.write("\t\t\t\treturn "); w.write("\t\t\t\treturn ");
// this does not clean null on purpose, neither does CleaningResultSetMapper // this does not clean null on purpose, neither does CleaningResultSetMapper
clean(w, cleaner).write(";\n\t\t\t} else {\n\t\t\t\treturn null;\n\t\t\t}\n"); clean(w, cleaner).write(";\n\t\t\t} else {\n\t\t\t\treturn ");
if(returnTypeMirror.getKind().isPrimitive())
w.append(TypeMappingsFactory.getInstance().fixNull(typeMirrorToClass(returnTypeMirror)).toString()); // todo: ok, but could be better
else
w.append("null");
w.append(";\n\t\t\t}\n");
} }
private void toResultSetIterable(final Writer w, final String[] keys, final TypeMirror returnTypeMirror, final String cal, final String cleaner, final boolean closePs, final ReflectionFields reflectionFields) throws IOException, ClassNotFoundException { private void toResultSetIterable(final Writer w, final String[] keys, final TypeMirror returnTypeMirror, final String cal, final String cleaner, final boolean closePs, final ReflectionFields reflectionFields) throws IOException, ClassNotFoundException {

View File

@ -48,6 +48,9 @@ public interface PersonDAO extends Closeable {
@JdbcMapper.SQL("UPDATE person SET first_name = {firstName} WHERE person_no = {personNo}") @JdbcMapper.SQL("UPDATE person SET first_name = {firstName} WHERE person_no = {personNo}")
void setFirstNameBlob(@JdbcMapper.Blob String firstName, long personNo) throws SQLException; void setFirstNameBlob(@JdbcMapper.Blob String firstName, long personNo) throws SQLException;
@JdbcMapper.SQL("SELECT person_no FROM person WHERE last_name = {lastName}")
long getPersonNo(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE last_name = {lastName}") @JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE last_name = {lastName}")
ResultSet getPeopleResultSet(String lastName) throws SQLException; ResultSet getPeopleResultSet(String lastName) throws SQLException;

View File

@ -48,6 +48,9 @@ public interface PrestoPersonDAO extends PersonDAO {
@JdbcMapper.SQL("UPDATE person SET first_name = {firstName} WHERE person_no = {personNo}") @JdbcMapper.SQL("UPDATE person SET first_name = {firstName} WHERE person_no = {personNo}")
void setFirstNameBlob(@JdbcMapper.Blob String firstName, long personNo) throws SQLException; void setFirstNameBlob(@JdbcMapper.Blob String firstName, long personNo) throws SQLException;
@JdbcMapper.SQL("SELECT person_no FROM person WHERE last_name = {lastName}")
long getPersonNo(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE last_name = {lastName}") @JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE last_name = {lastName}")
ResultSet getPeopleResultSet(String lastName) throws SQLException; ResultSet getPeopleResultSet(String lastName) throws SQLException;