Add support for java 8 while keeping java 6 compatible artifacts

This commit is contained in:
Travis Burtrum 2017-06-12 20:59:04 -04:00
parent 099d88c26d
commit c902da5126
6 changed files with 282 additions and 44 deletions

View File

@ -81,4 +81,20 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>jdk16</id>
<activation>
<jdk>[1.6,1.8)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -76,4 +76,13 @@ class InListVariableElement implements VariableElement {
public <R, P> R accept(final ElementVisitor<R, P> v, final P p) {
return delegate.accept(v, p);
}
//IFJAVA8_START
@Override
public <A extends Annotation> A[] getAnnotationsByType(final Class<A> annotationType) {
return delegate.getAnnotationsByType(annotationType);
}
//IFJAVA8_END
}

View File

@ -22,7 +22,7 @@ import static org.junit.Assert.assertEquals;
*/
public class JdbcMapperTest {
private static PersonDAO dao;
public static PersonDAO dao;
@BeforeClass
public static void setUp() throws Throwable {
@ -35,13 +35,9 @@ public class JdbcMapperTest {
tryClose(dao);
}
public PersonDAO getDao() {
return dao;
}
@Test
public void testName() throws Throwable {
assertEquals(fieldPerson1.getFirstName(), getDao().getFirstName(fieldPerson1.getPersonNo()));
assertEquals(fieldPerson1.getFirstName(), dao.getFirstName(fieldPerson1.getPersonNo()));
}
@Test

142
pom.xml
View File

@ -62,15 +62,11 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<pushChanges>false</pushChanges>
<localCheckout>true</localCheckout>
<source.classifier>sources</source.classifier>
<javadoc.classifier>javadoc</javadoc.classifier>
<jar.classifier />
</properties>
<packaging>pom</packaging>
<modules>
<module>common</module>
<module>runtime-compiler</module>
<module>querymapper</module>
<module>jdbcmapper</module>
<module>presto-sqlparser</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
@ -172,4 +168,136 @@
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>jdk6</id>
<activation>
<jdk>[1.6,1.8)</jdk>
</activation>
<properties>
<source.classifier>jdk16-sources</source.classifier>
<maven.javadoc.skip>true</maven.javadoc.skip>
<jar.classifier>jdk16</jar.classifier>
</properties>
<modules>
<module>common</module>
<module>runtime-compiler</module>
<module>querymapper</module>
<module>jdbcmapper</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>*/src/main/java/**/*</include>
</includes>
<excludes>
<exclude>target/**</exclude>
</excludes>
<replacements>
<replacement>
<token>//IFJAVA8_START</token>
<value>/*IFJAVA8_START</value>
</replacement>
<replacement>
<token>//IFJAVA8_END</token>
<value>IFJAVA8_END*/</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<excludes>
<exclude>**/module-info.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<configuration>
<testExcludes>
<exclude>**/module-info.java</exclude>
</testExcludes>
</configuration>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>jdk8</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<modules>
<module>common</module>
<module>runtime-compiler</module>
<module>querymapper</module>
<module>jdbcmapper</module>
<module>presto-sqlparser</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<excludes>
<exclude>**/module-info.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<configuration>
<testExcludes>
<exclude>**/module-info.java</exclude>
</testExcludes>
</configuration>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -1,12 +1,14 @@
package com.moparisthebest.jdbc.codegen;
import com.moparisthebest.jdbc.Cleaner;
import com.moparisthebest.jdbc.dto.FieldPerson;
import com.moparisthebest.jdbc.dto.Person;
import com.moparisthebest.jdbc.util.ResultSetIterable;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.*;
/**
* Created by mopar on 5/24/17.
@ -18,39 +20,128 @@ import java.util.Map;
)
public interface PrestoPersonDAO extends PersonDAO {
@JdbcMapper.SQL("UPDATE person SET first_name = {firstName} WHERE last_name = {lastName}")
int setFirstName(String firstName, String lastName);
@JdbcMapper.SQL("UPDATE person SET first_name = {firstName} WHERE person_no = {personNo}")
void setFirstName(String firstName, long personNo) throws SQLException;
@JdbcMapper.SQL("UPDATE person SET first_name = {firstName} WHERE last_name = {lastName}")
int setFirstName(String firstName, String lastName);
@JdbcMapper.SQL("UPDATE person SET first_name = {firstName} WHERE person_no = {personNo}")
void setFirstNameBlob(byte[] firstName, long personNo) throws SQLException;
@JdbcMapper.SQL("UPDATE person SET first_name = {firstName} WHERE person_no = {personNo}")
void setFirstName(String firstName, long personNo) throws SQLException;
@JdbcMapper.SQL("SELECT first_name FROM person WHERE person_no = {personNo}")
String getFirstName(long personNo) throws SQLException;
@JdbcMapper.SQL("UPDATE person SET first_name = {firstName} WHERE person_no = {personNo}")
void setFirstNameBlob(byte[] firstName, long personNo) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE person_no = {personNo}")
FieldPerson getPerson(long personNo) throws SQLException;
@JdbcMapper.SQL("UPDATE person SET first_name = {firstName} WHERE person_no = {personNo}")
void setFirstNameBlob(@JdbcMapper.Blob String firstName, long personNo) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE last_name = {lastName}")
List<FieldPerson> getPeople(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name FROM person WHERE person_no = {personNo}")
String getFirstName(long personNo) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE last_name = {lastName}")
FieldPerson[] getPeopleArray(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}")
FieldPerson getPerson(long personNo, Calendar cal) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE last_name = {lastName}")
Iterator<FieldPerson> getPeopleIterator(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}")
FieldPerson getPerson(long personNo) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE last_name = {lastName}")
ListIterator<FieldPerson> getPeopleListIterator(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE last_name = {lastName}")
List<FieldPerson> getPeople(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, person_no FROM person WHERE last_name = {lastName}")
Map<String, FieldPerson> getPersonMap(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE {last_name not in lastName}")
List<FieldPerson> getPeople(String[] lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, person_no FROM person WHERE last_name = {lastName}")
Map<String, List<FieldPerson>> getPersonMapList(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE {last_name in lastName}")
List<FieldPerson> getPeople(List<String> lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE last_name = {lastName}")
FieldPerson[] getPeopleArray(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE last_name = {lastName}")
Iterator<FieldPerson> getPeopleIterator(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name FROM person WHERE last_name = {lastName}")
ListIterator<FieldPerson> getPeopleListIterator(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, person_no FROM person WHERE last_name = {lastName}")
Map<String, FieldPerson> getPersonMap(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, person_no FROM person WHERE last_name = {lastName}")
Map<String, List<FieldPerson>> getPersonMapList(String lastName) throws SQLException;
@JdbcMapper.SQL("SELECT first_name FROM person WHERE person_no = {personNo} and last_name = {lastName}")
String getFirstName(long personNo, String lastName) throws SQLException;
// various date checks here
@JdbcMapper.SQL("SELECT birth_date FROM person WHERE person_no = {personNo}")
Calendar getBirthDateCalendar(long personNo) throws SQLException;
@JdbcMapper.SQL("SELECT birth_date FROM person WHERE person_no = {personNo}")
Calendar getBirthDateCalendar(long personNo, Calendar mycal) throws SQLException;
@JdbcMapper.SQL("SELECT birth_date FROM person WHERE person_no = {personNo}")
Timestamp getBirthDateTimestamp(long personNo) throws SQLException;
@JdbcMapper.SQL("SELECT birth_date FROM person WHERE person_no = {personNo}")
Timestamp getBirthDateTimestamp(long personNo, Calendar mycal) throws SQLException;
@JdbcMapper.SQL("SELECT birth_date FROM person WHERE person_no = {personNo}")
Time getBirthDateTime(long personNo) throws SQLException;
@JdbcMapper.SQL("SELECT birth_date FROM person WHERE person_no = {personNo}")
Time getBirthDateTime(long personNo, Calendar mycal) throws SQLException;
@JdbcMapper.SQL("SELECT birth_date FROM person WHERE person_no = {personNo}")
java.sql.Date getBirthDateSqlDate(long personNo) throws SQLException;
@JdbcMapper.SQL("SELECT birth_date FROM person WHERE person_no = {personNo}")
java.sql.Date getBirthDateSqlDate(long personNo, Calendar mycal) throws SQLException;
@JdbcMapper.SQL("SELECT birth_date FROM person WHERE person_no = {personNo}")
java.util.Date getBirthDateUtilDate(long personNo) throws SQLException;
@JdbcMapper.SQL("SELECT birth_date FROM person WHERE person_no = {personNo}")
java.util.Date getBirthDateUtilDate(long personNo, Calendar mycal) throws SQLException;
// cleaner checks
@JdbcMapper.SQL("SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}")
FieldPerson getPersonCleanFieldPerson(long personNo, Cleaner<FieldPerson> clean) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}")
FieldPerson getPersonCleanPerson(long personNo, Cleaner<Person> clean) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}")
FieldPerson getPersonCleanObject(long personNo, Cleaner<Object> clean) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}")
List<FieldPerson> getPersonCleanPersonList(long personNo, Cleaner<Person> clean) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}")
Map<String, FieldPerson> getPersonCleanPersonMap(long personNo, Cleaner<Person> clean) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}")
Map<String, List<FieldPerson>> getPersonCleanPersonMapList(long personNo, Cleaner<Person> clean) throws SQLException;
/*
// this should NOT compile:
@JdbcMapper.SQL("SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}")
FieldPerson getPersonCleanNumber(long personNo, Cleaner<Number> clean) throws SQLException;
*/
// max row checks
@JdbcMapper.SQL("SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}")
Map<String, FieldPerson> getPersonDynamicLimit(long personNo, byte maxRows) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}")
Map<String, FieldPerson> getPersonDynamicLimit(long personNo, short arrayMaxLength) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}")
List<FieldPerson> getPersonDynamicLimit(long personNo, int maxRows) throws SQLException;
@JdbcMapper.SQL("SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}")
Map<String, List<FieldPerson>> getPersonDynamicLimit(long personNo, long rowLimit) throws SQLException;
@JdbcMapper.SQL(value = "SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}", maxRows = Byte.MAX_VALUE)
List<FieldPerson> getPersonStaticLimitListByte(long personNo) throws SQLException;
@JdbcMapper.SQL(value = "SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}", maxRows = Short.MAX_VALUE)
List<FieldPerson> getPersonStaticLimitList(long personNo) throws SQLException;
@JdbcMapper.SQL(value = "SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}", maxRows = Integer.MAX_VALUE)
Map<String, FieldPerson> getPersonStaticLimitMap(long personNo) throws SQLException;
@JdbcMapper.SQL(value = "SELECT first_name, last_name, birth_date FROM person WHERE person_no = {personNo}", maxRows = Long.MAX_VALUE)
Map<String, List<FieldPerson>> getPersonStaticLimitMapList(long personNo) throws SQLException;
@JdbcMapper.SQL("SELECT person_no, birth_date, last_name, first_name from person WHERE person_no IN ({personNo1},{personNo2},{personNo3}) ORDER BY person_no")
List<FieldPerson> getPeopleList(long personNo1, long personNo2, long personNo3) throws SQLException;
@JdbcMapper.SQL("SELECT person_no, birth_date, last_name, first_name from person WHERE person_no IN ({personNo1},{personNo2},{personNo3}) ORDER BY person_no")
ResultSetIterable<FieldPerson> getPeopleResultSetIterable(long personNo1, long personNo2, long personNo3) throws SQLException;
@JdbcMapper.SQL(value = "SELECT person_no, birth_date, last_name, first_name from person WHERE person_no IN ({personNo1},{personNo2},{personNo3}) ORDER BY person_no", cachePreparedStatement = JdbcMapper.OptionalBool.TRUE)
ResultSetIterable<FieldPerson> getPeopleResultSetIterableCachedPreparedStatement(long personNo1, long personNo2, long personNo3) throws SQLException;
@JdbcMapper.SQL("SELECT first_name FROM person WHERE person_no = {personNo} and last_name = {lastName}")
String getFirstName(long personNo, String lastName) throws SQLException;
}

View File

@ -14,8 +14,6 @@ import static org.junit.Assert.assertEquals;
*/
public class PrestoPersonDAOTest extends JdbcMapperTest {
private static PersonDAO dao;
@BeforeClass
public static void setUp() throws Throwable {
dao = JdbcMapperFactory.create(PrestoPersonDAO.class, getConnection());
@ -24,7 +22,7 @@ public class PrestoPersonDAOTest extends JdbcMapperTest {
@AfterClass
public static void tearDown() throws Throwable {
//tryClose(dao);
tryClose(dao);
}
public PersonDAO getDao() {