Пример #1
0
  public void createDDL() throws SQLException, IOException {
    TableReader sourceReader = new TableReader(sourceConnection);
    TableReader destionationReader = new TableReader(destinationConnection);
    List<Index> sourceIndexes = sourceReader.getIndexes(schema, table);
    List<Index> destinationIndexes = destionationReader.getIndexes(schema, table);

    for (Index destIndex : destinationIndexes) {
      boolean found = false;
      boolean drop = false;

      if (destIndex.getName().startsWith("SYS")) {
        continue;
      }
      for (Index sourceIndex : sourceIndexes) {
        if (destIndex.getName().equalsIgnoreCase(sourceIndex.getName())) {
          if (!destIndex.getColumns().containsAll(sourceIndex.getColumns())) {
            drop = true;
          }
          found = true;
          break;
        } else if (destIndex.getColumns().size() == sourceIndex.getColumns().size()
            && destIndex.getColumns().containsAll(sourceIndex.getColumns())) {
          found = true;
          break;
        }
      }

      if (drop) {
        dropDDL(destIndex.getName());
        createIndexDDL(destIndex);
      } else if (!found) {
        createIndexDDL(destIndex);
      }
    }
  }
Пример #2
0
  private void createIndexDDL(Index index) throws IOException {
    String ddl = null;

    if (index.getType().startsWith("DOMAIN")) {
      ddl = Templates.CREATE_INDEX_DOMAIN_TEMPLATE.replace(Templates.INDEX_NAME, index.getName());
      ddl = ddl.replace(Templates.INDEX_TYPE, index.getSpecialType());
      ddl = ddl.replace(Templates.PARAMETERS, index.getParameters());
    } else {
      ddl = Templates.CREATE_INDEX_TEMPLATE.replace(Templates.INDEX_NAME, index.getName());
      if (null != index.getTableSpace())
        ddl =
            ddl.replace(
                Templates.TABLE_SPACE,
                Templates.CREATE_INDEX_TABLE_SPACE_TEMPLATE.replace(
                    Templates.TABLE_SPACE, index.getTableSpace()));
      else ddl = ddl.replace(Templates.TABLE_SPACE, "");
      ddl = ddl.replace(Templates.NEXT_EXTENT, Utils.getAsString(index.getNextExtend()));
    }
    ddl = ddl.replace(Templates.TABLE_NAME, table);
    List<String> columns = index.getColumns();
    StringBuilder builder = new StringBuilder();
    int size = columns.size();
    for (int i = 0; i < size; i++) {
      builder.append(columns.get(i));
      if (i != size - 1) builder.append(',');
      builder.append("\r\n");
    }
    ddl = ddl.replace(Templates.COLUMNS, builder.toString());
    write(ddl);
  }
Пример #3
0
 public Index addIndex(Index index) {
   Index current = (Index) indexes.get(index.getName());
   if (current != null) {
     throw new MappingException("Index " + index.getName() + " already exists!");
   }
   indexes.put(index.getName(), index);
   return index;
 }
 private static void updateStatsUndefinedResults(
     LocalizableMessageBuilder debugMessage, Index index) {
   if (!index.isTrusted()) {
     debugMessage.append(INFO_INDEX_FILTER_INDEX_NOT_TRUSTED.get(index.getName()));
   } else if (index.isRebuildRunning()) {
     debugMessage.append(INFO_INDEX_FILTER_INDEX_REBUILD_IN_PROGRESS.get(index.getName()));
   } else {
     debugMessage.append(INFO_INDEX_FILTER_INDEX_LIMIT_EXCEEDED.get(index.getName()));
   }
 }
  /**
   * add
   *
   * @param i a {@link org.opennms.netmgt.dao.db.Index} object.
   */
  public void add(Index i) {
    String lowerName = i.getName().toLowerCase();
    if (m_nameMap.containsKey(lowerName)) {
      throw new IllegalArgumentException("Index with name of '" + lowerName + "' already exists.");
    }

    m_nameMap.put(lowerName, i);

    getIndexesForTableCreateIfEmpty(i.getTable().toLowerCase()).add(i);
  }
Пример #6
0
 /**
  * * 获取高亮处理后的文件名显示串。
  *
  * @return 高亮文本串
  */
 public Spanned highlightedName() {
   String source = Index.getName(mIndex);
   StringBuffer sb = new StringBuffer();
   for (int i = 0; i < mHilite.length; i++) {
     if (mHilite[i]) {
       sb.append("<font color='#ffff00'>" + source.charAt(i) + "</font>");
     } else {
       sb.append(source.charAt(i));
     }
   }
   return Html.fromHtml(sb.toString());
 }
Пример #7
0
 protected void init2ndPassIndexNamesWithDefaults() {
   for (int i = 0; i < indexes.size(); i++) {
     Index index = indexes.get(i);
     if (index.getName() == null) {
       String indexName = "IDX_" + getTableName();
       List<Property> properties = index.getProperties();
       for (int j = 0; j < properties.size(); j++) {
         Property property = properties.get(j);
         indexName += "_" + property.getColumnName();
         if ("DESC".equalsIgnoreCase(index.getPropertiesOrder().get(j))) {
           indexName += "_DESC";
         }
       }
       // TODO can this get too long? how to shorten reliably without depending on the order (i)
       index.setName(indexName);
     }
   }
 }
Пример #8
0
  protected boolean doSetup(
      Object source,
      String database,
      String username,
      String password,
      String table,
      boolean doDelete)
      throws ClassNotFoundException, IOException, SQLException {
    try {
      Document doc = null;
      if (source instanceof String) {
        doc = this.readDocument((String) source);
      } else if (source instanceof InputStream) {
        doc = this.readDocument((InputStream) source);
      }

      // //////////////////////////////////////////////////////
      // Make sure we can connect to the database

      JDBC.loadDriver(database);
      if (this.isQuiet() == false) System.out.println("Successfully loaded the database driver.");

      m_conn = connect(database, username, password);
      if (this.isQuiet() == false) System.out.println("Successfully connected to the database.");

      Collection collTypeMaps = null;
      if (m_typeMapFile != null) {
        collTypeMaps = TypeMap.readTypeMaps(readDocument(m_typeMapFile).getFirstChild());
      } else if (m_typeMapStream != null) {
        collTypeMaps = TypeMap.readTypeMaps(readDocument(m_typeMapStream).getFirstChild());
      } else {
        collTypeMaps = TypeMap.readTypeMaps(doc.getFirstChild());
      }

      /**
       * // check to see if we're dealing with a view or a table Node dbSetupNode =
       * doc.getFirstChild(); // actually, its the first child of the main node in the schema
       *
       * <p>NodeList nodeList = dbSetupNode.getChildNodes(); for(int i=0;i < nodeList.getLength();
       * i++) { Node rootNode = nodeList.item(i);
       * if(rootNode.getNodeName().equalsIgnoreCase("table")) {
       */
      Node rootNode = doc.getFirstChild();
      Iterator iterTab = Table.getTables(rootNode, JDBC.toType(database), this).iterator();

      // /////////////////////////////////////////////////////////////////
      // Open the log file if we are supposed to log SQL statements.
      if (m_logFileName != null) {
        m_log = new FileWriter(m_logFileName, m_logAppend);
      }

      while (iterTab.hasNext() == true) {
        Table tab = (Table) iterTab.next();

        if (table != null) {
          if (!table.equals(tab.getName())) {
            continue;
          }
          if (doDelete) tab.clear();
        }

        if (this.isVerbose() == true) System.out.println("Processing Table: " + tab.getName());

        if (m_bDMLonly == false) {
          // ////////////////////////////////////////////////////////////
          // Create the Table
          try {
            // Only attempt to create the table if the table tag has columns

            if (tab.getColumns().size() > 0) {
              tab.create(collTypeMaps);

              if (this.isQuiet() == false) System.out.println("Created Table: " + tab.getName());

              this.m_lCreatedTables++;
            }
          } catch (SQLException e) {
            if (this.isQuiet() == false) {
              System.out.println("Error: " + "Cannot create table " + tab.getName());
              JDBC.printSQLException(e);
            }

            this.m_lFailedTables++;
          }

          // /////////////////////////////////////////////////////////////
          // Create the Indexes

          Iterator iterCol = tab.getIndexes().iterator();

          while (iterCol.hasNext() == true) {
            Index idx = (Index) iterCol.next();

            try {
              idx.create();

              if (this.isQuiet() == false)
                System.out.println(
                    "Created Index: "
                        + idx.getName()
                        + " for Table \'"
                        + idx.getTable().getName()
                        + '\'');

              this.m_lCreatedIndexes++;
            } catch (SQLException e) {
              if (this.isQuiet() == false) {
                System.out.println("Error: Cannot create index " + idx.getName());
                JDBC.printSQLException(e);
              }

              this.m_lFailedIndexes++;
            }
          }
        }

        // ////////////////////////////////////////////////////////////
        // Create the Data

        DataSet dataset = tab.getDataSet();

        try {
          int iRowCnt = dataset.create();

          if (this.isQuiet() == false) System.out.println("Created " + iRowCnt + " Row(s).");
        } catch (SQLException e) {
          if (this.isQuiet() == false) {
            System.out.println("Error: " + "Cannot create Row.");
            JDBC.printSQLException(e);

            if (this.isVerbose() == true) e.printStackTrace();
          }
        }
      }
      // }

      // if(rootNode.getNodeName().equalsIgnoreCase("view")) {
      // process views
      Iterator iterView = View.getViews(rootNode, JDBC.toType(database), this).iterator();
      // //////////////////////////////////////////////////
      // /////////////
      // Open the log file if we are supposed to log SQL statements.
      if (m_logFileName != null) {
        m_log = new FileWriter(m_logFileName, m_logAppend);
      }

      while (iterView.hasNext() == true) {
        View view = (View) iterView.next();

        if (this.isVerbose() == true) System.out.println("Processing view: " + view.getName());

        if (m_bDMLonly == false) {
          // //////////////////////////////////////////
          // ////////////////
          // Create the View
          try {
            view.create(collTypeMaps);

            if (this.isQuiet() == false) System.out.println("Created View: " + view.getName());

            this.m_lCreatedViews++;
          } catch (SQLException e) {
            if (this.isQuiet() == false) {
              System.out.println("Error: " + "Cannot create View.");
              JDBC.printSQLException(e);

              if (this.isVerbose() == true) e.printStackTrace();
            }
          }
        }
      }
      // }
      // }

      // ////////////////////////////////////////////////////////////
      // Print Results

      if (this.isQuiet() == false) {
        DecimalFormat fmt = new DecimalFormat("#,###");

        System.out.println();
        System.out.println(fmt.format(this.m_lCreatedTables) + " tables created succesfully.");
        System.out.println(fmt.format(this.m_lCreatedViews) + " views created succesfully.");
        System.out.println(fmt.format(this.m_lCreatedIndexes) + " indexes created successfully.");
        System.out.println(fmt.format(this.m_lFailedTables) + " tables failed to create.");
        System.out.println(fmt.format(this.m_lFailedIndexes) + " indexes failed to create.");
      }
    } catch (SAXException e) {
      e.printStackTrace();
      throw new IOException(e.getMessage());
    } finally {
      if (m_log != null) {
        try {
          m_log.close();
        } catch (Exception e) {
        }
      }

      try {
        if (m_conn != null) m_conn.close();
      } catch (SQLException e) {
      }
    }

    return true;
  }
Пример #9
0
 /**
  * 获取文件名。
  *
  * @return 文件名
  */
 public String name() {
   return Index.getName(mIndex);
 }
Пример #10
0
 /**
  * 匹配项构造函数。
  *
  * @param entry 此成功匹配的索引条目
  */
 public Match(int index) {
   mIndex = index;
   mHilite = new boolean[Index.getName(index).length()];
 }