Package nexj.core.runtime

Examples of nexj.core.runtime.InstanceArrayList$InstanceIterator


   }

   public void testReadAssocVirtualFKToRelationalCollection() throws Exception
   {
      Metaclass virtualClass = getMetadata().getMetaclass("Animal");
      InstanceArrayList list;
      Instance inst, inst2;

      list = (InstanceArrayList)Query.createRead(virtualClass,
         parse("(commonName (virtFKToRelColl firstName lastName))"),
         null,
         null,
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(4, list.getCount());
      inst = list.getInstance(0);
      assertEquals("Dog", inst.getValue("commonName"));
      inst2 = (Instance)inst.getValue("virtFKToRelColl");
      assertEquals("Zoe", inst2.getValue("firstName"));

      inst = list.getInstance(1);
      assertEquals("Cat", inst.getValue("commonName"));
      inst2 = (Instance)inst.getValue("virtFKToRelColl");
      assertEquals("Zoe", inst2.getValue("firstName"));
      assertEquals("Test", inst2.getValue("lastName"));

      inst = list.getInstance(2);
      assertEquals("Spider", inst.getValue("commonName"));
      assertNull(inst.getValue("virtFKToRelColl"));


      // Read the reverse (the relational collection)
      Metaclass relationalClass = getMetadata().getMetaclass("PetOwner");
      InstanceArrayList list2;

      list = (InstanceArrayList)Query.createRead(relationalClass,
         parse("(firstName (relCollFromVirtFK commonName))"),
         parse("(= (@ lastName) \"Test\")"),
         parse("((firstName . #t))"),
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(2, list.size());
      inst = list.getInstance(0);
      assertEquals("Joe", inst.getValue("firstName"));
      assertEquals(0, ((InstanceArrayList)inst.getValue("relCollFromVirtFK")).size());

      inst = list.getInstance(1);
      assertEquals("Zoe", inst.getValue("firstName"));
      list2 = (InstanceArrayList)inst.getValue("relCollFromVirtFK");
      assertEquals(2, list2.size());
      inst2 = list2.getInstance(0);
      assertEquals("Dog", inst2.getValue("commonName"));
      inst2 = list2.getInstance(1);
      assertEquals("Cat", inst2.getValue("commonName"));
      assertEquals("Felis catus", inst2.getValue("scientificName"));
   }
View Full Code Here


   }

   public void testReadAssocVirtualAttrToRelationalFKNoAttr() throws Exception
   {
      Metaclass virtualClass = getMetadata().getMetaclass("Animal");
      InstanceArrayList list;
      Instance inst, inst2;

      list = (InstanceArrayList)Query.createRead(virtualClass,
         parse("(commonName (virtAttrToRelFKNoAttr firstName lastName))"),
         null,
         null,
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(4, list.getCount());
      inst = list.getInstance(0);
      assertEquals("Dog", inst.getValue("commonName"));
      inst2 = (Instance)inst.getValue("virtAttrToRelFKNoAttr");
      assertEquals("Zoe", inst2.getValue("firstName"));
      assertEquals("Test", inst2.getValue("lastName"));

      inst = list.getInstance(1);
      assertEquals("Cat", inst.getValue("commonName"));
      assertNull(inst.getValue("virtAttrToRelFKNoAttr"));

      inst = list.getInstance(2);
      assertEquals("Spider", inst.getValue("commonName"));
      assertNull(inst.getValue("virtAttrToRelFKNoAttr"));
   }
View Full Code Here

    * Tests that an attribute in a where clause does not get expanded into OID components.
    */
   public void testReadAssocVirtualFKToRelationalCollectionWhereClause() throws Exception
   {
      Metaclass virtualClass = getMetadata().getMetaclass("Animal");
      InstanceArrayList list;
      Instance inst, inst2;

      list = (InstanceArrayList)Query.createRead(virtualClass,
         parse("(commonName (virtFKToRelColl firstName))"),
         parseEval("`(= (@ virtFKToRelColl) ,(oid #z00000000000000000000000000008802 \"main\"))"),
         null,
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(2, list.getCount());
      inst = list.getInstance(0);
      assertEquals("Dog", inst.getValue("commonName"));
      inst2 = (Instance)inst.getValue("virtFKToRelColl");
      assertEquals("Zoe", inst2.getValue("firstName"));

      inst = list.getInstance(1);
      assertEquals("Cat", inst.getValue("commonName"));
      inst2 = (Instance)inst.getValue("virtFKToRelColl");
      assertEquals("Zoe", inst2.getValue("firstName"));
      assertEquals("Test", inst2.getValue("lastName"));

      list = (InstanceArrayList)Query.createRead(virtualClass,
         parse("(commonName (virtFKToRelColl firstName))"),
         parseEval("`(= (@ virtFKToRelColl) ,(oid #z00000000000000000000000000008801))"),
         null,
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertTrue(list.isEmpty());
   }
View Full Code Here

            // A composition attribute
            Cursor cursor = new VirtualCursor(getCompositionQuery(attribute, query), getIterator(value, metaclass));

            try
            {
               InstanceList instanceList = new InstanceArrayList();

               instanceList.setAssociation(instance, attribute, true);
               instanceList.setLazy(false);
               instance.setOldValueDirect(nOrdinal, instanceList);

               Instance assoc;

               while ((assoc = cursor.next()) != null)
               {
                  if (!instanceList.contains(assoc))
                  {
                     instanceList.add(assoc, InstanceList.DIRECT);
                  }
               }
            }
            finally
            {
View Full Code Here

      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))
                  {
                     addInstanceToDelete(instance, composite, parentTobj);
                  }
                  else
                  {
View Full Code Here

            if (msg.isRequired())
            {
               throw new IntegrationException("err.integration.minPartCount", new Object[]{msg.getFullPath()});
            }

            return new InstanceArrayList(0);
         }

         List list = (List)obj;
         int nCount = list.size();

         if (nCount < msg.getMinCount())
         {
            throw new IntegrationException("err.integration.minPartCount", new Object[]{msg.getFullPath()});
         }

         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

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

         list = new InstanceArrayList(4);
      }
      else
      {
         Pair attributes =
            new Pair(Symbol.define("name"),
View Full Code Here

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

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

      String sDataFileName = mapOIDToFile(oid);
     
      if (sDataFileName == null)
      {
         //Interpret badly-formatted OID as "not found"
         return new InstanceArrayList(0);
      }

      //Open file directly
      FileDataSourceFragment fragment = (FileDataSourceFragment)query.getFragment();
      File dataFile = nexj.core.rpc.file.ra.FileManagedConnection.splitNameToSubdirs(
         new File(fragment.getDataDirectory()), sDataFileName,
            fragment.getMaxNameSplits(), fragment.getNameSplitSize(), false);

      if (!dataFile.exists())
      {
         //Not found
         return new InstanceArrayList(0);
      }

      LockableFile directFile = new LockableFile(dataFile);

      //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;
            }
         }
        
         InstanceArrayList result = new InstanceArrayList(1);
        
         result.add(instance);
        
         return result;
      }
      finally
      {
View Full Code Here

TOP

Related Classes of nexj.core.runtime.InstanceArrayList$InstanceIterator

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.