Skip to content

Commit

Permalink
Enforce no rawtypes; fix occurrences
Browse files Browse the repository at this point in the history
- Added `HierarchicalInfileObjectLoader#setIgnoredClasses(Set<Class<?>>)`
- Deprecated `HierarchicalInfileObjectLoader#setClassesToIgnore(Set<Class>)`
  • Loading branch information
Brian Corcoran committed Dec 21, 2015
1 parent c0c43fd commit 76ac6e1
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 21 deletions.
14 changes: 13 additions & 1 deletion pom.xml
Expand Up @@ -101,6 +101,19 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.maven.compiler.plugin}</version>
<configuration>
<compilerArgs>
<arg>-Werror</arg>
<arg>-Xlint:rawtypes</arg>
</compilerArgs>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -223,7 +236,6 @@
<scope>test</scope>
</dependency>
</dependencies>

<reporting>
<plugins>
<plugin>
Expand Down
1 change: 1 addition & 0 deletions release_notes.txt
Expand Up @@ -2,6 +2,7 @@ New in 1.7.12
Many minor code improvements
Minor fixes for performance test
Now uses Spring 3.2.6
Added `HierarchicalInfileObjectLoader#setIgnoredClasses`; deprecated `HierarchicalInfileObjectLoader#setClassesToIgnore`

New in 1.7.11
Added greater precision when persisting float values
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class C3P0JdbcDriverSupport implements InfileStatementCallback.JdbcDriver
// of the method on the MySQL statement that we invoke via reflection.
private static final String INFILE_MUTATOR_METHOD = "setLocalInfileInputStream";

private static Class targetInterface;
private static Class<?> targetInterface;

static {
try {
Expand Down
Expand Up @@ -69,7 +69,7 @@ public class HierarchicalInfileObjectLoader implements Flushable, Closeable {
private Map<Class<?>, SingleInfileObjectLoader<Object>> secondaryTableObjectLoaders = newLinkedHashMap();
private Map<Class<?>, Set<Method>> parentDependent = newHashMap();
private Map<Class<?>, Set<Method>> childDependent = newHashMap();
private Set<Class> classesToIgnore = ImmutableSet.of();
private Set<Class<?>> classesToIgnore = ImmutableSet.of();
private Set<String> secondaryClassesToIgnore = ImmutableSet.of();
private boolean useReplace = false;

Expand Down Expand Up @@ -230,7 +230,7 @@ public boolean apply(Method m) {
PersistenceAnnotationInspector annotationInspector =
HierarchicalInfileObjectLoader.this.persistenceAnnotationInspector;
return annotationInspector.hasAnnotation(m, OneToOne.class)
&& !annotationInspector.hasAnnotation(m, PrimaryKeyJoinColumn.class);
&& !annotationInspector.hasAnnotation(m, PrimaryKeyJoinColumn.class);
}
}));

Expand All @@ -242,17 +242,15 @@ public boolean apply(Method m) {
}
}

private Class getReturnType(Method m) {
final Class returnType;
private Class<?> getReturnType(Method m) {
if (m.getGenericReturnType() instanceof ParameterizedType) {
// For List<String> etc...
ParameterizedType type = (ParameterizedType) m.getGenericReturnType();
returnType = (Class) type.getActualTypeArguments()[0];
return (Class<?>) type.getActualTypeArguments()[0];
}
else {
returnType = (Class) m.getGenericReturnType();
return (Class<?>) m.getGenericReturnType();
}
return returnType;
}

private InfileDataBuffer newInfileDataBuffer() {
Expand Down Expand Up @@ -314,8 +312,29 @@ public Boolean doInStatement(Statement statement) throws SQLException {
});
}

/**
* This method is deprecated.
*
* @param classToIgnore classes to ignore
* @deprecated due to improper type handling; use {@link #setIgnoredClasses(Set)} instead.
*/
@SuppressWarnings("rawtypes") // For legacy compatibility
@Deprecated
public void setClassesToIgnore(Set<Class> classToIgnore) {
this.classesToIgnore = classToIgnore;
ImmutableSet.Builder<Class<?>> typedClassesToIgnore = ImmutableSet.builder();
for (Class untypedClass : classToIgnore) {
typedClassesToIgnore.add(untypedClass);
}
setIgnoredClasses(typedClassesToIgnore.build());
}

/**
* Set the classes to ignore.
* @param classesToIgnore classes to ignore
* @since 1.7.12
*/
public void setIgnoredClasses(Set<Class<?>> classesToIgnore) {
this.classesToIgnore = classesToIgnore;
}

public void setSecondaryClassesToIgnore(Set<String> secondaryClassesToIgnore) {
Expand Down
Expand Up @@ -69,12 +69,12 @@ public int hashCode() {
public static <T> T create(final T impl) {
ProxyFactory factory = new ProxyFactory();
factory.setSuperclass(impl.getClass());
Class cachedClass = factory.createClass();
@SuppressWarnings("unchecked")
Class<? extends T> cachedClass = factory.createClass();
try {
@SuppressWarnings("unchecked")
T cachedInstance = (T) cachedClass.newInstance();
T cachedInstance = cachedClass.newInstance();
((ProxyObject) cachedInstance).setHandler(new MethodHandler() {
final LoadingCache<Args, Optional> cache = createCache(impl);
final LoadingCache<Args, Optional<Object>> cache = createCache(impl);

/**
* Returns the cached value of this method. If the method returns null then null is returned.
Expand All @@ -93,12 +93,12 @@ public Object invoke(Object self, Method thisMethod, Method proceed, Object[] ar
}
}

private static LoadingCache<Args, Optional> createCache(final Object impl) {
private static LoadingCache<Args, Optional<Object>> createCache(final Object impl) {
return CacheBuilder.newBuilder()
.softValues()
.build(new CacheLoader<Args, Optional>() {
.build(new CacheLoader<Args, Optional<Object>>() {
@Override
public Optional load(@Nonnull Args key)
public Optional<Object> load(@Nonnull Args key)
throws InvocationTargetException, IllegalAccessException {
return Optional.fromNullable(key.method.invoke(impl, key.args));
}
Expand Down
Expand Up @@ -202,7 +202,7 @@ public Method setterFromGetter(Method getter) {
Preconditions.checkNotNull(getter, "Cannot find setter from null getter");
checkGetterPreconditions(getter);

Class aClass = getter.getDeclaringClass();
Class<?> aClass = getter.getDeclaringClass();
String getterPrefix = getGetterPrefix(getter);

String setterName = getter.getName().replaceFirst(getterPrefix, SETTER_PREFIX);
Expand All @@ -221,7 +221,7 @@ public Method getterFromSetter(Method setter) {
Preconditions.checkState(setter.getParameterTypes().length == 1, "Setter must have just one parameter");
Preconditions.checkState(setter.getName().startsWith(SETTER_PREFIX), "Setter must start with %s", SETTER_PREFIX);

Class aClass = setter.getDeclaringClass();
Class<?> aClass = setter.getDeclaringClass();

Method getter = ReflectionUtils.findMethod(aClass, setter.getName().replaceFirst(SETTER_PREFIX, GETTER_PREFIX));

Expand All @@ -242,7 +242,7 @@ public Method getterFromSetter(Method setter) {
public Field fieldFromGetter(Method getter) {
Preconditions.checkNotNull(getter, "Cannot find field from null getter");
checkGetterPreconditions(getter);
Class aClass = getter.getDeclaringClass();
Class<?> aClass = getter.getDeclaringClass();

String getterName = getter.getName();
String getterPrefix = getGetterPrefix(getter);
Expand Down
Expand Up @@ -144,7 +144,8 @@ public Data mapRow(ResultSet rs, int rowNum) throws SQLException {
}

@Test
public void testIgnore() {
@SuppressWarnings({"rawtypes", "deprecation"}) // Testing deprecated method
public void testClassesToIgnore() {
this.hierarchicalInfileObjectLoader.setClassesToIgnore(ImmutableSet.<Class>of(Customer.class));

Customer customer = ObjectFactory.newCustomer();
Expand All @@ -153,6 +154,16 @@ public void testIgnore() {
assertNull(customer.getId());
}

@Test
public void testIgnoredClasses() {
this.hierarchicalInfileObjectLoader.setIgnoredClasses(ImmutableSet.<Class<?>>of(Customer.class));

Customer customer = ObjectFactory.newCustomer();
this.hierarchicalInfileObjectLoader.persist(customer);

assertNull(customer.getId());
}

@Test
public void testEventCallback() {
HierarchicalInfileObjectLoader.CallBack callBack = mock(HierarchicalInfileObjectLoader.CallBack.class);
Expand Down

0 comments on commit 76ac6e1

Please sign in to comment.