Package nexj.core.meta

Examples of nexj.core.meta.Metaclass$ClassPointcutHelper


    * (Derived & base must use class codes, derived class mapping must have "derived == true",
    * and they must be on the same datasource).
    */
   public void testPersistenceRoot()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      Metaclass domAnimalClass = m_metadata.getMetaclass("DomesticAnimal");

      assertSame(animalClass, domAnimalClass.getPersistenceRoot());
   }
View Full Code Here


   /**
    * Tests reads.
    */
   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);
View Full Code Here

   /**
    * Tests that read result without OID throws an error.
    */
   public void testReadNotReturningOID()
   {
      Metaclass testClass = m_metadata.getMetaclass("TestVirtualClass");

      try
      {
         // Read by a1, which is broken: doesn't set the TransferObject's OID
         Query.createRead(testClass,
View Full Code Here

   /**
    * Tests that missing requested attributes become null.
    */
   public void testReadNullAssocAttribute()
   {
      Metaclass testClass = m_metadata.getMetaclass("TestVirtualClass");
      Instance inst = Query.createRead(testClass,
         parse("(a1 b1 b2)"), parse("(= (@ b) 1)"), null, -1, 0, false, Query.SEC_ALL, m_context
      ).read().getInstance(0);

      assertEquals("Test", inst.getValue("a1"));
View Full Code Here

   /**
    * Tests that an exception is thrown if the locking attribute is not updated.
    */
   public void testUpdateWithoutChangingLocking()
   {
      Metaclass testClass = m_metadata.getMetaclass("TestVirtualClass");
      Instance inst = new Instance(testClass, m_context);

      inst.setOID(new OID(new Object[]{Binary.parse("0013")}));
      inst.setValue("locking", Primitive.createLong(17L));
      inst.setClean();
View Full Code Here

    * Tests that a read mapping can set attributes not in the attribute read list.
    * Missing unrequested attributes are left undefined.
    */
   public void testReadAttributesNotInList()
   {
      Metaclass testClass = m_metadata.getMetaclass("TestVirtualClass");
      Instance inst = Query.createRead(testClass,
         parse("(c1)"), parse("(= (@ c) 1)"), null, -1, 0, false, Query.SEC_ALL, m_context
      ).read().getInstance(0);

      assertEquals("Requested", inst.getValue("c1"));
      assertEquals("Extra", inst.getValue("b2"))// This is done without performing a lazy load.
      assertNull(inst.getValue("a1"));
      assertSame(Undefined.VALUE, inst.getValueDirect(testClass.findAttribute("b1").getOrdinal()));

      Instance assoc = (Instance)inst.getValue("b3");

      assertEquals(testClass, assoc.getLazyMetaclass());
      assertTrue(assoc.isLazy());
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;

View Full Code Here

   /**
    * Tests that an empty collection means 0 results.
    */
   public void testReadEmptyCollection()
   {
      Metaclass testClass = m_metadata.getMetaclass("TestVirtualClass");

      assertEquals(0, Query.createRead(testClass,
         parse("(a1)"), parse("(= (@ e) 1)"), null, -1, 0, false, Query.SEC_ALL, m_context
      ).read().size());
   }
View Full Code Here

      ).read().size());
   }

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

   /**
    * Tests single instance delete (via a batch-delete mapping) and optimistic locking.
    */
   public void testDelete()
   {
      Metaclass animalClass = m_metadata.getMetaclass("Animal");
      Instance inst = null;
      InstanceList list = null;

      // Read all
      list = Query.createRead(animalClass,
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.