Package nexj.core.runtime

Examples of nexj.core.runtime.Instance


            {
               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());

            instance.setValue("value", Primitive.createLong(counter.getLimit()));
            lValue = counter.next();
         }

         m_context.commitAndResume(uowOld);
         bCommitted = true;
View Full Code Here


      {
         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);
            }
View Full Code Here

   /**
    * Cleans up the resources.
    */
   public void delete(Instance instance, ActionContext actx)
   {
      Instance object = (Instance)instance.getValue("object");

      if (s_logger.isDebugEnabled())
      {
         State state = (State)instance.getValue("state");

View Full Code Here

               if (assoc !=  null && !(assoc instanceof Pair))
               {
                  assoc = new Pair(assoc);
               }

               Instance parentInstance = resultList.getInstance(0);
               Metaclass parentMetaclass = parentInstance.getMetaclass();

               // Check for attributes without persistence mappings
               if (i == 0)
               {
                  Metaclass containerMetaclass = parentMetaclass;

                  for (Pair pair = (Pair)assoc; pair != null; pair = pair.getNext())
                  {
                     Attribute attribute = containerMetaclass.findAttribute((Symbol)pair.getHead());

                     if (attribute == null)
                     {
                        break;
                     }

                     attribute.checkReadAccess(m_context.getPrivilegeSet());

                     if (!attribute.isPersistent() &&
                        !attribute.getType().isPrimitive() &&
                        event == null &&
                        ((Metaclass)attribute.getType()).findEvent("read", 6)
                           .findAction("main").getDeclarator().getBase() == null)
                     {
                        if (parentList.size() > 1)
                        {
                           throw new InvalidQueryException("err.persistence.multipleParentsWithoutPersistence",
                              new Object[]{classSym, assoc, parentMetaclass.getName()});
                        }

                        if (where != null || bookmark != null || orderBy != null)
                        {
                           throw new InvalidQueryException("err.persistence.whereWithoutPersistence",
                              new Object[]{classSym, assoc, parentMetaclass.getName()});
                        }

                        resultList = new InstanceArrayList();
                        collectAssociatedInstances((Pair)assoc, parentInstance, resultList);

                        int nOffset = (offset == null) ? 0 : offset.intValue();
                        int nCount = (count == null) ? -1 : count.intValue();

                        if (nOffset < 0)
                        {
                           nOffset = 0;
                        }

                        if (nCount < 0 || nCount > resultList.size() - nOffset)
                        {
                           nCount = resultList.size() - nOffset;

                           if (nCount < 0)
                           {
                              nCount = 0;
                           }
                        }

                        if (nOffset > 0 || resultList.size() > nCount)
                        {
                           InstanceList list = new InstanceArrayList(nCount);

                           for (int k = 0; k < nCount; ++k)
                           {
                              list.add(resultList.getInstance(k + nOffset), InstanceList.REPLACE | InstanceList.DIRECT);
                           }

                           resultList = list;
                        }

                        if (next != null && !next.booleanValue())
                        {
                           resultList.reverse();
                        }

                        for (int k = 0; k < nCount; ++k)
                        {
                           resultList.getInstance(k).invoke("load", attributes);
                        }

                        reader.setValue("results", resultList);

                        return resultList;
                     }

                     if (attribute.getType().isPrimitive())
                     {
                        break;
                     }

                     containerMetaclass = (Metaclass)attribute.getType();
                  }
               }

               assoc = new Pair(Symbol.ATAT, new Pair(parentMetaclass.getSymbol(), assoc));

               Pair cond = Pair.binary(Symbol.EQ, assoc, parentInstance.getOID());

               if (bConj)
               {
                  where = new Pair(cond, where);
               }
View Full Code Here

    * The system new event main action.
    * new(class, values)
    */
   public Instance newInstance(Metaclass metaclass, Pair values, ActionContext actx)
   {
      Instance instance = new Instance(metaclass, m_context);

      instance.setNew();

      for (; values != null; values = values.getNext())
      {
         Pair pair = (Pair)values.getHead();
         Symbol sym = (Symbol)pair.getHead();

         if (sym == Symbol._OID)
         {
            instance.setOID((OID)pair.getTail());
         }
         else
         {
            instance.setValue(sym.getName(), pair.getTail());
         }
      }

      ((Event)metaclass.getSelector("create").getMember(0)).invoke(instance, (Object[])null, m_context.getMachine());

View Full Code Here

    * invoke(instance, rulesetName, attribute, attributes)
    */
   public Object invokeRulesEngine(Metaclass metaclass, Instance instance, String sName, Symbol attribute, Pair attributes, ActionContext actx)
   {
      Lookup2D objMap = (Lookup2D)metaclass.getValue("objMap");
      Instance engine = (Instance)objMap.get(instance, sName);
      boolean bCreate = (engine == null);
     
      if (bCreate)
      {
         engine = getRulesEngine(metaclass, instance, sName);
         objMap.put(instance, sName, engine);
      }

      try
      {
         Object[] args = new Object[]{attribute};
         Object obj = engine.invoke("compute", args);
        
         for (; attributes != null; attributes = attributes.getNext())
         {
            args[0] = attributes.getHead();
            engine.invoke("compute", args);
         }

         return obj;
      }
      finally
View Full Code Here

               attribute.getName(),
               attribute.getMetaclass().getName()
            });
         }

         Instance obj = instantiate((TransferObject)item);

         if (obj != null)
         {
            if (!type.isUpcast(obj.getMetaclass()))
            {
               throw new RequestException("err.rpc.classCast", new Object[]
               {
                  obj.getMetaclass().getName(),
                  attribute.getName(),
                  attribute.getMetaclass().getName()
               });
            }
View Full Code Here

      {
         for (int i = nStart; i < nEnd; ++i)
         {
            SQLWork work = (SQLWork)workArray[i];
                             
            Instance instance = work.getInstance();

            if (instance.getOID() == null)
            {
               OID oid = work.computeOID();

               if (oid == null)
               {
                  throw new PersistenceException("err.persistence.requiredOID",
                     new Object[]{instance.getLazyMetaclass()});
               }

               instance.setOID(oid);
            }

            work.fixup();
         }
View Full Code Here

      //BLOCKING
      directFile.lock(true);
     
      try
      {
         Instance instance = m_context.findInstance(query.getMetaclass(), oid);

         if (instance == null)
         {
            instance = new Instance(query.getMetaclass(), m_context);
            instance.cache(oid);
         }

         for (Iterator i = query.getFieldIterator(); i.hasNext(); )
         {
            Field field = (Field)i.next();
            Attribute attribute = field.getAttribute();
            FilePrimitiveMapping primitiveMapping = (FilePrimitiveMapping)query.getPersistenceMapping().getAttributeMapping(attribute);
           
            switch (primitiveMapping.getSysId())
            {
               case FilePrimitiveMapping.SYSID_ID:
                  instance.setOldValueDirect(attribute.getOrdinal(), oid.getValue(0));
                  break;
                 
               case FilePrimitiveMapping.SYSID_DATA:
                  Object value = null;
                 
                  try
                  {
                     value = (primitiveMapping.getAttribute().getType() == Primitive.STRING) ?
                        (Object)directFile.getDataAsString() : directFile.getDataAsBinary();
                  }
                  catch (IOException ex)
                  {
                     throw new PersistenceException("err.persistence.file.io", ex);
                  }
                 
                  instance.setOldValueDirect(attribute.getOrdinal(), value);
                 
                  break;
              
               case FilePrimitiveMapping.SYSID_LOCKING:
                  instance.setOldValueDirect(attribute.getOrdinal(),
                     Primitive.createLong(dataFile.lastModified()) );
                  break;
            }
         }
        
View Full Code Here

      if (m_bDone)
      {
         return null;
      }
     
      Instance result = null;
      InstanceList resultList = m_adapter.read(m_query);
     
      m_bDone = true;
     
      if (resultList != null && resultList.size() == 1)
View Full Code Here

TOP

Related Classes of nexj.core.runtime.Instance

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.