/******************************************************************************* * Copyright (c) 2007, 2010 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.db.procore.cluster; import gnu.trove.map.hash.TObjectIntHashMap; import org.simantics.db.exception.DatabaseException; import org.simantics.db.impl.ClusterI.Procedure; import org.simantics.db.impl.ClusterSupport; import org.simantics.db.impl.Modifier; import org.simantics.db.impl.Table; import org.simantics.db.impl.TableFactory; import org.simantics.db.impl.TableSizeListener; import org.simantics.db.service.ClusterUID; import org.simantics.db.service.ResourceUID; final class ForeignElement { private static final int CLUSTER_OFFSET = 0; // resourceUID private static final int SIZE_OF = 3; static void constructForeign(long[] table, int index, ResourceUID resourceUID) { int i = CLUSTER_OFFSET + index; resourceUID.toLong(table, i); } static void destructForeign(long[] table, int index) { int i = CLUSTER_OFFSET + index; table[i++] = 0; table[i++] = 0; table[i++] = 0; } static int getSizeOf() { return SIZE_OF; } static ResourceUID getResourceUID(long[] table, int index) { int i = CLUSTER_OFFSET + index; return new ResourceUID(table, i); } static void fillResourceUID(long[] table, int index, ClusterSmall cluster) { int i = CLUSTER_OFFSET + index; cluster.clusterUID1 = table[i]; cluster.clusterUID2 = table[i+1]; cluster.executeIndex = (short)table[i+2]; } } public final class ForeignTable extends Table { public ForeignTable(TableSizeListener sizeListener, int[] header, int headerBase) { super(TableFactory.getLongFactory(), sizeListener, header, headerBase); } public ForeignTable(TableSizeListener sizeListener, int[] header, int headerBase, long[] longs) { super(TableFactory.getLongFactory(), sizeListener, header, headerBase, longs); } public int getUsedSize() { return getTableCount(); } TObjectIntHashMap getHashMap() throws DatabaseException { int ELEMENT_SIZE = ForeignElement.getSizeOf(); final int TABLE_SIZE = getTableCount(); final int FOREIGN_COUNT = getForeignCount(); final int BASE = this.getTableBase(); final int TOP = BASE + TABLE_SIZE * ELEMENT_SIZE; long[] table = this.getTable(); int count = 0; int index = ZERO_SHIFT; TObjectIntHashMap hm = new TObjectIntHashMap(FOREIGN_COUNT); for (int i=BASE; i getResourceHashMap() throws DatabaseException { int ELEMENT_SIZE = ForeignElement.getSizeOf(); assert(ELEMENT_SIZE == 3); final int TABLE_SIZE = getTableCount(); final int FOREIGN_COUNT = getForeignCount(); final int BASE = this.getTableBase(); final int TOP = BASE + TABLE_SIZE * ELEMENT_SIZE; long[] table = this.getTable(); int count = 0; int index = ZERO_SHIFT; TObjectIntHashMap hm = new TObjectIntHashMap(FOREIGN_COUNT); for (int i=BASE; i