Package nexj.core.meta

Examples of nexj.core.meta.Attribute$InverseDependency


      Metaclass metaclass = null;

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

         if (obj == null)
         {
            if (part.isRequired())
            {
               throw new IntegrationException("err.integration.minPartCount", new Object[]{part.getFullPath()});
            }

            return null;
         }

         if (derivedPart instanceof CompositeMessagePart)
         {
            metaclass = (Metaclass)getSystemAttributeValue((CompositeMessagePart)derivedPart,
               (TransferObject)obj, ObjectMessagePartMapping.ATTR_CLASS);
         }

         if (m_context.isSecure())
         {
            if (attribute != null)
            {
               attribute.checkReadAccess(m_context.getPrivilegeSet());
            }

            if (metaclass != null)
            {
               metaclass.checkReadAccess(m_context.getPrivilegeSet());
            }
         }

         if (derivedPart instanceof PrimitiveMessagePart)
         {
            Object validatedValue = ((PrimitiveMessagePart)derivedPart).validateValue(obj);
           
            if (attribute == null)
            {
               return validatedValue;
            }

            validatedValue = attribute.getType().convert(validatedValue);

            int nMaxLength = attribute.getMaxLength();

            if (nMaxLength > 0 && mapping.isTruncated())
            {
               if (validatedValue instanceof String)
               {
                  String sValue = (String) validatedValue;

                  if (sValue.length() > nMaxLength)
                  {
                     validatedValue = sValue.substring(0, nMaxLength);

                     if (s_logger.isDebugEnabled())
                     {
                        s_logger.debug("Value of attribute " + attribute.getName()
                           + " has been truncated to maximum allowed length " + nMaxLength
                           + ". The original value is \"" + sValue + "\".");
                     }
                  }
               }
               else if (validatedValue instanceof Binary)
               {
                  byte[] binaryValue = ((Binary) validatedValue).getData();

                  if (binaryValue.length > nMaxLength)
                  {
                     byte[] truncatedValue = new byte[nMaxLength];

                     System.arraycopy(binaryValue, 0, truncatedValue, 0, nMaxLength);
                     validatedValue = new Binary(truncatedValue);

                     if (s_logger.isDebugEnabled())
                     {
                        s_logger.debug("Value of attribute " + attribute.getName()
                           + " has been truncated to maximum allowed length " + nMaxLength
                           + ". The original value is \"" + binaryValue + "\".");
                     }
                  }
               }
View Full Code Here


            ObjectMessagePartMapping partMapping = (ObjectMessagePartMapping)part.getMapping();

            if (isUpdateRequired(partMapping, instance, bNew))
            {
               Object value = instantiate(tobj.getValue(part.getName()), part);
               Attribute attribute = partMapping.getAttribute();

               if (attribute == null || instance == null)
               {
                  if (partMapping.getSystemAttribute() == ObjectMessagePartMapping.ATTR_OID)
                  {
                     if (value != null && !(value instanceof OID))
                     {
                        instance.setOID(OID.fromBinary(Primitive.toBinary(value)));
                     }
                     else
                     {
                        instance.setOID((OID)value);
                     }
                  }

                  continue;
               }

               if (bNew)
               {
                  instance.setValue(attribute.getOrdinal(), value);
               }
               else
               {
                  if (conflictResolution != null &&
                     !conflictResolution.shouldUpdate(instance, attribute, value))
                  {
                     continue;
                  }

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

                     for (int l = 0; l < valueList.size(); ++l)
                     {
                        Instance newInst = valueList.getInstance(l);

                        if (!list.contains(newInst))
                        {
                           list.add(newInst);
                        }
                     }
                  }
                  else if (!partMapping.isKey() && !ObjUtil.equal(instance.getValue(attribute.getOrdinal()), value))
                  {
                     instance.setValue(attribute.getOrdinal(), value);
                  }
               }
            }
         }
      }
View Full Code Here

      if (user != null)
      {
         Metaclass metaclass = user.getMetaclass();
         PersistenceMapping mapping = metaclass.getPersistenceMapping();
         Attribute attribute = null;

         assert m_userClass.isUpcast(metaclass);

         if (mapping != null)
         {
            attribute = mapping.getFragmentAttribute();
         }

         if (attribute == null)
         {
            attribute = metaclass.findAttribute("fragmentName");
         }

         if (attribute != null)
         {
            sFragmentName = (String)((attribute.isStatic()) ?
               metaclass.getValue(attribute.getOrdinal()) :
                  user.getValue(attribute.getOrdinal()));
         }

         attribute = metaclass.findAttribute("partition");

         if (attribute != null)
         {
            partition = (Instance)((attribute.isStatic()) ?
               metaclass.getValue(attribute.getOrdinal()) :
                  user.getValue(attribute.getOrdinal()));
         }

         privilegeSet = (PrivilegeSet)user.getValue("privilegeSet");
      }
View Full Code Here

      for (value = dispParent; value != null && dispAssoc != null; dispAssoc = dispAssoc.getNext())
      {
         dispParent = (Accessor)value;

         Attribute attribute = dispParent.getMetaclass().getAttribute(((Symbol)dispAssoc.getHead()).getName());

         attribute.checkReadAccess(m_context.getPrivilegeSet());
         value = dispParent.getValue(attribute.getOrdinal());
      }

      for (; dispValues != null; dispValues = dispValues.getNext())
      {
         if (Intrinsic.equal(value, dispValues.getHead()))
View Full Code Here

               {
                  Metaclass containerMetaclass = parentMetaclass;

                  for (Pair pair = (Pair)assoc; pair != null; pair = pair.getNext())
                  {
                     Attribute attribute = containerMetaclass.findAttribute((Symbol)pair.getHead());

                     if (attribute == null)
                     {
                        break;
                     }

                     attribute.checkReadAccess(m_context.getPrivilegeSet());

                     if (!attribute.isPersistent() &&
                        !attribute.getType().isPrimitive() &&
                        event == null &&
                        ((Metaclass)attribute.getType()).findEvent("read", 6)
                           .findAction("main").getDeclarator().getBase() == null)
                     {
                        if (parentList.size() > 1)
                        {
                           throw new InvalidQueryException("err.persistence.multipleParentsWithoutPersistence",
                              new Object[]{classSym, assoc, parentMetaclass.getName()});
                        }

                        if (where != null || bookmark != null || orderBy != null)
                        {
                           throw new InvalidQueryException("err.persistence.whereWithoutPersistence",
                              new Object[]{classSym, assoc, parentMetaclass.getName()});
                        }

                        resultList = new InstanceArrayList();
                        collectAssociatedInstances((Pair)assoc, parentInstance, resultList);

                        int nOffset = (offset == null) ? 0 : offset.intValue();
                        int nCount = (count == null) ? -1 : count.intValue();

                        if (nOffset < 0)
                        {
                           nOffset = 0;
                        }

                        if (nCount < 0 || nCount > resultList.size() - nOffset)
                        {
                           nCount = resultList.size() - nOffset;

                           if (nCount < 0)
                           {
                              nCount = 0;
                           }
                        }

                        if (nOffset > 0 || resultList.size() > nCount)
                        {
                           InstanceList list = new InstanceArrayList(nCount);

                           for (int k = 0; k < nCount; ++k)
                           {
                              list.add(resultList.getInstance(k + nOffset), InstanceList.REPLACE | InstanceList.DIRECT);
                           }

                           resultList = list;
                        }

                        if (next != null && !next.booleanValue())
                        {
                           resultList.reverse();
                        }

                        for (int k = 0; k < nCount; ++k)
                        {
                           resultList.getInstance(k).invoke("load", attributes);
                        }

                        reader.setValue("results", resultList);

                        return resultList;
                     }

                     if (attribute.getType().isPrimitive())
                     {
                        break;
                     }

                     containerMetaclass = (Metaclass)attribute.getType();
                  }
               }

               assoc = new Pair(Symbol.ATAT, new Pair(parentMetaclass.getSymbol(), assoc));
View Full Code Here

         Instance instance = (Instance)value;

         try
         {
            Attribute attr = instance.getMetaclass().getNameAttribute();

            if (attr != null)
            {
               appendValue(buf, instance.getValue(attr.getOrdinal()), true);
               buf.append(": ");
            }
         }
         catch (Exception e)
         {
View Full Code Here

      {
         return instance;
      }

      Metaclass metaclass = m_context.getMetadata().getMetaclass(tobj.getClassName());
      Attribute lockingAttribute = (metaclass.getPersistenceMapping() != null) ? metaclass.getPersistenceMapping()
         .getLockingAttribute() : null;
      OID oid = tobj.getOID();

      if (isCached())
      {
         if (oid == null)
         {
            instance = null;
         }
         else
         {
            instance = m_context.lockInstance(metaclass, oid, tobj.getEventName() != null);

            if (instance != null && instance.isLazy())
            {
               if (tobj.getVersion() >= 0)
               {
                  instance.setMetaclass(metaclass);
               }
               else if (instance.getLazyMetaclass().isUpcast(metaclass))
               {
                  instance.setLazyMetaclass(metaclass);
               }
            }
         }

         if ("create".equals(tobj.getEventName()))
         {
            if (instance == null)
            {
               instance = new Instance(metaclass, m_context);
               instance.setNew();
               instance.setOID(oid);
            }
         }
         else
         {
            if (instance == null)
            {
               instance = new Instance(metaclass, tobj.getVersion() < 0, m_context);
               m_context.getUnitOfWork().lock(instance.cache(oid), tobj.getEventName() != null);
            }
            else if ((m_nMode & CACHE) != 0 && instance.isCached())
            {
               return instance;
            }
         }

         if ((m_nMode & CACHE) != 0)
         {
            instance.setCached(true);
         }
      }
      else
      {
         if (oid == null)
         {
            instance = new Instance(metaclass, m_context);
            instance.setNew();
            instance.getUnitOfWork().keepChange(instance);
         }
         else
         {
            if (m_context.isProtected() && m_context.isSecure())
            {
               metaclass.checkReadAccess(m_context.getPrivilegeSet());
            }

            instance = m_context.lockInstance(metaclass, oid, tobj.getEventName() != null);

            if (instance == null)
            {
               PersistenceMapping mapping = metaclass.getPersistenceMapping();

               if (mapping != null)
               {
                  Object[] valueArray = oid.getValueArray();
                  Key key = mapping.getObjectKey();

                  if (key.getPartCount() != valueArray.length)
                  {
                     throw new RequestException("err.rpc.oidPartCount", new Object[]
                     {
                        metaclass.getName()
                     });
                  }

                  for (int i = 0; i < valueArray.length; ++i)
                  {
                     valueArray[i] = key.getPartType(i).convert(valueArray[i]);
                  }
               }

               instance = new Instance(metaclass, m_context);
               m_context.getUnitOfWork().lock(instance.cache(oid), tobj.getEventName() != null);
            }
         }
      }

      m_identityMap.put(tobj, instance);

      if ((m_nMode & STATE) != 0 && tobj.getVersion() >= 0)
      {
         instance.load();

         if (lockingAttribute != null && instance.getState() != Instance.NEW)
         {
            Object oldValue = instance.getOldValueDirect(lockingAttribute.getOrdinal());

            if (!(oldValue instanceof Undefined))
            {
               Object value = tobj.findValue(lockingAttribute.getName());

               if (value != null && !ObjUtil.equal(lockingAttribute.getType().convert(value), oldValue))
               {
                  m_bLockMismatch = true;

                  if ((m_nMode & LOCK) != 0)
                  {
                     throw new OptimisticLockException(instance);
                  }

                  if (isCached())
                  {
                     return instance;
                  }

                  if (m_context.isLocked(instance))
                  {
                     throw new OptimisticLockException(instance);
                  }
               }
            }
         }

         TransferObject preObj = null;

         if ((m_nMode & PRE) != 0)
         {
            Object value = tobj.findValue(PRE_NAME);

            if (value != null)
            {
               if (value instanceof TransferObject)
               {
                  preObj = (TransferObject)value;
               }
               else
               {
                  throw new RequestException("err.rpc.preObjectType");
               }
            }
         }

         for (PropertyIterator itr = tobj.getIterator(); itr.hasNext();)
         {
            String sName = (String)itr.next();

            if ((m_nMode & PRE) != 0 && sName.equals(PRE_NAME))
            {
               continue;
            }

            Attribute attribute = metaclass.getAttribute(sName);
            Object value = itr.getValue();

            if (attribute.isStatic())
            {
               throw new RequestException("err.rpc.staticAttribute", new Object[]
               {
                  attribute.getName(),
                  metaclass.getName()
               });
            }

            if (isCached())
            {
               if (!(instance.getOldValueDirect(attribute.getOrdinal()) instanceof Undefined))
               {
                  continue;
               }
            }
            else
            {
               if (!attribute.isCached())
               {
                  throw new RequestException("err.rpc.uncachedAttribute", new Object[]
                  {
                     attribute.getName(),
                     metaclass.getName()
                  });
               }

               if (m_context.isProtected() && m_context.isSecure())
               {
                  attribute.checkReadAccess(m_context.getPrivilegeSet());
               }

               instance.checkUpdateAccess(attribute);
            }

            Object pre = (preObj == null) ? Undefined.VALUE : preObj.findValue(sName, Undefined.VALUE);

            if (attribute.getType().isPrimitive())
            {
               value = instantiatePrimitive(value, attribute);

               if (pre != Undefined.VALUE)
               {
                  pre = instantiatePrimitive(pre, attribute);
               }
            }
            else
            {
               if (attribute.isCollection())
               {
                  InstanceList instanceList;

                  if (pre != Undefined.VALUE)
                  {
                     pre = instanceList = instantiateList(pre, attribute);

                     if (isCached())
                     {
                        instanceList.setLazy(false);
                     }
                  }

                  value = instanceList = instantiateList(value, attribute);

                  if (isCached())
                  {
                     instanceList.setLazy(false);
                  }
                  else
                  {
                     if (attribute.getReverse() != null)
                     {
                        instanceList.checkUpdateAccess(attribute.getReverse(), instance);
                     }
                  }

                  instanceList.setAssociation(instance, attribute, true);
               }
               else
               {
                  Instance inst;

                  if (pre != Undefined.VALUE)
                  {
                     pre = inst = instantiateObject(pre, attribute);
                  }

                  value = inst = instantiateObject(value, attribute);

                  if (isCached() && attribute.getReverse() != null && inst != null && !inst.isLazy())
                  {
                     inst.associate(attribute.getReverse().getOrdinal(), instance, true);
                  }
               }
            }

            if (pre != Undefined.VALUE && ObjUtil.equal(value, pre))
            {
               pre = Undefined.VALUE;
            }

            if (isCached())
            {
               if (pre != Undefined.VALUE)
               {
                  instance.setPreValueDirect(attribute.getOrdinal(), pre);
               }

               instance.setOldValueDirect(attribute.getOrdinal(), value);
            }
            else
            {
               m_fixupList.add(instance);
               m_fixupList.add(attribute);
View Full Code Here

         // Invalidate the dependencies
         for (int i = 0, n = fixupList.size(); i != n; i += 4)
         {
            Instance instance = (Instance)fixupList.get(i);
            Attribute attribute = (Attribute)fixupList.get(i + 1);

            if (attribute.getInverseDependency() != null)
            {
               attribute.invalidateDependency(instance, Invalid.VALUE);
            }

            Attribute reverse = attribute.getReverse();

            if (reverse != null && attribute.isReverseOf(reverse) && reverse.getInverseDependency() != null)
            {
               Object value = fixupList.get(i + 2);

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

                     for (int k = 0, m = list.getCount(); k != m; ++k)
                     {
                        reverse.invalidateDependency(list.getInstance(k), Invalid.VALUE);
                     }
                  }
                  else
                  {
                     reverse.invalidateDependency((Instance)value, Invalid.VALUE);
                  }
               }
            }
         }

         // Assign the values
         for (int i = 0, n = fixupList.size(); i != n; i += 4)
         {
            Instance instance = (Instance)fixupList.get(i);
            Attribute attribute = (Attribute)fixupList.get(i + 1);
            Object value = fixupList.get(i + 2);
            Object pre = fixupList.get(i + 3);

            instance.assign(attribute, value, true);
View Full Code Here

         }

         for (Iterator i = query.getFieldIterator(); i.hasNext(); )
         {
            Field field = (Field)i.next();
            Attribute attribute = field.getAttribute();
            FilePrimitiveMapping primitiveMapping = (FilePrimitiveMapping)query.getPersistenceMapping().getAttributeMapping(attribute);
           
            switch (primitiveMapping.getSysId())
            {
               case FilePrimitiveMapping.SYSID_ID:
                  instance.setOldValueDirect(attribute.getOrdinal(), oid.getValue(0));
                  break;
                 
               case FilePrimitiveMapping.SYSID_DATA:
                  Object value = null;
                 
                  try
                  {
                     value = (primitiveMapping.getAttribute().getType() == Primitive.STRING) ?
                        (Object)directFile.getDataAsString() : directFile.getDataAsBinary();
                  }
                  catch (IOException ex)
                  {
                     throw new PersistenceException("err.persistence.file.io", ex);
                  }
                 
                  instance.setOldValueDirect(attribute.getOrdinal(), value);
                 
                  break;
              
               case FilePrimitiveMapping.SYSID_LOCKING:
                  instance.setOldValueDirect(attribute.getOrdinal(),
                     Primitive.createLong(dataFile.lastModified()) );
                  break;
            }
         }
        
View Full Code Here

   /**
    * Performs the work represented by this work item.
    */
   public void executeCommand()
   {
      Attribute lockAttrib = m_mapping.getLockingAttribute();
     
      //Compute filename from instance id
      String sDataFile = m_adapter.mapOIDToFile(m_instance.getOID());
     
      if (sDataFile == null)
      {
         throw new PersistenceException("err.persistence.file.invalidFileName",
            new Object[]{m_instance.getOID().toString(), m_instance.getClassName()});
      }
     
      if (s_logger.isDebugEnabled())
      {
         s_logger.debug("Executing on file: " + sDataFile);
      }
     
     
      //Get the connection to use
      FileConnection connection = m_adapter.getConnection((FileDataSourceFragment)getFragment(), sDataFile);

      try
      {
         //Check for optimistic lock violation
         if (m_nType == UPDATE || m_nType == DELETE)
         {
            Object lockValue = m_instance.getOldValueDirect(lockAttrib.getOrdinal());
            long lCurrentLockValue = connection.getLastModified();
           
            if (s_logger.isDebugEnabled())
            {
               s_logger.debug("LOCKING " + ( (((Long)lockValue).longValue() < lCurrentLockValue) ? "BAD" : "GOOD") + " instance=" + lockValue + " file=" + lCurrentLockValue);
            }
           
            if (((Long)lockValue).longValue() < lCurrentLockValue)
            {
               throw new OptimisticLockException(m_instance);
            }
         }
        
         Object dataToWrite = null;
        
         if (m_nType == INSERT || m_nType == UPDATE)
         {
            Metaclass metaclass = m_instance.getMetaclass();
           
            for (int i = 0, nCount = metaclass.getInstanceAttributeCount(); i < nCount; i++)
            {
               Attribute attribute = metaclass.getInstanceAttribute(i);
               AttributeMapping attributeMapping = m_mapping.getAttributeMapping(attribute);
              
               if (attributeMapping == null)
               {
                  continue;
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.