Package nexj.core.scripting

Examples of nexj.core.scripting.Pair


      }

      for (Pair pair = attributes; pair != null; pair = pair.getNext())
      {
         Object head = pair.getHead();
         Pair assoc;
         Attribute attribute;

         if (head instanceof Pair)
         {
            assoc = (Pair)head;

            Symbol sym = (Symbol)assoc.getHead();

            assoc = assoc.getNext();

            if (sym == Symbol.ATAT)
            {
               if (m_metaclass.getMetadata().getMetaclass(((Symbol)assoc.getHead()).getName())
                     .isUpcast(m_metaclass) && !isLoaded(assoc.getNext()))
               {
                  return false;
               }

               continue;
View Full Code Here


   private Pair preload(Pair attributes, Pair tail, boolean bPersistent)
   {
      for (Pair pair = attributes, prev = null; pair != null; pair = pair.getNext())
      {
         Object head = pair.getHead();
         Pair assoc;
         Attribute attribute;

         if (head instanceof Pair)
         {
            assoc = (Pair)head;

            Symbol sym = (Symbol)assoc.getHead();

            assoc = assoc.getNext();

            if (sym == Symbol.ATAT)
            {
               if (m_metaclass.getMetadata().getMetaclass(((Symbol)assoc.getHead()).getName()).isUpcast(m_metaclass))
               {
                  if (tail == null)
                  {
                     pair.setHead(null);
                     pair = preload(assoc.getNext(), pair, bPersistent);

                     if (pair.getHead() == null && tail == null)
                     {
                        if (prev == null)
                        {
                           attributes = pair.getNext();
                        }
                        else
                        {
                           prev.setTail(pair.getTail());
                        }
                     }
                  }
                  else
                  {
                     tail = preload(assoc.getNext(), tail, bPersistent);
                  }
               }
               else
               {
                  if (tail == null)
                  {
                     if (prev == null)
                     {
                        attributes = pair.getNext();
                     }
                     else
                     {
                        prev.setTail(pair.getTail());
                     }
                  }
               }

               continue;
            }

            if (!bPersistent)
            {
               continue;
            }

            attribute = m_metaclass.getAttribute(sym);
         }
         else
         {
            if (head == null)
            {
               if (tail == null)
               {
                  if (prev == null)
                  {
                     attributes = pair.getNext();
                  }
                  else
                  {
                     prev.setTail(pair.getTail());
                  }
               }

               continue;
            }

            if (!bPersistent)
            {
               continue;
            }

            assoc = null;
            attribute = m_metaclass.getAttribute((Symbol)head);
         }

         if (attribute.isStatic())
         {
            if (tail == null)
            {
               if (prev == null)
               {
                  attributes = pair.getNext();
               }
               else
               {
                  prev.setTail(pair.getTail());
               }
            }
         }
         else
         {
            Object value = getValueDirect(attribute.getOrdinal());

            if (!(value instanceof Undefined))
            {
               if (isLoaded(value, attribute, assoc))
               {
                  if (tail == null)
                  {
                     if (prev == null)
                     {
                        attributes = pair.getNext();
                     }
                     else
                     {
                        prev.setTail(pair.getTail());
                     }
                  }
               }
               else
               {
                  if (tail == null)
                  {
                     prev = pair;
                  }
                  else if (tail.getHead() == null)
                  {
                     tail.setHead(pair.getHead());
                  }
                  else
                  {
                     Pair copy = new Pair(pair.getHead(), tail.getTail());

                     tail.setTail(copy);
                     tail = copy;
                  }

                  if (attribute.isPersistent())
                  {
                     m_nFlags |= LOAD_READ;
                  }
               }
            }
            else
            {
               if (tail == null)
               {
                  prev = pair;
               }
               else if (tail.getHead() == null)
               {
                  tail.setHead(pair.getHead());
               }
               else
               {
                  Pair copy = new Pair(pair.getHead(), tail.getTail());

                  tail.setTail(copy);
                  tail = copy;
               }
View Full Code Here

         }

         if (bRead)
         {
            Query query = Query.createRead(m_metaclass, attributes,
               new Pair(Symbol.AT).eq(m_oid), null, -1, 0, false,
               Query.SEC_NONE, m_context);

            for (int i = 0, nCount = m_metaclass.getInstanceAttributeCount(); i < nCount; ++i)
            {
               Attribute attribute = m_metaclass.getInstanceAttribute(i);

               if ((isLazy() || getValueDirect(attribute.getOrdinal()) == Undefined.VALUE) &&
                  !attribute.isLazy())
               {
                  query.addAttribute(Query.ASSOC_QUERY, attribute, null, false, Query.OUTPUT_EAGER);
               }
            }

            if (query.getFirstOutputField() != null &&
               (query.getFirstOutputField().getNext() != null ||
                  query.getFirstOutputField().getAttribute() !=
                  mapping.getLockingAttribute()) ||
               query.getAssocCount(Query.ASSOC_QUERY) > 0)
            {
               if (s_logger.isDebugEnabled())
               {
                  String sMsg = "Loading attributes " + attributes + " of " + this;

                  if (s_logger.isDumpEnabled())
                  {
                     StackTrace t = new StackTrace();

                     m_context.getMachine().updateStackTrace(t);
                     s_logger.dump(sMsg, t);
                  }
                  else
                  {
                     s_logger.debug(sMsg);
                  }
               }

               if (query.read().isEmpty())
               {
                  if (bSafe)
                  {
                     return attributes;
                  }

                  // The instance could not be found
                  if (isLazy())
                  {
                     // Just the OID was available - check the referrer
                     for (Iterator itr = m_context.getInstanceRefIterator(); itr.hasNext();)
                     {
                        InstanceRef ref = (InstanceRef)itr.next();

                        if (ref != null)
                        {
                           Instance instance = ref.getInstance();

                           if (instance != null && !instance.isLazy() &&
                              instance.getState() != NEW && instance.getOID() != null)
                           {
                              Metaclass metaclass = instance.getMetaclass();

                              if (metaclass.getPersistenceMapping() != null)
                              {
                                 for (int i = 0, n = metaclass.getInstanceAttributeCount(); i < n; ++i)
                                 {
                                    Attribute attribute = metaclass.getInstanceAttribute(i);

                                    if (!attribute.isCollection() && attribute.isPersistent() &&
                                       instance.getOldValueDirect(i) == this)
                                    {
                                       if (!Query.createRead(metaclass, new Pair(attribute.getSymbol()),
                                          new Pair(Symbol.AT).eq(instance), null, -1, 0, false, Query.SEC_NONE,
                                          m_context).read().isEmpty() &&
                                          instance.getOldValueDirect(i) == this)
                                       {
                                          throw new AssociationIntegrityException(instance, attribute.getName());
                                       }

                                       throw new OptimisticLockException(this);
                                    }
                                 }
                              }
                           }
                        }
                     }
                  }
                  else if (!Query.createRead(getLazyMetaclass(), null, new Pair(Symbol.AT).eq(m_oid),
                     null, -1, 0, false, Query.SEC_NONE, m_context).read().isEmpty())
                  {
                     throw new AssociationIntegrityException(this);
                  }

                  throw new OptimisticLockException(this);
               }
            }

            if (bLoad)
            {
               attributes = preload(attributes, null, false);
            }
         }
         else
         {
            bRead = true;
         }
      }
      else
      {
         attributes = preload(attributes, null, false);
      }

      for (; attributes != null; attributes = attributes.getNext())
      {
         Object head = attributes.getHead();
         Pair assoc = (head instanceof Pair) ? (Pair)head : null;
         Attribute attribute = m_metaclass.getAttribute(
            (Symbol)((assoc != null) ? assoc.getHead() : head));

         if (!attribute.isStatic())
         {
            Object value = getValueDirect(attribute.getOrdinal());

            if (value instanceof Undefined)
            {
               switch (m_nState)
               {
               case INIT:
               case NEW:
                  if (attribute.getInitializerFunction() != null)
                  {
                     setCalcValue(attribute,
                        m_context.getMachine().invoke(attribute.getInitializerFunction(), this, (Object[])null));

                     continue;
                  }

                  break;

               case CLEAN:
               case DIRTY:
                  if (attribute.getValueFunction() != null)
                  {
                     if (attribute.isCached())
                     {
                        setCalcValue(attribute,
                           m_context.getMachine().invoke(attribute.getValueFunction(), this, (Object[])null));
                     }

                     continue;
                  }

                  break;
               }

               if (attribute.isCollection())
               {
                  InstanceList list = new InstanceArrayList(0);

                  setValueDirect(attribute.getOrdinal(), list);
                  list.setAssociation(this, attribute, true);
                  list.setLazy(false);
               }
               else
               {
                  setValueDirect(attribute.getOrdinal(), null);
               }

               if (s_logger.isDebugEnabled())
               {
                  s_logger.debug("Uninitialized " + attribute + ", set to " + getValueDirect(attribute.getOrdinal()));
               }
            }
            else if (value != null && !bRead)
            {
               if (assoc != null && assoc.getTail() != null)
               {
                  if (value instanceof InstanceList)
                  {
                     InstanceList list = (InstanceList)value;

                     for (int i = 0, n = list.getCount(); i < n; ++i)
                     {
                        Instance instance = list.getInstance(i);

                        if (instance != null && !instance.isLoading())
                        {
                           instance.invoke("load", assoc.getNext());
                        }
                     }
                  }
                  else if (value instanceof Instance)
                  {
                     Instance instance = (Instance)value;

                     if (!instance.isLoading())
                     {
                        instance.invoke("load", assoc.getNext());
                     }
                  }
               }
            }
         }
View Full Code Here

         switch (m_nState)
         {
            case CLEAN:
            case DIRTY:
            case DELETED:
               Pair attributes = null;

               if (m_nState == CLEAN)
               {
                  for (int i = m_metaclass.getInstanceAttributeCount() - 1; i >= 0; --i)
                  {
                     Attribute attribute = m_metaclass.getInstanceAttribute(i);

                     if (!(getValueDirect(i) instanceof Undefined) && !attribute.isCollection())
                     {
                        attributes = new Pair(attribute.getSymbol(), attributes);
                     }
                  }
               }

               Query.createRead(m_metaclass, attributes, new Pair(Symbol.AT).eq(m_oid),
                  null, -1, 0, true, Query.SEC_NONE, m_context).read();

               break;
         }
      }
View Full Code Here

    * @param sKey Additional key part. Null for the main class cache.
    * @return The class cache key.
    */
   public static Object getClassKey(Metaclass metaclass, String sKey)
   {
      return new Pair(metaclass.getSymbol(), sKey);
   }
View Full Code Here

    * @param oid The instance OID.
    * @return The instance cache key.
    */
   public static Object getInstanceKey(Metaclass metaclass, OID oid)
   {
      return new Pair(metaclass.getSymbol(), oid);
   }
View Full Code Here

    */
   public Object getPartitionedKey(Object key)
   {
      if (m_bPartitioned && m_partition != null)
      {
         return new Pair(key, m_partition.getOID());
      }

      return key;
   }
View Full Code Here

         if (!(props.getHead() instanceof Pair))
         {
            throw new RPCException("err.rpc.mailPropertyFormat");
         }

         Pair pair = (Pair)props.getHead();
         Object name = pair.getHead();

         if (!(name instanceof Symbol) && !(name instanceof String))
         {
            throw new RPCException("err.rpc.mailPropertyFormat");
         }

         String sName = name.toString();

         if (sName.equals("CC"))
         {
            msg.setValue(Mail.CC, toAddress(pair.getNext()));
         }
         else if (sName.equals("BCC"))
         {
            msg.setValue(Mail.BCC, toAddress(pair.getNext()));
         }
         else if (sName.equals("Reply-To"))
         {
            msg.setValue(Mail.REPLY, toAddress(pair.getNext()));
         }
         else
         {
            throw new RPCException("err.rpc.mailProperty", new Object[]{sName});
         }
View Full Code Here

      if (!(addr instanceof Pair)) // not a Pair list
      {
         return addr;
      }

      Pair pair = (Pair)addr;

      if (pair.getHead() instanceof String &&
          (pair.getTail() == null || pair.getTail() instanceof String))
      {
         TransferObject address = new TransferObject(2);

         address.setValue(Mail.ADDRESS, ((Pair)addr).getHead());
         address.setValue(Mail.PERSONAL, ((Pair)addr).getTail());
View Full Code Here

      TransferObject tobj = new TransferObject();

      for (; list != null; list = list.getNext())
      {
         Pair header = (Pair)list.getHead();
         String sKey = (header.getHead() instanceof Symbol)
                     ? ((Symbol)header.getHead()).getName() : (String)header.getHead();
         String sValue = (String)header.getTail(); // string required by protocol

         tobj.setValue(sKey, sValue);
      }

      return tobj;
View Full Code Here

TOP

Related Classes of nexj.core.scripting.Pair

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.