Package nexj.core.runtime

Examples of nexj.core.runtime.Instance


      Cursor cursor = query.openCursor();
      Lookup map = new HashTab();

      while (cursor.step(map))
      {
         Instance instance = (Instance)map.get(query);
         List row = new ArrayList();

         for (Pair pair = attributes; pair != null; pair = pair.getNext())
         {
            Object head = pair.getHead();

            if (head instanceof Symbol)
            {
               row.add(instance.getValue(((Symbol)head).getName()));
            }
            else
            {
               addColumn((Pair)head, map, query, row);
            }
View Full Code Here


   protected void addColumn(Pair attributes, Lookup map, Query parentQuery, List row)
   {
      Metaclass parentClass = parentQuery.getMetaclass();
      Query query = parentQuery.findAssoc(Query.ASSOC_QUERY, parentClass.getAttribute((Symbol)attributes.getHead()), null, false);
      Instance instance = (Instance)map.get(query);

      for (attributes = attributes.getNext(); attributes != null; attributes = attributes.getNext())
      {
         Object head = attributes.getHead();

         if (head instanceof Symbol)
         {
            row.add((instance == null) ? "<null>" : instance.getValue(((Symbol)head).getName()));
         }
         else
         {
            addColumn((Pair)head, map, query, row);
         }
View Full Code Here

   public void testReadAssocVirtualFKToRelationalCollection() throws Exception
   {
      Metaclass virtualClass = getMetadata().getMetaclass("Animal");
      InstanceArrayList list;
      Instance inst, inst2;

      list = (InstanceArrayList)Query.createRead(virtualClass,
         parse("(commonName (virtFKToRelColl firstName lastName))"),
         null,
         null,
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(4, list.getCount());
      inst = list.getInstance(0);
      assertEquals("Dog", inst.getValue("commonName"));
      inst2 = (Instance)inst.getValue("virtFKToRelColl");
      assertEquals("Zoe", inst2.getValue("firstName"));

      inst = list.getInstance(1);
      assertEquals("Cat", inst.getValue("commonName"));
      inst2 = (Instance)inst.getValue("virtFKToRelColl");
      assertEquals("Zoe", inst2.getValue("firstName"));
      assertEquals("Test", inst2.getValue("lastName"));

      inst = list.getInstance(2);
      assertEquals("Spider", inst.getValue("commonName"));
      assertNull(inst.getValue("virtFKToRelColl"));


      // Read the reverse (the relational collection)
      Metaclass relationalClass = getMetadata().getMetaclass("PetOwner");
      InstanceArrayList list2;

      list = (InstanceArrayList)Query.createRead(relationalClass,
         parse("(firstName (relCollFromVirtFK commonName))"),
         parse("(= (@ lastName) \"Test\")"),
         parse("((firstName . #t))"),
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(2, list.size());
      inst = list.getInstance(0);
      assertEquals("Joe", inst.getValue("firstName"));
      assertEquals(0, ((InstanceArrayList)inst.getValue("relCollFromVirtFK")).size());

      inst = list.getInstance(1);
      assertEquals("Zoe", inst.getValue("firstName"));
      list2 = (InstanceArrayList)inst.getValue("relCollFromVirtFK");
      assertEquals(2, list2.size());
      inst2 = list2.getInstance(0);
      assertEquals("Dog", inst2.getValue("commonName"));
      inst2 = list2.getInstance(1);
      assertEquals("Cat", inst2.getValue("commonName"));
View Full Code Here

   public void testReadAssocVirtualAttrToRelationalFKNoAttr() throws Exception
   {
      Metaclass virtualClass = getMetadata().getMetaclass("Animal");
      InstanceArrayList list;
      Instance inst, inst2;

      list = (InstanceArrayList)Query.createRead(virtualClass,
         parse("(commonName (virtAttrToRelFKNoAttr firstName lastName))"),
         null,
         null,
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(4, list.getCount());
      inst = list.getInstance(0);
      assertEquals("Dog", inst.getValue("commonName"));
      inst2 = (Instance)inst.getValue("virtAttrToRelFKNoAttr");
      assertEquals("Zoe", inst2.getValue("firstName"));
      assertEquals("Test", inst2.getValue("lastName"));

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

      inst = list.getInstance(2);
      assertEquals("Spider", inst.getValue("commonName"));
      assertNull(inst.getValue("virtAttrToRelFKNoAttr"));
   }
View Full Code Here

    */
   public void testReadAssocVirtualFKToRelationalCollectionWhereClause() throws Exception
   {
      Metaclass virtualClass = getMetadata().getMetaclass("Animal");
      InstanceArrayList list;
      Instance inst, inst2;

      list = (InstanceArrayList)Query.createRead(virtualClass,
         parse("(commonName (virtFKToRelColl firstName))"),
         parseEval("`(= (@ virtFKToRelColl) ,(oid #z00000000000000000000000000008802 \"main\"))"),
         null,
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(2, list.getCount());
      inst = list.getInstance(0);
      assertEquals("Dog", inst.getValue("commonName"));
      inst2 = (Instance)inst.getValue("virtFKToRelColl");
      assertEquals("Zoe", inst2.getValue("firstName"));

      inst = list.getInstance(1);
      assertEquals("Cat", inst.getValue("commonName"));
      inst2 = (Instance)inst.getValue("virtFKToRelColl");
      assertEquals("Zoe", inst2.getValue("firstName"));
      assertEquals("Test", inst2.getValue("lastName"));

      list = (InstanceArrayList)Query.createRead(virtualClass,
         parse("(commonName (virtFKToRelColl firstName))"),
View Full Code Here

   public void testReadAssocRelationalFKToVirtualNone() throws Exception
   {
      Metaclass relationalClass = getMetadata().getMetaclass("PetOwner");
      InstanceArrayList list;
      Instance inst, inst2;

      list = (InstanceArrayList)Query.createRead(relationalClass,
         parse("(firstName lastName (relFKToVirtNone commonName))"),
         null,
         null,
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(2, list.getCount());
      inst = list.getInstance(0);
      assertEquals("Joe", inst.getValue("firstName"));
      inst2 = (Instance)inst.getValue("relFKToVirtNone");
      assertEquals("Beaver", inst2.getValue("commonName"));
      assertEquals("Castor canadensis", inst2.getValue("scientificName"));

      inst = list.getInstance(1);
      assertEquals("Zoe", inst.getValue("firstName"));
      inst2 = (Instance)inst.getValue("relFKToVirtNone");
      assertEquals("Spider", inst2.getValue("commonName"));
   }
View Full Code Here

   public void testLazyRelationalJoiningVirtual() throws Exception
   {
      Metaclass relationalClass = getMetadata().getMetaclass("PetOwner");
      Metaclass virtualClass = getMetadata().getMetaclass("Animal");
      InstanceArrayList list;
      Instance inst;
      int nStartCallCount;

      nStartCallCount = ((Integer)virtualClass.getValue("objectKeyReadCount")).intValue();
      list = (InstanceArrayList)Query.createRead(relationalClass,
         null,
         null,
         null,
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(2, list.getCount());
      assertEquals(nStartCallCount, ((Integer)virtualClass.getValue("objectKeyReadCount")).intValue());
      inst = list.getInstance(0);
      assertEquals(nStartCallCount, ((Integer)virtualClass.getValue("objectKeyReadCount")).intValue());
      s_logger.info("***** Start lazy load *****");
      assertEquals("Joe", inst.getValue("firstName"));
      s_logger.info("***** End lazy load *****");

      // Ensure no joins on lazy load:
      assertEquals(nStartCallCount, ((Integer)virtualClass.getValue("objectKeyReadCount")).intValue());
   }
View Full Code Here

   public void testLazyVirtualJoiningRelational() throws Exception
   {
      Metaclass virtualClass = getMetadata().getMetaclass("Animal");
      ReadCountHook readCountHook = (ReadCountHook)((SQLAdapter)getMetadata().getDataSource("DefaultRelationalDatabase").getComponent().getInstance(m_context)).getSQLHook();
      InstanceArrayList list;
      Instance inst;
      int nStartReadCount;

      nStartReadCount = readCountHook.getReadCount();
      list = (InstanceArrayList)Query.createRead(virtualClass,
         null,
         null,
         null,
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(4, list.getCount());
      assertEquals(nStartReadCount, readCountHook.getReadCount());
      inst = list.getInstance(0);
      assertEquals(nStartReadCount, readCountHook.getReadCount());
      assertEquals("Dog", inst.getValue("commonName"));
      assertEquals(nStartReadCount, readCountHook.getReadCount());
   }
View Full Code Here

   public void testReadAssocRelationalFKToVirtualAttr() throws Exception
   {
      Metaclass relationalClass = getMetadata().getMetaclass("PetOwner");
      InstanceArrayList list;
      Instance inst, inst2;

      list = (InstanceArrayList)Query.createRead(relationalClass,
         parse("(firstName lastName (relFKToVirtAttr commonName))"),
         null,
         null,
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(2, list.getCount());
      inst = list.getInstance(0);
      assertEquals("Joe", inst.getValue("firstName"));
      inst2 = (Instance)inst.getValue("relFKToVirtAttr");
      assertEquals("Spider", inst2.getValue("commonName"));

      inst = list.getInstance(1);
      assertEquals("Zoe", inst.getValue("firstName"));
      inst2 = (Instance)inst.getValue("relFKToVirtAttr");
      assertEquals("Cat", inst2.getValue("commonName"));
      assertEquals("Felis catus", inst2.getValue("scientificName"));

      // Read the reverse attribute
      Metaclass virtualClass = getMetadata().getMetaclass("Animal");

      list = (InstanceArrayList)Query.createRead(virtualClass,
         parse("(commonName (virtAttrFromRelFK firstName))"),
         null,
         null,
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(4, list.getCount());
      inst = list.getInstance(0);
      assertEquals("Dog", inst.getValue("commonName"));
      assertNull(inst.getValue("virtAttrFromRelFK"));

      inst = list.getInstance(1);
      assertEquals("Cat", inst.getValue("commonName"));
      inst2 = (Instance)inst.getValue("virtAttrFromRelFK");
      assertEquals("Zoe", inst2.getValue("firstName"));

      inst = list.getInstance(2);
      assertEquals("Spider", inst.getValue("commonName"));
      inst2 = (Instance)inst.getValue("virtAttrFromRelFK");
      assertEquals("Joe", inst2.getValue("firstName"));
      assertEquals("Test", inst2.getValue("lastName"));
   }
View Full Code Here

   public void testReadAssocRelationalFKToVirtualCollection() throws Exception
   {
      Metaclass relationalClass = getMetadata().getMetaclass("PetOwner");
      InstanceArrayList list;
      Instance inst, inst2;

      list = (InstanceArrayList)Query.createRead(relationalClass,
         parse("(firstName (relFKToVirtColl scientificName))"),
         parse("(= (@ lastName) \"Test\")"),
         parse("((firstName . #f))"),
         -1, 0, false, Query.SEC_NODE, m_context).read();

      assertEquals(2, list.getCount());
      inst = list.getInstance(0);
      assertEquals("Zoe", inst.getValue("firstName"));
      assertNull(inst.getValue("relFKToVirtColl"));
      inst = list.getInstance(1);
      assertEquals("Joe", inst.getValue("firstName"));
      inst2 = (Instance)inst.getValue("relFKToVirtColl");
      assertEquals("Felis catus", inst2.getValue("scientificName"));
      assertEquals("Cat", inst2.getValue("commonName"));


      // Read the reverse (the virtual collection)
      Metaclass virtualClass = getMetadata().getMetaclass("Animal");
      InstanceArrayList list2;

      list = (InstanceArrayList)virtualClass.invoke("read", new Object[]{
         parse("(commonName (virtCollFromRelFK firstName))"), null, null, null, null, null
      });

      assertEquals(4, list.size());
      inst = list.getInstance(0);
      assertEquals("Dog", inst.getValue("commonName"));
      assertEquals(0, ((InstanceArrayList)inst.getValue("virtCollFromRelFK")).size());

      inst = list.getInstance(1);
      assertEquals("Cat", inst.getValue("commonName"));
      list2 = (InstanceArrayList)inst.getValue("virtCollFromRelFK");
      assertEquals(1, list2.size());
      inst2 = list2.getInstance(0);
      assertEquals("Joe", inst2.getValue("firstName"));
      assertEquals("Test", inst2.getValue("lastName"));
   }
View Full Code Here

TOP

Related Classes of nexj.core.runtime.Instance

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.