/** * This method retrieves the value from the feature at the given index. It retrieves the value * either from the views's store or the internal pre-registration Map. * * @param feature the feature to retrieve the value from * @param index the given index of the object in the feature * @return the value from the feature at the given index */ private Object getValueFromRevision(EStructuralFeature feature, int index) { InternalCDORevision revision = cdoRevision(); Object object = revision.get(feature, index); if (object == null) { return null; } if (object instanceof CDOElementProxy) { // Resolve proxy CDOElementProxy proxy = (CDOElementProxy) object; object = viewAndState .view .getSession() .resolveElementProxy(revision, feature, index, proxy.getIndex()); } if (object instanceof CDOLegacyWrapper) { return ((CDOLegacyWrapper) object).cdoInternalInstance(); } CDOType type = CDOModelUtil.getType(feature.getEType()); object = viewAndState.view.getStore().convertToEMF(instance, revision, feature, index, object); if (type == CDOType.OBJECT) { if (object instanceof CDOID) { CDOID id = (CDOID) object; if (id.isNull()) { return null; } object = getRegisteredWrapper(id); if (object != null) { return ((CDOLegacyWrapper) object).cdoInternalInstance(); } if (id.isExternal()) { object = viewAndState .view .getResourceSet() .getEObject(URI.createURI(id.toURIFragment()), true); } else { object = viewAndState.view.getObject(id); } if (object instanceof CDOObjectWrapper) { return ((CDOObjectWrapper) object).cdoInternalInstance(); } } } return object; }
/** @since 4.0 */ protected void writeSystemValues(CDODataOutput out) throws IOException { EClass eClass = getEClass(); CDOClassifierRef classRef = new CDOClassifierRef(eClass); if (TRACER.isEnabled()) { TRACER.format( "Writing revision: ID={0}, className={1}, version={2}, branchPoint={3}, revised={4}, resource={5}, container={6}, featureID={7}", //$NON-NLS-1$ id, eClass.getName(), getVersion(), branchPoint, revised, resourceID, containerID, containingFeatureID); } out.writeCDOClassifierRef(classRef); out.writeCDOID(id); out.writeCDOBranchPoint(branchPoint); out.writeInt(getVersion()); if (!id.isTemporary()) { out.writeLong(revised); } out.writeCDOID(resourceID); out.writeCDOID(out.getIDProvider().provideCDOID(containerID)); out.writeInt(containingFeatureID); }
/** @since 4.0 */ protected void readSystemValues(CDODataInput in) throws IOException { EClassifier classifier = in.readCDOClassifierRefAndResolve(); initClassInfo((EClass) classifier); id = in.readCDOID(); branchPoint = in.readCDOBranchPoint(); version = in.readInt(); if (!id.isTemporary()) { revised = in.readLong(); } resourceID = in.readCDOID(); containerID = in.readCDOID(); containingFeatureID = in.readInt(); if (TRACER.isEnabled()) { TRACER.format( "Reading revision: ID={0}, className={1}, version={2}, branchPoint={3}, revised={4}, resource={5}, container={6}, featureID={7}", //$NON-NLS-1$ id, getEClass().getName(), version, branchPoint, revised, resourceID, containerID, containingFeatureID); } }
/** * @param feature in case that a proxy has to be created the feature that will determine the * interface type of the proxy and that will be used later to resolve the proxy. <code>null * </code> indicates that proxy creation will be avoided! */ protected InternalEObject getEObjectFromPotentialID( InternalCDOView view, EStructuralFeature feature, Object potentialID) { CDOLegacyWrapper wrapper; if (potentialID instanceof CDOID && (wrapper = getRegisteredWrapper((CDOID) potentialID)) != null) { potentialID = wrapper.instance; if (TRACER.isEnabled()) { TRACER.format( "Getting Object (" + potentialID + ") from localThread instead of the view"); //$NON-NLS-1$ //$NON-NLS-2$ } } else { if (potentialID instanceof CDOID) { CDOID id = (CDOID) potentialID; if (id.isNull()) { return null; } if (id.isExternal()) { URI uri = URI.createURI(id.toURIFragment()); InternalEObject eObject = (InternalEObject) viewAndState.view.getResourceSet().getEObject(uri, true); return eObject; } boolean loadOnDemand = feature == null; potentialID = viewAndState.view.getObject(id, loadOnDemand); if (potentialID == null && !loadOnDemand) { return createProxy(view, feature, id); } } if (potentialID instanceof InternalCDOObject) { return ((InternalCDOObject) potentialID).cdoInternalInstance(); } } return (InternalEObject) potentialID; }
public static Object remapID( Object value, Map<CDOID, CDOID> idMappings, boolean allowUnmappedTempIDs) { if (value instanceof CDOID) { CDOID oldID = (CDOID) value; if (!oldID.isNull()) { CDOID newID = idMappings.get(oldID); if (newID != null) { if (TRACER.isEnabled()) { TRACER.format("Adjusting ID: {0} --> {1}", oldID, newID); } return newID; } if (oldID instanceof CDOIDTemp) { throw new IllegalStateException( MessageFormat.format(Messages.getString("AbstractCDORevision.2"), oldID)); } } } return value; }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.equals(getIDMethod)) { return id; } if (method.equals(eIsProxyMethod)) { return true; } if (method.equals(eProxyURIMethod)) { // Use container's resource because it's guaranteed to be in the same CDOView as the // resource of the target! Resource resource = wrapper.eResource(); // TODO Consider using a "fake" Resource implementation. See Resource.getEObject(...) return resource.getURI().appendFragment(id.toURIFragment()); } // A client must have invoked the proxy while being told not to do so! throw new UnsupportedOperationException(method.getName()); }
protected ooId getOidFromCDOID(CDOID id) { ooId oid = null; // if (OBJYCDOIDUtil.isValidObjyId(id)) // oid = OBJYCDOIDUtil.getooId(id); if (id.isTemporary()) { // see if we've seen it before CDOID nearId = idMapper.get(id); if (nearId != null) { oid = OBJYCDOIDUtil.getooId(nearId); } else { // create that object since it wasn't created and mapped yet. InternalCDORevision containerRevision = newObjectsMap.get(id); if (containerRevision != null) { oid = createObjectAndAddToMapping(containerRevision).ooId(); } } } else { oid = OBJYCDOIDUtil.getooId(id); } return oid; }
@Override protected int doCompareTo(CDOID o) throws ClassCastException { // conversion to uri fragment is pretty heavy but afaics the compareTo // is not used in a critical place. return toURIFragment().compareTo(o.toURIFragment()); }
@Override public int hashCode() { return id.hashCode() ^ branch.hashCode(); }