Package nexj.core.meta

Examples of nexj.core.meta.Attribute$IndirectInverseDependency


      if (isLazy())
      {
         return false;
      }

      Attribute attribute = m_metaclass.getAttribute(sName);

      if (attribute.isStatic())
      {
         return false;
      }

      return isUpdated(attribute.getOrdinal());
   }
View Full Code Here


               .getComponent().getInstance(m_context);
         ValidationException e = null;

         for (int i = 0, nCount = m_metaclass.getInstanceAttributeCount(); i != nCount; ++i)
         {
            Attribute attribute = m_metaclass.getInstanceAttribute(i);
            Object value = getValueDirect(i);

            if (value instanceof Undefined)
            {
               if ((m_nState == NEW || value == Invalid.VALUE) &&
                  (attribute.isPersistent() ||
                     (attribute.isRequired() ||
                        attribute.getValidationFunction() != null ||
                        m_nState == NEW && attribute.getInitializer() != Undefined.VALUE ||
                        attribute.isConstrained() && attribute.getEnumeration() != attribute.getType()) && bFull))
               {
                  value = getValue(i);
               }
               else
               {
                  continue;
               }
            }

            if (m_nState == DIRTY && !isDirty(i))
            {
               continue;
            }

            Type type = attribute.getType();

            if (attribute.isRequired())
            {
               boolean bMissing = (value == null);

               if (!bMissing)
               {
                  if (type.isPrimitive())
                  {
                     bMissing = (type == Primitive.STRING && value.equals(""));
                  }
                  else
                  {
                     bMissing = (attribute.isCollection() && ((InstanceList)value).isEmpty());
                  }
               }

               if (bMissing)
               {
                  e = createValidationException(e);

                  ValidationException x = new ValidationException("err.validation.requiredAttribute",
                     new Object[]{new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});

                  x.setClassName(m_metaclass.getName());
                  x.setOIDHolder(this);
                  e.addException(attribute.getName(), x);
               }
            }

            if (attribute.getMaxLength() > 0)
            {
               int nLength = 0;

               if (value instanceof String)
               {
                  nLength = ((String)value).length();
               }
               else if (value instanceof Binary)
               {
                  nLength = ((Binary)value).getData().length;
               }

               if (nLength > attribute.getMaxLength())
               {
                  e = createValidationException(e);

                  ValidationException x = new ValidationException("err.validation.maxDataLength",
                     new Object[]{Primitive.createInteger(attribute.getMaxLength()),
                        new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});

                  x.setClassName(m_metaclass.getName());
                  x.setOIDHolder(this);
                  e.addException(attribute.getName(), x);
               }
            }

            if (bFull)
            {
               if (attribute.isConstrained() &&
                  attribute.getEnumeration() != type &&
                  value != null && e == null)
               {
                  if (((InstanceList)attribute.getEnumeration().invoke("read",
                     new Object[]{null, (type.isPrimitive()) ?
                        Pair.attribute(Metaclass.ENUMERATION_VALUE).eq(value) :
                        new Pair(Symbol.AT).eq(value), null, Primitive.createInteger(-1),
                        Primitive.ZERO_INTEGER, Boolean.FALSE})).isEmpty())
                  {
                     e = createValidationException(e);

                     ValidationException x = new ValidationException("err.validation.enumerationValue",
                        new Object[]{new StringId(attribute.getEnumeration().getCaption()),
                           new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});

                     x.setClassName(m_metaclass.getName());
                     x.setOIDHolder(this);
                     e.addException(attribute.getName(), x);
                  }
               }

               if (attribute.getValidationFunction() != null && e == null)
               {
                  Object result = m_context.getMachine().invoke(attribute.getValidationFunction(), this, value, null);

                  if (result != null)
                  {
                     ValidationException x = null;

                     if (result instanceof Boolean)
                     {
                        if (!((Boolean)result).booleanValue())
                        {
                           x = new ValidationException("err.validation.valueRange",
                              new Object[]{new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});
                        }
                     }
                     else if (result instanceof String)
                     {
                        x = new ValidationException((String)result);
                     }
                     else if (result instanceof Pair)
                     {
                        x = new ValidationException((String)((Pair)result).getHead(),
                              Pair.toArray(((Pair)result).getNext()));
                     }

                     if (x != null)
                     {
                        x.setClassName(m_metaclass.getName());
                        x.setOIDHolder(this);
                        e = createValidationException(e);
                        e.addException(attribute.getName(), x);
                     }
                  }
               }
            }

            if (type.isPrimitive() && attribute.isPersistent() && adapter != null)
            {
               try
               {
                  adapter.validate(persistenceMapping.getAttributeMapping(attribute), value);
               }
               catch (ValidationException x)
               {
                  x.setClassName(m_metaclass.getName());
                  x.setOIDHolder(this);
                  e = createValidationException(e);
                  e.addException(attribute.getName(), x);
               }
            }
         }

         if (bFull && m_metaclass.getValidationFunction() != null && e == null)
View Full Code Here

      for (Pair pair = attributes; pair != null; pair = pair.getNext())
      {
         Object head = pair.getHead();
         Pair assoc;
         Attribute attribute;

         if (head instanceof Pair)
         {
            assoc = (Pair)head;

            Symbol sym = (Symbol)assoc.getHead();

            assoc = assoc.getNext();

            if (sym == Symbol.ATAT)
            {
               if (m_metaclass.getMetadata().getMetaclass(((Symbol)assoc.getHead()).getName())
                     .isUpcast(m_metaclass) && !isLoaded(assoc.getNext()))
               {
                  return false;
               }

               continue;
            }

            attribute = m_metaclass.getAttribute(sym);
         }
         else
         {
            if (head == null)
            {
               continue;
            }

            assoc = null;
            attribute = m_metaclass.getAttribute((Symbol)head);
         }

         if (!attribute.isStatic())
         {
            Object value = getValueDirect(attribute.getOrdinal());

            if (!(value instanceof Undefined))
            {
               if (!isLoaded(value, attribute, assoc))
               {
                  return false;
               }
            }
            else
            {
               if (attribute.isPersistent() && value == Undefined.VALUE)
               {
                  return false;
               }
            }
         }
View Full Code Here

   {
      for (Pair pair = attributes, prev = null; pair != null; pair = pair.getNext())
      {
         Object head = pair.getHead();
         Pair assoc;
         Attribute attribute;

         if (head instanceof Pair)
         {
            assoc = (Pair)head;

            Symbol sym = (Symbol)assoc.getHead();

            assoc = assoc.getNext();

            if (sym == Symbol.ATAT)
            {
               if (m_metaclass.getMetadata().getMetaclass(((Symbol)assoc.getHead()).getName()).isUpcast(m_metaclass))
               {
                  if (tail == null)
                  {
                     pair.setHead(null);
                     pair = preload(assoc.getNext(), pair, bPersistent);

                     if (pair.getHead() == null && tail == null)
                     {
                        if (prev == null)
                        {
                           attributes = pair.getNext();
                        }
                        else
                        {
                           prev.setTail(pair.getTail());
                        }
                     }
                  }
                  else
                  {
                     tail = preload(assoc.getNext(), tail, bPersistent);
                  }
               }
               else
               {
                  if (tail == null)
                  {
                     if (prev == null)
                     {
                        attributes = pair.getNext();
                     }
                     else
                     {
                        prev.setTail(pair.getTail());
                     }
                  }
               }

               continue;
            }

            if (!bPersistent)
            {
               continue;
            }

            attribute = m_metaclass.getAttribute(sym);
         }
         else
         {
            if (head == null)
            {
               if (tail == null)
               {
                  if (prev == null)
                  {
                     attributes = pair.getNext();
                  }
                  else
                  {
                     prev.setTail(pair.getTail());
                  }
               }

               continue;
            }

            if (!bPersistent)
            {
               continue;
            }

            assoc = null;
            attribute = m_metaclass.getAttribute((Symbol)head);
         }

         if (attribute.isStatic())
         {
            if (tail == null)
            {
               if (prev == null)
               {
                  attributes = pair.getNext();
               }
               else
               {
                  prev.setTail(pair.getTail());
               }
            }
         }
         else
         {
            Object value = getValueDirect(attribute.getOrdinal());

            if (!(value instanceof Undefined))
            {
               if (isLoaded(value, attribute, assoc))
               {
                  if (tail == null)
                  {
                     if (prev == null)
                     {
                        attributes = pair.getNext();
                     }
                     else
                     {
                        prev.setTail(pair.getTail());
                     }
                  }
               }
               else
               {
                  if (tail == null)
                  {
                     prev = pair;
                  }
                  else if (tail.getHead() == null)
                  {
                     tail.setHead(pair.getHead());
                  }
                  else
                  {
                     Pair copy = new Pair(pair.getHead(), tail.getTail());

                     tail.setTail(copy);
                     tail = copy;
                  }

                  if (attribute.isPersistent())
                  {
                     m_nFlags |= LOAD_READ;
                  }
               }
            }
            else
            {
               if (tail == null)
               {
                  prev = pair;
               }
               else if (tail.getHead() == null)
               {
                  tail.setHead(pair.getHead());
               }
               else
               {
                  Pair copy = new Pair(pair.getHead(), tail.getTail());

                  tail.setTail(copy);
                  tail = copy;
               }

               if ((m_nFlags & LOAD_READ) == 0 && attribute.isPersistent() && value == Undefined.VALUE)
               {
                  m_nFlags |= LOAD_READ;
               }
            }
         }
View Full Code Here

               new Pair(Symbol.AT).eq(m_oid), null, -1, 0, false,
               Query.SEC_NONE, m_context);

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

               if ((isLazy() || getValueDirect(attribute.getOrdinal()) == Undefined.VALUE) &&
                  !attribute.isLazy())
               {
                  query.addAttribute(Query.ASSOC_QUERY, attribute, null, false, Query.OUTPUT_EAGER);
               }
            }

            if (query.getFirstOutputField() != null &&
               (query.getFirstOutputField().getNext() != null ||
                  query.getFirstOutputField().getAttribute() !=
                  mapping.getLockingAttribute()) ||
               query.getAssocCount(Query.ASSOC_QUERY) > 0)
            {
               if (s_logger.isDebugEnabled())
               {
                  String sMsg = "Loading attributes " + attributes + " of " + this;

                  if (s_logger.isDumpEnabled())
                  {
                     StackTrace t = new StackTrace();

                     m_context.getMachine().updateStackTrace(t);
                     s_logger.dump(sMsg, t);
                  }
                  else
                  {
                     s_logger.debug(sMsg);
                  }
               }

               if (query.read().isEmpty())
               {
                  if (bSafe)
                  {
                     return attributes;
                  }

                  // The instance could not be found
                  if (isLazy())
                  {
                     // Just the OID was available - check the referrer
                     for (Iterator itr = m_context.getInstanceRefIterator(); itr.hasNext();)
                     {
                        InstanceRef ref = (InstanceRef)itr.next();

                        if (ref != null)
                        {
                           Instance instance = ref.getInstance();

                           if (instance != null && !instance.isLazy() &&
                              instance.getState() != NEW && instance.getOID() != null)
                           {
                              Metaclass metaclass = instance.getMetaclass();

                              if (metaclass.getPersistenceMapping() != null)
                              {
                                 for (int i = 0, n = metaclass.getInstanceAttributeCount(); i < n; ++i)
                                 {
                                    Attribute attribute = metaclass.getInstanceAttribute(i);

                                    if (!attribute.isCollection() && attribute.isPersistent() &&
                                       instance.getOldValueDirect(i) == this)
                                    {
                                       if (!Query.createRead(metaclass, new Pair(attribute.getSymbol()),
                                          new Pair(Symbol.AT).eq(instance), null, -1, 0, false, Query.SEC_NONE,
                                          m_context).read().isEmpty() &&
                                          instance.getOldValueDirect(i) == this)
                                       {
                                          throw new AssociationIntegrityException(instance, attribute.getName());
                                       }

                                       throw new OptimisticLockException(this);
                                    }
                                 }
                              }
                           }
                        }
                     }
                  }
                  else if (!Query.createRead(getLazyMetaclass(), null, new Pair(Symbol.AT).eq(m_oid),
                     null, -1, 0, false, Query.SEC_NONE, m_context).read().isEmpty())
                  {
                     throw new AssociationIntegrityException(this);
                  }

                  throw new OptimisticLockException(this);
               }
            }

            if (bLoad)
            {
               attributes = preload(attributes, null, false);
            }
         }
         else
         {
            bRead = true;
         }
      }
      else
      {
         attributes = preload(attributes, null, false);
      }

      for (; attributes != null; attributes = attributes.getNext())
      {
         Object head = attributes.getHead();
         Pair assoc = (head instanceof Pair) ? (Pair)head : null;
         Attribute attribute = m_metaclass.getAttribute(
            (Symbol)((assoc != null) ? assoc.getHead() : head));

         if (!attribute.isStatic())
         {
            Object value = getValueDirect(attribute.getOrdinal());

            if (value instanceof Undefined)
            {
               switch (m_nState)
               {
               case INIT:
               case NEW:
                  if (attribute.getInitializerFunction() != null)
                  {
                     setCalcValue(attribute,
                        m_context.getMachine().invoke(attribute.getInitializerFunction(), this, (Object[])null));

                     continue;
                  }

                  break;

               case CLEAN:
               case DIRTY:
                  if (attribute.getValueFunction() != null)
                  {
                     if (attribute.isCached())
                     {
                        setCalcValue(attribute,
                           m_context.getMachine().invoke(attribute.getValueFunction(), this, (Object[])null));
                     }

                     continue;
                  }

                  break;
               }

               if (attribute.isCollection())
               {
                  InstanceList list = new InstanceArrayList(0);

                  setValueDirect(attribute.getOrdinal(), list);
                  list.setAssociation(this, attribute, true);
                  list.setLazy(false);
               }
               else
               {
                  setValueDirect(attribute.getOrdinal(), null);
               }

               if (s_logger.isDebugEnabled())
               {
                  s_logger.debug("Uninitialized " + attribute + ", set to " + getValueDirect(attribute.getOrdinal()));
               }
            }
            else if (value != null && !bRead)
            {
               if (assoc != null && assoc.getTail() != null)
View Full Code Here

               if (m_nState == CLEAN)
               {
                  for (int i = m_metaclass.getInstanceAttributeCount() - 1; i >= 0; --i)
                  {
                     Attribute attribute = m_metaclass.getInstanceAttribute(i);

                     if (!(getValueDirect(i) instanceof Undefined) && !attribute.isCollection())
                     {
                        attributes = new Pair(attribute.getSymbol(), attributes);
                     }
                  }
               }

               Query.createRead(m_metaclass, attributes, new Pair(Symbol.AT).eq(m_oid),
View Full Code Here

         try
         {
            // check cancellation conditions first
            for (int i = m_metaclass.getInstanceAttributeCount() - 1; i >= 0; --i)
            {
               Attribute attribute = m_metaclass.getInstanceAttribute(i);

               if (attribute.getCascadeMode() == Attribute.CASCADE_CANCEL)
               {
                  boolean bCancel;

                  if (attribute.isCollection())
                  {
                     InstanceList list = (InstanceList)getValue(attribute.getOrdinal());

                     bCancel = (list != null && !list.isEmpty());
                  }
                  else
                  {
                     Instance instance = (Instance)getValue(attribute.getOrdinal());

                     bCancel = (instance != null && instance.tryLoad());
                  }

                  if (bCancel)
                  {
                     ConstraintViolationException e = new ConstraintViolationException(
                        "err.persistence.cascadeCancel",
                        new Object[]{new StringId(m_metaclass.getCaption()),
                           getName(), new StringId(attribute.getCaption())});

                     e.setClassName(getClassName());
                     e.setOIDHolder(this);

                     throw e;
                  }
               }
            }

            // then do the rest of the cascade operations
            for (int i = m_metaclass.getInstanceAttributeCount() - 1; i >= 0; --i)
            {
               Attribute attribute = m_metaclass.getInstanceAttribute(i);

               switch (attribute.getCascadeMode())
               {
                  case Attribute.CASCADE_NONE:
                     if (attribute.isSymmetric())
                     {
                        Object value = getValueDirect(attribute.getOrdinal());

                        if (value != null)
                        {
                           if (value == Undefined.VALUE &&
                              attribute.isReverseInverseDependencyPersistent())
                           {
                              value = getValue(attribute.getOrdinal());
                           }

                           if (!(value instanceof Undefined))
                           {
                              if (attribute.isCollection())
                              {
                                 if (value != null)
                                 {
                                    InstanceList list = (InstanceList)value;

                                    // Full load of the list is triggered by size()
                                    if (list.size() == 0)
                                    {
                                       continue;
                                    }

                                    do
                                    {
                                       int nOrdinal = list.size() - 1;
                                       Instance instance = list.getInstance(nOrdinal);
                                       byte nInstanceFlagsSaved = instance.m_nFlags;

                                       instance.m_nFlags |= UPDATEABLE;

                                       try
                                       {
                                          list.remove(nOrdinal);
                                       }
                                       finally
                                       {
                                          instance.m_nFlags &= ~UPDATEABLE;
                                          instance.m_nFlags |= nInstanceFlagsSaved & UPDATEABLE;
                                       }
                                    }
                                    while (!list.isEmpty());
                                 }
                              }
                              else
                              {
                                 if (value != null)
                                 {
                                    Instance instance = (Instance)value;

                                    if (instance.tryLoad())
                                    {
                                       byte nInstanceFlagsSaved = instance.m_nFlags;

                                       instance.m_nFlags |= UPDATEABLE;

                                       try
                                       {
                                          setValue(attribute.getOrdinal(), null);
                                       }
                                       finally
                                       {
                                          instance.m_nFlags &= ~UPDATEABLE;
                                          instance.m_nFlags |= nInstanceFlagsSaved & UPDATEABLE;
                                       }
                                    }
                                    else
                                    {
                                       setValueDirect(attribute.getOrdinal(), null);
                                    }
                                 }
                              }
                           }
                        }
                     }

                     continue;

                  case Attribute.CASCADE_DELETE:
                  case Attribute.CASCADE_CLEAR:
                     break;

                  default:
                     continue;
               }

               if (attribute.isCollection())
               {
                  InstanceList list = (InstanceList)getValue(attribute.getOrdinal());

                  if (list == null)
                  {
                     continue;
                  }

                  switch (attribute.getCascadeMode())
                  {
                     case Attribute.CASCADE_DELETE:
                        // Full load of the list is triggered by size()
                        if (list.size() == 0)
                        {
                           continue;
                        }

                        do
                        {
                           int nOrdinal = list.size() - 1;
                           Instance instance = list.getInstance(nOrdinal);
                           byte nInstanceFlagsSaved = instance.m_nFlags;

                           // Remove the association first to avoid circular deletions in business logic
                           instance.m_nFlags |= UPDATEABLE;

                           try
                           {
                              list.remove(nOrdinal);
                           }
                           finally
                           {
                              instance.m_nFlags &= ~UPDATEABLE;
                              instance.m_nFlags |= nInstanceFlagsSaved & UPDATEABLE;
                           }

                           instance.invoke("delete", (Object[])null);
                        }
                        while (!list.isEmpty());

                        break;

                     case Attribute.CASCADE_CLEAR:
                        // Full load of the list is triggered by size()
                        if (list.size() == 0)
                        {
                           continue;
                        }

                        list.clear();
                        break;
                  }
               }
               else
               {
                  Instance instance = (Instance)getValue(attribute.getOrdinal());

                  if (instance == null)
                  {
                     continue;
                  }

                  if (instance.tryLoad())
                  {
                     switch (attribute.getCascadeMode())
                     {
                        case Attribute.CASCADE_DELETE:
                           // Remove the association first to avoid circular deletions in business logic
                           byte nInstanceFlagsSaved = instance.m_nFlags;

                           instance.m_nFlags |= UPDATEABLE;

                           try
                           {
                              setValue(attribute.getOrdinal(), null);
                           }
                           finally
                           {
                              instance.m_nFlags &= ~UPDATEABLE;
                              instance.m_nFlags |= nInstanceFlagsSaved & UPDATEABLE;
                           }

                           instance.invoke("delete", (Object[])null);
                           break;

                        case Attribute.CASCADE_CLEAR:
                           setValue(attribute.getOrdinal(), null);
                           break;
                     }
                  }
                  else
                  {
                     setValueDirect(attribute.getOrdinal(), null);
                  }
               }
            }
         }
         finally
View Full Code Here

                  column = ((RelationalPrimitiveMapping)mapping.getAttributeMapping(m_lockingAttribute)).getColumn();
                  sqlWork = (SQLWork)work;

                  if (sqlWork.getTable() == column.getTable())
                  {
                     Attribute lockingAttribute = inst.getPersistenceMapping().getLockingAttribute();

                     sqlWork.setInstanceValue(column, (lockingAttribute != null) ? inst.getValue(lockingAttribute.getOrdinal()) : null);
                  }
               }
            }
         }
      }
View Full Code Here

      if (nAspectCount != 0)
      {
         for (int nAttribute = 0, nAttributeCount = m_metaclass.getInstanceAttributeCount();
            nAttribute < nAttributeCount; ++nAttribute)
         {
            Attribute attribute = m_metaclass.getInstanceAttribute(nAttribute);
  
            for (int nAspect = 0; nAspect < nAspectCount; ++nAspect)
            {
               ClassAspect aspect = (ClassAspect)m_metaclass.getAspect(nAspect);
               Attribute aspectAttribute = aspect.findAttribute(attribute.getName());

               if (aspectAttribute != null)
               {
                  PersistenceMapping aspectMapping = aspect.findPersistenceMapping(m_dataSource);
View Full Code Here

   {
      Metaclass metaclass = m_instance.getMetaclass();
      int nAttributeCount = metaclass.getInstanceAttributeCount();
      VirtualMapping mapping = (VirtualMapping)m_mapping;
      WorkMapping operation = mapping.getCreateMapping();
      Attribute lockingAttribute = mapping.getLockingAttribute();
      int nLockingOrdinal = (lockingAttribute == null) ? -1 : lockingAttribute.getOrdinal();
      String sLockingAttributeName = (lockingAttribute == null) ? null :  lockingAttribute.getName();
      VirtualDataSourceFragment fragment = (VirtualDataSourceFragment)getFragment();
      ArrayList tobjList = new ArrayList(nEnd - nStart);

      for (int i = nStart; i < nEnd; i++)
      {
         Instance instance = workArray[i].getInstance();
         TransferObject tobj = new TransferObject(instance.getOID(), metaclass.getName(), EVENT, nAttributeCount);

         for (int k = 0; k < nAttributeCount; k++)
         {
            if (instance.isDirty(k))
            {
               Attribute attribute = metaclass.getInstanceAttribute(k);
               AttributeMapping attrMapping = m_mapping.getAttributeMapping(attribute);

               if (attrMapping != null)
               {
                  int nKeyPart = (attrMapping instanceof VirtualPrimitiveMapping) ?
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.