From 8e125d8e684d294b3f499643d5de0320c025bb99 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Wed, 7 Jun 2017 19:15:00 -0400 Subject: [PATCH] Clean up random todos --- .../jdbc/codegen/CompileTimeResultSetMapper.java | 11 ++++++++--- .../codegen/CompileTimeRowToObjectMapper.java | 15 ++++++++------- .../jdbc/codegen/JdbcMapperProcessor.java | 2 +- .../javax.annotation.processing.Processor | 1 + .../jdbc/CompilingRowToObjectMapper.java | 1 - .../javax.annotation.processing.Processor | 1 - 6 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 jdbcmapper/src/main/resources/META-INF.services/javax.annotation.processing.Processor delete mode 100644 querymapper/src/main/resources/META-INF.services/javax.annotation.processing.Processor diff --git a/jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/CompileTimeResultSetMapper.java b/jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/CompileTimeResultSetMapper.java index 9553d1e..4038080 100644 --- a/jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/CompileTimeResultSetMapper.java +++ b/jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/CompileTimeResultSetMapper.java @@ -1,5 +1,6 @@ package com.moparisthebest.jdbc.codegen; +import com.moparisthebest.jdbc.Finishable; import com.moparisthebest.jdbc.ResultSetMapper; import javax.annotation.processing.ProcessingEnvironment; @@ -13,6 +14,7 @@ import javax.lang.model.util.Elements; import javax.lang.model.util.Types; import java.io.IOException; import java.io.Writer; +import java.sql.ResultSet; import java.util.*; import static com.moparisthebest.jdbc.codegen.JdbcMapperProcessor.typeMirrorStringNoGenerics; @@ -23,8 +25,8 @@ import static com.moparisthebest.jdbc.codegen.JdbcMapperProcessor.typeMirrorToCl */ public class CompileTimeResultSetMapper { - private final Types types; - private final TypeMirror collectionType, mapType, mapCollectionType, iteratorType, listIteratorType; + public final Types types; + public final TypeMirror collectionType, mapType, mapCollectionType, iteratorType, listIteratorType, finishableType, resultSetType; public CompileTimeResultSetMapper(final ProcessingEnvironment processingEnv) { types = processingEnv.getTypeUtils(); @@ -36,6 +38,9 @@ public class CompileTimeResultSetMapper { iteratorType = types.getDeclaredType(elements.getTypeElement(Iterator.class.getCanonicalName()), types.getWildcardType(null, null)); listIteratorType = types.getDeclaredType(elements.getTypeElement(ListIterator.class.getCanonicalName()), types.getWildcardType(null, null)); + + finishableType = elements.getTypeElement(Finishable.class.getCanonicalName()).asType(); + resultSetType = elements.getTypeElement(ResultSet.class.getCanonicalName()).asType(); } public static String getConcreteClassCanonicalName(final TypeMirror returnType, final Class defaultConcreteClass) { @@ -89,7 +94,7 @@ public class CompileTimeResultSetMapper { } public CompileTimeRowToObjectMapper getRowMapper(final String[] keys, TypeMirror returnTypeClass, Calendar cal, TypeMirror mapValType, TypeMirror mapKeyType) { - return new CompileTimeRowToObjectMapper(keys, returnTypeClass, cal, mapValType, mapKeyType); + return new CompileTimeRowToObjectMapper(this, keys, returnTypeClass, cal, mapValType, mapKeyType); } public void writeObject(final Writer w, final String[] keys, final TypeMirror returnTypeMirror, final Calendar cal) throws IOException, ClassNotFoundException { diff --git a/jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/CompileTimeRowToObjectMapper.java b/jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/CompileTimeRowToObjectMapper.java index 061baab..fd3bda4 100644 --- a/jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/CompileTimeRowToObjectMapper.java +++ b/jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/CompileTimeRowToObjectMapper.java @@ -28,7 +28,8 @@ public class CompileTimeRowToObjectMapper { protected static final TypeMappingsFactory _tmf = TypeMappingsFactory.getInstance(); - final String[] keys; + protected final CompileTimeResultSetMapper rsm; + protected final String[] keys; /** * Calendar instance for date/time mappings. @@ -53,7 +54,8 @@ public class CompileTimeRowToObjectMapper { protected Element[] _fields = null; protected int[] _fieldTypes; - public CompileTimeRowToObjectMapper(final String[] keys, final TypeMirror returnTypeClass, final Calendar cal, final TypeMirror mapValType, final TypeMirror mapKeyType) { + public CompileTimeRowToObjectMapper(final CompileTimeResultSetMapper rsm, final String[] keys, final TypeMirror returnTypeClass, final Calendar cal, final TypeMirror mapValType, final TypeMirror mapKeyType) { + this.rsm = rsm; this.keys = keys; _cal = cal; @@ -63,7 +65,7 @@ public class CompileTimeRowToObjectMapper { mapOnlySecondColumn = _mapKeyType != null && _columnCount == 2; - returnMap = false;//todo: Map.class.isAssignableFrom(returnTypeClass); + returnMap = rsm.types.isAssignable(returnTypeClass, rsm.mapType); if (returnMap) { // todo: need this? _returnTypeClass = ResultSetMapper.getConcreteClass(returnTypeClass, HashMap.class); _returnTypeClass = null; @@ -83,7 +85,7 @@ public class CompileTimeRowToObjectMapper { final List params = ((ExecutableElement)e).getParameters(); if(params.isEmpty()) defaultConstructor = true; - else if(params.size() == 1 && params.get(0).asType().toString().equals("java.sql.ResultSet")) // todo: this better + else if(params.size() == 1 && rsm.types.isSameType(params.get(0).asType(), rsm.resultSetType)) resultSetConstructor = true; } } @@ -269,7 +271,6 @@ public class CompileTimeRowToObjectMapper { if (returnMap) // we want a map try { - // todo: does not call getMapImplementation, I think that's fine java.append("final ").append(tType).append(" ret = new ").append(tType).append("();\n"); final int columnLength = _columnCount + 1; int typeId = getTypeId(componentType); @@ -378,8 +379,8 @@ public class CompileTimeRowToObjectMapper { } } // if this resultObject is Finishable, call finish() - //if (Finishable.class.isAssignableFrom(_returnTypeClass)) - //todo: java.append("ret.finish(rs);\n"); + if (rsm.types.isAssignable(_returnTypeClass, rsm.finishableType)) + java.append("ret.finish(rs);\n"); } public static int getTypeId(TypeMirror classType) { diff --git a/jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/JdbcMapperProcessor.java b/jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/JdbcMapperProcessor.java index 5bbcf7c..d274627 100644 --- a/jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/JdbcMapperProcessor.java +++ b/jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/JdbcMapperProcessor.java @@ -122,7 +122,7 @@ public class JdbcMapperProcessor extends AbstractProcessor { } if (doJndi) { w.write("import javax.naming.InitialContext;\n"); - w.write("import javax.sql.DataSource;\n"); + // * imported below w.write("import javax.sql.DataSource;\n"); } w.write("import java.sql.*;\n\n"); w.write("import static com.moparisthebest.jdbc.util.ResultSetUtil.*;\n"); diff --git a/jdbcmapper/src/main/resources/META-INF.services/javax.annotation.processing.Processor b/jdbcmapper/src/main/resources/META-INF.services/javax.annotation.processing.Processor new file mode 100644 index 0000000..4982cf0 --- /dev/null +++ b/jdbcmapper/src/main/resources/META-INF.services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +com.moparisthebest.jdbc.codegen.JdbcMapperProcessor \ No newline at end of file diff --git a/querymapper/src/main/java/com/moparisthebest/jdbc/CompilingRowToObjectMapper.java b/querymapper/src/main/java/com/moparisthebest/jdbc/CompilingRowToObjectMapper.java index 134c68f..b9f19b2 100644 --- a/querymapper/src/main/java/com/moparisthebest/jdbc/CompilingRowToObjectMapper.java +++ b/querymapper/src/main/java/com/moparisthebest/jdbc/CompilingRowToObjectMapper.java @@ -195,7 +195,6 @@ public class CompilingRowToObjectMapper extends RowToObjectMapper { if (returnMap) // we want a map try { - // todo: does not call getMapImplementation, I think that's fine java.append("final ").append(tType).append(" ret = new ").append(tType).append("();\n"); final int columnLength = _columnCount + 1; if (componentType != null && componentType != Object.class) { // we want a specific value type diff --git a/querymapper/src/main/resources/META-INF.services/javax.annotation.processing.Processor b/querymapper/src/main/resources/META-INF.services/javax.annotation.processing.Processor deleted file mode 100644 index 5c38051..0000000 --- a/querymapper/src/main/resources/META-INF.services/javax.annotation.processing.Processor +++ /dev/null @@ -1 +0,0 @@ -com.moparisthebest.jdbc.codegen.JdbcMapperProcessor