Package nexj.core.runtime

Examples of nexj.core.runtime.InstanceList


      CompositeMessagePart parentComposite)
   {
      if (composite.isCollection())
      {
         List list = getList(obj, composite);
         InstanceList foundInstances = new InstanceArrayList(list.size());
         ObjectMessagePartMapping mapping = (ObjectMessagePartMapping)composite.getMapping();

         for (int i = 0, n = list.size(); i != n; ++i)
         {
            Instance instance = findInstance1((TransferObject)list.get(i), composite, parentTobj, parentComposite);

            if (instance != null)
            {
               foundInstances.add(instance, InstanceList.REPLACE | InstanceList.DIRECT);
            }
         }

         if (mapping.isDelete() && obj != null) // Delete all unmatched instances
         {
            Object where = mapping.getWhere();

            if (mapping.isLocal() && parentComposite.getMapping() != null)
            {
               Pair eq = Pair.list(Symbol.ATAT, ((ObjectMessagePartMapping)
                  parentComposite.getMapping()).getMetaclass().getSymbol(),
                  mapping.getAttribute().getSymbol()).eq(m_instanceByTobjMap.get(parentTobj));

               where = eq.and(where);
            }

            InstanceList allInstances = Query.createRead(mapping.getMetaclass(), getAttributes(composite),
               where, null, -1, 0, false, Query.SEC_NONE, m_context).read();

            if (!allInstances.isEmpty())
            {
               List instToKeepList = new ArrayList();

               for (Iterator itr = allInstances.iterator(); itr.hasNext();)
               {
                  Instance instance = (Instance)itr.next();

                  if (!foundInstances.contains(instance))
                  {
View Full Code Here


                  m_instanceByTobjMap.put(tobj, null);
               }
               else if (!mapping.isLocal() || m_instanceByTobjMap.contains(parentTobj))
               {
                  Pair where = getWhere1(tobj, composite, parentTobj, parentComposite, null, true);
                  InstanceList list = null;

                  if (where != EMPTY && !(mapping.isLocal() && m_instanceByTobjMap.get(parentTobj) == null))
                  {
                     if (mapping.isLocal())
                     {
                        Pair eq = Pair.list(Symbol.ATAT, ((ObjectMessagePartMapping)
                           parentComposite.getMapping()).getMetaclass().getSymbol(),
                           mapping.getAttribute().getSymbol()).eq(m_instanceByTobjMap.get(parentTobj));

                        if (where != null)
                        {
                           where = where.and(eq);
                        }
                        else
                        {
                           where = eq;
                        }
                     }

                     if (where != null)
                     {
                        list = (InstanceList)m_queryMap.get(derivedComposite, where);

                        if (list == null)
                        {
                           list = Query.createRead(derivedClass, getAttributes(derivedComposite), where, null,
                              2, 0, false, Query.SEC_NONE, m_context).read();

                           m_queryMap.put(derivedComposite, where, list);
                        }
                     }
                     else
                     {
                        where = EMPTY;
                     }
                  }

                  if (where != EMPTY && list != null && list.size() != 0)
                  {
                     if (list.size() > 1)
                     {
                        throw new IntegrationException("err.integration.object.ambiguousMatch",
                           new Object[]{derivedComposite.getFullPath()});
                     }

                     instance = list.getInstance(0);
                     m_instanceByTobjMap.put(tobj, instance);
                  }
                  else if (!bDelete)
                  {
                     if (tobj.getEventName() != null && (!mapping.isLocal() || m_instanceByTobjMap.get(parentTobj) == null) ||
View Full Code Here

         if (nCount > msg.getMaxCount())
         {
            throw new IntegrationException("err.integration.maxPartCount", new Object[]{msg.getFullPath()});
         }

         InstanceList instanceList = new InstanceArrayList(list.size());

         for (int i = 0; i < nCount; ++i)
         {
            Object instance = instantiate1(list.get(i), msg);

            if (instance != null && ! instanceList.contains(instance))
            {
               instanceList.add(instance);
            }
         }

         return instanceList;
      }
View Full Code Here

                     continue;
                  }

                  if (attribute.isCollection())
                  {
                     InstanceList list = (InstanceList)instance.getValue(attribute.getOrdinal());
                     InstanceList valueList = (InstanceList)value;

                     for (int l = 0; l < valueList.size(); ++l)
                     {
                        Instance newInst = valueList.getInstance(l);

                        if (!list.contains(newInst))
                        {
                           list.add(newInst);
                        }
View Full Code Here

        
         String sName = attributes.getHead().toString();
        
         if (sName.equals("object"))
         {
            InstanceList list = null;
            String sClassName = (String)instance.getValue("class");
            Binary serializedOID = (Binary)instance.getValue("oid");
           
            if (sClassName != null && serializedOID != null)
            {
               Metaclass metaclass = m_context.getMetadata().findMetaclass(sClassName);
              
               if (metaclass != null && metaclass.getPersistenceMapping() != null)
               {
                  list = (InstanceList)metaclass.invoke("read",
                     new Object[]{null, new Pair(Symbol.EQ, new Pair(new Pair(Symbol.AT),
                        new Pair(OID.fromBinary(serializedOID)))), null, null, null, null});
               }
            }

            instance.setValue("object", (list == null || list.isEmpty()) ? null : list.get(0));
         }
         else if (sName.equals("values"))
         {
            SerializablePropertyMap map = new GenericSerializablePropertyMap(GenericSerializablePropertyMap.LEAVE);
View Full Code Here

      UnitOfWork uowOld = m_context.beginTransaction(false);
      boolean bCommitted = false;

      try
      {
         InstanceList list = Query.createRead(metaclass, ATTRIBUTES,
            Pair.binary(Symbol.EQ, Symbol.NAME, sName),
            null, -1, 0, true, Query.SEC_NONE, m_context).read();

         if (list.isEmpty())
         {
            throw new UncheckedException("err.runtime.unknownCounter", new Object[]{sName});
         }

         long lValue;

         m_bBusy = true;

         synchronized (s_counterMap)
         {
            counter = (Counter)s_counterMap.get(sName);

            if (counter != null && !counter.isStale())
            {
               return Primitive.createLong(counter.next());
            }

            if (counter == null)
            {
               counter = new Counter();
               s_counterMap.put(sName, counter);
            }

            Instance instance = list.getInstance(0);

            counter.initialize(((Number)instance.getValue("value")).longValue(),
               ((Number)instance.getValue("increment")).longValue(),
               ((Number)instance.getValue("cache")).intValue());
View Full Code Here

    * @param primary The instance for which to retrieve the flows.
    * @return The list of retrieved flows.
    */
   public InstanceList forInstance(Metaclass metaclass, Instance primary, ActionContext actx)
   {
      InstanceList list = getCachedFlowList(metaclass, primary);

      if (list != null && !list.isLazy())
      {
         return list;
      }

      OID oid = primary.getOID();

      if (oid == null)
      {
         if (list != null)
         {
            return list;
         }

         list = new InstanceArrayList(4);
      }
      else
      {
         Pair attributes =
            new Pair(Symbol.define("name"),
            new Pair(Symbol.define("version"),
            new Pair(Symbol.define("serializedState"),
            new Pair(Symbol.define("serializedVariables")))));
         Object where = Pair.attribute("oid").eq(oid.toBinary()).and(
            Pair.attribute("class").eq(primary.getMetaclass().getName()));

         InstanceList ilist = Query.createRead(metaclass, attributes, where, null, -1, 0,
            false, Query.SEC_NONE, m_context).read();

         if (list == null)
         {
            list = ilist;
         }
         else
         {
            for (int i = 0, nCount = ilist.size(); i < nCount; ++i)
            {
               list.add(ilist.getInstance(i), InstanceList.REPLACE | InstanceList.DIRECT);
            }
         }
      }

      list.setLazy(false);
View Full Code Here

      if (primary == null && bGlobal)
      {
         return null;
      }

      InstanceList list = (primary == null) ? null :
         (bGlobal) ? forInstance(metaclass, primary, actx) : getCachedFlowList(metaclass, primary);

      if (list == null && primary != null)
      {
         list = new InstanceArrayList(4);
         list.setLazy(false);
      }
      else if (bGlobal)
      {
         for (int i = 0, n = list.getCount(); i != n; ++i)
         {
            if (list.getInstance(i).getValue("name").equals(sName))
            {
               return null;
            }
         }
      }

      Flow flow = getFlow(sName);

      if (primary != null)
      {
         if (flow.getMetaclass() == null || !flow.getMetaclass().isUpcast(primary.getMetaclass()))
         {
            throw new WorkflowException("err.workflow.invalidClass",
               new Object[]{flow.getName(), primary.getMetaclass().getName()});
         }

         if (primary.getMetaclass().getPersistenceMapping() == null)
         {
            throw new MetadataException("err.meta.workflow.nonPersistentClass",
               new Object[]{primary.getMetaclass().getName(), flow.getFullName()});
         }
      }

      if (s_logger.isDebugEnabled())
      {
         s_logger.debug("Starting " + flow + " for " + primary);
      }

      boolean bSecure = m_context.isSecure();
      Instance instance = null;

      try
      {
         m_context.setSecure(false);
         instance = new Instance(metaclass, m_context);

         if (list != null)
         {
            list.add(instance);

            if (m_key == null)
            {
               m_key = new FlowKey();
            }

            m_key.instance = primary;
            m_context.getUnitOfWork().cacheTransient(m_key, list);
            m_key = null;
         }

         State state = new State(flow, true);

         state.setReservedValue(0, instance);
         state.setReservedValue(1, state);

         instance.setNew();
         instance.setValue("name", flow.getName());
         instance.setValue("version", Primitive.createInteger(flow.getVersion()));
         instance.setValue("oid", EMPTY_BINARY);
         instance.setValue("class", (primary == null) ? "" : primary.getMetaclass().getName());
         instance.setValue("local", (bGlobal) ? EMPTY_BINARY : GUIDUtil.generateGUID());
         instance.setValue("object", primary);
         instance.setValue("state", state);
         instance.setValue("serializedState", null);
         instance.setValue("serializedVariables", null);
         instance.invoke("create");
         m_context.setSecure(bSecure);
         instance.invoke("run");
      }
      catch (Throwable e)
      {
         if (instance != null)
         {
            m_context.setSecure(false);
            instance.invoke("delete");

            if (list != null)
            {
               list.remove(instance);
            }
         }

         ObjUtil.rethrow(e);
      }
View Full Code Here

         }
      }

      if (object != null)
      {
         InstanceList list = getCachedFlowList(instance.getMetaclass(), object);

         if (list != null)
         {
            list.remove(instance);
            m_context.getUnitOfWork().cacheTransient(m_key, list);
            m_key = null;
         }
      }
   }
View Full Code Here

            {
               instance.setValue("object", null);
            }
            else
            {
               InstanceList list = (InstanceList)m_context.getMetadata().getMetaclass(sClass).invoke("read",
                  new Object[]{flow.getAttributes(), new Pair(Symbol.AT).eq(OID.fromBinary((Binary)instance.getValue("oid"))),
                     null, null, null, null});

               instance.setValue("object", (list.isEmpty()) ? null : list.get(0));
            }
         }
         else if (sName.equals("state"))
         {
            Flow flow = getFlow((String)instance.getValue("name"), ((Number)instance.getValue("version")).intValue());
View Full Code Here

TOP

Related Classes of nexj.core.runtime.InstanceList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.