1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.procore.cluster;
\r
14 import org.simantics.db.exception.DatabaseException;
\r
15 import org.simantics.db.impl.ClusterI;
\r
16 import org.simantics.db.impl.ClusterTraitsBase;
\r
19 public final class ClusterTraitsSmall extends ClusterTraitsBase {
\r
20 static final short FOREIGN_INDEX_BITS = 15;
\r
21 static final short FOREIGN_INDEX_MAX = (1<<FOREIGN_INDEX_BITS)-1;
\r
22 static final int VALUE_INDEX_BITS = 22;
\r
23 static final int VALUE_INDEX_MAX = (1<<VALUE_INDEX_BITS)-1;
\r
24 static final int VALUE_INDEX_EX = VALUE_INDEX_MAX;
\r
25 static final int VALUE_SIZE_BITS = 15;
\r
26 public static final int VALUE_SIZE_MAX = (1<<VALUE_SIZE_BITS)-1;
\r
27 public static final short makeForeignRef(short foreignIndex) {
\r
28 assert(foreignIndex <= FOREIGN_INDEX_MAX);
\r
29 return (short)(foreignIndex | 1<<FOREIGN_INDEX_BITS);
\r
31 public static short resourceRefGetForeignIndex(short resourceRef)
\r
32 throws DatabaseException {
\r
33 if (resourceRef >>> FOREIGN_INDEX_BITS == 0)
\r
34 throw new DatabaseException("Local resource refence doesn't have foreing index. reference=" + resourceRef);
\r
35 return (short)(resourceRef & FOREIGN_INDEX_MAX);
\r
37 public static boolean resourceRefIsLocal(short resourceRef) {
\r
38 return resourceRef > 0;
\r
40 public static ClusterI.CompleteTypeEnum completeRefAndTypeGetType(int completeRefAndType) {
\r
41 return ClusterI.CompleteTypeEnum.make((completeRefAndType >>> 16) & 0x3);
\r
43 public static short completeRefAndTypeGetRef(int completeRefAndType) {
\r
44 return (short)(completeRefAndType & (1<<16)-1);
\r