Package nexj.core.persistence

Examples of nexj.core.persistence.OID


      assertEquals("Dog", inst.getValue("commonName"));
      collection = (InstanceArrayList)inst.getValue("licenses");
      assertEquals(2, collection.size());
      inst2 = collection.getInstance(0);
      assertEquals("City Dog License", inst2.getValue("name"));
      assertEquals(new OID(new Object[]{Binary.parse("80")}), inst2.getOID());
      inst2 = collection.getInstance(1);
      assertEquals("Vaccination Certificate for Kerberos the dog", inst2.getValue("name"));
      assertEquals(new OID(new Object[]{Binary.parse("81")}), inst2.getOID());

      inst = list.getInstance(1);
      assertEquals("Cat", inst.getValue("commonName"));
      collection = (InstanceArrayList)inst.getValue("licenses");
      assertEquals(0, collection.size());
View Full Code Here


   {
      // create argument transfer object
      TransferObject tobj = new TransferObject(sName);
     
      tobj.setEventName("test" + nSuffix);
      tobj.setOID(new OID(new Object[] { "oid" + nSuffix }));
      tobj.setVersion((short)nSuffix);
     
      for (int i = 0; i < nSizeMultiplier; ++i)
      {
         List l = new ArrayList();
View Full Code Here

      Query query;

      // Lazy association type adjustment
      Instance instance = new Instance(getMetadata().getMetaclass("Principal"), true, m_context);

      instance.cache(new OID(new Object[]{Binary.parse("00000000000000000000000000000002")}));
      query = Query.createRead(getMetadata().getMetaclass("UserGroupAssoc"), parse("(user)"),
         parse("(= (@) (oid #z00000000000000000000000000000003))"),
         null, -1, 0, false, Query.SEC_NONE, m_context);
      assertEquals("User", ((Instance)query.read().getInstance(0).getValue("user")).getLazyMetaclass().getName());
      m_context.removeInstance(instance);
      instance = null;

      // Unsupported where clause
      try
      {
         Query.createRead(getMetadata().getMetaclass("Contact"), null, parse("(> (myfun firstName) 0)"), null, -1, 0, false, Query.SEC_NONE, m_context);
         fail("Expected InvalidQueryException");
      }
      catch (InvalidQueryException e)
      {
         assertEquals("err.persistence.unsupportedExpression", e.getErrorCode());
      }
     
      attributes = parse("(firstName lastName (addresses country city street code) (user name))");
      query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
         parse("(= classCode \"CON\")"),
         parse("((firstName . #t)(lastName . #t)((@ addresses) . #t))"),
         -1, 0, false, Query.SEC_NONE, m_context);
      AssertUtil.assertEquals(getURL("read.xml"), query.read(), attributes);

      query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
         parse("(and (null? (@ noAddresses city)) (= classCode \"CON\"))"),
         parse("((firstName . #t)(lastName . #t)((@ addresses) . #t))"),
         -1, 0, false, Query.SEC_NONE, m_context);
      AssertUtil.assertEquals(getURL("read.xml"), query.read(), attributes);

      String sSQL = ((SQLGenerator)query.getGenerator()).getSQL();

      query = Query.createRead(getMetadata().getMetaclass("Contact"),
         parse("((user name) lastName (addresses country city street code) firstName)"),
         parse("(and (null? (@ noAddresses city)) (= classCode \"CON\"))"),
         parse("((firstName . #t)(lastName . #t)((@ addresses) . #t))"),
         -1, 0, false, Query.SEC_NONE, m_context);
      AssertUtil.assertEquals(getURL("read.xml"), query.read(), attributes);

      assertEquals(sSQL, ((SQLGenerator)query.getGenerator()).getSQL());

      query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
         parse("(= classCode \"CON\")"),
         parse("((firstName . #t)(lastName . #t)((@) . #t)((@ addresses) . #t))"),
         2, 0, false, Query.SEC_NONE, m_context);
      AssertUtil.assertEquals(getURL("readCount.xml"), query.read(), attributes);

      query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
         parse("(= classCode \"CON\")"),
         parse("((firstName . #t)(lastName . #t)((@) . #t)((@ addresses) . #t))"),
         2, 2, false, Query.SEC_NONE, m_context);
      AssertUtil.assertEquals(getURL("readOffset.xml"), query.read(), attributes);

      query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
         parse("(and (like? firstName \"J*\") (= lastName \"Smith\") (in? (@ readPrincipal name) \"users\" \"QA\" \"jsmith\")))"),
         parse("((firstName . #t)(lastName . #t)((@) . #t)((@ addresses) . #t))"),
         -1, 0, false, Query.SEC_NONE, m_context);
      AssertUtil.assertEquals(getURL("readWhere.xml"), query.read(), attributes);

      query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
         parse("(and (like? firstName \"J*\") (= lastName \"Smith\") (in? (@ readPrincipal name) \"users\" \"QA\" \"jsmith\" " +
                "\"1\" \"2\" \"3\" \"4\" \"5\" \"6\" \"7\" \"8\" \"9\" \"10\" \"11\" \"12\" \"13\" \"14\" \"15\" \"16\" " +
                "\"17\" \"18\" \"19\" \"20\" \"21\" \"22\" \"23\" \"24\" \"25\" \"26\" \"27\" \"28\" \"29\" \"30\")))"),
         parse("((firstName . #t)(lastName . #t)((@) . #t)((@ addresses) . #t))"),
         -1, 0, false, Query.SEC_NONE, m_context);
      AssertUtil.assertEquals(getURL("readWhere.xml"), query.read(), attributes);

      List inList = new ArrayList(3000);

      for (int i = 0; i < 3000; ++i)
      {
         inList.add(String.valueOf(i));
      }

      inList.add("users");
      inList.add("QA");
      inList.add("jsmith");

      query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes,
         parse("(and (like? firstName \"J*\") (= lastName \"Smith\"))")
            .and(Pair.attribute("readPrincipal name").in(new Pair(inList))),
         parse("((firstName . #t)(lastName . #t)((@) . #t)((@ addresses) . #t))"),
         -1, 0, false, Query.SEC_NONE, m_context);
      AssertUtil.assertEquals(getURL("readWhere.xml"), query.read(), attributes);
      inList = null;

      query = Query.createRead(getMetadata().getMetaclass("Contact"), attributes, parse("(= lastName ())"),
         parse("((firstName . #t)(lastName . #t)((@) . #t)((@ addresses) . #t))"),
         -1, 0, false, Query.SEC_NODE, m_context);
      AssertUtil.assertEquals(getURL("readWhereNull.xml"), query.read(), attributes);

      attributes = parse("(type country city)");
      query = Query.createRead(getMetadata().getMetaclass("Address"), attributes,
         new Pair(Symbol.EQ,
            new Pair(parse("(@@ Contact addresses)"),
            new Pair(new OID(new Object[]{Binary.parse("00000000000000000000000000000001")})))),
         parse("((type . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
      AssertUtil.assertEquals(getURL("readReverse.xml"), query.read(), attributes);

      query = Query.createRead(getMetadata().getMetaclass("Address"), attributes,
         new Pair(Symbol.OR, new Pair(Boolean.FALSE, new Pair(
            new Pair(Symbol.EQ,
               new Pair(parse("(@@ User contact addresses)"),
                  new Pair(new OID(new Object[]{Binary.parse("00000000000000000000000000000001")}))))))),
         parse("((type . #t) ((@) . #t))"), -1, 0, false, Query.SEC_NONE, m_context);
      AssertUtil.assertEquals(getURL("readReverse2.xml"), query.read(), attributes);

      query = Query.createRead(getMetadata().getMetaclass("Address"), attributes,
               parse("(= (@@ Contact businessAddress2) (oid #z00000000000000000000000000000001))"),
View Full Code Here

   }

   public void testNew()
   {
      Metaclass metaclass = getMetadata().getMetaclass("Principal");
      OID oid = new OID(new Object[]{Binary.parse("00000000000000000000000000000004")});
      Instance principal = m_context.findInstance(metaclass, oid);

      if (principal == null)
      {
         principal = new Instance(metaclass, m_context);
         principal.cache(oid);
      }

      Instance contact = new Instance(getMetadata().getMetaclass("Contact"), Instance.NEW, m_context);

      contact.setValue("firstName", "Ozzy");
      contact.setValue("lastName", "Osbourne");
      contact.setValue("testCategory", "");
      contact.setValue("readPrincipal", principal);
      contact.setValue("version", Primitive.ZERO_INTEGER);

      // Test async invocation on new instances
      getMetadata().getMetaclass("SysQueue").invoke("invoke", new Object[]{contact, Symbol.define("testAsync")});
      getMetadata().getMetaclass("SysQueue").invoke("invoke", new Object[]{contact, Symbol.define("testAsync"), new Object[]{"test"}});

      InstanceList list = (InstanceList)contact.getValue("addresses");
      Instance address = new Instance(getMetadata().getMetaclass("Address"), Instance.NEW, m_context);

      address.setValue("type", "Business");
      address.setValue("country", "USA");

      list.add(address);

      Instance cottage = Query.createRead(getMetadata().getMetaclass("AddressType"),
         parse("(type)"), parse("(and (= type \"Cottage\") (= locale \"en\"))"),
         null, -1, 0, false, Query.SEC_NONE, m_context).read().getInstance(0);

      address = new Instance(getMetadata().getMetaclass("Address"), Instance.NEW, m_context);

      address.setValue("typeEnum", cottage);
      address.setValue("country", "Canada");

      list.add(address);
      contact.setValue("primaryAddress", address);

      contact = new Instance(getMetadata().getMetaclass("Contact"), Instance.NEW, m_context);

      contact.setValue("firstName", "Ronnie");
      contact.setValue("lastName", "Dio");
      contact.setValue("readPrincipal", principal);
      contact.setValue("version", Primitive.ZERO_INTEGER);

      list = (InstanceList)contact.getValue("phones");
      Instance phone = new Instance(getMetadata().getMetaclass("Phone"), Instance.NEW, m_context);

      phone.setValue("type", "Business");
      phone.setValue("number", "(111) 222-3344");

      list.add(phone);
      commit();

      assertEquals(Primitive.ZERO_INTEGER, m_context.getMachine().getGlobalEnvironment().getVariable(Symbol.define("update-count")));
      assertEquals(Primitive.createInteger(2), m_context.getMachine().getGlobalEnvironment().getVariable(Symbol.define("commit-count")));
     
      assertEquals(7, Query.createRead(getMetadata().getMetaclass("Contact"), null,
         parse("(= classCode \"CON\")"), null, -1, 0, false, Query.SEC_NONE, m_context).read().size());

      assertEquals(2, Query.createRead(getMetadata().getMetaclass("Contact"), null,
         parse("(in? lastName \"Osbourne\" \"Dio\")"), null,
         -1, 0, false, Query.SEC_NONE, m_context).read().size());

      list = Query.createRead(getMetadata().getMetaclass("Contact"), null,
         parse("(= testCategory \"\")"), null,
         -1, 0, false, Query.SEC_NONE, m_context).read();

      assertEquals(1, list.size());
      assertEquals("", list.getInstance(0).getValue("testCategory"));

      assertEquals(8, Query.createRead(getMetadata().getMetaclass("Contact"), null,
         parse("(null? testCategory)"), null, -1, 0, false, Query.SEC_NONE, m_context).read().size());

      assertEquals(1, Query.createRead(getMetadata().getMetaclass("Address"), null,
         parse("(and (= (@ contact firstName) \"Ozzy\") (= country \"USA\"))"), null,
         -1, 0, false, Query.SEC_NONE, m_context).read().size());

      assertEquals(1, Query.createRead(getMetadata().getMetaclass("Address"), null,
         parse("(and (= (@ contact firstName) \"Ozzy\") (= country \"Canada\"))"), null,
         -1, 0, false, Query.SEC_NONE, m_context).read().size());

      assertEquals(1, Query.createRead(getMetadata().getMetaclass("Phone"), null,
         parse("(= number \"(111) 222-3344\")"), null,
         -1, 0, false, Query.SEC_NONE, m_context).read().size());

      Instance ref = new Instance(getMetadata().getMetaclass("PrincipalRef2"), Instance.NEW, m_context);

      ref.setValue("name", "a");
      ref.setValue("count", Primitive.createInteger(3));

      ref = new Instance(getMetadata().getMetaclass("PrincipalRef2"), Instance.NEW, m_context);

      ref.setValue("name", "b");

      commit();

      m_context.removeInstance(ref);

      ref = Query.createRead(getMetadata().getMetaclass("PrincipalRef2"), null,
         parse("(= name \"b\")"), null, -1, 0, false, Query.SEC_NONE, m_context).read().getInstance(0);
      ref.setValue("count", Primitive.createInteger(7));

      commit();

      assertEquals(1, Query.createRead(getMetadata().getMetaclass("PrincipalRef2"), null,
         parse("(and (= name \"a\") (= count 3))"), null,
         -1, 0, false, Query.SEC_NONE, m_context).read().size());

      assertEquals(1, Query.createRead(getMetadata().getMetaclass("PrincipalRef2"), null,
         parse("(and (= name \"b\") (= count 7))"), null,
         -1, 0, false, Query.SEC_NONE, m_context).read().size());

      // KeyGenerator.MaxPlus1 and KeyGenerator.Counter test

      new Instance(getMetadata().getMetaclass("Max1Test"), Instance.NEW, m_context);
      new Instance(getMetadata().getMetaclass("Max1Test"), Instance.NEW, m_context);
      new Instance(getMetadata().getMetaclass("CounterTest"), Instance.NEW, m_context);
      new Instance(getMetadata().getMetaclass("CounterTest"), Instance.NEW, m_context);

      commit();

      assertEquals(2, Query.createRead(getMetadata().getMetaclass("Max1Test"), null,
         null, null, -1, 0, false, Query.SEC_NONE, m_context).read().size());

      assertEquals(2, Query.createRead(getMetadata().getMetaclass("CounterTest"), null,
         null, null, -1, 0, false, Query.SEC_NONE, m_context).read().size());

      // Test non-primitive initializer
      new Instance(getMetadata().getMetaclass("ContactWithInits"), Instance.NEW, m_context);

      commit();
      reset();

      list = Query.createRead(getMetadata().getMetaclass("ContactWithInits"),
         parse("((initAddress city))"), null, null, -1, 0, false, Query.SEC_NONE, m_context).read();

      assertEquals(1, list.size());
      assertEquals("Canada", ((Instance)list.getInstance(0).getValue("initAddress")).getValue("country"));

      // Duplicate unique constraint test
      m_context.setSecure(false);

      Instance wfqueue = new Instance(getMetadata().getMetaclass("SysWorkflowQueue"), Instance.NEW, m_context);

      wfqueue.setOID(new OID(new Object[]{Binary.parse("00000000000000000000000000000001")}));
      wfqueue.setValue("name", "custom");
      wfqueue.setValue("type", "WFLIFOQueue");
      wfqueue.setValue("caption", "LIFO");
      wfqueue.setValue("customized", Boolean.FALSE);
View Full Code Here

      {
         return;
      }

      Metaclass metaclass = getMetadata().getMetaclass("Principal");
      OID oid = new OID(new Object[]{Binary.parse("00000000000000000000000000000004")});
      Instance principal = m_context.findInstance(metaclass, oid);

      if (principal == null)
      {
         principal = new Instance(metaclass, m_context);
View Full Code Here

      int i = 0;

      while (i < timerList.size())
      {
         Instance timer = timerList.getInstance(i);
         OID timerOID = timer.getOID();

         assertEquals(1, timerOID.getCount());

         if (((Binary)timerOID.getValue(0)).toString().equals("00000000000000000000000000000001"))
         {
            timerList.remove(i);
         }
         else
         {
View Full Code Here

         s_logger.dump("fullName[" + i + "] = \"" + list.getInstance(i).getValue("fullName") + "\"");
      }
     
      Metaclass address = Repository.getMetadata().getMetaclass("XJAddress");
      attributes = (Pair)parse("(country city)");
      where = new Pair(Symbol.EQ, new Pair (parse("(@@ XJContact addresses)"), new Pair(new OID(new Object[]{"12345678901234567890123456789012"}))));

      query = Query.createRead(address, attributes, where, null, 10, 0, false, Query.SEC_NONE, m_context);
      query.read();
     
      Metaclass xjobj = Repository.getMetadata().getMetaclass("XJJObj");
      attributes = (Pair)parse("(mimeType mimeData)");
      where = new Pair(Symbol.EQ, new Pair (parse("(@@ XJContact image)"), new Pair(new OID(new Object[]{"78B14B58F66611CEBB8500AA0020A75A"}))));
      query = Query.createRead(xjobj, attributes, where, null, 1, 0, false, Query.SEC_NONE, m_context);
      list = query.read();
     
      if (list.size() == 1)
      {
         s_logger.debug("mime = " + list.getInstance(0).getValue("mimeType"));
        
         try
         {
               FileOutputStream fos = new FileOutputStream("c:/tmp/pic.bin");
               fos.write(((Binary)list.getInstance(0).getValue("mimeData")).getData());
               fos.close();
         }
         catch (Exception e)
         {
            s_logger.error("Exception", e);
         }
      }

      Query.createRead(Repository.getMetadata().getMetaclass("XJContact"), null,
         new Pair(Symbol.EQ, new Pair(parse("(@@ XJDoc conGroups contact)"),
         new Pair(new OID(new Object[]{"1"})))), null, -1, 0, false, Query.SEC_NONE, m_context).read();

      Query.createRead(Repository.getMetadata().getMetaclass("XJAddress"), (Pair)parse("(addrGUID)"),
         new Pair(Symbol.EQ, new Pair(parse("(@@ XJContact addresses)"),
         new Pair(new OID(new Object[]{"1"})))), (Pair)parse("((addrGUID . #t)((@) . #t))"), -1, 0, false,
         Query.SEC_NONE, m_context).read();
   }
View Full Code Here

TOP

Related Classes of nexj.core.persistence.OID

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.