Package nexj.core.runtime

Examples of nexj.core.runtime.InstanceArrayList$Change


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

      // Read all
      list = (InstanceArrayList)animalClass.invoke("read", new Object[]{
         null, null, parse("((commonName . #t))"), null, null, null
      });

      assertEquals(4, list.size());
      inst = list.getInstance(0);
      assertEquals("Beaver", inst.getValue("commonName"));
      inst = list.getInstance(1);
      assertEquals("Cat", inst.getValue("commonName"));
      inst = list.getInstance(2);
      assertEquals("Dog", inst.getValue("commonName"));
      inst = list.getInstance(3);
      assertEquals("Spider", inst.getValue("commonName"));

      m_context.initialize(m_context.getPrincipal(), m_context.getMachine().getGlobalEnvironment());

      // Read just 4-legged animals
      list = (InstanceArrayList)animalClass.invoke("read", new Object[]{
         parse("(commonName)"), Pair.list(Symbol.EQ, Pair.attribute("limbCount"), Primitive.createInteger(4)), null, null, null, null
      });

      assertEquals(3, list.size());
      inst = list.getInstance(0);
      assertEquals("Dog", inst.getValue("commonName"));
      inst = list.getInstance(1);
      assertEquals("Cat", inst.getValue("commonName"));
      assertEquals("Felis catus", inst.getValue("scientificName"));
      inst = list.getInstance(2);
      assertEquals("Beaver", inst.getValue("commonName"));

      // Read all with a cursor
      Cursor cur = Query.createRead(animalClass, null, null, null, -1, 0, false, Query.SEC_ALL, m_context).openCursor();

      inst = cur.next();
      assertEquals("Dog", inst.getValue("commonName"));
      inst = cur.next();
      assertEquals("Cat", inst.getValue("commonName"));
      inst = cur.next();
      assertEquals("Spider", inst.getValue("commonName"));
      inst = cur.next();
      assertEquals("Beaver", inst.getValue("commonName"));
      assertNull(cur.next());

      // Read all with a cursor, canceling early
      cur = Query.createRead(animalClass, null, null, null, -1, 0, false, Query.SEC_ALL, m_context).openCursor();

      inst = cur.next();
      assertEquals("Dog", inst.getValue("commonName"));
      cur.close();
      assertNull(cur.next());
      assertNull(cur.next());

      // Read class that has 2-part OID
      Metaclass penClass = m_metadata.getMetaclass("AnimalPen");

      list = (InstanceArrayList)penClass.invoke("read", new Object[] {
         null, Pair.list(Symbol.EQ, Pair.attribute("name"), "Dog pen"), null, null, null, null
      });

      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals(0, ((Integer)inst.getValue("locking")).intValue());
      assertEquals(2, inst.getOID().getCount());
      assertEquals("North", inst.getOID().getValue(0));
      assertEquals(8, ((Integer)inst.getOID().getValue(1)).intValue());
      assertEquals("North", inst.getValue("k1"));
      assertEquals(8, ((Integer)inst.getValue("k2")).intValue());

      // Read parent, getting sub-class attribute.
      list = (InstanceArrayList)animalClass.invoke("read", new Object[]{
         parse("(commonName (@@ DomesticAnimal petName))"), parse("(= (@ commonName) \"Dog\")"), null, null, null, null
      });

      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("DomesticAnimal", inst.getClassName());
      assertEquals("Dog", inst.getValue("commonName"));
      assertEquals("Kerberos", inst.getValue("petName"));

      // Read sub-class directly.
      Metaclass domAnimalClass = m_metadata.getMetaclass("DomesticAnimal");

      list = (InstanceArrayList)domAnimalClass.invoke("read", new Object[]{
         parse("(petName commonName)"), parse("(= (@ petName) \"Cleopatra\")"), null, null, null, null
      });

      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("DomesticAnimal", inst.getClassName());
      assertEquals("Cat", inst.getValue("commonName"));
   }
View Full Code Here


    */
   public void testUpdate()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      Instance inst = null;
      InstanceArrayList list = null;
      Collection data;

      // Read dog.
      list = (InstanceArrayList)animalClass.invoke("read", new Object[]{
         parse("(scientificName)"), parse("(= (@ commonName) \"Dog\")"), null, null, null, null
      });

      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertNull(inst.getValue("scientificName"));
      inst.setValue("scientificName", "Canis lupus familiaris");
      inst.setValue("petName", "Cerberus")// Update sub-class attribute
      m_context.getUnitOfWork().commit();

      // Read dog again.
      list = (InstanceArrayList)animalClass.invoke("read", new Object[]{
         null, Pair.list(Symbol.EQ, Pair.attribute("commonName"), "Dog"), null, null, null, null
      });

      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("Canis lupus familiaris", inst.getValue("scientificName"));
      assertEquals("Cerberus", inst.getValue("petName"));

      // Test optimistic locking detection (when updated elsewhere)
      inst.setValue("scientificName", "Doggie");
View Full Code Here

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

      list = (InstanceArrayList)animalClass.invoke("read", new Object[]{
         null, null, null, null, null, null
      });

      assertEquals(4, list.size());
      inst = list.getInstance(0);
      inst.setValue("limbCount", Primitive.ZERO_INTEGER);
      inst = list.getInstance(1);
      inst.setValue("limbCount", Primitive.ZERO_INTEGER);
      inst = list.getInstance(2);
      inst.setValue("limbCount", Primitive.ZERO_INTEGER);
      inst = list.getInstance(3);
      inst.setValue("limbCount", Primitive.ZERO_INTEGER);

      int nStartCallCount = ((Integer)animalClass.getValue("updateMapping2Count")).intValue();

      m_context.getUnitOfWork().commit();

      int nEndCallCount = ((Integer)animalClass.getValue("updateMapping2Count")).intValue();

      try
      {
         assertEquals(nStartCallCount + 2, nEndCallCount)// Update Animal and DomesticAnimal.
      }
      catch (AssertionFailedError ex)
      {
         assertEquals("Furthermore, the number of calls is not consistent with no batching.",
            nStartCallCount + 3, nEndCallCount);

         throw ex;
      }

      list = (InstanceArrayList)animalClass.invoke("read", new Object[]{
         null, null, null, null, null, null
      });

      assertEquals(4, list.size());
      inst = list.getInstance(0);
      assertEquals(0, ((Integer)inst.getValue("limbCount")).intValue());
      inst = list.getInstance(1);
      assertEquals(0, ((Integer)inst.getValue("limbCount")).intValue());
      inst = list.getInstance(2);
      assertEquals(0, ((Integer)inst.getValue("limbCount")).intValue());
      inst = list.getInstance(3);
      assertEquals(0, ((Integer)inst.getValue("limbCount")).intValue());
   }
View Full Code Here

    */
   public void testCreate()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      Instance inst = null;
      InstanceArrayList list = null;
      Collection data;

      data = (Collection)m_context.getMachine().eval(parse("(AnimalStore'data)"));
      assertEquals(4, data.size());

      // Create new animal
      inst = (Instance)animalClass.invoke("new", new Object[]
      {
         new Pair(Symbol.define("commonName"), "Chimpanzee"),
         new Pair(Symbol.define("scientificName"), "Pan troglodytes"),
         new Pair(Symbol.define("limbCount"), Primitive.createInteger(4))
      });
      data = (Collection)m_context.getMachine().eval(parse("(AnimalStore'data)"));
      assertEquals(4, data.size());

      m_context.getUnitOfWork().commit();

      data = (Collection)m_context.getMachine().eval(parse("(AnimalStore'data)"));
      assertEquals(5, data.size());

      // Read it
      list = (InstanceArrayList)animalClass.invoke("read", new Object[]{
         null, Pair.list(Symbol.EQ, Pair.attribute("commonName"), "Chimpanzee"), null, null, null, null
      });
      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("Pan troglodytes", inst.getValue("scientificName"));
   }
View Full Code Here

   public void testCreateWithOIDFromAttributes()
   {
      Metaclass penClass = m_metadata.getMetaclass("AnimalPen");
      Instance inst;
      Collection data;
      InstanceArrayList list;
      OID oid;

      data = (Collection)m_context.getMachine().eval(parse("(AnimalPenStore'data)"));
      assertEquals(2, data.size());

      inst = (Instance)penClass.invoke("new", new Object[]
      {
         new Pair(Symbol.define("name"), "Monkey pen"),
         new Pair(Symbol.define("k1"), "ATTR_SRC"),
         new Pair(Symbol.define("k2"), Primitive.createInteger(42))
      });

      data = (Collection)m_context.getMachine().eval(parse("(AnimalPenStore'data)"));
      assertEquals(2, data.size());
      assertNull(inst.getOID());

      m_context.getUnitOfWork().commit();

      data = (Collection)m_context.getMachine().eval(parse("(AnimalPenStore'data)"));
      assertEquals(3, data.size());

      assertEquals(2, inst.getOID().getCount());
      assertEquals("ATTR_SRC", inst.getOID().getValue(0));
      assertEquals(42, ((Integer)inst.getOID().getValue(1)).intValue());
      assertEquals("ATTR_SRC", inst.getValue("k1"));
      assertEquals(42, ((Integer)inst.getValue("k2")).intValue());
      oid = (OID)m_context.getMachine().eval(parse("(car ((AnimalPenStore'data)'get 2))"));
      assertEquals("ATTR_SRC", oid.getValue(0));
      assertEquals(42, ((Integer)oid.getValue(1)).intValue());

      list = (InstanceArrayList)penClass.invoke("read", new Object[] {
         null, Pair.list(Symbol.EQ, Pair.attribute("name"), "Monkey pen"), null, null, null, null
      });

      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("ATTR_SRC", inst.getValue("k1"));
      assertEquals(42, ((Integer)inst.getValue("k2")).intValue());
   }
View Full Code Here

   public void testReadManyToOneHeterogeneousAssocWithNonLazyPrimitivesOnAssociatedInstances()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      Metaclass penClass = m_metadata.getMetaclass("AnimalPen");
      Instance inst, assocInst;
      InstanceArrayList list;
      int nStartCallCount, nEndCallCount;

      list = (InstanceArrayList)animalClass.invoke("read", new Object[]{
         parse("(commonName limbCount (pen name))"), null, null, null, null, null
      });

      assertEquals(4, list.size());
      inst = list.getInstance(0);
      assertEquals("Dog", inst.getValue("commonName"));
      assocInst = (Instance)inst.getValue("pen");
      assertNotNull(assocInst);
      nStartCallCount = ((Integer)penClass.getValue("objectKeyReadCount")).intValue();
      assertEquals("Dog pen", assocInst.getValue("name"));
      nEndCallCount = ((Integer)penClass.getValue("objectKeyReadCount")).intValue();
      assertEquals(nStartCallCount, nEndCallCount)// Loaded during read
      assertEquals(2, ((InstanceList)assocInst.getValue("animals")).size());
      assertSame(inst, ((InstanceList)assocInst.getValue("animals")).getInstance(0));

      inst = list.getInstance(1);
      assertEquals("Cat", inst.getValue("commonName"));
      assocInst = (Instance)inst.getValue("pen");
      assertNotNull(assocInst);
      nStartCallCount = ((Integer)penClass.getValue("objectKeyReadCount")).intValue();
      assertEquals("Cat pen", assocInst.getValue("name"));
      nEndCallCount = ((Integer)penClass.getValue("objectKeyReadCount")).intValue();
      assertEquals(nStartCallCount, nEndCallCount)// Loaded during read
      assertEquals(1, ((InstanceList)assocInst.getValue("animals")).size());
      assertSame(inst, ((InstanceList)assocInst.getValue("animals")).getInstance(0));

      inst = list.getInstance(2);
      assertEquals("Spider", inst.getValue("commonName"));
      assocInst = (Instance)inst.getValue("pen");
      assertNotNull(assocInst);
      nStartCallCount = ((Integer)penClass.getValue("objectKeyReadCount")).intValue();
      assertEquals("Dog pen", assocInst.getValue("name"));
View Full Code Here

   public void testReadHeterogeneousCollection()
   {
      Metaclass penClass = m_metadata.getMetaclass("AnimalPen");
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      Instance inst, assocInst;
      InstanceArrayList list, collection;
      int nStartCallCount, nEndCallCount;

      list = (InstanceArrayList)penClass.invoke("read", new Object[]{
         parse("(name animals)"), null, null, null, null, null
      });

      assertEquals(2, list.size());
      inst = list.getInstance(0);
      assertEquals("Dog pen", inst.getValue("name"));
      collection = (InstanceArrayList)inst.getValue("animals");
      assertEquals(2, collection.size());
      assocInst = collection.getInstance(0);
      nStartCallCount = ((Integer)animalClass.getValue("objectKeyReadCount")).intValue();
      assertEquals("Dog", assocInst.getValue("commonName"));
      nEndCallCount = ((Integer)animalClass.getValue("objectKeyReadCount")).intValue();
      assertEquals(nStartCallCount, nEndCallCount)// Not lazy loaded
      assertSame(inst, assocInst.getValue("pen"));
      assocInst = collection.getInstance(1);
      assertEquals("Spider", assocInst.getValue("commonName"));
      assertSame(inst, assocInst.getValue("pen"));

      inst = list.getInstance(1);
      assertEquals("Cat pen", inst.getValue("name"));
      collection = (InstanceArrayList)inst.getValue("animals");
      assertEquals(1, collection.size());
      assocInst = collection.getInstance(0);
      assertEquals("Cat", assocInst.getValue("commonName"));
View Full Code Here

   public void testReadHeterogeneousCollectionWithNonLazyPrimitives()
   {
      Metaclass penClass = m_metadata.getMetaclass("AnimalPen");
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      Instance inst, assocInst;
      InstanceArrayList list, collection;
      int nStartCallCount, nEndCallCount;

      list = (InstanceArrayList)penClass.invoke("read", new Object[]{
         parse("(name (animals commonName (@@ DomesticAnimal petName)))"), null, null, null, null, null
      });

      assertEquals(2, list.size());
      inst = list.getInstance(0);
      assertEquals("Dog pen", inst.getValue("name"));
      collection = (InstanceArrayList)inst.getValue("animals");
      assertEquals(2, collection.size());
      assocInst = collection.getInstance(0);
      nStartCallCount = ((Integer)animalClass.getValue("objectKeyReadCount")).intValue();
      assertEquals("Dog", assocInst.getValue("commonName"))// Loaded during read
      assertEquals("Kerberos", assocInst.getValue("petName"));
      nEndCallCount = ((Integer)animalClass.getValue("objectKeyReadCount")).intValue();
      assertEquals(nStartCallCount, nEndCallCount);
      assertSame(inst, assocInst.getValue("pen"));
      assocInst = collection.getInstance(1);
      assertEquals("Spider", assocInst.getValue("commonName"));
      assertFalse(assocInst.hasValue("petName"));
      assertSame(inst, assocInst.getValue("pen"));

      inst = list.getInstance(1);
      assertEquals("Cat pen", inst.getValue("name"));
      collection = (InstanceArrayList)inst.getValue("animals");
      assertEquals(1, collection.size());
      assocInst = collection.getInstance(0);
      assertEquals("Cat", assocInst.getValue("commonName"));
View Full Code Here

    * Reads a sub-collection whose values are provided by a composition mapping.
    */
   public void testReadHomogeneousCollection()
   {
      Metaclass domesticAnimalClass = m_metadata.getMetaclass("Animal");
      InstanceArrayList list, collection;
      Instance inst, inst2;

      list = (InstanceArrayList)domesticAnimalClass.invoke("read", new Object[]{
         parse("(commonName (licenses name))"), null, null, null, null, null
      });

      assertEquals(4, list.size());
      inst = list.getInstance(0);

      assertEquals("Dog", inst.getValue("commonName"));
      collection = (InstanceArrayList)inst.getValue("licenses");
      assertEquals(2, collection.size());
      inst2 = collection.getInstance(0);
      assertEquals("City Dog License", inst2.getValue("name"));
      assertEquals(new OID(new Object[]{Binary.parse("80")}), inst2.getOID());
      inst2 = collection.getInstance(1);
      assertEquals("Vaccination Certificate for Kerberos the dog", inst2.getValue("name"));
      assertEquals(new OID(new Object[]{Binary.parse("81")}), inst2.getOID());

      inst = list.getInstance(1);
      assertEquals("Cat", inst.getValue("commonName"));
      collection = (InstanceArrayList)inst.getValue("licenses");
      assertEquals(0, collection.size());

      inst = list.getInstance(2);
      assertEquals("Spider", inst.getValue("commonName"));
      collection = (InstanceArrayList)inst.getValue("licenses");
      assertEquals(0, collection.size());

      inst = list.getInstance(3);
      assertEquals("Beaver", inst.getValue("commonName"));
      collection = (InstanceArrayList)inst.getValue("licenses");
      assertEquals(0, collection.size());
   }
View Full Code Here

         }
      }
     
      Metaclass supportGroupMetaclass = getMetadata().getMetaclass("SupportGroup");
      Instance group = new Instance(supportGroupMetaclass, m_context);
      InstanceList participants = new InstanceArrayList(2);
     
      group.setNew();
      group.setValue("name", "A group");
      group.setValue("participants", participants);
      participants.add(contact);
      participants.add(doctor);
      commit();
     
      TransferObject groupTobj = new TransferObject(group.getOID(), "Object_SupportGroup", "update", 3);
      List participantTobjList = new ArrayList();
      TransferObject contactTobj = new TransferObject(contact.getOID(), "Contact", "update", 3);
      TransferObject doctorTobj = new TransferObject(doctor.getOID(), "Doctor", "update", 3);

      groupTobj.setValue("participants", participantTobjList);
      groupTobj.setValue("name", "Updated");
      participantTobjList.add(doctorTobj);
      doctorTobj.setValue("licenseNumber", "license for Doctor");
      m_formatter.format(groupTobj, getMessage("Object_SupportGroup"), new ObjectOutput());
      commit();
  
      group = Query.createRead(supportGroupMetaclass, null, null, null, -1, 0, false, Query.SEC_NONE, m_context).read().getInstance(0);
      assertEquals("Updated", group.getValue("name"));
      participants = (InstanceList)group.getValue("participants");
     
      for (Iterator itr = participants.iterator(); itr.hasNext(); )
      {
         Instance participant = (Instance)itr.next();
        
         if (participant.getClassName().equals("Doctor"))
         {
View Full Code Here

TOP

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

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.