Package nexj.core.meta.persistence

Examples of nexj.core.meta.persistence.AttributeMapping


   {
      verifyNotReadOnly();

      if (m_type == Primitive.STRING || m_type == Primitive.BINARY)
      {
         AttributeMapping attributeMapping = getPersistenceMapping();

         if (attributeMapping != null)
         {
            m_nMaxLength = attributeMapping.getMaxLength((Primitive)m_type);
         }
      }
   }
View Full Code Here


      PersistenceMapping mapping = instance.getPersistenceMapping();

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

         if (attributeMapping == null)
         {
            continue;
         }

         Object value = instance.getValueDirect(i);

         // The value cannot be undefined, the Instance.validate() has taken care of that.

         if (attribute.getType().isPrimitive())
         {
            addPrimitiveWork(uow, instance, primaryWork, attributeMapping, value);
         }
         else
         {
            InstanceList list = null;
            Instance inst = null;
            boolean bNull;

            if (attribute.isCollection())
            {
               list = (InstanceList)value;
               bNull = (list == null || list.isEmpty());
            }
            else
            {
               inst = (Instance)value;
               bNull = (inst == null);
            }

            if (!bNull)
            {
               // TODO: Insert with composition mappings.
               ClassMapping assocMapping = (ClassMapping)attributeMapping;
               boolean bSuccessor = isCreateSuccessor(primaryWork, assocMapping, bOID);

               if (bSuccessor)
               {
                  if (list == null)
                  {
                     inst.getAdapter().addDependency(uow, primaryWork, inst,
                        assocMapping.getKey(true), assocMapping.getKey(false), true);
                  }
                  else
                  {
                     for (int k = 0; k < list.getCount(); ++k)
                     {
                        inst = list.getInstance(k);

                        if (inst != null)
                        {
                           inst.getAdapter().addDependency(uow, primaryWork, inst,
                              assocMapping.getKey(true), assocMapping.getKey(false), true);
                        }
                     }
                  }
               }
               else
               {
                  Work work = addClassWork(uow, instance, primaryWork, assocMapping);

                  if (list != null)
                  {
                     inst = list.getInstance(0);
                  }

                  if (inst.getOID() != null)
                  {
                     work.setKeyValue(assocMapping.getKey(false), assocMapping.getKey(true), inst);

                     if (assocMapping.getKey(false) == mapping.getObjectKey())
                     {
                        instance.setOID(inst.getOID());
                     }
                  }
                  else
                  {
                     inst.getAdapter().addDependency(uow, work, inst,
                        assocMapping.getKey(false), assocMapping.getKey(true), false);
                  }
               }
            }
         }

         if (attributeMapping.isDenormalized())
         {
            uow.addDenorm(instance, attributeMapping);
         }
      }
View Full Code Here

      PersistenceMapping mapping = instance.getPersistenceMapping();

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

         if (attributeMapping == null)
         {
            continue;
         }

         Object value = instance.getValueDirect(i);

         if (value == Undefined.VALUE || ObjUtil.equal(value, instance.getOldValueDirect(i)))
         {
            continue;
         }

         if (attribute.getType().isPrimitive())
         {
            addPrimitiveWork(uow, instance, primaryWork, attributeMapping, value);
         }
         else
         {
            InstanceList list = null;
            Instance inst = null;
            boolean bNull;

            if (attribute.isCollection())
            {
               list = (InstanceList)value;
               bNull = (list == null || list.isEmpty());
            }
            else
            {
               inst = (Instance)value;
               bNull = (inst == null);
            }

            ClassMapping assocMapping = (ClassMapping)attributeMapping;
            boolean bSuccessor;

            // TODO: Update composition mappings

            if (assocMapping.getKey(false).isObjectKey())
            {
               bSuccessor = true;
            }
            else if (assocMapping.getKey(true).isObjectKey())
            {
               bSuccessor = false;
            }
            else if (attribute.isCollection())
            {
               bSuccessor = true;
            }
            else
            {
               bSuccessor = false;
            }

            if (bSuccessor)
            {
               if (!bNull)
               {
                  if (list == null)
                  {
                     inst.getAdapter().addDependency(uow, primaryWork, inst,
                        assocMapping.getKey(true), assocMapping.getKey(false), true);
                  }
                  else
                  {
                     for (int k = 0; k < list.getCount(); ++k)
                     {
                        inst = list.getInstance(k);

                        if (inst != null)
                        {
                           inst.getAdapter().addDependency(uow, primaryWork, inst,
                              assocMapping.getKey(true), assocMapping.getKey(false), true);
                        }
                     }
                  }
               }
            }
            else
            {
               Work work = addClassWork(uow, instance, primaryWork, assocMapping);

               if (bNull)
               {
                  if (assocMapping.getKey(false) != mapping.getObjectKey())
                  {
                     work.setKeyValue(assocMapping.getKey(false), assocMapping.getKey(true), null);
                  }
               }
               else
               {
                  if (list != null)
                  {
                     inst = list.getInstance(0);
                  }

                  if (inst.getOID() != null)
                  {
                     if (assocMapping.getKey(false) != mapping.getObjectKey())
                     {
                        work.setKeyValue(assocMapping.getKey(false), assocMapping.getKey(true), inst);
                     }
                  }
                  else
                  {
                     inst.getAdapter().addDependency(uow, work, inst,
                        assocMapping.getKey(false), assocMapping.getKey(true), false);
                  }
               }
            }
         }

         if (attributeMapping.isDenormalized())
         {
            uow.addDenorm(instance, attributeMapping);
         }
      }
   }
View Full Code Here

    */
   protected void deriveAttributeMapping(Attribute attribute, Attribute base, AttributeMapping baseMapping)
   {
      if (attribute.getType() == base.getType())
      {
         AttributeMapping mapping = (AttributeMapping)baseMapping.clone();

         mapping.setAttribute(attribute);
         addAttributeMapping(mapping);
      }
   }
View Full Code Here

         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) ?
                     ((VirtualPrimitiveMapping)attrMapping).getObjectKeyPart() : -1;
View Full Code Here

      for (int i = 0; i < nCount; i++)
      {
         if (instance.isDirty(i))
         {
            Attribute attribute = metaclass.getInstanceAttribute(i);
            AttributeMapping attributeMapping = m_mapping.getAttributeMapping(attribute);

            if (attributeMapping != null && (attribute.getType().isPrimitive() ||
               !((VirtualClassMapping)attributeMapping).getKey(false).isObjectKey()))
            {
               m_attributeSet.set(i);
View Full Code Here

                        public void handleElement(Element element)
                        {
                           String sName = XMLUtil.getReqStringAttr(element, "name");
                           int nMaxLength = XMLUtil.getIntAttr(element, "maxLength", 0);
                           final Attribute attribute = metaclass.getAttribute(sName);
                           AttributeMapping attrMapping;

                           if (attribute.getType().isPrimitive())
                           {
                              VirtualPrimitiveMapping primitiveMapping = new VirtualPrimitiveMapping();

                              attrMapping = primitiveMapping;

                              if (element.hasAttribute("attributes"))
                              {
                                 throw new MetadataException("err.meta.persistence.virtual.invalidPropertySpecified",
                                    new Object[]{"attributes", sName, metaclass.getName()});
                              }

                              if (XMLUtil.getBooleanAttr(element, "objectSourceKey", false))
                              {
                                 throw new MetadataException("err.meta.persistence.virtual.invalidPropertySpecified",
                                    new Object[]{"objectSourceKey", sName, metaclass.getName()});
                              }

                              if (element.hasAttribute("destinationKey"))
                              {
                                 throw new MetadataException("err.meta.persistence.virtual.invalidPropertySpecified",
                                    new Object[]{"destinationKey", sName, metaclass.getName()});
                              }

                              if (nMaxLength != 0)
                              {
                                 if (attribute.getType() != Primitive.BINARY && attribute.getType() != Primitive.STRING)
                                 {
                                    throw new MetadataException("err.meta.persistence.virtual.maxLengthSpecified",
                                       new Object[]{attribute.getName(), metaclass.getName()});
                                 }

                                 primitiveMapping.setMaxLength(nMaxLength);
                              }
                           }
                           else
                           {
                              final VirtualClassMapping classMapping = new VirtualClassMapping();

                              attrMapping = classMapping;

                              classMapping.setComposition((Pair)m_helper.parse(
                                 XMLUtil.getStringAttr(element, "attributes"),
                                 true, null, null, metadata.getGlobalEnvironment()
                              ));

                              final boolean bObjectSourceKey = XMLUtil.getBooleanAttr(element, "objectSourceKey", false);
                              final String sDestinationKeyName = XMLUtil.getStringAttr(element, "destinationKey");

                              if (nMaxLength != 0)
                              {
                                 throw new MetadataException("err.meta.persistence.virtual.maxLengthSpecified",
                                    new Object[]{attribute.getName(), metaclass.getName()});
                              }

                              loader.addPersistenceMappingFixup(new ContextFixup(m_helper)
                              {
                                 public void fixup()
                                 {
                                    Metaclass type = (Metaclass)attribute.getType();
                                    PersistenceMapping assocClassMapping = type.getPersistenceMapping();

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

                                    classMapping.setSourceKey((bObjectSourceKey) ? mapping.getObjectKey() : new VirtualKey(attribute));
                                    classMapping.setDestinationKey(assocClassMapping.addForeignKey(sDestinationKeyName, classMapping));
                                 }
                              });

                              loader.addComponentFixup(new ContextFixup(m_helper)
                              {
                                 public void fixup()
                                 {
                                    classMapping.validate(metadata, m_helper.getWarnings());
                                 }
                              });
                           }

                           attrMapping.setAttribute(attribute);
                           mapping.addAttributeMapping(attrMapping);
                        }
                     });
                  }
               });
View Full Code Here

            }

            for (int i = 0, nCount = mapping.getMetaclass().getInstanceAttributeCount(); i < nCount; ++i)
            {
               Attribute baseAttribute = mapping.getMetaclass().getInstanceAttribute(i);
               AttributeMapping baseAttrMapping = mapping.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);
                     }
                  }
                  else if (m_typeCodeAttribute != null || mapping.m_typeCodeAttribute != null)
                  {
View Full Code Here

      {
         if (attribute.getMetaclass() instanceof Aspect)
         {
            if (getAttributeMapping(attribute) == null)
            {
               AttributeMapping mapping = (AttributeMapping)baseMapping.clone();

               mapping.setAttribute(attribute);
               addAttributeMapping(mapping);
            }
         }
         else
         {
View Full Code Here

         {
            RelationalClassMapping mapping = (RelationalClassMapping)getAttributeMapping(attribute);

            if (mapping == null)
            {
               AttributeMapping attributeMapping = reverse.findPersistenceMapping(this, true);

               if (attributeMapping instanceof RelationalClassMapping)
               {
                  RelationalClassMapping reverseMapping = (RelationalClassMapping)attributeMapping;

                  if (reverseMapping != null)
                  {
                     mapping = new RelationalClassMapping();
                     mapping.setPersistenceMapping(this);
                     mapping.setAttribute(attribute);
                     mapping.setMapping(attributeMapping.getPersistenceMapping());
                     mapping.setSourceKey((Index)reverseMapping.getDestinationKey());
                     mapping.setDestinationKey(reverseMapping.getSourceKey());
                     addAttributeMapping(mapping);
                  }
               }
View Full Code Here

TOP

Related Classes of nexj.core.meta.persistence.AttributeMapping

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.