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.DevelopmentKeys;
15 import org.simantics.db.Resource;
16 import org.simantics.db.impl.support.ResourceSupport;
17 import org.simantics.db.service.ClusterUID;
19 final public class ResourceImpl implements Resource {
21 final public ResourceSupport support;
24 public ResourceImpl(final ResourceSupport support, final int id) {
26 this.support = support;
31 final public long getResourceId() {
32 return support.getRandomAccessId(id);
36 public boolean isPersistent() {
41 public Resource get() {
46 public int hashCode() {
51 public int getThreadHash() {
56 public boolean equals(Object object) {
59 else if (object == null)
61 else if (!(object instanceof ResourceImpl))
63 ResourceImpl r = (ResourceImpl)object;
68 public boolean equalsResource(Resource other) {
69 ResourceImpl r = (ResourceImpl)other;
74 public int compareTo(Resource o) {
77 if(o instanceof ResourceImpl)
78 return id - ((ResourceImpl)o).id;
84 public String toString() {
85 StringBuilder sb = new StringBuilder(32);
87 long rid = getResourceId();
88 if(DevelopmentKeys.VERBOSE) {
94 short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id);
96 int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id);
105 } catch (Exception e) {
106 sb.append("[internal id=");
108 sb.append(", persistent resource id failed]");
110 return sb.toString();
112 public String toString(ClusterSupport support) {
113 StringBuilder sb = new StringBuilder(32);
114 long rid = getResourceId();
115 if (DevelopmentKeys.VERBOSE) {
118 sb.append(" - rid=");
121 short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id);
123 int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id);
126 ClusterBase cb = support.getClusterByClusterKey(ck);
128 ClusterUID clusterUID = cb.getClusterUID();
130 sb.append(clusterUID.toString());
138 return sb.toString();