Package nexj.core.meta

Examples of nexj.core.meta.Metaclass$AttributeDependencyVisitor


    * @param attributes The attribute name Symbol list.
    * @return The attribute bitmap.
    */
   public BitSet getBitSet(Pair attributes)
   {
      Metaclass metaclass = m_virtualMapping.getMetaclass();
      int nCount = metaclass.getInstanceAttributeCount();
      BitSet attrSet = new BitSet(nCount);

      while (attributes != null)
      {
         Symbol sym = (Symbol)attributes.getHead();
         Attribute attr = metaclass.getAttribute(sym);

         if (attr.isStatic())
         {
            throw new MetadataException("err.meta.persistence.virtual.updateStaticAttribute",
               new Object[]{attr.getName(), metaclass.getName()});
         }

         attrSet.set(attr.getOrdinal());
         attributes = attributes.getNext();
      }
View Full Code Here


    * @param bitmap The attribute bitmap.
    * @return An attribute list.
    */
   public Pair getAttributes(BitSet bitmap)
   {
      Metaclass metaclass = m_virtualMapping.getMetaclass();
      Pair attrList = null;

      for (int i = bitmap.nextSetBit(0); i >= 0; i = bitmap.nextSetBit(i + 1))
      {
         attrList = new Pair(metaclass.getInstanceAttribute(i).getSymbol(), attrList);
      }

      return attrList;
   }
View Full Code Here

    * Converts instance state into transfer objects.
    * @see RPCUtil#transfer(Object, Pair, Lookup, Lookup, int)
    */
   protected static TransferObject transfer(Instance instance, Pair attributes, Lookup diffMap, Lookup identityMap, int nTF)
   {
      Metaclass metaclass = (attributes != null || (nTF & TF_LAZY) == 0) ? instance.getMetaclass() : instance.getLazyMetaclass();
      Attribute lockingAttribute = (metaclass.getPersistenceMapping() == null) ? null : metaclass.getPersistenceMapping().getLockingAttribute();
      TransferObject tobj = (TransferObject)identityMap.get(instance);
      TransferObject orig = (diffMap == null) ? null : (TransferObject)diffMap.get(instance);
      boolean bMerge;

      if (tobj == null)
      {
         if ((nTF & (TF_READABLE | TF_ALL)) == TF_READABLE && !instance.isReadable())
         {
            return ((nTF & (TF_HIDDEN | TF_REF)) == (TF_HIDDEN | TF_REF)) ? new TransferObject(metaclass.getName(), 0) : null;
         }

         tobj = new TransferObject(metaclass.getName());
         tobj.setOID(instance.getOID());

         if ((nTF & TF_CACHE) == 0)
         {
            switch (instance.getState())
            {
               case Instance.NEW:
                  tobj.setEventName("create");

                  if ((nTF & TF_IDENTITY) == 0 || instance.getOID() == null)
                  {
                     nTF |= TF_STATE;
                  }

                  break;

               case Instance.DIRTY:
                  tobj.setEventName("update");
                  break;

               case Instance.DELETED:
                  tobj.setEventName("delete");
                  break;
            }
         }

         if (instance.isLazy())
         {
            tobj.setVersion((short)-1);
         }

         identityMap.put(instance, tobj);
         bMerge = false;
      }
      else
      {
         bMerge = true;
      }

      nTF |= TF_READABLE | TF_REF;

      boolean bOld = (nTF & TF_OLD) != 0 || ((nTF & TF_DELETED) != 0 && instance.getState() == Instance.DELETED);

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

         if (head instanceof Pair)
         {
            Pair field = (Pair)head;
            Symbol sym = (Symbol)field.getHead();

            if (sym == Symbol.ATAT)
            {
               field = field.getNext();

               if (metaclass.getMetadata().getMetaclass(
                  ((Symbol)field.getHead()).getName()).isUpcast(metaclass))
               {
                  transfer(instance, field.getNext(), diffMap, identityMap, nTF);
               }

               continue;
            }

            if (sym == Symbol.COLON)
            {
               sName = ((Symbol)field.getNext().getHead()).getName();
               tobj.setValue(sName, transfer(instance.findAnnotation(sName), null, diffMap, identityMap, nTF));

               continue;
            }

            sName = sym.getName();
            pair = field.getNext();
         }
         else
         {
            sName = ((Symbol)head).getName();

            if (bMerge && tobj.hasValue(sName))
            {
               continue;
            }

            pair = null;
         }

         Attribute attribute = metaclass.getAttribute(sName);
         Object value = (attribute.isStatic()) ? metaclass.getValue(attribute.getOrdinal()) :
            (bOld) ? instance.getOldValue(attribute.getOrdinal()) : instance.getValue(attribute.getOrdinal());

         if (value instanceof Instance)
         {
            tobj.setValue(sName, transfer((Instance)value, pair, diffMap, identityMap, nTF));
         }
         else if (value instanceof InstanceList)
         {
            tobj.setValue(sName, transfer((InstanceList)value, pair, diffMap, identityMap, nTF));
         }
         else if (orig == null || attribute == lockingAttribute ||
            !ObjUtil.equal(value, orig.findValue(sName, Undefined.VALUE)))
         {
            tobj.setValue(sName, value);
         }
      }

      // For non-persisted objects, add all the attributes with read/write access
      if (!bMerge && (nTF & TF_STATE) != 0 &&
         (tobj.getOID() == null || instance.getState() == Instance.NEW))
      {
         if (lockingAttribute != null)
         {
            instance.getValue(lockingAttribute.getOrdinal());
         }

         for (int i = 0, n = metaclass.getInstanceAttributeCount(); i < n; ++i)
         {
            Attribute attribute = metaclass.getInstanceAttribute(i);
            Object value = instance.getValueDirect(attribute.getOrdinal());

            if (!(value instanceof Undefined) && !tobj.hasValue(attribute.getName()) &&
               instance.isReadable(attribute) && instance.isUpdateable(attribute) &&
               (!attribute.isCalculated() || instance.isOverridden(attribute.getOrdinal())))
View Full Code Here

         if (result != null)
         {
            return result;
         }

         Metaclass metaclass = instance.getMetaclass();

         if ((nTF & (TF_READABLE | TF_ALL)) == TF_READABLE && !instance.isReadable())
         {
            return ((nTF & (TF_HIDDEN | TF_REF)) == (TF_HIDDEN | TF_REF)) ? new TransferObject(metaclass.getName(), 0) : null;
         }

         TransferObject tobj = new TransferObject(metaclass.getName());

         tobj.setOID(instance.getOID());
         identityMap.put(obj, tobj);

         if (instance.getOID() != null && metaclass.getPersistenceMapping() != null)
         {
            if (valueSet == null || !valueSet.contains(instance))
            {
               return tobj;
            }

            tobj.setEventName("create");
         }

         nTF |= TF_READABLE | TF_REF;

         for (int i = 0, nCount = metaclass.getInstanceAttributeCount(); i < nCount; ++i)
         {
            Attribute attribute = metaclass.getInstanceAttribute(i);
            Type type = attribute.getType();
            Object value;

            if (type.isPrimitive())
            {
View Full Code Here

         if (result != null)
         {
            return result;
         }

         Metaclass metaclass = instance.getMetaclass();

         if ((nTF & (TF_READABLE | TF_ALL)) == TF_READABLE && !instance.isReadable())
         {
            return ((nTF & (TF_HIDDEN | TF_REF)) == (TF_HIDDEN | TF_REF)) ? new TransferObject(metaclass.getName(), 0) : null;
         }

         TransferObject tobj = new TransferObject(metaclass.getName());
         tobj.setOID(instance.getOID());

         switch (instance.getState())
         {
            case Instance.NEW:
               tobj.setEventName("create");
               nTF |= TF_STATE;
               break;

            case Instance.DIRTY:
               tobj.setEventName("update");
               break;

            case Instance.DELETED:
               tobj.setEventName("delete");
               break;
         }

         identityMap.put(obj, tobj);

         nTF |= TF_READABLE | TF_REF;

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

            if (attribute.isPersistent() && instance.isDirty(attribute.getOrdinal()))
            {
               Type type = attribute.getType();
               Object value;

               if (type.isPrimitive())
               {
                  value = instance.getValue(attribute.getOrdinal());

                  if ((nTF & TF_SERIALIZABLE) != 0 &&
                     type == Primitive.ANY &&
                     !TextMarshaller.isSerializable(value))
                  {
                     continue;
                  }
               }
               else
               {
                  value = transferUpdates(instance.getValue(attribute.getOrdinal()), identityMap, nTF);
               }

               tobj.setValue(attribute.getName(), value);
            }
         }

         // Set the read access attribute value
         Attribute attribute = metaclass.getReadAccessAttribute();

         if (attribute != null)
         {
            tobj.setValue(attribute.getName(), Boolean.valueOf(instance.isReadable()));
         }
View Full Code Here

      /*
       * Inherit the persistence mappings
       */
      if (baseMapping != null && baseMapping.getDataSource() == m_dataSource)
      {
         Metaclass baseClass = baseMapping.getMetaclass();

         // Inherit attribute mappings
         for (int i = 0, nCount = baseClass.getInstanceAttributeCount(); i < nCount; i++)
         {
            Attribute baseAttribute = baseClass.getInstanceAttribute(i);
            AttributeMapping baseAttrMapping = baseMapping.getAttributeMapping(baseAttribute);

            if (baseAttrMapping != null)
            {
               Attribute derivedAttribute = m_metaclass.getDerivedAttribute(baseAttribute);
View Full Code Here

                                 m_loader.addPersistenceMappingFixup(new ContextFixup(getHelper())
                                 {
                                    public void fixup()
                                    {
                                       Metaclass type = (Metaclass)attribute.getType();
                                       PersistenceMapping mapping = type.getPersistenceMapping();

                                       if (mapping == null)
                                       {
                                          throw new MetadataException("err.meta.missingAssocPersistenceMapping",
                                             new Object[]{attribute.getName(), metaclass.getName(), type.getName()});
                                       }

                                       classMapping.setDestinationKey(mapping.addForeignKey(sDestinationKeyName, classMapping));
                                    }
                                 });
View Full Code Here

    */
   public void addAttribute(Attribute attribute)
   {
      verifyNotReadOnly();
     
      Metaclass metaclass = attribute.getRootDeclarator();

      if (m_lastMetaclass != null)
      {
         if (!metaclass.isUpcast(m_lastMetaclass) && !m_lastMetaclass.isUpcast(metaclass))
         {
            m_bMultiplexed = true;
         }
      }
      else
View Full Code Here

    * @param mapping The virtual persistence mapping.
    * @throws IOException If an I/O error occurs.
    */
   protected void exportObjectKey(VirtualMapping mapping) throws IOException
   {
      Metaclass metaclass = mapping.getMetaclass();
      Key key = mapping.getObjectKey();
      int nCount = (key == null) ? 0 : key.getPartCount();

      if (nCount > 0)
      {
         m_writer.startElement("KeyParts");

         for (int i = 0; i < nCount; i++)
         {
            Primitive type = key.getPartType(i);

            m_writer.openElement("KeyPart");
            m_writer.writeAttribute("type", type.getName());

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

               if (attributeMapping instanceof VirtualPrimitiveMapping)
               {
                  VirtualPrimitiveMapping primitiveMapping = (VirtualPrimitiveMapping)attributeMapping;
View Full Code Here

    * @param mapping The virtual persistence mapping.
    * @throws IOException If an I/O error occurs.
    */
   protected void exportAttributeMappings(VirtualMapping mapping) throws IOException
   {
      Metaclass metaclass = mapping.getMetaclass();
      int nCount = metaclass.getInstanceAttributeCount();
      boolean bWroteMapping = false;

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

         if (attrMapping != null)
         {
            if (!bWroteMapping)
View Full Code Here

TOP

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

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.