mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-11-24 01:52:22 -05:00
Add java6 support for @RunInTransaction
This commit is contained in:
parent
72906cf3c5
commit
2eb39703ec
@ -22,6 +22,7 @@ import java.time.*;
|
||||
//IFJAVA8_END
|
||||
|
||||
import static com.moparisthebest.jdbc.TryClose.tryClose;
|
||||
import static com.moparisthebest.jdbc.codegen.JdbcMapperFactory.SUFFIX;
|
||||
|
||||
/**
|
||||
* Created by mopar on 5/24/17.
|
||||
@ -171,9 +172,9 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
||||
final boolean doJndi = !mapper.jndiName().isEmpty();
|
||||
Writer w = null;
|
||||
try {
|
||||
w = processingEnv.getFiler().createSourceFile(qualifiedName + JdbcMapperFactory.SUFFIX).openWriter();
|
||||
w = processingEnv.getFiler().createSourceFile(qualifiedName + SUFFIX).openWriter();
|
||||
final String packageName = ((PackageElement) genClass.getEnclosingElement()).getQualifiedName().toString();
|
||||
final String className = genClass.getSimpleName() + JdbcMapperFactory.SUFFIX;
|
||||
final String className = genClass.getSimpleName() + SUFFIX;
|
||||
if (!packageName.isEmpty()) {
|
||||
w.write("package ");
|
||||
w.write(packageName);
|
||||
@ -555,13 +556,6 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
||||
final boolean thisDaoImplementsJdbcMapper = types.isAssignable(thisDao.asType(), jdbcMapperType);
|
||||
final String thisDaoName = thisDao.getSimpleName().toString();
|
||||
|
||||
if(!java8)
|
||||
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@JdbcMapper.RunInTransaction cannot be used in java6 yet, java8+ only", eeMethod);
|
||||
|
||||
// todo: *can* this be done in java6 without reflection or something? we need to call super, not this, which causes infinite recursion, bail for now
|
||||
if(!java8)
|
||||
w.append("\t\tfinal ").append(thisDaoName).append(" jdbcMapperGeneratedTransactionThis = this;\n");
|
||||
|
||||
w.write("\t\treturn com.moparisthebest.jdbc.QueryRunner.run");
|
||||
if(thisDaoImplementsJdbcMapper)
|
||||
w.write("InTransaction(this, ");
|
||||
@ -569,10 +563,11 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
||||
w.write("ConnectionInTransaction(this.conn, ");
|
||||
|
||||
if(!java8) {
|
||||
w.append("new com.moparisthebest.jdbc.QueryRunner.Runner<").append(thisDaoName).append(", ").append(returnType).append(">() {\n" +
|
||||
final String tType = thisDaoImplementsJdbcMapper ? thisDaoName : "Connection";
|
||||
w.append("new com.moparisthebest.jdbc.QueryRunner.Runner<").append(tType).append(", ").append(returnType).append(">() {\n" +
|
||||
"\t\t\t@Override\n" +
|
||||
"\t\t\tpublic ").append(returnType).append(" run(").append(eeMethod.getEnclosingElement().getSimpleName()).append(" dao) throws SQLException {\n" +
|
||||
"\t\t\t\treturn jdbcMapperGeneratedTransactionThis");
|
||||
"\t\t\tpublic ").append(returnType).append(" run(").append(tType).append(" dao) throws SQLException {\n" +
|
||||
"\t\t\t\treturn ").append(thisDaoName).append(SUFFIX).append(".super");
|
||||
} else {
|
||||
|
||||
w.append("dao -> ");
|
||||
|
@ -113,4 +113,10 @@ try(QueryMapper qm = new QueryMapper("java:/comp/env/jdbc/testPool", new ResultS
|
||||
// instead of toCollection can use toList, toArray, toResultSetIterable, toStream (java8+)
|
||||
System.out.println(qm.toCollection("SELECT person_no, first_name, last_name, birth_date FROM person WHERE last_name = ?", new ArrayList<String>(), String.class, "Person")); // [Person{personNo=0,birthDate=null,firstName=First,lastName=Person}, Person{personNo=1,birthDate=null,firstName=Second,lastName=Person}]
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
TODO
|
||||
----
|
||||
|
||||
* Binding of Enum to String by default
|
||||
* sql other than select return boolean, int > 0 ?
|
Loading…
Reference in New Issue
Block a user