Package nexj.core.runtime

Examples of nexj.core.runtime.InstanceList


         {
            if (value instanceof InstanceList)
            {
               assoc = assoc.getNext();

               InstanceList list = (InstanceList)value;

               for (int i = 0, nCount = list.size(); i < nCount; ++i)
               {
                  collectAssociatedInstances(assoc, list.getInstance(i), results);
               }
            }
            else if (value instanceof Instance)
            {
               collectAssociatedInstances(assoc.getNext(), (Instance)value, results);
View Full Code Here


         }

         return true;
      }

      InstanceList resultList = (InstanceList)dispParent.getValue("results");

      if (resultList == null || resultList.isEmpty())
      {
         return false;
      }

      dispParent = resultList.getInstance(0);

      Pair dispAssoc = (Pair)reader.getValue("dispatchAttribute");
      Pair dispValues = (Pair)reader.getValue("dispatchValues");

      if (dispAssoc == null)
View Full Code Here

            boolean bConj = false;

            for (int i = parentList.size() - 1; i >= 0; --i)
            {
               Accessor parent = (Accessor)parentList.get(i);
               InstanceList resultList = (InstanceList)parent.getValue("results");

               if (resultList == null || resultList.size() == 0)
               {
                  return setEmptyResult(reader);
               }

               Object assoc = assocList.get(i);

               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);
               }
               else if (where != null)
               {
                  where = new Pair(cond, new Pair(where));
                  bConj = true;
               }
               else
               {
                  where = cond;
               }
            }

            if (bConj)
            {
               where = new Pair(Symbol.AND, where);
            }
         }

         // Handle the bookmark
         boolean bNext = true;

         if (next != null && orderBy != null)
         {
            bNext = next.booleanValue();

            if (!bNext)
            {
               // Flip sort order
               Pair pair = orderBy;
               Pair last = orderBy = null;

               for (; pair != null; pair = pair.getNext())
               {
                  Pair head = (Pair)pair.getHead();
                  Pair item = new Pair(new Pair(head.getHead(),
                     Boolean.valueOf(!((Boolean)head.getTail()).booleanValue())));

                  if (last == null)
                  {
                     orderBy = item;
                  }
                  else
                  {
                     last.setTail(item);
                  }

                  last = item;
               }
            }

            // The bookmark has the following format: (value1 ... valueN)
            // If values are missing, then the start or the end of the recordset is
            // retrieved, depending on the value of next (inclusive is ignored in this case)

            if (bookmark != null)
            {
               where = addBookmarkToWhere(where, orderBy, bookmark, inclusive);
            }
         }

         // This takes care of the bookmark attributes access rights
         metaclass.checkOrderByAccess(orderBy, m_context.getPrivilegeSet());
         attributes = Pair.nconc(security, attributes);

         InstanceList resultList;
        
         if (event != null)
         {
            setValue(event, "attributes", argArray, attributes);
            setValue(event, "where", argArray, where);
            setValue(event, "orderBy", argArray, orderBy);

            resultList = (InstanceList)event.invoke(argArray, m_context.getMachine());
         }
         else
         {
            resultList = (InstanceList)metaclass.invoke("read",
               new Object[]{attributes, where, orderBy, count, offset, xlock});
         }

         if (!bNext)
         {
            resultList.reverse();
         }

         reader.setValue("results", resultList);

         if (key != null)
View Full Code Here

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

      if (m_bDone || nMaxCount <= 0)
      {
         return new InstanceArrayList(0);
      }
     
      InstanceList resultList = m_adapter.read(m_query);
     
      m_bDone = true;
     
      if (resultList != null && resultList.size() == 1)
      {
         return resultList;
      }
     
      return new InstanceArrayList(0);
View Full Code Here

         });
      }

      List list = (List)value;
      int nCount = list.size();
      InstanceList instanceList = new InstanceArrayList(nCount);
      Metaclass type = (Metaclass)attribute.getType();

      for (int i = 0; i < nCount; ++i)
      {
         Object item = list.get(i);

         if (!(item instanceof TransferObject))
         {
            throw new RequestException("err.rpc.collectionItemType", new Object[]
            {
               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()
               });
            }

            instanceList.add(obj);
         }
      }

      return instanceList;
   }
View Full Code Here

            }
            else
            {
               if (attribute.isCollection())
               {
                  InstanceList instanceList;

                  if (pre != Undefined.VALUE)
                  {
                     pre = instanceList = instantiateList(pre, attribute);

                     if (isCached())
                     {
                        instanceList.setLazy(false);
                     }
                  }

                  value = instanceList = instantiateList(value, attribute);

                  if (isCached())
                  {
                     instanceList.setLazy(false);
                  }
                  else
                  {
                     if (attribute.getReverse() != null)
                     {
                        instanceList.checkUpdateAccess(attribute.getReverse(), instance);
                     }
                  }

                  instanceList.setAssociation(instance, attribute, true);
               }
               else
               {
                  Instance inst;
View Full Code Here

            return new InstanceArrayList(0);
         }

         if (list.get(0) instanceof TransferObject)
         {
            InstanceList instanceList = new InstanceArrayList(nCount);

            for (int i = 0; i < nCount; ++i)
            {
               instanceList.add(instantiate((TransferObject)list.get(i)));
            }

            return instanceList;
         }
View Full Code Here

               if (value != null)
               {
                  if (attribute.isCollection())
                  {
                     InstanceList list = (InstanceList)value;

                     for (int k = 0, m = list.getCount(); k != m; ++k)
                     {
                        reverse.invalidateDependency(list.getInstance(k), Invalid.VALUE);
                     }
                  }
                  else
                  {
                     reverse.invalidateDependency((Instance)value, Invalid.VALUE);
View Full Code Here

                  instance.invoke("load", Pair.nconc(instance.getMetaclass()
                     .checkReadAccess(attributes, m_context.getPrivilegeSet()), attributes));
               }
               else if (result instanceof InstanceList)
               {
                  InstanceList list = (InstanceList)result;
                  Lookup classMap = new HashTab(4);

                  for (int k = 0, n = list.size(); k < n; ++k)
                  {
                     Instance instance = list.getInstance(k);
                     Metaclass metaclass = instance.getMetaclass();
                     Pair all = (Pair)classMap.get(metaclass);

                     if (all == null)
                     {
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.