Browse Source

Add java6 support for @RunInTransaction

Travis Burtrum 10 months ago
parent
commit
2eb39703ec

+ 7
- 12
jdbcmapper/src/main/java/com/moparisthebest/jdbc/codegen/JdbcMapperProcessor.java View File

@@ -22,6 +22,7 @@ import java.time.*;
22 22
 //IFJAVA8_END
23 23
 
24 24
 import static com.moparisthebest.jdbc.TryClose.tryClose;
25
+import static com.moparisthebest.jdbc.codegen.JdbcMapperFactory.SUFFIX;
25 26
 
26 27
 /**
27 28
  * Created by mopar on 5/24/17.
@@ -171,9 +172,9 @@ public class JdbcMapperProcessor extends AbstractProcessor {
171 172
 					final boolean doJndi = !mapper.jndiName().isEmpty();
172 173
 					Writer w = null;
173 174
 					try {
174
-						w = processingEnv.getFiler().createSourceFile(qualifiedName + JdbcMapperFactory.SUFFIX).openWriter();
175
+						w = processingEnv.getFiler().createSourceFile(qualifiedName + SUFFIX).openWriter();
175 176
 						final String packageName = ((PackageElement) genClass.getEnclosingElement()).getQualifiedName().toString();
176
-						final String className = genClass.getSimpleName() + JdbcMapperFactory.SUFFIX;
177
+						final String className = genClass.getSimpleName() + SUFFIX;
177 178
 						if (!packageName.isEmpty()) {
178 179
 							w.write("package ");
179 180
 							w.write(packageName);
@@ -555,13 +556,6 @@ public class JdbcMapperProcessor extends AbstractProcessor {
555 556
 		final boolean thisDaoImplementsJdbcMapper = types.isAssignable(thisDao.asType(), jdbcMapperType);
556 557
 		final String thisDaoName = thisDao.getSimpleName().toString();
557 558
 
558
-		if(!java8)
559
-			processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "@JdbcMapper.RunInTransaction cannot be used in java6 yet, java8+ only", eeMethod);
560
-
561
-		// 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
562
-		if(!java8)
563
-			w.append("\t\tfinal ").append(thisDaoName).append(" jdbcMapperGeneratedTransactionThis = this;\n");
564
-
565 559
 		w.write("\t\treturn com.moparisthebest.jdbc.QueryRunner.run");
566 560
 		if(thisDaoImplementsJdbcMapper)
567 561
 			w.write("InTransaction(this, ");
@@ -569,10 +563,11 @@ public class JdbcMapperProcessor extends AbstractProcessor {
569 563
 			w.write("ConnectionInTransaction(this.conn, ");
570 564
 
571 565
 		if(!java8) {
572
-			w.append("new com.moparisthebest.jdbc.QueryRunner.Runner<").append(thisDaoName).append(", ").append(returnType).append(">() {\n" +
566
+			final String tType = thisDaoImplementsJdbcMapper ? thisDaoName : "Connection";
567
+			w.append("new com.moparisthebest.jdbc.QueryRunner.Runner<").append(tType).append(", ").append(returnType).append(">() {\n" +
573 568
 					"\t\t\t@Override\n" +
574
-					"\t\t\tpublic ").append(returnType).append(" run(").append(eeMethod.getEnclosingElement().getSimpleName()).append(" dao) throws SQLException {\n" +
575
-					"\t\t\t\treturn jdbcMapperGeneratedTransactionThis");
569
+					"\t\t\tpublic ").append(returnType).append(" run(").append(tType).append(" dao) throws SQLException {\n" +
570
+					"\t\t\t\treturn ").append(thisDaoName).append(SUFFIX).append(".super");
576 571
 		} else {
577 572
 
578 573
 			w.append("dao -> ");

+ 7
- 1
readme.md View File

@@ -113,4 +113,10 @@ try(QueryMapper qm = new QueryMapper("java:/comp/env/jdbc/testPool", new ResultS
113 113
     // instead of toCollection can use toList, toArray, toResultSetIterable, toStream (java8+)
114 114
     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}]
115 115
 }
116
-```
116
+```
117
+
118
+TODO
119
+----
120
+
121
+ * Binding of Enum to String by default
122
+ * sql other than select return boolean, int > 0 ?