mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-11-22 00:52:16 -05:00
Add JdbcMapper.WarnOnUnusedParams annotation
This commit is contained in:
parent
6f23696952
commit
d2353bd74b
@ -50,6 +50,13 @@ public interface JdbcMapper extends Closeable {
|
|||||||
String arrayStringTypeName() default "";
|
String arrayStringTypeName() default "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
|
@Target({ElementType.METHOD})
|
||||||
|
/**
|
||||||
|
* Instead of a compile-time error this will only warn on unused params, mainly for debugging or presenting an unfinished API
|
||||||
|
*/
|
||||||
|
public @interface WarnOnUnusedParams {}
|
||||||
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@Target({ElementType.METHOD})
|
@Target({ElementType.METHOD})
|
||||||
public @interface SQL {
|
public @interface SQL {
|
||||||
|
@ -205,6 +205,7 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
|||||||
lookupCloseMethod = false;
|
lookupCloseMethod = false;
|
||||||
continue; // skip close method
|
continue; // skip close method
|
||||||
}
|
}
|
||||||
|
final JdbcMapper.WarnOnUnusedParams warnOnUnusedParams = eeMethod.getAnnotation(JdbcMapper.WarnOnUnusedParams.class);
|
||||||
final JdbcMapper.SQL sql = eeMethod.getAnnotation(JdbcMapper.SQL.class);
|
final JdbcMapper.SQL sql = eeMethod.getAnnotation(JdbcMapper.SQL.class);
|
||||||
if (sql == null || sql.value().isEmpty()) {
|
if (sql == null || sql.value().isEmpty()) {
|
||||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@JdbcMapper.SQL with non-empty query is required on abstract or interface methods", methodElement);
|
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@JdbcMapper.SQL with non-empty query is required on abstract or interface methods", methodElement);
|
||||||
@ -318,7 +319,7 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
|||||||
} else if(isPrimitiveInteger(unusedType.getKind()) && maxRows == null && this.allowedMaxRowParamNames.contains(unusedParam.getKey())) {
|
} else if(isPrimitiveInteger(unusedType.getKind()) && maxRows == null && this.allowedMaxRowParamNames.contains(unusedParam.getKey())) {
|
||||||
maxRows = CompileTimeResultSetMapper.MaxRows.getMaxRows(unusedParam.getKey(), unusedType.toString());
|
maxRows = CompileTimeResultSetMapper.MaxRows.getMaxRows(unusedParam.getKey(), unusedType.toString());
|
||||||
} else
|
} else
|
||||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, String.format("@JdbcMapper.SQL method has unused parameter '%s'", unusedParam.getKey()), unusedParam.getValue());
|
processingEnv.getMessager().printMessage(warnOnUnusedParams != null ? Diagnostic.Kind.MANDATORY_WARNING : Diagnostic.Kind.ERROR, String.format("@JdbcMapper.SQL method has unused parameter '%s'", unusedParam.getKey()), unusedParam.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,10 @@ public interface PersonDAO extends JdbcMapper {
|
|||||||
@JdbcMapper.SQL("SELECT person_no FROM person WHERE last_name = {lastName}")
|
@JdbcMapper.SQL("SELECT person_no FROM person WHERE last_name = {lastName}")
|
||||||
long getPersonNo(String lastName) throws SQLException;
|
long getPersonNo(String lastName) throws SQLException;
|
||||||
|
|
||||||
|
@JdbcMapper.WarnOnUnusedParams
|
||||||
|
@JdbcMapper.SQL("SELECT person_no FROM person WHERE last_name = {lastName}")
|
||||||
|
long getPersonNoUnusedParam(String lastName, String unused) 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;
|
||||||
|
|
||||||
|
@ -51,6 +51,10 @@ public interface PrestoPersonDAO extends PersonDAO {
|
|||||||
@JdbcMapper.SQL("SELECT person_no FROM person WHERE last_name = {lastName}")
|
@JdbcMapper.SQL("SELECT person_no FROM person WHERE last_name = {lastName}")
|
||||||
long getPersonNo(String lastName) throws SQLException;
|
long getPersonNo(String lastName) throws SQLException;
|
||||||
|
|
||||||
|
@JdbcMapper.WarnOnUnusedParams
|
||||||
|
@JdbcMapper.SQL("SELECT person_no FROM person WHERE last_name = {lastName}")
|
||||||
|
long getPersonNoUnusedParam(String lastName, String unused) 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;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user