Package nexj.core.meta.persistence.sql

Examples of nexj.core.meta.persistence.sql.IndexColumn


      assertEquals(1, table.getIndex(0).getIndexColumnCount());
      table.setType(Table.MANAGED); // comes in as Table.EXTERNAL from DB

      Index aspect = new Index("aspect", Index.ASPECT, null);

      aspect.addIndexColumn(new IndexColumn(table.getColumn(1), true));
      schema.addIndex(aspect);

      ApplyIndexAspectStep step = new ApplyIndexAspectStep();

      step.setAspectName(aspect.getName());
View Full Code Here


      table.setName("test"); // table name required to add table to schema, to add index to schema
      schema.addTable(table);
      column.setType(Primitive.INTEGER);
      table.addColumn(column);
      index.addIndexColumn(new IndexColumn(column, true));
      table.addIndex(index);
      table.setPrimaryKey(index);
      schema.setDataSource(m_database);

      // validate initial schema state
View Full Code Here

      assertEquals(2, table.getIndex(0).getIndexColumnCount());
      table.setType(Table.MANAGED); // comes in as Table.EXTERNAL from DB

      Index aspect = new Index("aspect", Index.ASPECT, null);

      aspect.addIndexColumn(new IndexColumn(table.getColumn("value"), true));
      table.getIndex(0).addAspect(aspect);
      schema.addIndex(aspect);

      RemoveIndexAspectStep step = new RemoveIndexAspectStep();
View Full Code Here

      index.setType(m_nType);
      index.setFill(m_nFill);

      for (int i = 0, n = getColumnCount(); i < n; ++i)
      {
         index.addIndexColumn(new IndexColumn(
            index.getTable().getColumn(getColumnName(i)),
            isColumnAscending(i)));
      }

      if (m_aspectOverrideList != null)
View Full Code Here

               if (!bIgnore)
               {
                  try
                  {
                     index.addIndexColumn(new IndexColumn(table.getColumn(sColumnName), bAscending));
                  }
                  catch (MetadataException e)
                  {
                     s_logger.error("Cannot find column \"" + sColumnName +
                        "\", ignoring index \"" + sIndexName + "\"", e);
                     bIgnore = true;
                  }
               }
            }

            if (index != null && !bIgnore)
            {
               if (addIndex(table, index))
               {
                  bPortable &= isPortable(index);
               }
            }

            rs.close();
            rs = null;

            // Read the primary key

            rs = getPrimaryKeys(names[0], names[1], table.getTableName());
            index = null;
            bIgnore = false;

            try
            {
               while (rs.next())
               {
                  String sColumnName = toMetadataCase(rs.getString("COLUMN_NAME"));
                 
                  if (index == null)
                  {
                     String sIndexName = rs.getString("PK_NAME");

                     if (sIndexName == null)
                     {
                        sIndexName = table.getName() + ".PK";
                        index = new Index(sIndexName, Index.BTREE, table);
                     }
                     else
                     {
                        sIndexName = generateIndexName(table.getTableName(), sIndexName, "PK");
                        index = table.findIndex(sIndexName);

                        if (index == null)
                        {
                           index = new Index(sIndexName, Index.BTREE, table);
                        }
                        else
                        {
                           table.setPrimaryKey(index);
                           bIgnore = true;

                           break;
                        }
                     }
                  }

                  if (s_logger.isDebugEnabled())
                  {
                     s_logger.debug("Read primary key column \"" + index.getName() + "." + sColumnName + "\"");
                  }

                  index.setUnique(true);
                  index.addIndexColumn(new IndexColumn(table.getColumn(sColumnName), true));
               }
            }
            catch (MetadataException e)
            {
               s_logger.error("Cannot add primary key to table \"" + table.getName() + "\"", e);
               bIgnore = true;
            }

            if (index != null)
            {
               if (!bIgnore)
               {
                  if (addIndex(table, index))
                  {
                     table.setPrimaryKey(index);
                     bPortable &= isPortable(index);
                  }
               }
            }
            else
            {
               for (int i = 0; i < table.getIndexCount(); ++i)
               {
                  index = table.getIndex(i);
                 
                  if (index.isUnique())
                  {
                     table.setPrimaryKey(index);
                    
                     break;
                  }
               }
            }
           
            if (s_logger.isDebugEnabled())
            {
               if (table.getPrimaryKey() != null)
               {
                  s_logger.debug("The primary key of table \"" + table.getName() +
                     "\" is \"" + table.getPrimaryKey().getName() + "\"");
               }
               else
               {
                  s_logger.debug("Table \"" + table.getName() + "\" has no primary key");
               }
            }

            rs.close();
            rs = null;
         }

         // Read the foreign keys

         nCurTable = 0;

         for (Iterator itr = schema.getTableIterator(); itr.hasNext();)
         {
            Table table = (Table)itr.next();
            String[] names = (String[])tableMap.get(table);
            Index index = null;
            boolean bIgnore = false;

            if (progress != null)
            {
               progress.progress("info.sql.schemaManager.readingForeignKeys", new Object[]{table.getName()},
                  0.70 + 0.30 * (nCurTable++ / nTableCount));
            }

            rs = dbmeta.getExportedKeys(names[0], names[1], table.getTableName());

            while (rs.next())
            {
               String sColumnName = toMetadataCase(rs.getString("FKCOLUMN_NAME"));
               String sSchemaName = rs.getString("FKTABLE_SCHEM");
               String sTableName = rs.getString("FKTABLE_NAME");
               String sIndexName = rs.getString("FK_NAME");

               Table foreignTable = schema.findTable(getFullTableName(sSchemaName, sTableName));

               if (foreignTable == null)
               {
                  continue;
               }

               sIndexName = generateIndexName(foreignTable.getTableName(), sIndexName, "FK" + (foreignTable.getIndexCount() + 1));

               if (index != null && !index.getName().equals(sIndexName))
               {
                  if (!bIgnore)
                  {
                     if (addIndex(index.getTable(), index))
                     {
                        addRelatedKey(table, index);
                        bPortable &= isPortable(index);
                     }
                  }

                  index = null;
                  bIgnore = false;
               }

               if (index == null)
               {
                  if (rs.getString("FK_NAME") == null)
                  {
                     index = new Index(sIndexName, Index.BTREE, foreignTable);
                  }
                  else
                  {
                     index = foreignTable.findIndex(sIndexName);
                    
                     if (index == null)
                     {
                        index = new Index(sIndexName, Index.BTREE, foreignTable);
                     }
                     else
                     {
                        addRelatedKey(table, index);
                        bIgnore = true;
                     }
                  }
               }

               if (s_logger.isDebugEnabled())
               {
                  s_logger.debug("Read foreign key column \"" + index.getName() + "." + sColumnName + "\"");
               }

               if (!bIgnore)
               {
                  index.setType(Index.BTREE);
                  index.setUnique(false);

                  try
                  {
                     index.addIndexColumn(new IndexColumn(index.getTable().getColumn(sColumnName),
                        table.getPrimaryKey().getIndexColumn(index.getIndexColumnCount()).isAscending()));
                  }
                  catch (MetadataException e)
                  {
                     s_logger.error("Cannot add foreign key column to index \"" + index.getName() + "\"", e);
View Full Code Here

   {
      buf.append('(');
     
      for (int i = 0; i < index.getIndexColumnCount(); ++i)
      {
         IndexColumn icol = index.getIndexColumn(i);
        
         if (i > 0)
         {
            buf.append(", ");
         }
View Full Code Here

      table.setPrimaryKey(primary);

      // reuse PrimaryKey columns since they are not modified
      for (int i = 0, nCount = srcPK.getIndexColumnCount(); i < nCount; ++i)
      {
         primary.addIndexColumn(new IndexColumn(srcPK.getIndexColumn(i).getColumn(), true));
      }

      return table;
   }
View Full Code Here

            if (index.getType() != Index.VIRTUAL && index.getType() != Index.QUERY)
            {
               for (int i = 0, n = index.getIndexColumnCount(); i < n; ++i)
               {
                  IndexColumn indexColumn = index.getIndexColumn(i);
  
                  if (indexFinal.findIndexColumn(indexColumn.getColumn().getName()) == null)
                  {
                     eh = addException(eh, new MetadataException("err.meta.upgrade.sql.extraIndexColumn",
                        new Object[]{indexColumn.getColumn().getName(), index.getName(),
                           index.getTable().getName(), m_final.getDataSource().getName()}));
                  }
               }

               for (int i = 0, n = indexFinal.getIndexColumnCount(); i < n; ++i)
               {
                  IndexColumn indexColumnFinal = indexFinal.getIndexColumn(i);
                  IndexColumn indexColumn = index.findIndexColumn(indexColumnFinal.getColumn().getName());

                  if (indexColumn == null)
                  {
                     eh = addException(eh, new MetadataException("err.meta.upgrade.sql.missingIndexColumn",
                        new Object[]{indexColumnFinal.getColumn().getName(), indexFinal.getName(),
                           indexFinal.getTable().getName(), m_final.getDataSource().getName()}));
                  }
                  else
                  {
                     if (indexColumnFinal.getOrdinal() != indexColumn.getOrdinal())
                     {
                        eh = addException(eh, new MetadataException("err.meta.upgrade.sql.indexColumnOrdinalMismatch",
                           new Object[]{Primitive.createInteger(indexColumnFinal.getOrdinal()),
                              Primitive.createInteger(indexColumn.getOrdinal()), indexColumnFinal.getColumn().getName(),
                              indexFinal.getName(), indexFinal.getTable().getName(), m_final.getDataSource().getName()}));
                     }

                     if (indexColumnFinal.isAscending() != indexColumn.isAscending())
                     {
                        eh = addException(eh, new MetadataException("err.meta.upgrade.sql.indexColumnAscendingMismatch",
                           new Object[]{Boolean.valueOf(indexColumnFinal.isAscending()),
                              Boolean.valueOf(indexColumn.isAscending()), indexColumnFinal.getColumn().getName(),
                              indexFinal.getName(), indexFinal.getTable().getName(), m_final.getDataSource().getName()}));
                     }
                  }
               }
            }
View Full Code Here

               op = query.getOrderByOperator(i - nPrefixColumnCount);
               bAscending = query.isOrderByAscending(i - nPrefixColumnCount);
            }
            else
            {
               IndexColumn indexColumn = index.getIndexColumn(i);
               Column column = indexColumn.getColumn();
               Field field = new Field(query, mapping, column, column.getValueType(),
                  m_adapter.getConverter(column.getValueType(), column),
                  m_adapter.getBind(column), false);

               op = new AttributeOperator(field);
               bAscending = indexColumn.isAscending() ^ bSortDirectionReversed;
            }

            int nOffset = buf.length();
            String sSuffix = m_adapter.appendSortPrefix(buf, op);
View Full Code Here

            column = (Column)field.getItem();
         }

         if (column != null && column.isPrimary())
         {
            IndexColumn indexColumn = ((Index)((RelationalMapping)source.getQuery()
               .getPersistenceMapping()).getObjectKey()).findIndexColumn(column);

            if (indexColumn != null && indexColumn.getOrdinal() < oid.getCount())
            {
               return oid.getValue(indexColumn.getOrdinal());
            }
         }
      }
      else
      {
View Full Code Here

TOP

Related Classes of nexj.core.meta.persistence.sql.IndexColumn

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.