mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-11-28 20:02:18 -05:00
Clean up random todos
This commit is contained in:
parent
6897043392
commit
8e125d8e68
@ -1,5 +1,6 @@
|
|||||||
package com.moparisthebest.jdbc.codegen;
|
package com.moparisthebest.jdbc.codegen;
|
||||||
|
|
||||||
|
import com.moparisthebest.jdbc.Finishable;
|
||||||
import com.moparisthebest.jdbc.ResultSetMapper;
|
import com.moparisthebest.jdbc.ResultSetMapper;
|
||||||
|
|
||||||
import javax.annotation.processing.ProcessingEnvironment;
|
import javax.annotation.processing.ProcessingEnvironment;
|
||||||
@ -13,6 +14,7 @@ import javax.lang.model.util.Elements;
|
|||||||
import javax.lang.model.util.Types;
|
import javax.lang.model.util.Types;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static com.moparisthebest.jdbc.codegen.JdbcMapperProcessor.typeMirrorStringNoGenerics;
|
import static com.moparisthebest.jdbc.codegen.JdbcMapperProcessor.typeMirrorStringNoGenerics;
|
||||||
@ -23,8 +25,8 @@ import static com.moparisthebest.jdbc.codegen.JdbcMapperProcessor.typeMirrorToCl
|
|||||||
*/
|
*/
|
||||||
public class CompileTimeResultSetMapper {
|
public class CompileTimeResultSetMapper {
|
||||||
|
|
||||||
private final Types types;
|
public final Types types;
|
||||||
private final TypeMirror collectionType, mapType, mapCollectionType, iteratorType, listIteratorType;
|
public final TypeMirror collectionType, mapType, mapCollectionType, iteratorType, listIteratorType, finishableType, resultSetType;
|
||||||
|
|
||||||
public CompileTimeResultSetMapper(final ProcessingEnvironment processingEnv) {
|
public CompileTimeResultSetMapper(final ProcessingEnvironment processingEnv) {
|
||||||
types = processingEnv.getTypeUtils();
|
types = processingEnv.getTypeUtils();
|
||||||
@ -36,6 +38,9 @@ public class CompileTimeResultSetMapper {
|
|||||||
|
|
||||||
iteratorType = types.getDeclaredType(elements.getTypeElement(Iterator.class.getCanonicalName()), types.getWildcardType(null, null));
|
iteratorType = types.getDeclaredType(elements.getTypeElement(Iterator.class.getCanonicalName()), types.getWildcardType(null, null));
|
||||||
listIteratorType = types.getDeclaredType(elements.getTypeElement(ListIterator.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) {
|
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) {
|
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 {
|
public void writeObject(final Writer w, final String[] keys, final TypeMirror returnTypeMirror, final Calendar cal) throws IOException, ClassNotFoundException {
|
||||||
|
@ -28,7 +28,8 @@ public class CompileTimeRowToObjectMapper {
|
|||||||
|
|
||||||
protected static final TypeMappingsFactory _tmf = TypeMappingsFactory.getInstance();
|
protected static final TypeMappingsFactory _tmf = TypeMappingsFactory.getInstance();
|
||||||
|
|
||||||
final String[] keys;
|
protected final CompileTimeResultSetMapper rsm;
|
||||||
|
protected final String[] keys;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calendar instance for date/time mappings.
|
* Calendar instance for date/time mappings.
|
||||||
@ -53,7 +54,8 @@ public class CompileTimeRowToObjectMapper {
|
|||||||
protected Element[] _fields = null;
|
protected Element[] _fields = null;
|
||||||
protected int[] _fieldTypes;
|
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;
|
this.keys = keys;
|
||||||
|
|
||||||
_cal = cal;
|
_cal = cal;
|
||||||
@ -63,7 +65,7 @@ public class CompileTimeRowToObjectMapper {
|
|||||||
|
|
||||||
mapOnlySecondColumn = _mapKeyType != null && _columnCount == 2;
|
mapOnlySecondColumn = _mapKeyType != null && _columnCount == 2;
|
||||||
|
|
||||||
returnMap = false;//todo: Map.class.isAssignableFrom(returnTypeClass);
|
returnMap = rsm.types.isAssignable(returnTypeClass, rsm.mapType);
|
||||||
if (returnMap) {
|
if (returnMap) {
|
||||||
// todo: need this? _returnTypeClass = ResultSetMapper.getConcreteClass(returnTypeClass, HashMap.class);
|
// todo: need this? _returnTypeClass = ResultSetMapper.getConcreteClass(returnTypeClass, HashMap.class);
|
||||||
_returnTypeClass = null;
|
_returnTypeClass = null;
|
||||||
@ -83,7 +85,7 @@ public class CompileTimeRowToObjectMapper {
|
|||||||
final List<? extends VariableElement> params = ((ExecutableElement)e).getParameters();
|
final List<? extends VariableElement> params = ((ExecutableElement)e).getParameters();
|
||||||
if(params.isEmpty())
|
if(params.isEmpty())
|
||||||
defaultConstructor = true;
|
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;
|
resultSetConstructor = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -269,7 +271,6 @@ public class CompileTimeRowToObjectMapper {
|
|||||||
|
|
||||||
if (returnMap) // we want a map
|
if (returnMap) // we want a map
|
||||||
try {
|
try {
|
||||||
// todo: does not call getMapImplementation, I think that's fine
|
|
||||||
java.append("final ").append(tType).append("<String, Object> ret = new ").append(tType).append("<String, Object>();\n");
|
java.append("final ").append(tType).append("<String, Object> ret = new ").append(tType).append("<String, Object>();\n");
|
||||||
final int columnLength = _columnCount + 1;
|
final int columnLength = _columnCount + 1;
|
||||||
int typeId = getTypeId(componentType);
|
int typeId = getTypeId(componentType);
|
||||||
@ -378,8 +379,8 @@ public class CompileTimeRowToObjectMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if this resultObject is Finishable, call finish()
|
// if this resultObject is Finishable, call finish()
|
||||||
//if (Finishable.class.isAssignableFrom(_returnTypeClass))
|
if (rsm.types.isAssignable(_returnTypeClass, rsm.finishableType))
|
||||||
//todo: java.append("ret.finish(rs);\n");
|
java.append("ret.finish(rs);\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getTypeId(TypeMirror classType) {
|
public static int getTypeId(TypeMirror classType) {
|
||||||
|
@ -122,7 +122,7 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
|||||||
}
|
}
|
||||||
if (doJndi) {
|
if (doJndi) {
|
||||||
w.write("import javax.naming.InitialContext;\n");
|
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 java.sql.*;\n\n");
|
||||||
w.write("import static com.moparisthebest.jdbc.util.ResultSetUtil.*;\n");
|
w.write("import static com.moparisthebest.jdbc.util.ResultSetUtil.*;\n");
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
com.moparisthebest.jdbc.codegen.JdbcMapperProcessor
|
@ -195,7 +195,6 @@ public class CompilingRowToObjectMapper<K, T> extends RowToObjectMapper<K, T> {
|
|||||||
|
|
||||||
if (returnMap) // we want a map
|
if (returnMap) // we want a map
|
||||||
try {
|
try {
|
||||||
// todo: does not call getMapImplementation, I think that's fine
|
|
||||||
java.append("final ").append(tType).append("<String, Object> ret = new ").append(tType).append("<String, Object>();\n");
|
java.append("final ").append(tType).append("<String, Object> ret = new ").append(tType).append("<String, Object>();\n");
|
||||||
final int columnLength = _columnCount + 1;
|
final int columnLength = _columnCount + 1;
|
||||||
if (componentType != null && componentType != Object.class) { // we want a specific value type
|
if (componentType != null && componentType != Object.class) { // we want a specific value type
|
||||||
|
@ -1 +0,0 @@
|
|||||||
com.moparisthebest.jdbc.codegen.JdbcMapperProcessor
|
|
Loading…
Reference in New Issue
Block a user