Package nexj.core.meta

Examples of nexj.core.meta.Attribute$IndirectInverseDependency


         if (nOutput == OUTPUT_EAGER)
         {
            if (!isAggregate() || m_bGroupedBy)
            {
               Attribute attribute = m_persistenceMapping.getLockingAttribute();

               if (attribute != null)
               {
                  m_lockingField = (Field)addAttribute(ASSOC_QUERY, attribute, null, false, OUTPUT_EAGER);
               }
View Full Code Here


            new Object[]{attribute.getName()});
      }

      if (nOutput > OUTPUT_NONE)
      {
         Attribute accessAttribute = m_metaclass.getReadAccessAttribute();

         if (accessAttribute != null &&
            attribute.getOrdinal() == accessAttribute.getOrdinal() &&
            attribute.isStatic() == accessAttribute.isStatic() &&
            m_nSecurity != SEC_NONE)
         {
            return null;
         }
      }

      Attribute root = attribute.getPersistenceRoot();
      AttributeMapping mapping = root.findPersistenceMapping(m_persistenceMapping, bInverse);

      if (mapping == null)
      {
         Object value = attribute.getDispatchedValue();

         if (value != Undefined.VALUE)
         {
            Field field = (Field)m_fieldMap.get(attribute);

            if (field == null)
            {
               // TODO: Optimize by pre-computing operator calculability
               Operator op = createOperator(key, value, OUTPUT_UNKNOWN);

               if (op != null)
               {
                  op = op.normalize(0);

                  if (op.isConstant())
                  {
                     return null;
                  }

                  Source source = op.getSource();

                  if (op instanceof AttributeOperator)
                  {
                     if (nOutput > OUTPUT_NONE)
                     {
                        source.output();
                     }

                     return source;
                  }

                  if (Operator.findCommonSource(source, this) != null)
                  {
                     field = addOperator(op);

                     if (field.getAttribute() == null)
                     {
                        field.setAttribute(attribute);
                     }
                     else
                     {
                        if (nOutput > OUTPUT_NONE)
                        {
                           addOutputField(new Field(field, attribute));
                        }
                     }

                     m_fieldMap.put(attribute, field);
                  }
               }
            }

            if (field != null)
            {
               if (nOutput > OUTPUT_NONE)
               {
                  addOutputField(field);
               }

               return field;
            }
         }

         if (nOutput == OUTPUT_NONE)
         {
            throw new InvalidQueryException("err.persistence.nonPersistentAttribute",
               new Object[]{attribute.getName()});
         }

         if (nOutput > OUTPUT_NONE)
         {
            addDependency(key, attribute.getMetaclass(), attribute.getMetaclass(),
               attribute.getCumulativeDependency(), OUTPUT_LAZY);
         }

         return null;
      }

      if (attribute.getType().isPrimitive())
      {
         Field field = (Field)m_fieldMap.get(root);

         if (field == null)
         {
            field = new Field(this, root);
            field.setAttributeMapping(mapping);
            m_fieldMap.put(root, field);
         }

         if (nOutput > OUTPUT_NONE)
         {
            addOutputField(field);
         }

         return field;
      }

      Query assoc;

      // Try to use the parent query with a reverse association

      if (m_attribute != null &&
         ((bInverse) ? m_bInverse && attribute.getOrdinal() == m_attribute.getOrdinal() :
         attribute.isReverseOf(m_attribute) && !attribute.isCollection()) &&
         (nOutput > OUTPUT_NONE || m_attribute.isRequired()))
      {
         assoc = m_parent;
         assoc.addRestriction(key, nOutput, 0, m_nRestriction);
      }
      else
      {
         Attribute req = (bInverse) ? attribute.getReverse() : attribute;
         boolean bRequired = (req != null && req.isRequired() &&
            req.getMetaclass().isUpcast(m_metaclass));

         assoc = findAssoc(key, root, filter, bInverse);

         if (assoc == null)
         {
View Full Code Here

               if (head == null || head.getHead() == null)
               {
                  throw new InvalidQueryException("err.persistence.queryDep");
               }

               Attribute attribute;
               Object operator = head.getHead();

               if (operator instanceof Symbol)
               {
                  if (operator == Symbol.ATAT)
                  {
                     Pair next = head.getNext();

                     if (next == null || !(next.getHead() instanceof Symbol))
                     {
                        throw new InvalidQueryException("err.persistence.queryPoly");
                     }

                     Metaclass subclass = metaclass.getMetadata().getMetaclass(next.getHead().toString());

                     if (!metaclass.isUpcast(subclass))
                     {
                        if (!subclass.isUpcast(metaclass))
                        {
                           if (base != metaclass && base.isUpcast(subclass))
                           {
                              continue;
                           }

                           throw new InvalidQueryException("err.persistence.querySubclass",
                              new Object[]{subclass.getName(), metaclass.getName()});
                        }

                        subclass = metaclass;
                     }

                     addDependency(key, subclass, subclass, next.getNext(), nOutput);

                     continue;
                  }

                  if (operator == Symbol.COLON)
                  {
                     Pair next = head.getNext();

                     if (next == null || !(next.getHead() instanceof Symbol))
                     {
                        throw new InvalidQueryException("err.persistence.queryAnnotation");
                     }

                     String sName = next.getHead().toString();

                     next = next.getNext();

                     if (next == null || next.getTail() != null)
                     {
                        throw new InvalidQueryException("err.persistence.queryAnnotation");
                     }

                     addAnnotation(sName, next.getHead());

                     continue;
                  }

                  attribute = metaclass.getAttribute(operator.toString());
               }
               else
               {
                  attribute = metaclass.getDerivedAttribute((Attribute)operator);
               }

               Source source = addAttribute(key, attribute, null, false, nOutput);

               if (source instanceof Query)
               {
                  Query query = (Query)source;
                  Metaclass type = (Metaclass)attribute.getType();

                  query.addDependency(key,
                     (query.getMetaclass().isUpcast(type)) ? type : query.getMetaclass(),
                     type, head.getNext(), nOutput);
               }
               else if (head.getTail() != null && attribute.getType().isPrimitive() &&
                  attribute.getType() != Primitive.ANY)
               {
                  throw new InvalidQueryException("err.persistence.queryDep");
               }
            }
            else
            {
               Attribute attribute;

               if (pair.getHead() instanceof Symbol)
               {
                  attribute = metaclass.getAttribute(pair.getHead().toString());
               }
View Full Code Here

            if (nOutput != OUTPUT_NONE)
            {
               return null;
            }

            Attribute attribute = m_metaclass.getAttribute(obj.toString());

            if (attribute.getValue() != Undefined.VALUE && !attribute.isPersistent())
            {
               return createOperator(key, attribute.getDispatchedValue(), nOutput);
            }

            return new AttributeOperator(addAttribute(key, attribute, null, false, nOutput));
         }
View Full Code Here

         addRestriction(query.getRestriction() & ~RESTRICTION_PARENT);

         for (Iterator itr = query.getFieldIterator(); itr.hasNext();)
         {
            Field srcField = (Field)itr.next();
            Attribute attribute = srcField.getAttribute();
            Field dstField = (Field)m_fieldMap.get(attribute);

            if (dstField == null)
            {
               srcField.setQuery(this);
View Full Code Here

    */
   public void addAssoc(Object key, Query assoc)
   {
      assert assoc != null;

      Attribute attribute = assoc.getAttribute();

      assert (assoc.isInverse()) ?
         m_metaclass.isUpcast(attribute.getType()) || attribute.getType().isUpcast(m_metaclass) :
         m_metaclass.isUpcast(attribute.getMetaclass()) || attribute.getMetaclass().isUpcast(m_metaclass);

      setAssocs(key, add(findAssocs(key), assoc));
      assoc.setParent(this);

      if (key instanceof Quantor)
      {
         assoc.setQuantorRoot(assoc);
      }

      AttributeMapping mapping = assoc.getAttributeMapping();

      if (mapping == null)
      {
         mapping = attribute.findPersistenceMapping(m_persistenceMapping, assoc.isInverse());
         assoc.setAttributeMapping(mapping);
      }

      if (mapping != null)
      {
View Full Code Here

            error(methodDoc, "Attribute tag without a name");

            continue;
         }

         Attribute attr = new Attribute(matcher.group());

         if (!matcher.find())
         {
            warning(methodDoc, "Attribute " + attr.getName() + " does not include type");
         }
         else
         {
            attr.setType(new TransientType(matcher.group()));

            int nStart = matcher.end();

            // Optional modifiers
            while (matcher.find())
            {
               String sKeyword = matcher.group().trim();

               if ("readonly".equalsIgnoreCase(sKeyword))
               {
                  attr.setReadOnly(true);
               }
               else if ("static".equalsIgnoreCase(sKeyword))
               {
                  attr.setStatic(true);
               }
               else if ("collection".equalsIgnoreCase(sKeyword))
               {
                  attr.setCollection(true);
               }
               else
               {
                  break;
               }

               nStart = matcher.end();
            }

            // The description is the rest
            attr.setDescription(sBody.substring(nStart).trim());
         }

         clazz.addAttribute(attr);
         attr.setDeclarator(clazz);
      }
   }
View Full Code Here

      {
         m_list = Collections.emptyList();
      }
      else
      {
         Attribute attribute = m_query.getAttribute();

         if (container.getMetaclass().isUpcast(attribute.getMetaclass()))
         {
            Object value = container.getValue(attribute.getOrdinal());

            if (value == null)
            {
               m_list = Collections.emptyList();
            }
            else if (attribute.isCollection())
            {
               m_list = (List)value;
            }
            else
            {
View Full Code Here

      boolean bSkipInstance = (m_instanceList.getCount() < m_nOffset);

      for (int nQuery = 0, nQueryCount = m_query.getOutputQueryCount(); nQuery < nQueryCount; ++nQuery)
      {
         Query query = m_query.getOutputQuery(nQuery);
         Attribute assoc = query.getAttribute();
         boolean bIdentity = query.isIdentity();
         Instance container;
         Attribute reverse;
         OID oid;

         // First output query must be main query node.
         assert (nQuery == 0) == (query == m_query);

         // Query ordinal is the output query ordinal (unless query is joined heterogeneously).
         assert nQuery == query.getOrdinal() || query.getRoot() != m_query;

         // Query ordinal is, by definition, the output query ordinal of its root.
         assert query.getRoot().getOutputQuery(query.getOrdinal()) == query;

         // Get the query class instance OID

         if (query == m_query)
         {
            container = null;
            reverse = null;
            oid = (bIdentity) ? getKey(query.getItem()) : null;
         }
         else
         {
            assert bIdentity;

            container = m_instanceArray[query.getParent().getOrdinal()];

            if (container == null || !assoc.getMetaclass().isUpcast(container.getMetaclass()))
            {
               if (query.getRoot() == m_query)
               {
                  m_instanceArray[query.getOrdinal()] = null;
               }

               continue;
            }

            assoc = container.getMetaclass().getDerivedAttribute(assoc);
            reverse = assoc.getReverse();

            if (reverse != null && reverse.isCollection())
            {
               reverse = null;
            }

            oid = getKey(query.getParentItem());
         }

         InstanceList instanceList;
         boolean bAdd = true;

         if (container == null)
         {
            instanceList = m_instanceList;
         }
         else
         {
            Object value = container.getOldValueDirect(assoc.getOrdinal());

            if (value == Undefined.VALUE)
            {
               if (assoc.isCollection())
               {
                  instanceList = new InstanceArrayList();
                  instanceList.setAssociation(container, assoc, true);
                  instanceList.setLazy(false);
                  container.setOldValueDirect(assoc.getOrdinal(), instanceList);
               }
               else
               {
                  instanceList = null;

                  if (oid == null)
                  {
                     container.setOldValueDirect(assoc.getOrdinal(), null);
                  }
               }
            }
            else
            {
               if (assoc.isCollection() && !(value instanceof Undefined))
               {
                  instanceList = (InstanceList)value;
                  instanceList.setLazy(false);
               }
               else
               {
                  instanceList = null;
                  bAdd = false;
               }
            }
         }

         Metaclass metaclass;

         if (bIdentity)
         {
            if (oid == null)
            {
               if (query.getRoot() == m_query)
               {
                  m_instanceArray[query.getOrdinal()] = null;
               }

               continue;
            }

            if (query.getRoot() != m_query && !query.isLazy())
            {
               if (!bSkipInstance)
               {
                  query.addParentInstance(container, oid);
               }

               continue;
            }

            Field field = query.getTypeCodeField();

            if (field != null)
            {
               metaclass = query.getPersistenceMapping().findMetaclassByTypeCode(getValue(field));

               if (metaclass == null)
               {
                  m_instanceArray[query.getOrdinal()] = null;

                  continue;
               }
            }
            else
            {
               metaclass = getMetaclass(query);
            }
         }
         else
         {
            metaclass = getMetaclass(query);
         }

         InstanceRef ref = m_query.getInvocationContext().findInstanceRef(metaclass, oid);
         Instance instance = (ref == null) ? null : ref.getInstance();

         // Check if the instance has already been retrieved
         if (instance != null)
         {
            // Already retrieved instance
            if (instance.isLazy())
            {
               if (query.isLazy())
               {
                  if (!metaclass.isUpcast(instance.getLazyMetaclass()))
                  {
                     instance.setLazyMetaclass(metaclass);
                  }
               }
               else
               {
                  instance.setMetaclass(metaclass);
               }
            }

            if (instanceList != null)
            {
               bAdd = !instanceList.contains(instance);

               if (bAdd &&
                  container == null &&
                  m_nMaxCount >= 0 &&
                  instanceList.getCount() == m_nOffset + m_nMaxCount)
               {
                  m_bEOF = bDiscardExtra;
                  m_bEOP = !bDiscardExtra;

                  return false;
               }
            }

            if (bAdd)
            {
               switch (instance.getState())
               {
                  case Instance.DELETED:
                     bAdd = false;
                     break;

                  case Instance.DIRTY:
                     if (reverse != null)
                     {
                        Object reverseValue = instance.getValueDirect(reverse.getOrdinal());

                        if (reverseValue != Undefined.VALUE && reverseValue != container)
                        {
                           bAdd = false;
                        }
                     }

                     break;
               }

               if (!bAdd && instanceList == null)
               {
                  if (container.getValueDirect(assoc.getOrdinal()) == Undefined.VALUE)
                  {
                     // Set the new value to null, old value to the retrieved instance
                     container.setValueDirect(assoc.getOrdinal(), null);
                  }

                  bAdd = true;
               }
            }

            if (m_instanceSet.get(query, instance) == null)
            {
               // Merge the not yet retrieved attribute values

               if (!bSkipInstance)
               {
                  // Overwrite only if the instance is clean
                  boolean bOverwrite = (instance.getUnitOfWork() == null);
                  Field lockingField = query.getLockingField();

                  if (lockingField != null)
                  {
                     Attribute lockingAttribute = lockingField.getAttribute();
                     Object oldValue = instance.getNewValueDirect(lockingAttribute.getOrdinal());

                     if (oldValue != Undefined.VALUE)
                     {
                        // Check the old lock value
                        Primitive primitive = (Primitive)lockingAttribute.getType();
                        Object value = getValue(lockingField);

                        if (((Boolean)primitive.findNEFunction(primitive).invoke(oldValue, value)).booleanValue())
                        {
                           // The lock values do not match
                           // If the instance is dirty/deleted or share-locked, throw an exception
                           if (!bOverwrite || ref.isLocked())
                           {
                              throw new OptimisticLockException(instance);
                           }

                           // Discard all the instance attributes
                           for (int i = 0, n = metaclass.getInstanceAttributeCount(); i != n; ++i)
                           {
                              discard(instance, metaclass.getInstanceAttribute(i));
                           }

                           instance.setOldValueDirect(lockingAttribute.getOrdinal(), value);
                        }
                        else
                        {
                           if (bOverwrite)
                           {
View Full Code Here

    */
   protected void addInstance(Instance instance, InstanceRef ref, Metaclass metaclass, Query query, boolean bOverwrite)
   {
      for (Field field = query.getFirstOutputField(); field != null; field = field.getNext())
      {
         Attribute attribute = field.getAttribute();

         // Consider only this class and inherited attributes
         if (attribute != null)
         {
            if (attribute.getMetaclass().isUpcast(metaclass))
            {
               int nOrdinal = attribute.getOrdinal();

               if (bOverwrite || instance.getOldValueDirect(nOrdinal) == Undefined.VALUE)
               {
                  instance.setOldValueDirect(nOrdinal, getValue(field));
               }
            }
            else if (!query.isIdentity())
            {
               instance.setAnnotation(attribute.getName(), getValue(field));
            }
         }

         String sAnnotation = field.getAnnotation();

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.