mirror of
https://github.com/moparisthebest/JdbcMapper
synced 2024-12-21 23:08:52 -05:00
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 {
|
||||
|
||||
String beanSuffix = System.getProperty("JdbcMapper.beanSuffix", "Bean");
|
||||
|
||||
Connection getConnection();
|
||||
|
||||
/*IFJAVA6_START
|
||||
|
@ -20,8 +20,6 @@ import static com.moparisthebest.jdbc.TryClose.tryClose;
|
||||
*/
|
||||
public class JdbcMapperFactory<T> implements Factory<T> {
|
||||
|
||||
static final String SUFFIX = "Bean";
|
||||
|
||||
static {
|
||||
try{
|
||||
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")
|
||||
public static <T> Class<? extends T> getImplementationClass(final Class<T> jdbcMapper) throws ClassNotFoundException {
|
||||
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
|
||||
return jdbcMapper;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import java.util.stream.Stream;
|
||||
|
||||
import static com.moparisthebest.jdbc.TryClose.tryClose;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -222,9 +222,9 @@ public class JdbcMapperProcessor extends AbstractProcessor {
|
||||
final boolean doJndi = !mapper.jndiName().isEmpty();
|
||||
Writer w = null;
|
||||
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 className = genClass.getSimpleName() + SUFFIX;
|
||||
final String className = genClass.getSimpleName() + beanSuffix;
|
||||
if (!packageName.isEmpty()) {
|
||||
w.write("package ");
|
||||
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" +
|
||||
"\t\t\t@Override\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 {
|
||||
|
||||
w.append("dao -> ");
|
||||
|
@ -17,10 +17,10 @@ public class PrestoPersonDAOTest {
|
||||
@Test
|
||||
public void testGeneratedFilesAreTheSame() throws IOException {
|
||||
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);
|
||||
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", "");
|
||||
assertEquals(personDaoBean, prestoPersonDaoBean);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user