Package nexj.core.meta

Examples of nexj.core.meta.Attribute$IndirectInverseDependency


      {
         RelationalPrimitiveMapping mapping = m_mappingArray[column.getOrdinal()];

         if (mapping != null)
         {
            Attribute attribute = mapping.getAttribute();

            m_instance.setValueDirect(attribute.getOrdinal(), ((Primitive)attribute.getType()).convert(value));
         }
      }
   }
View Full Code Here


    * Sets up the locking attribute, if available.
    */
   public final void setupLocking()
   {
      RelationalMapping relMapping = (RelationalMapping)m_mapping;
      Attribute lockAttribute = relMapping.getLockingAttribute();

      if (lockAttribute != null)
      {
         Object value = m_instance.getValueDirect(lockAttribute.getOrdinal());

         if (value != Undefined.VALUE)
         {
            Column column = ((RelationalPrimitiveMapping)relMapping
               .getAttributeMapping(lockAttribute)).getColumn();
View Full Code Here

      Metaclass metaclass = instance.getMetaclass();
      PersistenceMapping mapping = instance.getPersistenceMapping();

      for (int i = 0, nCount = metaclass.getInstanceAttributeCount(); i < nCount; ++i)
      {
         Attribute attribute = metaclass.getInstanceAttribute(i);
         AttributeMapping attributeMapping = mapping.getAttributeMapping(attribute);

         if (attributeMapping == null)
         {
            continue;
         }

         Object value = instance.getValueDirect(i);

         // The value cannot be undefined, the Instance.validate() has taken care of that.

         if (attribute.getType().isPrimitive())
         {
            addPrimitiveWork(uow, instance, primaryWork, attributeMapping, value);
         }
         else
         {
            InstanceList list = null;
            Instance inst = null;
            boolean bNull;

            if (attribute.isCollection())
            {
               list = (InstanceList)value;
               bNull = (list == null || list.isEmpty());
            }
            else
View Full Code Here

      Metaclass metaclass = instance.getMetaclass();
      PersistenceMapping mapping = instance.getPersistenceMapping();

      for (int i = 0, nCount = metaclass.getInstanceAttributeCount(); i < nCount; ++i)
      {
         Attribute attribute = metaclass.getInstanceAttribute(i);
         AttributeMapping attributeMapping = mapping.getAttributeMapping(attribute);

         if (attributeMapping == null)
         {
            continue;
         }

         Object value = instance.getValueDirect(i);

         if (value == Undefined.VALUE || ObjUtil.equal(value, instance.getOldValueDirect(i)))
         {
            continue;
         }

         if (attribute.getType().isPrimitive())
         {
            addPrimitiveWork(uow, instance, primaryWork, attributeMapping, value);
         }
         else
         {
            InstanceList list = null;
            Instance inst = null;
            boolean bNull;

            if (attribute.isCollection())
            {
               list = (InstanceList)value;
               bNull = (list == null || list.isEmpty());
            }
            else
            {
               inst = (Instance)value;
               bNull = (inst == null);
            }

            ClassMapping assocMapping = (ClassMapping)attributeMapping;
            boolean bSuccessor;

            // TODO: Update composition mappings

            if (assocMapping.getKey(false).isObjectKey())
            {
               bSuccessor = true;
            }
            else if (assocMapping.getKey(true).isObjectKey())
            {
               bSuccessor = false;
            }
            else if (attribute.isCollection())
            {
               bSuccessor = true;
            }
            else
            {
View Full Code Here

   public void testEvent() throws Exception
   {
      Metadata metadata = new XMLMetadata(null, null, null, null, null);
      Metaclass metaclass = new Metaclass("Test");
      Attribute attr = new Attribute("attr");
      Argument untyped = new Argument("untyped");
      Argument anytyped = new Argument("anytyped");
      Argument inttyped = new Argument("inttyped");
      Argument listtyped = new Argument("listtyped");
      Event protectedEv = new Event("protected");
      Event publicEv = new Event("public");
      Event staticEv = new Event("static");
      MockServer server = new MockServer(new Object[]{null});
      Timestamp ts =
         SOAPUtil.parseDateTime("1234-05-06T07:08:09", true, true, TimeZone.getDefault());

      attr.setType(Primitive.ANY);
      anytyped.setType(Primitive.ANY);
      inttyped.setType(Primitive.INTEGER);
      listtyped.setType(Primitive.STRING);
      listtyped.setCollection(true);
      protectedEv.setVisibility(Metaclass.PROTECTED);
      publicEv.addArgument(untyped);
      publicEv.addArgument(anytyped);
      publicEv.addArgument(inttyped);
      publicEv.addArgument(listtyped);
      staticEv.addArgument(untyped);
      staticEv.addArgument(anytyped);
      staticEv.addArgument(inttyped);
      staticEv.addArgument(listtyped);
      staticEv.setStatic(true);
      staticEv.setVarArg(true);
      metaclass.addAttribute(attr);
      metaclass.addEvent(protectedEv);
      metaclass.addEvent(publicEv);
      metaclass.addEvent(staticEv);
      metadata.addMetaclass(metaclass);

      // test protected event
      XMLUnmarshaller unmarshaller = new XMLUnmarshaller(new InvocationContext(metadata));
      String sElement = XSDGenerator.computeElementName(protectedEv);
      StringReader reader = new StringReader(
         "<" + sElement + " xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'/>");

      try
      {
         unmarshaller.deserialize(reader);
         fail(); // SOAPUnmarshallerException expected
      }
      catch (SOAPUnmarshallerException e)
      {
         assertEquals("err.rpc.soap.missingType", e.getErrorCode());
      }

      // test public non-static unbound event
      sElement = XSDGenerator.computeElementName(publicEv);
      reader = new StringReader(
         "<" + sElement + " xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
         " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
         " xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'>" +
         "<untyped xsi:type='xs:decimal'>3.1415926535897932384626433832795</untyped>" +
         "<anytyped xsi:type='xs:dateTime'>1234-05-06T07:08:09</anytyped>" +
         "<inttyped>42</inttyped>" +
         "<listtyped>abc</listtyped><listtyped>def</listtyped>" +
         "</" + sElement + ">");

      try
      {
         unmarshaller.deserialize(reader);
         fail(); // SOAPUnmarshallerException expected
      }
      catch (SOAPUnmarshallerException e)
      {
         assertEquals("err.rpc.soap.unmshComplex", e.getErrorCode());
      }

      // test public non-static event
      sElement = XSDGenerator.computeElementName(publicEv);
      reader = new StringReader(
         "<" + sElement + " xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
         " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
         " xmlns:tns='" + XML.NS_URI_TNS + "'" +
         " xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'>" +
         "<_instance><tns:" + attr.getName() + ">test</tns:" + attr.getName() + "></_instance>" +
         "<untyped xsi:type='xs:decimal'>3.1415926535897932384626433832795</untyped>" +
         "<anytyped xsi:type='xs:dateTime'>1234-05-06T07:08:09</anytyped>" +
         "<inttyped>42</inttyped>" +
         "<listtyped>abc</listtyped><listtyped>def</listtyped>" +
         "</" + sElement + ">");

      ((XMLInvocationRequest)unmarshaller.deserialize(reader)).invoke(server);

      Request request = server.getRequest();

      assertNotNull(request);
      assertEquals(1, request.getInvocationCount());

      Request.Invocation action = request.getInvocation(0);
      TransferObject tobj = action.getObject();
      Object[] argArray = action.getArguments();

      assertEquals(publicEv.getName(), action.getEventName());
      assertEquals(publicEv.getArgumentCount(), argArray.length);
      assertTrue(argArray[0] instanceof BigDecimal);
      assertEquals(3.1415926535897932384626433832795, ((BigDecimal)argArray[0]).doubleValue(), 0);
      assertTrue(argArray[1] instanceof Timestamp);
      assertEquals(ts.getTime(), ((Timestamp)argArray[1]).getTime());
      assertEquals(Primitive.createInteger(42), argArray[2]);
      assertTrue(argArray[3] instanceof List);
      assertEquals(2, ((List)argArray[3]).size());
      assertEquals("abc", ((List)argArray[3]).get(0));
      assertEquals("def", ((List)argArray[3]).get(1));
      assertEquals(metaclass.getName(), tobj.getClassName());
      assertNull(tobj.getEventName());
      assertNull(tobj.getOID());
      assertEquals(1, tobj.getValueCount());
      assertEquals("test", tobj.findValue(attr.getName()));

      // test static bound event
      sElement = XSDGenerator.computeElementName(staticEv);
      reader = new StringReader(
         "<" + sElement + " xmlns:xs='http://www.w3.org/2001/XMLSchema'" +
         " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
         " xmlns:tns='" + XML.NS_URI_TNS + "'" +
         " xmlns='" + XML.NS_URI_TNS + '/' + metaclass.getName() + "'>" +
         "<_instance><tns:" + attr.getName() + ">test</tns:" + attr.getName() + "></_instance>" +
         "<untyped xsi:type='xs:decimal'>3.1415926535897932384626433832795</untyped>" +
         "<anytyped xsi:type='xs:dateTime'>1234-05-06T07:08:09</anytyped>" +
         "<inttyped>42</inttyped>" +
         "<listtyped>abc</listtyped><listtyped>def</listtyped>" +
         "</" + sElement + ">");
View Full Code Here

               if (m_context.getGeneration() != InvocationContext.GEN_NEW)
               {
                  break;
               }

               Attribute attribute = m_metaclass.getReadAccessAttribute();

               if (m_nState == DIRTY && attribute != null && !attribute.isStatic() &&
                  getValueDirect(attribute.getOrdinal()) == Undefined.VALUE)
               {
                  break;
               }

               if (isReadable())
View Full Code Here

      if (!isLazy())
      {
         attribute = m_metaclass.getInstanceAttribute(attribute.getOrdinal());

         Attribute reverse = attribute.getReverse();
         byte nGenerationSaved = m_context.getGeneration();

         try
         {
            for (byte nGeneration = nGenerationSaved;;)
            {
               Object oldValue = getValueDirect(attribute.getOrdinal());

               if (!(oldValue instanceof Undefined))
               {
                  attribute.invalidateDependency(this, Undefined.VALUE);

                  if (oldValue != null)
                  {
                     if (attribute.isCollection())
                     {
                        InstanceList list = (InstanceList)oldValue;

                        list.setLazy(true);

                        for (int i = list.getCount() - 1; i >= 0; --i)
                        {
                           Instance instance = list.getInstance(i);

                           if (instance == null)
                           {
                              list.remove(i, InstanceList.DIRECT);
                           }
                           else if (instance.getUnitOfWork() == null && !instance.isLazy())
                           {
                              if (reverse != null)
                              {
                                 if (!(instance.getValueDirect(reverse.getOrdinal()) instanceof Undefined))
                                 {
                                    instance.setValueDirect(reverse.getOrdinal(), Undefined.VALUE);
                                    instance.getMetaclass().getInstanceAttribute(reverse.getOrdinal())
                                       .invalidateDependency(instance, Undefined.VALUE);
                                 }
                              }

                              list.remove(i, InstanceList.DIRECT);
                           }
                        }
                     }
                     else
                     {
                        if (reverse != null)
                        {
                           Instance instance = (Instance)oldValue;

                           if (instance.getUnitOfWork() == null && !instance.isLazy())
                           {
                              if (reverse.isCollection())
                              {
                                 if (bReverseCollection)
                                 {
                                    Object reverseValue = instance.getValueDirect(reverse.getOrdinal());

                                    if (reverseValue != Undefined.VALUE && reverseValue != null)
                                    {
                                       InstanceList list = (InstanceList)reverseValue;

                                       list.setLazy(true);

                                       if (list.remove(this, InstanceList.DIRECT))
                                       {
                                          instance.getMetaclass().getInstanceAttribute(reverse.getOrdinal())
                                             .invalidateDependency(instance, Undefined.VALUE);
                                       }
                                    }
                                 }
                              }
                              else
                              {
                                 instance.setValueDirect(reverse.getOrdinal(), Undefined.VALUE);
                              }
                           }
                        }

                        setValueDirect(attribute.getOrdinal(), Undefined.VALUE);
View Full Code Here

               if (nReplication == PersistenceMapping.REPLICATION_UNICAST)
               {
                  if (getFragmentName() == null)
                  {
                     Attribute attribute = mapping.getFragmentAttribute();

                     if (attribute != null)
                     {
                        uow.addReplicationFragment(this, (String)((attribute.isStatic()) ?
                           m_metaclass : (Accessor)this).getValue(attribute.getOrdinal()));
                     }
                  }
                  else
                  {
                     uow.addReplicationFragment(this, null);
View Full Code Here

         for (int i = 0, n = root.getPersistenceAliasCount(); i < n; ++i)
         {
            Metaclass alias = root.getPersistenceAlias(i);
            PersistenceMapping mapping = alias.getPersistenceMapping();
            Attribute typeCodeAttr = mapping.getTypeCodeAttribute();

            if (typeCodeAttr != null)
            {
               Metaclass metaclass = mapping.findMetaclassByTypeCode(getValue(typeCodeAttr.getOrdinal()));

               if (metaclass != null)
               {
                  alias = metaclass;
               }
View Full Code Here

         catch (PersistenceException e)
         {
         }
      }

      Attribute attribute = m_metaclass.getNameAttribute();

      if (attribute != null)
      {
         try
         {
            return (String)getValue(attribute.getOrdinal());
         }
         catch (PersistenceException e)
         {
         }
      }
View Full Code Here

TOP

Related Classes of nexj.core.meta.Attribute$IndirectInverseDependency

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.