Add support for returning ResultSet to jdbcmapper
This commit is contained in:
parent
dca6249667
commit
220a26c334
|
@ -132,7 +132,10 @@ public class CompileTimeResultSetMapper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//IFJAVA8_END
|
//IFJAVA8_END
|
||||||
else {
|
else if(types.isAssignable(returnTypeMirror, resultSetType)) {
|
||||||
|
toResultSet(w, closePs);
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
toObject(w, keys, returnTypeMirror, cal, cleaner, reflectionFields);
|
toObject(w, keys, returnTypeMirror, cal, cleaner, reflectionFields);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -154,6 +157,15 @@ public class CompileTimeResultSetMapper {
|
||||||
getRowMapper(keys, returnTypeMirror, resultSetName, cal, null, null, reflectionFields).gen(w, returnTypeMirror.toString());
|
getRowMapper(keys, returnTypeMirror, resultSetName, cal, null, null, reflectionFields).gen(w, returnTypeMirror.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void toResultSet(final Writer w, final boolean closePs) throws IOException {
|
||||||
|
w.append("\t\t\treturn ");
|
||||||
|
if(closePs)
|
||||||
|
w.append("new com.moparisthebest.jdbc.StatementClosingResultSet(rs, ps)");
|
||||||
|
else
|
||||||
|
w.append("rs");
|
||||||
|
w.append(";\n");
|
||||||
|
}
|
||||||
|
|
||||||
public void toObject(final Writer w, final String[] keys, final TypeMirror returnTypeMirror, final String cal, final String cleaner, final ReflectionFields reflectionFields) throws IOException, ClassNotFoundException {
|
public void toObject(final Writer w, final String[] keys, final TypeMirror returnTypeMirror, final String cal, final String cleaner, final ReflectionFields reflectionFields) throws IOException, ClassNotFoundException {
|
||||||
w.write("\t\t\tif(rs.next()) {\n");
|
w.write("\t\t\tif(rs.next()) {\n");
|
||||||
writeObject(w, keys, returnTypeMirror, cal, reflectionFields);
|
writeObject(w, keys, returnTypeMirror, cal, reflectionFields);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.moparisthebest.jdbc.dto.Person;
|
||||||
import com.moparisthebest.jdbc.util.ResultSetIterable;
|
import com.moparisthebest.jdbc.util.ResultSetIterable;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Time;
|
import java.sql.Time;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
@ -29,6 +30,12 @@ import java.time.*;
|
||||||
)
|
)
|
||||||
public interface PersonDAO extends Closeable {
|
public interface PersonDAO extends Closeable {
|
||||||
|
|
||||||
|
@JdbcMapper.SQL("CREATE TABLE person (person_no NUMERIC, first_name VARCHAR(40), last_name VARCHAR(40), birth_date TIMESTAMP)")
|
||||||
|
void createTablePerson();
|
||||||
|
|
||||||
|
@JdbcMapper.SQL("INSERT INTO person (person_no, birth_date, last_name, first_name) VALUES ({personNo}, {birthDate}, {firstName}, {lastName})")
|
||||||
|
int insertPerson(long personNo, Date birthDate, String firstName, String lastName);
|
||||||
|
|
||||||
@JdbcMapper.SQL("UPDATE person SET first_name = {firstName} WHERE last_name = {lastName}")
|
@JdbcMapper.SQL("UPDATE person SET first_name = {firstName} WHERE last_name = {lastName}")
|
||||||
int setFirstName(String firstName, String lastName);
|
int setFirstName(String firstName, String lastName);
|
||||||
|
|
||||||
|
@ -41,6 +48,12 @@ 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 first_name, last_name FROM person WHERE last_name = {lastName}")
|
||||||
|
ResultSet getPeopleResultSet(String lastName) throws SQLException;
|
||||||
|
|
||||||
|
@JdbcMapper.SQL(value = "SELECT first_name, last_name FROM person WHERE last_name = {lastName}", cachePreparedStatement = JdbcMapper.OptionalBool.TRUE)
|
||||||
|
ResultSet getPeopleResultSetCached(String lastName) throws SQLException;
|
||||||
|
|
||||||
@JdbcMapper.SQL("SELECT first_name FROM person WHERE person_no = {personNo}")
|
@JdbcMapper.SQL("SELECT first_name FROM person WHERE person_no = {personNo}")
|
||||||
String getFirstName(long personNo) throws SQLException;
|
String getFirstName(long personNo) throws SQLException;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue