mirror of https://github.com/apache/openjpa.git
OPENJPA-2065: allow interface as result class
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1190723 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3494fab794
commit
8d21608618
|
@ -117,10 +117,9 @@ public class ResultPacker {
|
|||
/**
|
||||
* Internal constructor.
|
||||
*/
|
||||
private ResultPacker(Class candidate, Class[] types, String[] aliases,
|
||||
Class resultClass) {
|
||||
private ResultPacker(Class<?> candidate, Class<?>[] types, String[] aliases, Class<?> resultClass) {
|
||||
_aliases = aliases;
|
||||
if (candidate == resultClass
|
||||
if (candidate == resultClass || isInterface(resultClass, candidate)
|
||||
||(types != null && types.length == 1 && types[0] == resultClass)
|
||||
|| resultClass.isArray()) {
|
||||
_resultClass = resultClass;
|
||||
|
@ -135,7 +134,7 @@ public class ResultPacker {
|
|||
_constructor = null;
|
||||
} else if (!_stdTypes.contains(_resultClass = resultClass)) {
|
||||
// check for a constructor that matches the projection types
|
||||
Constructor cons = null;
|
||||
Constructor<?> cons = null;
|
||||
if (types != null && types.length > 0) {
|
||||
try {
|
||||
cons = _resultClass.getConstructor(types);
|
||||
|
@ -150,7 +149,7 @@ public class ResultPacker {
|
|||
_put = findPut(methods);
|
||||
_sets = new Member[aliases.length];
|
||||
|
||||
Class type;
|
||||
Class<?> type;
|
||||
for (int i = 0; i < _sets.length; i++) {
|
||||
type = (types == null) ? candidate : types[i];
|
||||
_sets[i] = findSet(aliases[i], type, fields, methods);
|
||||
|
@ -173,6 +172,15 @@ public class ResultPacker {
|
|||
}
|
||||
}
|
||||
|
||||
boolean isInterface(Class<?> intf, Class<?> actual) {
|
||||
Class<?>[] intfs = actual.getInterfaces();
|
||||
for (Class<?> c : intfs) {
|
||||
if (c == intf)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that conversion is possible.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue