Package nexj.core.meta

Examples of nexj.core.meta.Attribute$InverseDependency


      Lookup polymorphicAttrMap = null;

      // Add primitive output attributes
      for (Field field = query.getFirstOutputField(); field != null; field = field.getNext())
      {
         Attribute attribute = field.getAttribute();
         Metaclass metaclass = attribute.getMetaclass();

         if (metaclass.isUpcast(query.getMetaclass()))
         {
            attributes = new Pair(attribute.getSymbol(), attributes);
         }
         else
         {
            // Attribute defined in subclass, add to polymorphic attribute list
            assert query.getMetaclass().isUpcast(metaclass);

            if (polymorphicAttrMap == null)
            {
               polymorphicAttrMap = new HashTab(2);
            }

            Pair subclassAttrs = (Pair)polymorphicAttrMap.get(metaclass);

            subclassAttrs = new Pair(attribute.getSymbol(), subclassAttrs);
            polymorphicAttrMap.put(metaclass, subclassAttrs);
         }
      }

      // Add non-primitive output attributes
      for (Iterator itr = query.getAssocIterator(Query.ASSOC_QUERY); itr.hasNext(); )
      {
         Query subQuery = (Query)itr.next();
         Attribute attribute = subQuery.getAttribute();
         Pair subQueryAttrs = getAttributes(subQuery);
         Metaclass metaclass = attribute.getMetaclass();
         Object itemToAdd = (subQueryAttrs == null) ? (Object)attribute.getSymbol() : new Pair(attribute.getSymbol(), subQueryAttrs);

         if (metaclass.isUpcast(query.getMetaclass()))
         {
            attributes = new Pair(itemToAdd, attributes);
         }
View Full Code Here


      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();
      }

      return attrSet;
   }
View Full Code Here

    * @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())))
            {
               if (value instanceof Instance)
               {
                  tobj.setValue(attribute.getName(), transfer((Instance)value, null, diffMap, identityMap, nTF));
               }
               else if (value instanceof InstanceList)
               {
                  tobj.setValue(attribute.getName(), transfer((InstanceList)value, null, diffMap, identityMap, nTF));
               }
               else if ((orig == null ||
                  attribute == lockingAttribute ||
                  !ObjUtil.equal(value, orig.findValue(attribute.getName(), Undefined.VALUE))) &&
                  ((nTF & TF_SERIALIZABLE) == 0 ||
                   attribute.getType() != Primitive.ANY ||
                   TextMarshaller.isSerializable(value)))
               {
                  tobj.setValue(attribute.getName(), value);
               }
            }
         }
      }

View Full Code Here

         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())
            {
               value = instance.getValue(attribute.getOrdinal());

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

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

         if ((nTF & TF_CACHE) != 0)
         {
            instance.setCached(true);
View Full Code Here

         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()));
         }

         return tobj;
      }
View Full Code Here

                  map.setValue(itr.getName(), value);
               }
               else
               {
                  Attribute attr = instance.getMetaclass().findAttribute(itr.getName());

                  if (attr != null && !attr.isStatic() && attr.getVisibility() == Metaclass.PUBLIC)
                  {
                     Object value = instance.getValueDirect(attr.getOrdinal());

                     if (!(value instanceof Undefined))
                     {
                        if (!TextMarshaller.isSerializable(value))
                        {
                           value = String.valueOf(value);
                        }

                        if (nMode == AUDIT_VALUES)
                        {
                           if (value != null)
                           {
                              map.setValue(attr.getName(), value);
                           }
                        }
                        else
                        {
                           Object oldValue = instance.getOldValueDirect(attr.getOrdinal());

                           if (!ObjUtil.equal(value, oldValue))
                           {
                              map.setValue(attr.getName(), value);

                              if (!(oldValue instanceof Undefined))
                              {
                                 map.setValue('-' + attr.getName(), oldValue);
                              }
                           }
                        }
                     }
                  }
View Full Code Here

         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);
               AttributeMapping derivedAttrMapping = getAttributeMapping(derivedAttribute);

               if (derivedAttrMapping == null)
               {
                  if (derivedAttribute.getType() == baseAttribute.getType())
                  {
                     derivedAttrMapping = (AttributeMapping)baseAttrMapping.clone(derivedAttribute);
                     derivedAttrMapping.setAttribute(derivedAttribute);
                     addAttributeMapping(derivedAttrMapping);
                  }
View Full Code Here

      {
         throw new MetadataException("err.meta.persistence.virtual.invalidAttributeKey",
            new Object[]{sName, m_metaclass.getName()});
      }

      Attribute attr = m_metaclass.getAttribute(tok.nextToken());

      if (!tok.hasMoreTokens())
      {
         return new VirtualKey(attr);
      }

      ArrayList attrList = new ArrayList(4);

      do
      {
         if (!attr.getType().isPrimitive())
         {
            throw new MetadataException("err.meta.persistence.virtual.invalidAttributeKey",
               new Object[]{attr.getName(), m_metaclass.getName()});
         }

         attrList.add(attr);
         attr = (tok.hasMoreTokens()) ? m_metaclass.getAttribute(tok.nextToken()) : null;
      }
View Full Code Here

                  if (!key.isUnique())
                  {
                     for (int k = 0, nCount = key.getAttributeCount(); k < nCount; k++)
                     {
                        Attribute attr = key.getAttribute(k);

                        assert attr.getMetaclass() == m_metaclass;
                        assert !attr.getType().isPrimitive();

                        filterSet.set(attr.getOrdinal());
                     }
                  }
               }
            }
         }

         nFilterCount = filterSet.cardinality();
      }

      // Create a set of attributes that participate in equality
      // comparisons and can be optionally excluded from the index.
      if (restrictions != null && restrictions.length > 0)
      {
         optionalSet = new BitSet(m_metaclass.getInstanceAttributeCount());

         for (int i = 0; i < restrictions.length; i++)
         {
            optionalSet.set(restrictions[i].getOrdinal());
         }
      }

      // Collect the sort keys
      for (int nSortKey = 0; nSortKey < m_sortKeyList.size(); nSortKey++)
      {
         VirtualSortKey sortKey = (VirtualSortKey)m_sortKeyList.get(nSortKey);

         // Ignore sort keys that do not start with the columns specified in the
         // association filter, in arbitrary order
         if (nFilterCount > 0)
         {
            if (sortKey.getAttributeCount() < nFilterCount)
            {
               continue;
            }

            int i;

            for (i = 0; i < nFilterCount; i++)
            {
               Attribute attr = sortKey.getAttribute(i);

               if (attr == null || !filterSet.get(attr.getOrdinal()))
               {
                  break;
               }
            }

            if (i < nFilterCount)
            {
               continue;
            }
         }

         // Find out if the sort key includes the primary key
         Key pk = getObjectKey();
         boolean bMatch = false;
         boolean bAscending = true;

         for (int i = 0, k = -1; i < sortKey.getAttributeCount(); i++)
         {
            Attribute attr = sortKey.getAttribute(i);

            if (attr == null)
            {
               bMatch = true;
               bAscending = sortKey.isAscending(i);

               break;
            }

            if (optionalSet != null && optionalSet.get(attr.getOrdinal()))
            {
               continue;
            }

            if (getAttributeMapping(attr) instanceof VirtualPrimitiveMapping)
            {
               VirtualPrimitiveMapping mapping = (VirtualPrimitiveMapping)getAttributeMapping(attr);

               if (mapping.getObjectKeyPart() >= 0)
               {
                  if (k == -1)
                  {
                     if (mapping.getObjectKeyPart() == 0)
                     {
                        k = 1;
                        bAscending = sortKey.isAscending(i);

                        continue;
                     }

                     break;
                  }

                  if (mapping.getObjectKeyPart() == k)
                  {
                     if ((pk.isPartAscending(0) ^ pk.isPartAscending(k)) != (bAscending ^ sortKey.isAscending(i)))
                     {
                        break;
                     }
                     else
                     {
                        if (k == pk.getPartCount() - 1)
                        {
                           bMatch = true;

                           break;
                        }
                     }
                  }
                  else
                  {
                     break;
                  }
               }
            }
         }

         Pair key = null;

         // If the above is true, then append the primary key
         // at the end of the sort key
         if (bMatch)
         {
            Pair[] objKeyAttributeArray = new Pair[pk.getPartCount()];

            for (int i = 0; i < m_metaclass.getInstanceAttributeCount(); i++)
            {
               Attribute attr = m_metaclass.getInstanceAttribute(i);

               if (getAttributeMapping(attr) instanceof VirtualPrimitiveMapping)
               {
                  VirtualPrimitiveMapping mapping = (VirtualPrimitiveMapping)getAttributeMapping(attr);

                  if (mapping.getObjectKeyPart() >= 0)
                  {
                     objKeyAttributeArray[mapping.getObjectKeyPart()] = new Pair(
                        attr.getSymbol(),
                        Boolean.valueOf(bAscending ^ !pk.isPartAscending(mapping.getObjectKeyPart()))
                     );
                  }
               }
            }

            boolean bObjKeyFullyMapped = true;

            for (int i = 0; i < objKeyAttributeArray.length; i++)
            {
               if (objKeyAttributeArray[i] == null)
               {
                  bObjKeyFullyMapped = false;

                  break;
               }
            }

            if (bObjKeyFullyMapped)
            {
               key = Pair.fromArray(objKeyAttributeArray);
            }
            else
            {
               key = new Pair(new Pair(new Pair(Symbol.AT),
                  Boolean.valueOf(bAscending)));
            }
         }
         else
         {
            pk = null;
         }

         int nCount;

         // Advance, stopping at first non-ignorable non-primitive-mapped attribute
         for (nCount = nFilterCount; nCount < sortKey.getAttributeCount(); nCount++)
         {
            Attribute attr = sortKey.getAttribute(nCount);

            if (attr == null || !attr.getType().isPrimitive())
            {
               if (optionalSet == null || attr == null || !optionalSet.get(attr.getOrdinal()))
               {
                  break;
               }
            }
         }

         bMatch = true;

         // Verify that remainder of index is the primary key, or that there is no remaining index
         if (pk != null)
         {
            if (nCount == sortKey.getAttributeCount())
            {
               key = null;
            }
            else
            {
               for (int i = nCount; i < sortKey.getAttributeCount(); i++)
               {
                  Attribute attr = sortKey.getAttribute(i);

                  if (attr != null)
                  {
                     AttributeMapping mapping = getAttributeMapping(attr);

                     if (mapping instanceof VirtualPrimitiveMapping)
                     {
                        if (((VirtualPrimitiveMapping)mapping).getObjectKeyPart() >= 0)
                        {
                           continue;
                        }
                     }

                     bMatch = false;

                     break;
                  }
               }
            }
         }

         if (!bMatch)
         {
            continue;
         }

         // Add non-ignorable primitive-mapped columns to the sort key
         for (int i = nCount - 1; i >= nFilterCount; i--)
         {
            Attribute attr = sortKey.getAttribute(i);

            if (attr.getType().isPrimitive())
            {
               if (optionalSet == null || !optionalSet.get(attr.getOrdinal()))
               {
                  key = new Pair(
                     new Pair(attr.getSymbol(), Boolean.valueOf(sortKey.isAscending(i))),
                     key
                  );
               }
            }
         }
View Full Code Here

                     XMLUtil.forEachChildElement(attributeMappingsElement, "AttributeMapping",
                        getHelper().new ElementHandler("attribute")
                     {
                        public void handleElement(Element attributeMappingElement, String sAttributeName)
                        {
                           final Attribute attribute = metaclass.getAttribute(sAttributeName);
                           final String sTableName = XMLUtil.getStringAttr(attributeMappingElement, "table");
                           final String sColumnName = XMLUtil.getStringAttr(attributeMappingElement, "column");
                           final String sSourceKeyName = XMLUtil.getStringAttr(attributeMappingElement, "sourceKey");
                           final String sDestinationKeyName = XMLUtil.getStringAttr(attributeMappingElement, "destinationKey");
                           AttributeMapping mapping;
                          
                           m_persistenceMappingElement = null;
                           XMLUtil.withFirstChildElement(attributeMappingElement,
                              "PersistenceMapping", false, m_persistenceMappingElementHandler);

                           if (attribute.getType().isPrimitive())
                           {
                              if (sColumnName == null || sSourceKeyName != null ||
                                 sDestinationKeyName != null || m_persistenceMappingElement != null)
                              {
                                 throw new MetadataException("err.meta.primitiveRelationalMapping",
                                    new Object[]{attribute.getName(), metaclass.getName()});
                              }
                             
                              if (attribute.isCollection())
                              {
                                 throw new MetadataException("err.meta.unsupportedRelationalMapping",
                                    new Object[]{attribute.getName(), metaclass.getName()});
                              }

                              RelationalPrimitiveMapping primitiveMapping = new RelationalPrimitiveMapping();
                              Table table = (sTableName == null) ? relationalMapping.getPrimaryTable() : m_schema.getTable(sTableName);

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

                              primitiveMapping.setColumn(table.getColumn(sColumnName));
                              primitiveMapping.setAttribute(attribute);
                              mapping = primitiveMapping;
                           }
                           else
                           {
                              if (sTableName != null || sColumnName != null ||
                                 m_persistenceMappingElement != null &&
                                 (sSourceKeyName != null || sDestinationKeyName != null))
                              {
                                 throw new MetadataException("err.meta.classRelationalMapping",
                                    new Object[]{attribute.getName(), metaclass.getName()});
                              }
                             
                              final RelationalClassMapping classMapping = new RelationalClassMapping();
                             
                              classMapping.setAttribute(attribute);

                              if (m_persistenceMappingElement != null)
                              {
                                 if (attribute.isCollection())
                                 {
                                    throw new MetadataException("err.meta.unsupportedRelationalMapping",
                                       new Object[]{attribute.getName(), metaclass.getName()});
                                 }

                                 classMapping.setSourceKey(relationalMapping.getPrimaryTable().getPrimaryKey());
                                 classMapping.setMapping(m_loader.loadPersistenceMapping(m_persistenceMappingElement, (Metaclass)attribute.getType()));
                              }
                              else
                              {
                                 if (sSourceKeyName != null)
                                 {
                                    classMapping.setSourceKey(m_schema.getIndex(sSourceKeyName));
                                 }
                                 else
                                 {
                                    Table primaryTable = relationalMapping.getPrimaryTable();

                                    if (primaryTable != null)
                                    {
                                       classMapping.setSourceKey(primaryTable.getPrimaryKey());
                                    }
                                 }

                                 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

TOP

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

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.