]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ListenerEntry.java
QueryListening sync is slow
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / ListenerEntry.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.impl.query;
13
14 import org.simantics.db.procedure.ListenerBase;
15
16 class ListenerEntry {
17     
18     public static final Object NO_VALUE = new Object() {
19         
20         public String toString() { return "NO_VALUE"; };
21         
22     };
23     public static final Object NOT_CHANGED = new Object() {
24       
25         public String toString() { return "NOT_CHANGED"; };
26         
27     };
28     
29     public ListenerBase base;
30     public Object procedure;
31     public CacheEntry entry;
32     
33     private Object lastKnownResult;
34     
35     public ListenerEntry(CacheEntry entry, ListenerBase base, Object procedure) {
36         this.entry = entry;
37         this.base = base;
38         this.procedure = procedure;
39         if(entry.isReady()) {
40             this.lastKnownResult = entry.getResult();
41         } else {
42             this.lastKnownResult = NO_VALUE;
43         }
44     }
45     
46     public void setLastKnown(Object object) {
47         lastKnownResult = object;
48     }
49     
50     public Object getLastKnown() {
51         return lastKnownResult;
52     }
53
54     @Override
55     public String toString() {
56 //      return "[ListenerEntry last = " + lastKnownResult + ", procedure = " + procedure + "]";
57         return "[ListenerEntry " + ", procedure = " + procedure + " base=" + base + "]";
58     }
59     
60     @Override
61     public int hashCode() {
62         return base.hashCode();
63     }
64     
65         @Override
66     public boolean equals(Object obj) {
67
68         if(obj == this) return true;
69         if(obj == null) return false;
70         if(obj.getClass() != this.getClass()) return false;
71         ListenerEntry other = (ListenerEntry)obj;
72         return base.equals(other.base);
73         
74     }
75     
76 }