Package nexj.core.runtime

Examples of nexj.core.runtime.InstanceList


        
         Metaclass testFPA = metadata.getMetaclass("TestFPA");
         Object where = parse("(= (@ id) \"u\")");
         Query query = Query.createRead(testFPA, null, where, null, 10, 0, false, Query.SEC_NONE, context);
        
         InstanceList resultList = query.read();
        
         assertEquals(1, resultList.size());
        
         Instance result = resultList.getInstance(0);
        
         assertEquals(new Binary("Original contents".getBytes("utf-8")), result.getValue("data"));
        
         result.setValue("data", new Binary("Modified through adapter.".getBytes("utf-8")));
        
View Full Code Here


        
         Metaclass testFPA = metadata.getMetaclass("TestFPA");
         Object where = parse("(= (@ id) \"d\")");
         Query query = Query.createRead(testFPA, null, where, null, 10, 0, false, Query.SEC_NONE, context);
        
         InstanceList resultList = query.read();
        
         assertEquals(1, resultList.size());
        
         Instance result = resultList.getInstance(0);
        
         assertEquals(new Binary("Original contents".getBytes("utf-8")), result.getValue("data"));
        
         //DELETE it
         result.invoke("delete");
View Full Code Here

   /**
    *  Bug 25488: formatting complex object messages can cause ArrayIndexOutOfBoundsException.
    */
   public void testSubclassInMessage() throws Exception
   {
      InstanceList instances = Query.createRead(getMetadata().getMetaclass("Contact"), null, null, null, -1, 0, false, Query.SEC_NONE, m_context).read();
      Instance contact = null;
      Instance doctor = null;

      for (Iterator itr = instances.iterator(); itr.hasNext(); )
      {
         Instance instance = (Instance)itr.next();
        
         if (instance.getMetaclass().getName().equals("Contact"))
         {
            contact = instance;
         }
        
         if (instance.getMetaclass().getName().equals("Doctor"))
         {
            doctor = instance;
         }
      }
     
      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

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

      // Create new animal & pen
      pen = (Instance)penClass.invoke("new", new Object[]
      {
         new Pair(Symbol.define("name"), "Chimpanzee pen")
      });
      animal = (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))
      });
      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) \"Chimpanzee\")"),
         null, -1, 0, false, Query.SEC_NODE, m_context).read();
      assertEquals(1, list.size());
      animal = list.getInstance(0);
      assertEquals("Chimpanzee", 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("Pan troglodytes", animal.getValue("scientificName"));
   }
View Full Code Here

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

      list = Query.createRead(animalClass,
         parse("(commonName limbCount pen)"), null, null, -1, 0, false, Query.SEC_NODE, m_context
      ).read();

      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 + 1, nEndCallCount)// Lazy loaded
      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 + 1, nEndCallCount)// Lazy loaded
      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

    * reading the attribute where the FK is stored.
    */
   public void testReadOneToOneHeterogeneousAssocForward()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      InstanceList list;
      Instance inst, assoc;

      list = (InstanceList)Query.createRead(animalClass, parse("(commonName (chaserOf commonName) (assocToPrimitiveFK commonName) (@@ DomesticAnimal petFriend commonName))"),
         parse("(= (@ commonName) \"Dog\")"), null, -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("Dog", inst.getValue("commonName"));
      assoc = (Instance)inst.getValue("chaserOf");
      assertEquals("Cat", assoc.getValue("commonName"));
      assoc = (Instance)inst.getValue("assocToPrimitiveFK");
      assertEquals("Spider", assoc.getValue("commonName"));
      assoc = (Instance)inst.getValue("petFriend");
      assertEquals("Cat", assoc.getValue("commonName"));
     

      list = Query.createRead(animalClass, parse("(commonName (chaserOf commonName))"),
         parse("(= (@ commonName) \"Beaver\")"), null, -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("Beaver", inst.getValue("commonName"));
      assertNull(inst.getValue("chaserOf"));
      assertNull(inst.getValue("assocToPrimitiveFK"));
   }
View Full Code Here

    * reading the reverse of the attribute where the FK is stored.
    */
   public void testReadOneToOneHeterogeneousAssocReverse()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      InstanceList list;
      Instance inst, assoc;

      list = Query.createRead(animalClass, parse("(commonName (chasedBy commonName))"),
         parse("(= (@ commonName) \"Cat\")"), null, -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("Cat", inst.getValue("commonName"));
      assoc = (Instance)inst.getValue("chasedBy");
      assertEquals("Dog", assoc.getValue("commonName"));

      list = Query.createRead(animalClass, parse("(commonName (chasedBy commonName))"),
         parse("(= (@ commonName) \"Beaver\")"), null, -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("Beaver", inst.getValue("commonName"));
      assertNull(inst.getValue("chasedBy"));
   }
View Full Code Here

   }

   public void testUpdateOneToOneHeterogeneousAssoc() throws Exception
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      InstanceList list, list2;
      Instance inst, inst2, assoc;

      list = Query.createRead(animalClass, parse("(commonName (chaserOf commonName))"),
         parse("(= (@ commonName) \"Cat\")"), null, -1, 0, false, Query.SEC_NODE, m_context).read();

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

      list2 = Query.createRead(animalClass, parse("(commonName chaserOf chasedBy)"),
         parse("(= (@ commonName) \"Spider\")"), null, -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(1, list2.size());
      inst2 = list2.getInstance(0);
      assertEquals("Spider", inst2.getValue("commonName"));
      assertNull(inst2.getValue("chasedBy"));

      inst.setValue("chaserOf", inst2);
      m_context.getUnitOfWork().commit();

      // Verify
      list = Query.createRead(animalClass, parse("(commonName (chaserOf commonName))"),
         parse("(= (@ commonName) \"Cat\")"), null, -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("Cat", inst.getValue("commonName"));
      assoc = (Instance)inst.getValue("chaserOf");
      assertEquals("Spider", assoc.getValue("commonName"));

      list2 = Query.createRead(animalClass, parse("(commonName chaserOf chasedBy)"),
View Full Code Here

   public void testCreateOneToOneHeterogeneousAssoc()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      Instance inst, assoc;
      InstanceList list;

      // Read the animal to associate with
      list = Query.createRead(animalClass, parse("(commonName)"),
         parse("(= (@ commonName) \"Cat\")"), null, -1, 0, false, Query.SEC_NODE, m_context).read();
      assoc = list.getInstance(0);

      // 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)),
         new Pair(Symbol.define("chaserOf"), assoc)
      });

      m_context.getUnitOfWork().commit();

      // Read it
      list = Query.createRead(animalClass, parse("(commonName (chaserOf commonName))"),
         parse("(= (@ commonName) \"Chimpanzee\")"), null, -1, 0, false, Query.SEC_NODE, m_context).read();
      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("Pan troglodytes", inst.getValue("scientificName"));
      assoc = (Instance)inst.getValue("chaserOf");
      assertEquals("Cat", assoc.getValue("commonName"));
   }
View Full Code Here

    * reading the composition attribute itself.
    */
   public void testReadOneToOneHomogeneousAssocForward()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      InstanceList list;
      Instance inst, assoc;

      list = (InstanceList)Query.createRead(animalClass, parse("(commonName (fondOf commonName))"),
         parse("(= (@ commonName) \"Cat\")"), null, -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("Cat", inst.getValue("commonName"));
      assoc = (Instance)inst.getValue("fondOf");
      assertEquals("Spider", assoc.getValue("commonName"));

      list = (InstanceList)Query.createRead(animalClass, parse("(commonName (fondOf commonName))"),
         parse("(= (@ commonName) \"Spider\")"), null, -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(1, list.size());
      inst = list.getInstance(0);
      assertEquals("Spider", inst.getValue("commonName"));
      assertNull(inst.getValue("fondOf"));
   }
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.