Package nexj.core.meta.persistence

Examples of nexj.core.meta.persistence.PersistenceMapping


    */
   public static VersionUpgrade create(
      String sName, Metadata metadata, Machine machine, Upgrade upgrade)
   {
      Metaclass versionClass = metadata.getMetaclass(Metadata.VERSION_CLASS_NAME);
      PersistenceMapping mapping = versionClass.getPersistenceMapping();
      DataSource ds = mapping.getDataSource();

      if (ds instanceof RelationalDatabase) // SysVersion persisted in RDBMS
      {
         Table table = ((RelationalMapping)mapping).getPrimaryTable();
         RelationalSchemaUpgrade version = new RelationalSchemaUpgrade(sName);
View Full Code Here


                              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)
                              {
View Full Code Here

    * Verifies the locking attribute and performs precomputations.
    * @throws MetadataException if the verification fails.
    */
   public void resolveInheritance() throws MetadataException
   {
      PersistenceMapping baseMapping = getBaseMapping();

      // Inherit the persistence mappings
      if (baseMapping != null && baseMapping.getDataSource() == m_dataSource)
      {
         RelationalMapping mapping = (RelationalMapping)baseMapping;

         if (m_primaryTable == mapping.getPrimaryTable())
         {
View Full Code Here

               }
            }
         }
      }

      PersistenceMapping baseMapping = getBaseMapping();

      // Inherit the key generators

      if (baseMapping != null && baseMapping.getDataSource() == getDataSource())
      {
         RelationalMapping mapping = (RelationalMapping)baseMapping;

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

         {
            filterSet = new BitSet(table.getColumnCount());

            for (int i = 0; i < assocs.length; ++i)
            {
               PersistenceMapping mapping = mappings[i];

               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();

                  for (int k = index.getIndexColumnCount() - 1; k >= 0; --k)
                  {
                     optionalSet.set(index.getIndexColumn(k).getColumn().getOrdinal());
                  }
               }
               else if (attributeMapping instanceof RelationalPrimitiveMapping)
               {
                  optionalSet.set(((RelationalPrimitiveMapping)attributeMapping).getColumn().getOrdinal());
               }
            }
         }

         // Collect the sort keys
         for (int nIndex = 0; nIndex < table.getIndexCount(); ++nIndex)
         {
            Index index = table.getIndex(nIndex);

            if (index.getType() != Index.CLUSTER &&
               index.getType() != Index.BTREE &&
               index.getType() != Index.QUERY)
            {
               continue;
            }

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

               int i;

               for (i = 0; i < nFilterCount; ++i)
               {
                  if (!filterSet.get(index.getIndexColumn(i).getColumn().getOrdinal()))
                  {
                     break;
                  }
               }

               if (i < nFilterCount)
               {
                  continue;
               }
            }

            Index pk = table.getPrimaryKey();
            boolean bMatch = true;
            boolean bAscending = true;
            Pair key = null;

            // Check whether the primary key columns are a subset of the index columns
            for (int i = 0; i < pk.getIndexColumnCount(); ++i)
            {
               IndexColumn pkIndexColumn = pk.getIndexColumn(i);
               Column pkColumn = pkIndexColumn.getColumn();

               if (optionalSet != null &&
                  optionalSet.get(pkColumn.getOrdinal()) &&
                  index.findIndexColumn(pkColumn) != null)
               {
                  continue;
               }

               int k;

               for (k = 0; k < index.getIndexColumnCount(); ++k)
               {
                  IndexColumn indexColumn = index.getIndexColumn(k);

                  if (indexColumn.getColumn() == pkColumn)
                  {
                     if (i == 0)
                     {
                        bAscending = indexColumn.isAscending();
                     }

                     break;
                  }
               }

               if (k == index.getIndexColumnCount())
               {
                  bMatch = false;

                  break;
               }
            }

            // If the above is true, then append the primary key
            // at the end of the sort key
            if (bMatch)
            {
               key = new Pair(new Pair(new Pair(Symbol.AT),
                  Boolean.valueOf(!(pk.getIndexColumn(0).isAscending() ^ bAscending))));
            }
            else
            {
               pk = null;
            }

            int nCount;

            for (nCount = nFilterCount; nCount < index.getIndexColumnCount(); ++nCount)
            {
               int nOrdinal = index.getIndexColumn(nCount).getColumn().getOrdinal();

               if (primitiveMappings[nOrdinal] == null)
               {
                  if (optionalSet == null || !optionalSet.get(nOrdinal))
                  {
                     break;
                  }
               }
            }

            bMatch = true;

            if (pk != null)
            {
               if (nCount == index.getIndexColumnCount())
               {
                  key = null;
               }
               else
               {
                  for (int i = nCount; i < index.getIndexColumnCount(); ++i)
                  {
                     if (!index.getIndexColumn(i).getColumn().isPrimary())
                     {
                        bMatch = false;
                        break;
                     }
                  }
               }
            }

            if (!bMatch)
            {
               continue;
            }

            boolean bPrimitive = false;

            for (int i = nCount - 1; i >= nFilterCount; --i)
            {
               IndexColumn indexColumn = index.getIndexColumn(i);
               int nOrdinal = indexColumn.getColumn().getOrdinal();
               RelationalPrimitiveMapping mapping = primitiveMappings[nOrdinal];

               if (mapping != null)
               {
                  if (optionalSet == null || !optionalSet.get(nOrdinal))
                  {
                     key = new Pair(new Pair(mapping.getAttribute().getSymbol(),
                        Boolean.valueOf(indexColumn.isAscending())), key);
                     bPrimitive = true;
                  }
               }
            }
View Full Code Here

   /**
    * @see nexj.core.meta.persistence.PersistenceMapping#resolveInheritance()
    */
   public void resolveInheritance() throws MetadataException
   {
      PersistenceMapping baseMapping = getBaseMapping();

      /*
       * Inherit the persistence mappings
       */
      if (baseMapping != null && baseMapping.getDataSource() == m_dataSource)
      {
         Metaclass baseClass = baseMapping.getMetaclass();

         // 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);
View Full Code Here

    */
   public void resolveInheritance2()
   {
      super.resolveInheritance2();

      PersistenceMapping baseMapping = getBaseMapping();

      // Inherit the key generator
      if (baseMapping != null && baseMapping.getDataSource() == m_dataSource)
      {
         VirtualMapping mapping = (VirtualMapping)baseMapping;

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

      {
         filterSet = new BitSet(m_metaclass.getInstanceAttributeCount());

         for (int i = 0; i < assocs.length; i++)
         {
            PersistenceMapping mapping = mappings[i];

            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()))
                     );
                  }
               }
            }
View Full Code Here

                                 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

   /**
    * Replicates the instance into the relevant fragments.
    */
   public void replicate()
   {
      PersistenceMapping mapping = getPersistenceMapping();

      if (mapping != null)
      {
         byte nReplication = mapping.getFragmentReplication();

         if (nReplication != PersistenceMapping.REPLICATION_NONE)
         {
            DataSource dataSource = mapping.getDataSource();

            if (dataSource.getFragmentCount() != 1)
            {
               UnitOfWork uow = m_uow;

               if (uow == null)
               {
                  uow = m_context.getUnitOfWork();
               }

               if (nReplication == PersistenceMapping.REPLICATION_UNICAST)
               {
                  if (getFragmentName() == null)
                  {
                     Attribute attribute = mapping.getFragmentAttribute();

                     if (attribute != null)
                     {
                        uow.addReplicationFragment(this, (String)((attribute.isStatic()) ?
                           m_metaclass : (Accessor)this).getValue(attribute.getOrdinal()));
View Full Code Here

TOP

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

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.