Package nexj.core.runtime

Examples of nexj.core.runtime.InstanceList


               Instance container = (Instance)itr.next();

               if (m_attribute.isCollection())
               {
                  Object value = container.getOldValueDirect(m_attribute.getOrdinal());
                  InstanceList list;

                  if (value instanceof Undefined)
                  {
                     if (value == Undefined.VALUE)
                     {
                        list = new InstanceArrayList();
                        list.setAssociation(container, m_attribute, true);
                        container.setOldValueDirect(m_attribute.getOrdinal(), list);
                     }
                     else
                     {
                        list = null;
                     }
                  }
                  else
                  {
                     list = (InstanceList)value;
                  }

                  if (list != null)
                  {
                     list.setLazy(false);
                     list.add(instance, InstanceList.DIRECT | InstanceList.REPLACE);
                  }
               }
               else
               {
                  container.setOldValueDirect(m_attribute.getOrdinal(), instance);
View Full Code Here


               Instance container = (Instance)itr.next();

               if (m_attribute.isCollection())
               {
                  Object value = container.getOldValueDirect(m_attribute.getOrdinal());
                  InstanceList list;

                  if (value instanceof Undefined)
                  {
                     if (value == Undefined.VALUE)
                     {
                        list = new InstanceArrayList();
                        list.setAssociation(container, m_attribute, true);
                        container.setOldValueDirect(m_attribute.getOrdinal(), list);
                     }
                     else
                     {
                        list = null;
                     }
                  }
                  else
                  {
                     list = (InstanceList)value;
                  }

                  if (list != null)
                  {
                     list.setLazy(false);
                  }
               }
               else if (container.getOldValueDirect(m_attribute.getOrdinal()) == Undefined.VALUE)
               {
                  container.setOldValueDirect(m_attribute.getOrdinal(), null);
View Full Code Here

      {
         Instance assoc = null;

         if (value instanceof InstanceList)
         {
            InstanceList list = (InstanceList)value;

            if (!list.isEmpty())
            {
               assoc = list.getInstance(0);
            }
         }
         else
         {
            assoc = (Instance)value;
View Full Code Here

      contact.setValue("lastName", "Peters");
      contact.setValue("account", account);
      m_formatter.format(account, getMessage("Object_AccountRecursive"), new ObjectOutput());
      commit();
  
      InstanceList instances = Query.createRead(getMetadata().getMetaclass("Account"),
         parse("(funds (contact lastName))"),
         null, null, -1, 0, false, Query.SEC_NONE, m_context).read();
      boolean bMatch = false;
     
      for (Iterator itr = instances.iterator(); itr.hasNext(); )
      {
         Instance accountRead = (Instance)itr.next();
        
         if (((Number)accountRead.getValue("funds")).intValue() == 123)
         {
View Full Code Here

    * Tests that null elements of a collection get skipped.
    */
   public void testReadCollectionWithNullValue()
   {
      Metaclass testClass = m_metadata.getMetaclass("TestVirtualClass");
      InstanceList list = Query.createRead(testClass,
         parse("(a1)"), parse("(= (@ d) 1)"), null, -1, 0, false, Query.SEC_ALL, m_context
      ).read();
      Instance inst;

      assertEquals(2, list.size());
      inst = list.getInstance(0);
      assertEquals("Element1", inst.getValue("a1"));
      inst = list.getInstance(1);
      assertEquals("Element3", inst.getValue("a1"));
   }
View Full Code Here

   }

   public void testWhereClauseOID1()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      InstanceList list = Query.createRead(animalClass,
         null, parseEval("`(= (@ virtFKToRelColl) ,(read-instance PetOwner '() '(= (@ firstName) \"Zoe\") #f))"),
         null, -1, 0, false, Query.SEC_ALL, m_context
      ).read();

      assertEquals(2, list.size());
      assertEquals("Dog", list.getInstance(0).getValue("commonName"));
      assertEquals("Cat", list.getInstance(1).getValue("commonName"));
   }
View Full Code Here

    */
   public void testDelete()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      Instance inst = null;
      InstanceList list = null;

      // Read all
      list = Query.createRead(animalClass,
         null, null, null, -1, 0, false, Query.SEC_ALL, m_context
      ).read();

      assertEquals(4, list.size());
      inst = list.getInstance(0);
      inst.invoke("delete");
      m_context.getUnitOfWork().commit();

      // Optimistic locking
      list = Query.createRead(animalClass,
         null, null, null, -1, 0, false, Query.SEC_ALL, m_context
      ).read();

      assertEquals(3, list.size());
      m_context.getMachine().eval(parse("((cdr ((AnimalStore'data)'get 0))'locking 10)"));
      inst = list.getInstance(0);
      inst.invoke("delete");

      try
      {
         m_context.getUnitOfWork().commit();
View Full Code Here

    * Tests that updating attributes that are mapped to the object key changes the object key.
    */
   public void testUpdateChangeOID()
   {
      Metaclass penClass = m_metadata.getMetaclass("AnimalPen");
      InstanceList list;
      Instance inst;

      list = Query.createRead(penClass,
         parse("(name)"), parseEval("`(= (@) ,(oid \"North\" 8))"),
         null, -1, 0, false, Query.SEC_NODE, m_context).read();
      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("Dog pen", inst.getValue("name"));

      // Change the OID-mapped attributes
      inst.setValue("k1", "South");
      inst.setValue("k2", Primitive.createInteger(2));
      m_context.getUnitOfWork().commit();

      // Verify that OID has changed.
      list = Query.createRead(penClass,
         parse("(name)"), parseEval("`(= (@) ,(oid \"North\" 8))"),
         null, -1, 0, false, Query.SEC_NODE, m_context).read();
      assertEquals(0, list.size());
      list = Query.createRead(penClass,
         parse("(name)"), parseEval("`(= (@) ,(oid \"South\" 2))"),
         null, -1, 0, false, Query.SEC_NODE, m_context).read();
      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("Dog pen", inst.getValue("name"));
   }
View Full Code Here

   public void testUpdateWithAssocToCreated()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      Metaclass penClass = m_metadata.getMetaclass("AnimalPen");
      Instance animal, pen;
      InstanceList list;

      // Create new pen & update existing animal
      pen = (Instance)penClass.invoke("new", new Object[]
      {
         new Pair(Symbol.define("name"), "Chimpanzee pen")
      });
      list = Query.createRead(animalClass,
         parse("(commonName pen)"), parse("(= (@ commonName) \"Beaver\")"),
         null, -1, 0, false, Query.SEC_NODE, m_context).read();
      assertEquals(1, list.size());
      animal = list.getInstance(0);
      assertEquals("Beaver", animal.getValue("commonName"));
      assertNull(animal.getValue("pen"));
      animal.setValue("pen", pen);

      m_context.getUnitOfWork().commit();

      // Read the animal, check the assoc to its pen
      list = Query.createRead(animalClass,
         parse("(commonName pen)"), parse("(= (@ commonName) \"Beaver\")"),
         null, -1, 0, false, Query.SEC_NODE, m_context).read();
      assertEquals(1, list.size());
      animal = list.getInstance(0);
      assertEquals("Beaver", animal.getValue("commonName"));
      pen = (Instance)animal.getValue("pen");
      assertEquals("Chimpanzee pen", pen.getValue("name"));

      // Read the pen, check the collection of its animals
      list = Query.createRead(penClass,
         parse("(name animals)"), parse("(= (@ name) \"Chimpanzee pen\")"),
         null, -1, 0, false, Query.SEC_NODE, m_context).read();
      assertEquals(1, list.size());
      pen = list.getInstance(0);
      assertEquals("Chimpanzee pen", pen.getValue("name"));
      list = (InstanceList)pen.getValue("animals");
      assertEquals(1, list.size());
      animal = list.getInstance(0);
      assertEquals("Beaver", animal.getValue("commonName"));
   }
View Full Code Here

        
         // Read (NOT FOUND)
         assertNull(context.beginTransaction());
           
         Query query = Query.createRead(testFPA, null, parse("(= (@ id) \"" + sOidName + "\")"), null, 10, 0, false, Query.SEC_NONE, context);
         InstanceList resultList = query.read();
           
         assertEquals(0, resultList.getCount());
        
         commit(context);

         // Create it (test that the read operation doesn't add the not-found instance to the invocation context)
         assertNull(context.beginTransaction());
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.