1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.impl;
14 import org.simantics.db.Resource;
15 import org.simantics.db.impl.support.ResourceSupport;
16 import org.simantics.db.service.ClusterUID;
18 final public class ResourceImpl implements Resource {
20 final public ResourceSupport support;
23 public ResourceImpl(final ResourceSupport support, final int id) {
25 this.support = support;
30 final public long getResourceId() {
31 return support.getRandomAccessId(id);
35 public boolean isPersistent() {
40 public Resource get() {
45 public int hashCode() {
50 public int getThreadHash() {
55 public boolean equals(Object object) {
58 else if (object == null)
60 else if (!(object instanceof ResourceImpl))
62 ResourceImpl r = (ResourceImpl)object;
67 public boolean equalsResource(Resource other) {
68 ResourceImpl r = (ResourceImpl)other;
73 public int compareTo(Resource o) {
76 if(o instanceof ResourceImpl)
77 return id - ((ResourceImpl)o).id;
83 public String toString() {
84 StringBuilder sb = new StringBuilder(32);
86 long rid = getResourceId();
87 if(DebugPolicy.VERBOSE) {
93 short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id);
95 int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id);
104 } catch (Exception e) {
105 sb.append("[internal id=");
107 sb.append(", persistent resource id failed]");
109 return sb.toString();
111 public String toString(ClusterSupport support) {
112 StringBuilder sb = new StringBuilder(32);
113 long rid = getResourceId();
114 if (DebugPolicy.VERBOSE) {
117 sb.append(" - rid=");
120 short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id);
122 int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id);
125 ClusterBase cb = support.getClusterByClusterKey(ck);
127 ClusterUID clusterUID = cb.getClusterUID();
129 sb.append(clusterUID.toString());
137 return sb.toString();