Exemplo n.º 1
0
    def getBeansForIds(self, ids):
        """Returns the AutoBeans corresponding to the given ids, or creates
        them if they do not yet exist.
        """
        domainClasses = list()
        domainIds = list()
        idsToLoad = list()

        # Create proxies for ephemeral or synthetic ids that we haven't seen. Queue
        # up the domain ids for entities that need to be loaded.
        for id_ in ids:
            domainClass = self._service.resolveDomainClass(id_.getProxyClass())
            if id_ in self.beans:
                # Already have a proxy for this id, no-op
                pass
            elif id_.isEphemeral() or id_.isSynthetic():
                # Create a new domain object for the short-lived id
                domain = self._service.createDomainObject(domainClass)
                if domain is None:
                    raise UnexpectedException('Could not create instance of '
                            + domainClass.getCanonicalName(), None)
                bean = self.createProxyBean(id_, domain)
                self.beans[id_] = bean
                self._domainObjectsToId[domain] = id_
            else:
                # Decode the domain parameter
                split = StringQuoter.split(id_.getServerId())
                param = self._service.getIdType(domainClass)
                if ValueCodex.canDecode(param):
                    domainParam = ValueCodex.decode(param, split)
                else:
                    domainParam = SimpleRequestProcessor(self._service).decodeOobMessage(param, split).get(0)

                # Enqueue
                domainClasses.append(self._service.resolveDomainClass(id_.getProxyClass()))
                domainIds.append(domainParam)
                idsToLoad.append(id_)

        # Actually load the data
        if len(domainClasses) > 0:
            assert (len(domainClasses) == len(domainIds)
                    and len(domainClasses) == len(idsToLoad))
            loaded = self._service.loadDomainObjects(domainClasses, domainIds)
            if len(idsToLoad) != len(loaded):
                raise UnexpectedException('Expected ' + len(idsToLoad)
                        + ' objects to be loaded, got ' + len(loaded), None)
            itLoaded = iter(loaded)
            for id_ in idsToLoad:
                domain = itLoaded.next()
                self._domainObjectsToId[domain] = id_
                bean = self.createProxyBean(id_, domain)
                self.beans[id_] = bean

        # Construct the return value
        toReturn = list()
        for id_ in ids:
            toReturn.append(self.beans.get(id_))

        return toReturn
 def visitValueProperty(self, propertyName, value, ctx):
     if propertyName in self._flatValueMap:
         split = self._flatValueMap[propertyName]
         newValue = ValueCodex.decode(ctx.getType(), split)
         resolved = self._state.getResolver().resolveDomainValue(newValue, False)
         self._procesor._service.setProperty(self._domain, propertyName,
                 ctx.getType(), resolved)
     return False
Exemplo n.º 3
0
    def getBeansForIds(self, ids):
        """Returns the AutoBeans corresponding to the given ids, or creates
        them if they do not yet exist.
        """
        domainClasses = list()
        domainIds = list()
        idsToLoad = list()

        # Create proxies for ephemeral or synthetic ids that we haven't seen. Queue
        # up the domain ids for entities that need to be loaded.
        for id_ in ids:
            domainClass = self._service.resolveDomainClass(id_.getProxyClass())
            if id_ in self.beans:
                # Already have a proxy for this id, no-op
                pass
            elif id_.isEphemeral() or id_.isSynthetic():
                # Create a new domain object for the short-lived id
                domain = self._service.createDomainObject(domainClass)
                if domain is None:
                    raise UnexpectedException(
                        'Could not create instance of ' +
                        domainClass.getCanonicalName(), None)
                bean = self.createProxyBean(id_, domain)
                self.beans[id_] = bean
                self._domainObjectsToId[domain] = id_
            else:
                # Decode the domain parameter
                split = StringQuoter.split(id_.getServerId())
                param = self._service.getIdType(domainClass)
                if ValueCodex.canDecode(param):
                    domainParam = ValueCodex.decode(param, split)
                else:
                    domainParam = SimpleRequestProcessor(
                        self._service).decodeOobMessage(param, split).get(0)

                # Enqueue
                domainClasses.append(
                    self._service.resolveDomainClass(id_.getProxyClass()))
                domainIds.append(domainParam)
                idsToLoad.append(id_)

        # Actually load the data
        if len(domainClasses) > 0:
            assert (len(domainClasses) == len(domainIds)
                    and len(domainClasses) == len(idsToLoad))
            loaded = self._service.loadDomainObjects(domainClasses, domainIds)
            if len(idsToLoad) != len(loaded):
                raise UnexpectedException(
                    'Expected ' + len(idsToLoad) +
                    ' objects to be loaded, got ' + len(loaded), None)
            itLoaded = iter(loaded)
            for id_ in idsToLoad:
                domain = itLoaded.next()
                self._domainObjectsToId[domain] = id_
                bean = self.createProxyBean(id_, domain)
                self.beans[id_] = bean

        # Construct the return value
        toReturn = list()
        for id_ in ids:
            toReturn.append(self.beans.get(id_))

        return toReturn