X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2FResourceImpl.java;h=78dacb98ff4ebad6997dcc1a027de5c0b902347e;hb=785f638bab44e70ec6103c3891daea95bcda9a07;hp=77764a323693caded1207522242831e13800e8cc;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ResourceImpl.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ResourceImpl.java index 77764a323..78dacb98f 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ResourceImpl.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ResourceImpl.java @@ -1,139 +1,140 @@ -/******************************************************************************* - * 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.impl; - -import org.simantics.db.Resource; -import org.simantics.db.impl.support.ResourceSupport; -import org.simantics.db.service.ClusterUID; - -final public class ResourceImpl implements Resource { - - final public ResourceSupport support; - final public int id; - - public ResourceImpl(final ResourceSupport support, final int id) { - assert(id != 0); - this.support = support; - this.id = id; - } - - @Override - final public long getResourceId() { - return support.getRandomAccessId(id); - } - - @Override - public boolean isPersistent() { - return id > 0; - } - - @Override - public Resource get() { - return this; - } - - @Override - public int hashCode() { - return id; - } - - @Override - public int getThreadHash() { - return id >>> 16; - } - - @Override - public boolean equals(Object object) { - if (this == object) - return true; - else if (object == null) - return false; - else if (!(object instanceof ResourceImpl)) - return false; - ResourceImpl r = (ResourceImpl)object; - return r.id == id; - } - - @Override - public boolean equalsResource(Resource other) { - ResourceImpl r = (ResourceImpl)other; - return r.id == id; - } - - @Override - public int compareTo(Resource o) { - if(this==o) - return 0; - if(o instanceof ResourceImpl) - return id - ((ResourceImpl)o).id; - else - return 1; - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(32); - try { - long rid = getResourceId(); - if(DebugPolicy.VERBOSE) { - sb.append("[id="); - sb.append(id); - sb.append(" - rid="); - sb.append(rid); - sb.append(" i="); - short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id); - sb.append(ri); - int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id); - sb.append(" c="); - sb.append(ck); - sb.append("]"); - } else { - sb.append("[id=$"); - sb.append(rid); - sb.append("]"); - } - } catch (Exception e) { - sb.append("[internal id="); - sb.append(id); - sb.append(", persistent resource id failed]"); - } - return sb.toString(); - } - public String toString(ClusterSupport support) { - StringBuilder sb = new StringBuilder(32); - long rid = getResourceId(); - if (DebugPolicy.VERBOSE) { - sb.append("[id="); - sb.append(id); - sb.append(" - rid="); - sb.append(rid); - sb.append(" i="); - short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id); - sb.append(ri); - int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id); - sb.append(" ck="); - sb.append(ck); - ClusterBase cb = support.getClusterByClusterKey(ck); - if (null != cb) { - ClusterUID clusterUID = cb.getClusterUID(); - sb.append(" c="); - sb.append(clusterUID.toString()); - } - sb.append("]"); - } else { - sb.append("[id=$"); - sb.append(rid); - sb.append("]"); - } - return sb.toString(); - } -} +/******************************************************************************* + * 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.impl; + +import org.simantics.db.DevelopmentKeys; +import org.simantics.db.Resource; +import org.simantics.db.impl.support.ResourceSupport; +import org.simantics.db.service.ClusterUID; + +final public class ResourceImpl implements Resource { + + final public ResourceSupport support; + final public int id; + + public ResourceImpl(final ResourceSupport support, final int id) { + assert(id != 0); + this.support = support; + this.id = id; + } + + @Override + final public long getResourceId() { + return support.getRandomAccessId(id); + } + + @Override + public boolean isPersistent() { + return id > 0; + } + + @Override + public Resource get() { + return this; + } + + @Override + public int hashCode() { + return id; + } + + @Override + public int getThreadHash() { + return id >>> 16; + } + + @Override + public boolean equals(Object object) { + if (this == object) + return true; + else if (object == null) + return false; + else if (!(object instanceof ResourceImpl)) + return false; + ResourceImpl r = (ResourceImpl)object; + return r.id == id; + } + + @Override + public boolean equalsResource(Resource other) { + ResourceImpl r = (ResourceImpl)other; + return r.id == id; + } + + @Override + public int compareTo(Resource o) { + if(this==o) + return 0; + if(o instanceof ResourceImpl) + return id - ((ResourceImpl)o).id; + else + return 1; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(32); + try { + long rid = getResourceId(); + if(DevelopmentKeys.VERBOSE) { + sb.append("[id="); + sb.append(id); + sb.append(" - rid="); + sb.append(rid); + sb.append(" i="); + short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id); + sb.append(ri); + int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id); + sb.append(" c="); + sb.append(ck); + sb.append("]"); + } else { + sb.append("[id=$"); + sb.append(rid); + sb.append("]"); + } + } catch (Exception e) { + sb.append("[internal id="); + sb.append(id); + sb.append(", persistent resource id failed]"); + } + return sb.toString(); + } + public String toString(ClusterSupport support) { + StringBuilder sb = new StringBuilder(32); + long rid = getResourceId(); + if (DevelopmentKeys.VERBOSE) { + sb.append("[id="); + sb.append(id); + sb.append(" - rid="); + sb.append(rid); + sb.append(" i="); + short ri = ClusterTraitsBase.getResourceIndexFromResourceKeyNoThrow(id); + sb.append(ri); + int ck = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(id); + sb.append(" ck="); + sb.append(ck); + ClusterBase cb = support.getClusterByClusterKey(ck); + if (null != cb) { + ClusterUID clusterUID = cb.getClusterUID(); + sb.append(" c="); + sb.append(clusterUID.toString()); + } + sb.append("]"); + } else { + sb.append("[id=$"); + sb.append(rid); + sb.append("]"); + } + return sb.toString(); + } +}