]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ClusterTraitsSmall.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.procore / src / org / simantics / db / procore / cluster / ClusterTraitsSmall.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.procore.cluster;
13
14 import org.simantics.db.exception.DatabaseException;
15 import org.simantics.db.impl.ClusterI;
16 import org.simantics.db.impl.ClusterTraitsBase;
17
18
19 public final class ClusterTraitsSmall extends ClusterTraitsBase {
20     static final short FOREIGN_INDEX_BITS = 15;
21     static final short FOREIGN_INDEX_MAX = (1<<FOREIGN_INDEX_BITS)-1;
22     static final int VALUE_INDEX_BITS = 22;
23     static final int VALUE_INDEX_MAX = (1<<VALUE_INDEX_BITS)-1;
24     static final int VALUE_INDEX_EX = VALUE_INDEX_MAX; 
25     static final int VALUE_SIZE_BITS = 15;
26     public static final int VALUE_SIZE_MAX = (1<<VALUE_SIZE_BITS)-1;
27     public static final short makeForeignRef(short foreignIndex) {
28         assert(foreignIndex <= FOREIGN_INDEX_MAX);
29         return (short)(foreignIndex | 1<<FOREIGN_INDEX_BITS);
30     }
31     public static short resourceRefGetForeignIndex(short resourceRef)
32     throws DatabaseException {
33         if (resourceRef >>> FOREIGN_INDEX_BITS == 0)
34             throw new DatabaseException("Local resource refence doesn't have foreing index. reference=" + resourceRef);
35         return (short)(resourceRef & FOREIGN_INDEX_MAX);
36     }
37     public static boolean resourceRefIsLocal(short resourceRef) {
38         return resourceRef > 0; 
39     }
40     public static ClusterI.CompleteTypeEnum completeRefAndTypeGetType(int completeRefAndType) {
41         return ClusterI.CompleteTypeEnum.make((completeRefAndType >>> 16) & 0x3);
42     }
43     public static short completeRefAndTypeGetRef(int completeRefAndType) {
44         return (short)(completeRefAndType & (1<<16)-1);
45     }
46 }
47