Package nexj.core.meta.persistence

Examples of nexj.core.meta.persistence.AttributeMapping


               if (mapping == null)
               {
                  continue;
               }

               AttributeMapping attributeMapping = mapping.getAttributeMapping(assocs[i]);

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

                  if (classMapping.getMapping() == this &&
                     classMapping.getDestinationKey() instanceof Index)
                  {
                     Index key = (Index)classMapping.getDestinationKey();

                     if (key.getTable() != table)
                     {
                        key = table.getPrimaryKey();
                     }

                     if (!key.isUnique())
                     {
                        for (int k = key.getIndexColumnCount() - 1; k >= 0; --k)
                        {
                           filterSet.set(key.getIndexColumn(k).getColumn().getOrdinal());
                        }
                     }
                  }
               }
            }

            nFilterCount = filterSet.cardinality();
         }

         // Create a set of columns, which participate in equality
         // comparisons and can be optionally excluded from the index.
         if (restrictions != null && restrictions.length > 0)
         {
            optionalSet = new BitSet(table.getColumnCount());

            for (int i = 0; i < restrictions.length; ++i)
            {
               AttributeMapping attributeMapping = getAttributeMapping(restrictions[i]);

               if (attributeMapping instanceof RelationalClassMapping)
               {
                  Index index = ((RelationalClassMapping)attributeMapping).getSourceKey();
View Full Code Here


            }

            break;
         }

         AttributeMapping mapping = getAttributeMapping(m_metaclass.getInstanceAttribute(ordinalArray[nTop]));

         if (mapping != null && !mapping.getAttribute().isCollection())
         {
            if (!(mapping instanceof RelationalClassMapping) ||
               ((RelationalClassMapping)mapping).getDestinationKey().isUnique())
            {
               int nSize =  getSubsetSize(mapping, index, useArray);
View Full Code Here

                     bitSetArray[i] = new BitSet(relMapping.getTable(i).getColumnCount());
                  }

                  for (int nAttr = 0; nAttr != metaclass.getInstanceAttributeCount(); ++nAttr)
                  {
                     AttributeMapping attrMapping = relMapping.getAttributeMapping(metaclass.getInstanceAttribute(nAttr));

                     if (attrMapping instanceof RelationalPrimitiveMapping)
                     {
                        RelationalPrimitiveMapping primitiveMapping = (RelationalPrimitiveMapping)attrMapping;
View Full Code Here

   {
      if (attribute.getType() == base.getType())
      {
         if (getAttributeMapping(attribute) == null)
         {
            AttributeMapping mapping = (AttributeMapping)baseMapping.clone();

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

         // Inherit attribute mappings
         for (int i = 0, nCount = baseClass.getInstanceAttributeCount(); i < nCount; i++)
         {
            Attribute baseAttribute = baseClass.getInstanceAttribute(i);
            AttributeMapping baseAttrMapping = baseMapping.getAttributeMapping(baseAttribute);

            if (baseAttrMapping != null)
            {
               Attribute derivedAttribute = m_metaclass.getDerivedAttribute(baseAttribute);
               AttributeMapping derivedAttrMapping = getAttributeMapping(derivedAttribute);

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

            if (mapping == null)
            {
               continue;
            }

            AttributeMapping attributeMapping = mapping.getAttributeMapping(assocs[i]);

            if (attributeMapping instanceof VirtualClassMapping)
            {
               VirtualClassMapping classMapping = (VirtualClassMapping)attributeMapping;

               if (classMapping.getMapping() == this && classMapping.getKey(true) instanceof VirtualKey)
               {
                  VirtualKey key = (VirtualKey)classMapping.getKey(true);

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

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

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

         nFilterCount = filterSet.cardinality();
      }

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

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

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

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

            int i;

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

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

            if (i < nFilterCount)
            {
               continue;
            }
         }

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

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

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

               break;
            }

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

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

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

                        continue;
                     }

                     break;
                  }

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

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

         Pair key = null;

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

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

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

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

            boolean bObjKeyFullyMapped = true;

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

                  break;
               }
            }

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

         int nCount;

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

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

         bMatch = true;

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

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

                     if (mapping instanceof VirtualPrimitiveMapping)
                     {
                        if (((VirtualPrimitiveMapping)mapping).getObjectKeyPart() >= 0)
                        {
View Full Code Here

               break;
            }
            else
            {
               AttributeMapping mapping = getAttributeMapping(attr);

               if (mapping instanceof VirtualPrimitiveMapping)
               {
                  if (((VirtualPrimitiveMapping)mapping).getObjectKeyPart() >= 0)
                  {
View Full Code Here

                           final Attribute attribute = metaclass.getAttribute(sAttributeName);
                           final String sTableName = XMLUtil.getStringAttr(attributeMappingElement, "table");
                           final String sColumnName = XMLUtil.getStringAttr(attributeMappingElement, "column");
                           final String sSourceKeyName = XMLUtil.getStringAttr(attributeMappingElement, "sourceKey");
                           final String sDestinationKeyName = XMLUtil.getStringAttr(attributeMappingElement, "destinationKey");
                           AttributeMapping mapping;
                          
                           m_persistenceMappingElement = null;
                           XMLUtil.withFirstChildElement(attributeMappingElement,
                              "PersistenceMapping", false, m_persistenceMappingElementHandler);

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

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

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

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

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

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

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

                                 m_loader.addPersistenceMappingFixup(new ContextFixup(getHelper())
                                 {
                                    public void fixup()
                                    {
                                       Metaclass type = (Metaclass)attribute.getType();
                                       PersistenceMapping mapping = type.getPersistenceMapping();

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

                                       classMapping.setDestinationKey(mapping.addForeignKey(sDestinationKeyName, classMapping));
                                    }
                                 });
                              }

                              mapping = classMapping;
View Full Code Here

            m_writer.writeAttribute("type", type.getName());

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

               if (attributeMapping instanceof VirtualPrimitiveMapping)
               {
                  VirtualPrimitiveMapping primitiveMapping = (VirtualPrimitiveMapping)attributeMapping;
View Full Code Here

      boolean bWroteMapping = false;

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

         if (attrMapping != null)
         {
            if (!bWroteMapping)
            {
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.