Make configurable system property JdbcMapper.beanSuffix
This commit is contained in:
parent
267e438ac0
commit
89966a616d
|
@ -14,6 +14,8 @@ import java.sql.Connection;
|
||||||
*/
|
*/
|
||||||
public interface JdbcMapper extends Closeable {
|
public interface JdbcMapper extends Closeable {
|
||||||
|
|
||||||
|
String beanSuffix = System.getProperty("JdbcMapper.beanSuffix", "Bean");
|
||||||
|
|
||||||
Connection getConnection();
|
Connection getConnection();
|
||||||
|
|
||||||
/*IFJAVA6_START
|
/*IFJAVA6_START
|
||||||
|
|
|
@ -20,8 +20,6 @@ import static com.moparisthebest.jdbc.TryClose.tryClose;
|
||||||
*/
|
*/
|
||||||
public class JdbcMapperFactory<T> implements Factory<T> {
|
public class JdbcMapperFactory<T> implements Factory<T> {
|
||||||
|
|
||||||
static final String SUFFIX = "Bean";
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try{
|
try{
|
||||||
final Class<?> ensureContext = Class.forName(System.getProperty("QueryMapper.ensureContext.class", System.getProperty("JdbcMapper.ensureContext.class", "com.gcl.containerless.EnsureContext")));
|
final Class<?> ensureContext = Class.forName(System.getProperty("QueryMapper.ensureContext.class", System.getProperty("JdbcMapper.ensureContext.class", "com.gcl.containerless.EnsureContext")));
|
||||||
|
@ -36,7 +34,7 @@ public class JdbcMapperFactory<T> implements Factory<T> {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> Class<? extends T> getImplementationClass(final Class<T> jdbcMapper) throws ClassNotFoundException {
|
public static <T> Class<? extends T> getImplementationClass(final Class<T> jdbcMapper) throws ClassNotFoundException {
|
||||||
if(jdbcMapper.isInterface() || Modifier.isAbstract(jdbcMapper.getModifiers()))
|
if(jdbcMapper.isInterface() || Modifier.isAbstract(jdbcMapper.getModifiers()))
|
||||||
return (Class<? extends T>) Class.forName(jdbcMapper.getName() + SUFFIX);
|
return (Class<? extends T>) Class.forName(jdbcMapper.getName() + JdbcMapper.beanSuffix);
|
||||||
else
|
else
|
||||||
return jdbcMapper;
|
return jdbcMapper;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ import java.util.stream.Stream;
|
||||||
|
|
||||||
import static com.moparisthebest.jdbc.TryClose.tryClose;
|
import static com.moparisthebest.jdbc.TryClose.tryClose;
|
||||||
import static com.moparisthebest.jdbc.codegen.JdbcMapper.DatabaseType.ORACLE;
|
import static com.moparisthebest.jdbc.codegen.JdbcMapper.DatabaseType.ORACLE;
|
||||||
import static com.moparisthebest.jdbc.codegen.JdbcMapperFactory.SUFFIX;
|
import static com.moparisthebest.jdbc.codegen.JdbcMapper.beanSuffix;
|
||||||
import static com.moparisthebest.jdbc.codegen.SpecialVariableElement.SpecialType.SQL;
|
import static com.moparisthebest.jdbc.codegen.SpecialVariableElement.SpecialType.SQL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -222,9 +222,9 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
||||||
final boolean doJndi = !mapper.jndiName().isEmpty();
|
final boolean doJndi = !mapper.jndiName().isEmpty();
|
||||||
Writer w = null;
|
Writer w = null;
|
||||||
try {
|
try {
|
||||||
w = processingEnv.getFiler().createSourceFile(qualifiedName + SUFFIX).openWriter();
|
w = processingEnv.getFiler().createSourceFile(qualifiedName + beanSuffix).openWriter();
|
||||||
final String packageName = ((PackageElement) genClass.getEnclosingElement()).getQualifiedName().toString();
|
final String packageName = ((PackageElement) genClass.getEnclosingElement()).getQualifiedName().toString();
|
||||||
final String className = genClass.getSimpleName() + SUFFIX;
|
final String className = genClass.getSimpleName() + beanSuffix;
|
||||||
if (!packageName.isEmpty()) {
|
if (!packageName.isEmpty()) {
|
||||||
w.write("package ");
|
w.write("package ");
|
||||||
w.write(packageName);
|
w.write(packageName);
|
||||||
|
@ -786,7 +786,7 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
||||||
w.append("new com.moparisthebest.jdbc.QueryRunner.Runner<").append(tType).append(", ").append(returnType).append(">() {\n" +
|
w.append("new com.moparisthebest.jdbc.QueryRunner.Runner<").append(tType).append(", ").append(returnType).append(">() {\n" +
|
||||||
"\t\t\t@Override\n" +
|
"\t\t\t@Override\n" +
|
||||||
"\t\t\tpublic ").append(returnType).append(" run(").append(tType).append(" dao) throws SQLException {\n" +
|
"\t\t\tpublic ").append(returnType).append(" run(").append(tType).append(" dao) throws SQLException {\n" +
|
||||||
"\t\t\t\treturn ").append(thisDaoName).append(SUFFIX).append(".super");
|
"\t\t\t\treturn ").append(thisDaoName).append(beanSuffix).append(".super");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
w.append("dao -> ");
|
w.append("dao -> ");
|
||||||
|
|
|
@ -17,10 +17,10 @@ public class PrestoPersonDAOTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGeneratedFilesAreTheSame() throws IOException {
|
public void testGeneratedFilesAreTheSame() throws IOException {
|
||||||
final String personDaoBean = new String(
|
final String personDaoBean = new String(
|
||||||
Files.readAllBytes(Paths.get("target/generated-sources/annotations/com/moparisthebest/jdbc/codegen/PersonDAOBean.java"))
|
Files.readAllBytes(Paths.get("target/generated-sources/annotations/com/moparisthebest/jdbc/codegen/PersonDAO" + JdbcMapper.beanSuffix + ".java"))
|
||||||
, StandardCharsets.UTF_8);
|
, StandardCharsets.UTF_8);
|
||||||
final String prestoPersonDaoBean = new String(
|
final String prestoPersonDaoBean = new String(
|
||||||
Files.readAllBytes(Paths.get("target/generated-sources/annotations/com/moparisthebest/jdbc/codegen/PrestoPersonDAOBean.java"))
|
Files.readAllBytes(Paths.get("target/generated-sources/annotations/com/moparisthebest/jdbc/codegen/PrestoPersonDAO" + JdbcMapper.beanSuffix + ".java"))
|
||||||
, StandardCharsets.UTF_8).replace("Presto", "");
|
, StandardCharsets.UTF_8).replace("Presto", "");
|
||||||
assertEquals(personDaoBean, prestoPersonDaoBean);
|
assertEquals(personDaoBean, prestoPersonDaoBean);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue