01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.jdo.query.mem;
12:
13: import com.versant.core.common.OID;
14:
15: import java.util.List;
16: import java.util.Comparator;
17: import java.util.Collections;
18:
19: import com.versant.core.common.OID;
20: import com.versant.core.jdo.PMProxy;
21: import com.versant.core.jdo.VersantPersistenceManagerImp;
22:
23: /**
24: * @keep-all
25: */
26: public class BCodeSorter implements Comparator {
27: private List toSort;
28: private PMProxy pmProxy;
29: private BCodeQuery bCodeCompare;
30:
31: public void sort(List listOfOids, PMProxy pmProxy,
32: BCodeQuery bCodeCompare) {
33: this .toSort = listOfOids;
34: this .pmProxy = pmProxy;
35: this .bCodeCompare = bCodeCompare;
36: Collections.sort(toSort, this );
37: }
38:
39: public int compare(Object o1, Object o2) {
40: return compare((OID) o1, (OID) o2);
41: }
42:
43: /**
44: * If there is a exception with the compare eg. null for one of the comp params then -1 is returned.
45: * @param o1
46: * @param o2
47: * @return
48: */
49: public int compare(OID o1, OID o2) {
50: int comp = 0;
51: try {
52: final VersantPersistenceManagerImp realPM = pmProxy
53: .getRealPM();
54: comp = bCodeCompare.compare(
55: realPM.getInternalSM(o1).queryStateWrapper, realPM
56: .getInternalSM(o2).queryStateWrapper);
57: } catch (Exception e) {
58: comp = -1;
59: }
60: return comp;
61: }
62: }
|