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.impl;
\r
14 import org.simantics.db.Resource;
\r
15 import org.simantics.db.impl.support.ResourceSupport;
\r
16 import org.simantics.db.service.ClusterUID;
\r
18 final public class ResourceImpl implements Resource {
\r
20 final public ResourceSupport support;
\r
21 final public int id;
\r
23 public ResourceImpl(final ResourceSupport support, final int id) {
\r
25 this.support = support;
\r
30 final public long getResourceId() {
\r
31 return support.getRandomAccessId(id);
\r
35 public boolean isPersistent() {
\r
40 public Resource get() {
\r
45 public int hashCode() {
\r
50 public int getThreadHash() {
\r
55 public boolean equals(Object object) {
\r
58 else if (object == null)
\r
60 else if (!(object instanceof ResourceImpl))
\r
62 ResourceImpl r = (ResourceImpl)object;
\r
67 public boolean equalsResource(Resource other) {
\r
68 ResourceImpl r = (ResourceImpl)other;
\r
73 public int compareTo(Resource o) {
\r
76 if(o instanceof ResourceImpl)
\r
77 return id - ((ResourceImpl)o).id;
\r
83 public String toString() {
\r
84 StringBuilder sb = new StringBuilder(32);
\r
86 long rid = getResourceId();
\r
87 if(DebugPolicy.VERBOSE) {
\r
90 sb.append(" - rid=");
\r
93 short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id);
\r
95 int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id);
\r
100 sb.append("[id=$");
\r
104 } catch (Exception e) {
\r
105 sb.append("[internal id=");
\r
107 sb.append(", persistent resource id failed]");
\r
109 return sb.toString();
\r
111 public String toString(ClusterSupport support) {
\r
112 StringBuilder sb = new StringBuilder(32);
\r
113 long rid = getResourceId();
\r
114 if (DebugPolicy.VERBOSE) {
\r
117 sb.append(" - rid=");
\r
120 short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id);
\r
122 int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id);
\r
125 ClusterBase cb = support.getClusterByClusterKey(ck);
\r
127 ClusterUID clusterUID = cb.getClusterUID();
\r
129 sb.append(clusterUID.toString());
\r
133 sb.append("[id=$");
\r
137 return sb.toString();
\r