public synchronized double getCost(Session session, int[] masks, SortOrder sortOrder) {
if (recursive) {
return 1000;
}
IntArray masksArray = new IntArray(masks == null ? Utils.EMPTY_INT_ARRAY : masks);
SynchronizedVerifier.check(costCache);
CostElement cachedCost = costCache.get(masksArray);
if (cachedCost != null) {
long time = System.currentTimeMillis();
if (time < cachedCost.evaluatedAt + Constants.VIEW_COST_CACHE_MAX_AGE) {
return cachedCost.cost;
}
}
Query q = (Query) session.prepare(querySQL, true);
if (masks != null) {
IntArray paramIndex = new IntArray();
for (int i = 0; i < masks.length; i++) {
int mask = masks[i];
if (mask == 0) {
continue;
}
paramIndex.add(i);
}
int len = paramIndex.size();
for (int i = 0; i < len; i++) {
int idx = paramIndex.get(i);
int mask = masks[idx];
int nextParamIndex = q.getParameters().size() + view.getParameterOffset();
if ((mask & IndexCondition.EQUALITY) != 0) {
Parameter param = new Parameter(nextParamIndex);
q.addGlobalCondition(param, idx, Comparison.EQUAL_NULL_SAFE);