Package nexj.core.meta

Examples of nexj.core.meta.Metaclass$ClassPointcutHelper


    * Tests reading a 1:1 association, using heterogeneous joins,
    * 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();
View Full Code Here


      assertFalse(m_versioned.isPointcut());
   }

   public void testRemoveColumn()
   {
      Metaclass metaclass = Repository.getMetadata().getMetaclass("Contact");
      RelationalSchema schema = new RelationalSchema();

      schema.addTable(m_locking.clone(schema));

      Table clone = m_contact.clone(schema);
      Column mappedCol = clone.getColumn("first_name");
      Column unmappedCol = clone.getColumn("title");
      int nMappedCol = mappedCol.getOrdinal();
      int nUnmappedCol = unmappedCol.getOrdinal();
      RelationalPrimitiveMapping[] tableMapping = m_contact.findMappingArray((RelationalMapping)metaclass.getPersistenceMapping());
      RelationalPrimitiveMapping[] cloneMapping = clone.findMappingArray((RelationalMapping)metaclass.getPersistenceMapping());
      RelationalPrimitiveMapping mappedColMapping = cloneMapping[mappedCol.getOrdinal()];

      clone.removeColumn(mappedCol);
      clone.removeColumn(unmappedCol);
View Full Code Here

    * Tests reading a 1:1 association, using heterogeneous joins,
    * 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();
View Full Code Here

      assertNull(inst.getValue("chasedBy"));
   }

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

      assertEquals("Cat", assoc.getValue("commonName"));
   }

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

    * Tests reading a 1:1 association, using homogeneous joins (composition mapping),
    * 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();
View Full Code Here

    * Tests that multiple associations (and levels of association) can be read
    * in a single query.
    */
   public void testReadMultipleAssocs()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      InstanceList list, col;
      Instance inst, assoc1, assoc2, assoc21, assoc3, assoc31;

      list = (InstanceList)Query.createRead(animalClass,
         parse("(commonName (licenses name) (fondOf commonName (fondOf commonName)) (pen name) (chaserOf commonName (pen name)))"),
View Full Code Here

    * Tests reading an association, with primitive attributes to read specified
    * to avoid lazy loads.
    */
   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"));
      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(1));
   }
View Full Code Here

    * Tests reading an association, with primitive and association attributes
    * specified to avoid lazy loads.
    */
   public void testReadManyToOneHeterogeneousAssocWithNonLazyCollectionsOnAssociatedInstances()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      Instance inst, assocInst;
      InstanceList list;
      int nStartCallCount, nEndCallCount;

      list = Query.createRead(animalClass, parse("(commonName limbCount (pen name animals))"),
         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);
      assertEquals("Dog pen", assocInst.getValue("name"));
      nStartCallCount = ((Integer)animalClass.getValue("penAttrReadCount")).intValue();
      assertEquals(2, ((InstanceList)assocInst.getValue("animals")).size());
      nEndCallCount = ((Integer)animalClass.getValue("penAttrReadCount")).intValue();
      assertEquals(nStartCallCount, nEndCallCount)// Loaded during read
      assertSame(inst, ((InstanceList)assocInst.getValue("animals")).getInstance(0));

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

      inst = list.getInstance(2);
      assertEquals("Spider", inst.getValue("commonName"));
      assocInst = (Instance)inst.getValue("pen");
      assertNotNull(assocInst);
      assertEquals("Dog pen", assocInst.getValue("name"));
      nStartCallCount = ((Integer)animalClass.getValue("penAttrReadCount")).intValue();
      assertEquals(2, ((InstanceList)assocInst.getValue("animals")).size());
      nEndCallCount = ((Integer)animalClass.getValue("penAttrReadCount")).intValue();
      assertEquals(nStartCallCount, nEndCallCount)// Loaded during read
      assertSame(inst, ((InstanceList)assocInst.getValue("animals")).getInstance(1));
   }
View Full Code Here

   /**
    * Tests reading an association sub-collection.
    */
   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"));
View Full Code Here

TOP

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

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.