Exemple #1
0
    def resolveClientProxy(self, domainEntity, proxyType, key):
        """Creates a proxy instance held by a Resolution for a given domain type."""
        if domainEntity is None:
            return None

        id_ = self._state.getStableId(domainEntity)

        isEntityProxy = self._state.isEntityType(proxyType)

        # Create the id or update an ephemeral id by calculating its address
        if (id_ is None) or id_.isEphemeral():
            # The address is an id or an id plus a path
            if isEntityProxy:
                # Compute data needed to return id to the client
                domainId = self._service.getId(domainEntity)
                domainVersion = self._service.getVersion(domainEntity)
            else:
                domainId = None
                domainVersion = None

            if id_ is None:
                if domainId is None:
                    # This will happen when server code attempts to return an unpersisted
                    # object to the client. In this case, we'll assign a synthetic id
                    # that is valid for the duration of the response. The client is
                    # expected to assign a client-local id to this object and then it
                    # will behave as though it were an object newly-created by the
                    # client.
                    self._syntheticId += 1
                    id_ = self._state.getIdFactory().allocateSyntheticId(
                        proxyType, self._syntheticId)
                else:
                    flatValue = self._state.flatten(domainId)
                    id_ = self._state.getIdFactory().getId(
                        proxyType, flatValue.getPayload(), 0)
            elif domainId is not None:
                # Mark an ephemeral id as having been persisted
                flatValue = self._state.flatten(domainId)
                id_.setServerId(flatValue.getPayload())
        elif isEntityProxy:
            # Already have the id, just pull the current version
            domainVersion = self._service.getVersion(domainEntity)
        else:
            # The version of a value object is always null
            domainVersion = None

        bean = self._state.getBeanForPayload(id_, domainEntity)
        bean.setTag(Constants.IN_RESPONSE, True)
        if domainVersion is not None:
            flatVersion = self._state.flatten(domainVersion)
            bean.setTag(Constants.VERSION_PROPERTY_B64,
                        toBase64(flatVersion.getPayload()))

        clientObject = bean.as_()
        return self.makeResolution(key, clientObject)
Exemple #2
0
    def resolveClientProxy(self, domainEntity, proxyType, key):
        """Creates a proxy instance held by a Resolution for a given domain type."""
        if domainEntity is None:
            return None

        id_ = self._state.getStableId(domainEntity)

        isEntityProxy = self._state.isEntityType(proxyType)

        # Create the id or update an ephemeral id by calculating its address
        if (id_ is None) or id_.isEphemeral():
            # The address is an id or an id plus a path
            if isEntityProxy:
                # Compute data needed to return id to the client
                domainId = self._service.getId(domainEntity)
                domainVersion = self._service.getVersion(domainEntity)
            else:
                domainId = None
                domainVersion = None

            if id_ is None:
                if domainId is None:
                    # This will happen when server code attempts to return an unpersisted
                    # object to the client. In this case, we'll assign a synthetic id
                    # that is valid for the duration of the response. The client is
                    # expected to assign a client-local id to this object and then it
                    # will behave as though it were an object newly-created by the
                    # client.
                    self._syntheticId += 1
                    id_ = self._state.getIdFactory().allocateSyntheticId(proxyType, self._syntheticId)
                else:
                    flatValue = self._state.flatten(domainId)
                    id_ = self._state.getIdFactory().getId(proxyType, flatValue.getPayload(), 0)
            elif domainId is not None:
                # Mark an ephemeral id as having been persisted
                flatValue = self._state.flatten(domainId)
                id_.setServerId(flatValue.getPayload())
        elif isEntityProxy:
            # Already have the id, just pull the current version
            domainVersion = self._service.getVersion(domainEntity)
        else:
            # The version of a value object is always null
            domainVersion = None

        bean = self._state.getBeanForPayload(id_, domainEntity)
        bean.setTag(Constants.IN_RESPONSE, True)
        if domainVersion is not None:
            flatVersion = self._state.flatten(domainVersion)
            bean.setTag(Constants.VERSION_PROPERTY_B64, toBase64(flatVersion.getPayload()))

        clientObject = bean.as_()
        return self.makeResolution(key, clientObject)
 def getSerializedProxyId(self, stableId):
     """EntityCodex support. This method is identical to
     {@link IdFactory#getHistoryToken(SimpleProxyId)} except that it
     base64-encodes the server ids.
     <p>
     XXX: Merge this with AbstsractRequestContext's implementation
     """
     bean = MessageFactoryHolder.FACTORY.id()
     ref = bean.as_()
     ref.setTypeToken(self._service.resolveTypeToken(stableId.getProxyClass()))
     if stableId.isSynthetic():
         ref.setStrength(Strength.SYNTHETIC)
         ref.setSyntheticId(stableId.getSyntheticId())
     elif stableId.isEphemeral():
         ref.setStrength(Strength.EPHEMERAL)
         ref.setClientId(stableId.getClientId())
     else:
         ref.setServerId(toBase64(stableId.getServerId()))
     return AutoBeanCodex.encode(bean)
Exemple #4
0
 def getSerializedProxyId(self, stableId):
     """EntityCodex support. This method is identical to
     {@link IdFactory#getHistoryToken(SimpleProxyId)} except that it
     base64-encodes the server ids.
     <p>
     XXX: Merge this with AbstsractRequestContext's implementation
     """
     bean = MessageFactoryHolder.FACTORY.id()
     ref = bean.as_()
     ref.setTypeToken(
         self._service.resolveTypeToken(stableId.getProxyClass()))
     if stableId.isSynthetic():
         ref.setStrength(Strength.SYNTHETIC)
         ref.setSyntheticId(stableId.getSyntheticId())
     elif stableId.isEphemeral():
         ref.setStrength(Strength.EPHEMERAL)
         ref.setClientId(stableId.getClientId())
     else:
         ref.setServerId(toBase64(stableId.getServerId()))
     return AutoBeanCodex.encode(bean)