[#1378] Upgrade internal jOOR dependency to jOOR 0.9.3

This commit is contained in:
Lukas Eder 2012-04-29 12:33:18 +02:00
parent d09b715976
commit 7150b098bc
4 changed files with 30 additions and 61 deletions

View File

@ -36,7 +36,6 @@
package org.jooq.impl;
import static org.jooq.impl.Util.accessible;
import static org.jooq.impl.Util.getAnnotatedGetter;
import static org.jooq.impl.Util.getAnnotatedMembers;
import static org.jooq.impl.Util.getAnnotatedSetters;
@ -68,6 +67,7 @@ import org.jooq.Table;
import org.jooq.UniqueKey;
import org.jooq.exception.MappingException;
import org.jooq.tools.Convert;
import org.jooq.tools.reflect.Reflect;
/**
* @author Lukas Eder
@ -621,7 +621,7 @@ abstract class AbstractRecord extends AbstractStore<Object> implements Record {
try {
// [#1340] Allow for using non-public default constructors
T result = accessible(type.getDeclaredConstructor()).newInstance();
T result = Reflect.accessible(type.getDeclaredConstructor()).newInstance();
return intoMutablePOJO(type, result);
}
@ -644,7 +644,7 @@ abstract class AbstractRecord extends AbstractStore<Object> implements Record {
// Match the first constructor by parameter length
if (parameterTypes.length == getFields().size()) {
Object[] converted = Util.convert(parameterTypes, intoArray());
return accessible(constructor).newInstance(converted);
return Reflect.accessible(constructor).newInstance(converted);
}
}

View File

@ -43,7 +43,6 @@ import static org.jooq.impl.Factory.nullSafe;
import static org.jooq.impl.Factory.val;
import static org.jooq.tools.StringUtils.leftPad;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.sql.Blob;
@ -86,6 +85,7 @@ import org.jooq.tools.Convert;
import org.jooq.tools.LoggerListener;
import org.jooq.tools.StopWatchListener;
import org.jooq.tools.StringUtils;
import org.jooq.tools.reflect.Reflect;
/**
* General jOOQ utilities
@ -171,7 +171,7 @@ final class Util {
else {
// [#919] Allow for accessing non-public constructors
result = accessible(type.getDeclaredConstructor()).newInstance();
result = Reflect.accessible(type.getDeclaredConstructor()).newInstance();
}
result.attach(configuration);
@ -851,17 +851,6 @@ final class Util {
return result;
}
/**
* Ensure an {@link AccessibleObject} is really accessible
*/
static final <T extends AccessibleObject> T accessible(T accessible) {
if (!accessible.isAccessible()) {
accessible.setAccessible(true);
}
return accessible;
}
/**
* Type-safely copy a value from one record to another
*/
@ -926,7 +915,7 @@ final class Util {
EXECUTE_LISTENERS.put(name, type);
}
return (ExecuteListener) accessible(type.getDeclaredConstructor()).newInstance();
return (ExecuteListener) Reflect.accessible(type.getDeclaredConstructor()).newInstance();
}
catch (Exception e) {
throw new RuntimeException(e);

View File

@ -1,5 +1,5 @@
/**
* Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com
* Copyright (c) 2011-2012, Lukas Eder, lukas.eder@gmail.com
* All rights reserved.
*
* This software is licensed to you under the Apache License, Version 2.0
@ -35,6 +35,7 @@
*/
package org.jooq.tools.reflect;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
@ -109,6 +110,24 @@ public class Reflect {
return new Reflect(object);
}
/**
* Conveniently render an {@link AccessibleObject} accessible
*
* @param accessible The object to render accessible
* @return The argument object rendered accessible
*/
public static <T extends AccessibleObject> T accessible(T accessible) {
if (accessible == null) {
return null;
}
if (!accessible.isAccessible()) {
accessible.setAccessible(true);
}
return accessible;
}
// ---------------------------------------------------------------------
// Members
// ---------------------------------------------------------------------
@ -139,12 +158,6 @@ public class Reflect {
this.isClass = false;
}
// ---------------------------------------------------------------------
// Fluent Configuration API
// ---------------------------------------------------------------------
// TODO: Allow for accessing non-public members, methods, etc
// ---------------------------------------------------------------------
// Fluent Reflection API
// ---------------------------------------------------------------------
@ -181,27 +194,15 @@ public class Reflect {
return this;
}
catch (Exception e1) {
boolean accessible = true;
Field field = null;
// Try again, setting a non-public field
try {
field = type().getDeclaredField(name);
accessible = field.isAccessible();
if (!accessible)
field.setAccessible(true);
field.set(object, unwrap(value));
accessible(type().getDeclaredField(name)).set(object, unwrap(value));
return this;
}
catch (Exception e2) {
throw new ReflectException(e2);
}
finally {
if (field != null && !accessible) {
field.setAccessible(false);
}
}
}
}
@ -245,27 +246,14 @@ public class Reflect {
return on(field.get(object));
}
catch (Exception e1) {
Field field = null;
boolean accessible = true;
// Try again, getting a non-public field
try {
field = type().getDeclaredField(name);
accessible = field.isAccessible();
if (!accessible)
field.setAccessible(true);
return on(field.get(object));
return on(accessible(type().getDeclaredField(name)).get(object));
}
catch (Exception e2) {
throw new ReflectException(e2);
}
finally {
if (field != null && !accessible) {
field.setAccessible(false);
}
}
}
}
@ -519,11 +507,8 @@ public class Reflect {
* Wrap an object returned from a method
*/
private static Reflect on(Method method, Object object, Object... args) throws ReflectException {
boolean accessible = method.isAccessible();
try {
if (!accessible)
method.setAccessible(true);
accessible(method);
if (method.getReturnType() == void.class) {
method.invoke(object, args);
@ -536,11 +521,6 @@ public class Reflect {
catch (Exception e) {
throw new ReflectException(e);
}
finally {
if (!accessible) {
method.setAccessible(false);
}
}
}
/**

View File

@ -1,5 +1,5 @@
/**
* Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com
* Copyright (c) 2011-2012, Lukas Eder, lukas.eder@gmail.com
* All rights reserved.
*
* This software is licensed to you under the Apache License, Version 2.0