Package nexj.core.meta

Examples of nexj.core.meta.Metaclass$Local


    * Tests single instance update and optimistic locking detection when the
    * instance is updated or deleted elsewhere.
    */
   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);
View Full Code Here


    */
   protected void setUp() throws Exception
   {
      super.setUp();
     
      Metaclass contact = Repository.getMetadata().getMetaclass("Contact");
     
      m_mapping = (RelationalPrimitiveMapping)((RelationalMapping)contact
         .getPersistenceMapping()).getAttributeMapping(contact.getAttribute("firstName"));
   }
View Full Code Here

   /**
    * Tests batch update.
    */
   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);
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))"),
View Full Code Here

   /**
    * Tests dependency sorting among work items.
    */
   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\")"),
View Full Code Here

   /**
    * Tests creation of a single instance.
    */
   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

   /**
    * Tests creating an instance where the OID is set by the create mapping.
    */
   public void testCreateWithExternallyGeneratedOID()
   {
      Metaclass penClass = m_metadata.getMetaclass("AnimalPen");
      Instance inst;
      Collection data;

      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")
      });

      data = (Collection)m_context.getMachine().eval(parse("(AnimalPenStore'data)"));
View Full Code Here

   /**
    * Tests creating an instance where the OID parts are specified in the instance attributes.
    */
   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);
View Full Code Here

   /**
    * Tests dependency sorting among work items.
    */
   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[]
      {
View Full Code Here

   /**
    * Tests reading an association.
    */
   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"));
      nEndCallCount = ((Integer)penClass.getValue("objectKeyReadCount")).intValue();
      assertEquals(nStartCallCount, nEndCallCount)// Loaded by a previous lazy load
      assertEquals(2, ((InstanceList)assocInst.getValue("animals")).size());
      assertSame(inst, ((InstanceList)assocInst.getValue("animals")).getInstance(1));
   }
View Full Code Here

TOP

Related Classes of nexj.core.meta.Metaclass$Local

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.