OPENJPA-924: Cache primary key field indices. Simplify QueryStatistics template.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@745329 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Pinaki Poddar 2009-02-18 00:49:51 +00:00
parent 3fc7f54a01
commit f08e4e1791
4 changed files with 18 additions and 14 deletions

View File

@ -60,8 +60,7 @@ public class FinderCacheImpl
// Key: class name Value: Reason why excluded
private final Map<String, String> _uncachables;
private List<String> _exclusionPatterns;
private QueryStatistics<FinderQuery<ClassMapping,SelectExecutor,Result>>
_stats;
private QueryStatistics<ClassMapping> _stats;
private ReentrantLock _lock = new ReentrantLock();
private Log _log;
private Localizer _loc = Localizer.forPackage(FinderCacheImpl.class);
@ -71,8 +70,7 @@ public class FinderCacheImpl
_delegate = new HashMap<ClassMapping,
FinderQuery<ClassMapping, SelectExecutor, Result>>();
_uncachables = new HashMap<String, String>();
_stats = new QueryStatistics.Default<FinderQuery<ClassMapping,
SelectExecutor,Result>>();
_stats = new QueryStatistics.Default<ClassMapping>();
}
/**
@ -96,8 +94,7 @@ public class FinderCacheImpl
/**
* Gets basic statistics of execution and hit count of finder queries.
*/
public QueryStatistics<FinderQuery<ClassMapping,SelectExecutor,Result>>
getStatistics() {
public QueryStatistics<ClassMapping> getStatistics() {
return _stats;
}
@ -121,7 +118,7 @@ public class FinderCacheImpl
return null;
FinderQuery<ClassMapping, SelectExecutor, Result> result =
_delegate.get(mapping);
_stats.recordExecution(result, result != null);
_stats.recordExecution(mapping, result != null);
return result;
}

View File

@ -36,6 +36,7 @@ import org.apache.openjpa.kernel.FetchConfiguration;
import org.apache.openjpa.kernel.FinderQuery;
import org.apache.openjpa.kernel.OpenJPAStateManager;
import org.apache.openjpa.kernel.StoreManager;
import org.apache.openjpa.meta.FieldMetaData;
import org.apache.openjpa.util.ApplicationIds;
import org.apache.openjpa.util.Id;
@ -55,6 +56,7 @@ public class FinderQueryImpl
private final SelectImpl _select;
private final Column[] _pkCols;
private final Joinable[] _joins;
private final int[] _pkIndices;
private final SQLBuffer _buffer;
private final String _sql;
@ -86,6 +88,12 @@ public class FinderQueryImpl
_joins = new Joinable[_pkCols.length];
for (int i = 0; i < _pkCols.length; i++)
_joins[i] = _mapping.assertJoinable(_pkCols[i]);
_pkIndices = new int[_pkCols.length];
for (int i = 0; i < _pkCols.length; i++) {
FieldMetaData pk = _mapping.getField(_joins[i].getFieldIndex());
_pkIndices[i] = pk == null ? 0 : pk.getPrimaryKeyIndex();
}
}
public ClassMapping getIdentifier() {
@ -111,12 +119,10 @@ public class FinderQueryImpl
for (int i = 0; i < _pkCols.length; i++, count++) {
if (pks == null)
val[0] = (oid == null)
? null
: Numbers.valueOf(((Id) oid).getId());
? null : Numbers.valueOf(((Id) oid).getId());
else {
val[i] = pks[_mapping.getField(_joins[i].getFieldIndex()).
getPrimaryKeyIndex()];
val[i] = _joins[i].getJoinValue(val[i], _pkCols[i], store);
val[i] = _joins[i].getJoinValue(pks[_pkIndices[i]], _pkCols[i],
store);
}
}
return val;

View File

@ -203,7 +203,8 @@ public class ManagedClassSubclasser {
private static Set<Class> collectUnspecifiedType(Class cls,
Collection<? extends Class> classes, Set<Class> unspecified) {
if (cls != null && !classes.contains(cls)
&& !ImplHelper.isManagedType(null, cls)) {
&& !ImplHelper.isManagedType(null, cls)
&& !cls.isInterface()) {
if (unspecified == null)
unspecified = new HashSet<Class>();
unspecified.add(cls);

View File

@ -140,5 +140,5 @@ public interface FinderCache<K,V,R> extends Configurable {
/**
* Gets the simple statistics for executed finder queries.
*/
public QueryStatistics<FinderQuery<K,V,R>> getStatistics();
public QueryStatistics<K> getStatistics();
}