Examples of DBIndex


Examples of org.apache.empire.db.DBIndex

            if (appendColumnDesc(c, sql, false)==false)
                continue; // Ignore and continue;
            addSeparator = true;
        }
        // Primary Key
        DBIndex pk = t.getPrimaryKey();
        if (pk != null)
        { // add the primary key
            sql.append(", PRIMARY KEY (");
            addSeparator = false;
            // columns
            DBColumn[] keyColumns = pk.getColumns();
            for (int i = 0; i < keyColumns.length; i++)
            {
                sql.append((addSeparator) ? ", " : "");
                keyColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                addSeparator = true;
            }
            sql.append(")");
        }
        sql.append(")");
        // Comment?
        String comment = t.getComment();
        if (StringUtils.isValid(comment))
        {   // Add the table comment
            sql.append(" COMMENT = '");
            sql.append(comment);
            sql.append("'");
        }
        // Create the table
        if (script.addStmt(sql) == false)
            return false;
        // Create other Indizes (except primary key)
        Iterator<DBIndex> indexes = t.getIndexes().iterator();
        while (indexes.hasNext())
        {
            DBIndex idx = indexes.next();
            if (idx == pk || idx.getType() == DBIndex.PRIMARYKEY)
                continue;

            // Cretae Index
            sql.setLength(0);
            sql.append((idx.getType() == DBIndex.UNIQUE) ? "CREATE UNIQUE INDEX " : "CREATE INDEX ");
            appendElementName(sql, idx.getName());
            sql.append(" ON ");
            t.addSQL(sql, DBExpr.CTX_FULLNAME);
            sql.append(" (");
            addSeparator = false;

            // columns
            DBColumn[] idxColumns = idx.getColumns();
            for (int i = 0; i < idxColumns.length; i++)
            {
                sql.append((addSeparator) ? ", " : "");
                idxColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                addSeparator = true;
View Full Code Here

Examples of org.apache.empire.db.DBIndex

            if (appendColumnDesc(c, sql)==false)
                continue; // Ignore and continue;
            addSeparator = true;
        }
        // Primary Key
        DBIndex pk = t.getPrimaryKey();
        if (pk != null)
        { // add the primary key
            sql.append(",\r\n CONSTRAINT ");
            appendElementName(sql, pk.getName());
            sql.append(" PRIMARY KEY (");
            addSeparator = false;
            // columns
            DBColumn[] keyColumns = pk.getColumns();
            for (int i = 0; i < keyColumns.length; i++)
            {
                sql.append((addSeparator) ? ", " : "");
                keyColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                addSeparator = true;
            }
            sql.append(")");
        }
        sql.append(")");
        // Create the table
        DBDatabase db = t.getDatabase();
        if (script.addStmt(sql) == false)
            return false;
        // Create other Indizes (except primary key)
        Iterator<DBIndex> indexes = t.getIndexes().iterator();
        while (indexes.hasNext())
        {
            DBIndex idx = indexes.next();
            if (idx == pk || idx.getType() == DBIndex.PRIMARYKEY)
                continue;

            // Cretae Index
            sql.setLength(0);
            sql.append((idx.getType() == DBIndex.UNIQUE) ? "CREATE UNIQUE INDEX " : "CREATE INDEX ");
            appendElementName(sql, idx.getName());
            sql.append(" ON ");
            t.addSQL(sql, DBExpr.CTX_FULLNAME);
            sql.append(" (");
            addSeparator = false;

            // columns
            DBColumn[] idxColumns = idx.getColumns();
            for (int i = 0; i < idxColumns.length; i++)
            {
                sql.append((addSeparator) ? ", " : "");
                idxColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                sql.append("");
View Full Code Here

Examples of org.apache.empire.db.DBIndex

            if (appendColumnDesc(c, sql)==false)
                continue; // Ignore and continue;
            addSeparator = true;
        }
        // Primary Key
        DBIndex pk = t.getPrimaryKey();
        if (pk != null)
        { // add the primary key
            sql.append(",\r\n CONSTRAINT ");
            appendElementName(sql, pk.getName());
            sql.append(" PRIMARY KEY (");
            addSeparator = false;
            // columns
            DBColumn[] keyColumns = pk.getColumns();
            for (int i = 0; i < keyColumns.length; i++)
            {
                sql.append((addSeparator) ? ", " : "");
                keyColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                addSeparator = true;
            }
            sql.append(")");
        }
        sql.append(")");
        // Create the table
        if (script.addStmt(sql) == false)
            return false;
        // Create other Indizes (except primary key)
        Iterator<DBIndex> indexes = t.getIndexes().iterator();
        while (indexes.hasNext())
        {
            DBIndex idx = indexes.next();
            if (idx == pk || idx.getType() == DBIndex.PRIMARYKEY)
                continue;

            // Cretae Index
            sql.setLength(0);
            sql.append((idx.getType() == DBIndex.UNIQUE) ? "CREATE UNIQUE INDEX " : "CREATE INDEX ");
            appendElementName(sql, idx.getName());
            sql.append(" ON ");
            t.addSQL(sql, DBExpr.CTX_FULLNAME);
            sql.append(" (");
            addSeparator = false;

            // columns
            DBColumn[] idxColumns = idx.getColumns();
            for (int i = 0; i < idxColumns.length; i++)
            {
                sql.append((addSeparator) ? ", " : "");
                idxColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                sql.append("");
View Full Code Here

Examples of org.apache.empire.db.DBIndex

            if (appendColumnDesc(c, sql, false)==false)
                continue; // Ignore and continue;
            addSeparator = true;
        }
        // Primary Key
        DBIndex pk = t.getPrimaryKey();
        if (pk != null)
        { // add the primary key
            sql.append(", PRIMARY KEY (");
            addSeparator = false;
            // columns
            DBColumn[] keyColumns = pk.getColumns();
            for (int i = 0; i < keyColumns.length; i++)
            {
                sql.append((addSeparator) ? ", " : "");
                keyColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                addSeparator = true;
            }
            sql.append(")");
        }
        sql.append(")");
        // Comment?
        String comment = t.getComment();
        if (StringUtils.isValid(comment))
        {   // Add the table comment
            sql.append(" COMMENT = '");
            sql.append(comment);
            sql.append("'");
        }
        // Create the table
        if (script.addStmt(sql) == false)
            return false;
        // Create other Indizes (except primary key)
        Iterator<DBIndex> indexes = t.getIndexes().iterator();
        while (indexes.hasNext())
        {
            DBIndex idx = indexes.next();
            if (idx == pk || idx.getType() == DBIndex.PRIMARYKEY)
                continue;

            // Cretae Index
            sql.setLength(0);
            sql.append((idx.getType() == DBIndex.UNIQUE) ? "CREATE UNIQUE INDEX " : "CREATE INDEX ");
            appendElementName(sql, idx.getName());
            sql.append(" ON ");
            t.addSQL(sql, DBExpr.CTX_FULLNAME);
            sql.append(" (");
            addSeparator = false;

            // columns
            DBColumn[] idxColumns = idx.getColumns();
            for (int i = 0; i < idxColumns.length; i++)
            {
                sql.append((addSeparator) ? ", " : "");
                idxColumns[i].addSQL(sql, DBExpr.CTX_NAME);
                addSeparator = true;
View Full Code Here

Examples of org.databene.jdbacl.model.DBIndex

  @Override
  protected int searchAndProcessObjectSimilarTo(DBIndex originalIndex, List<DBIndex> candidates, CompositeStructuralChange<?> ownerChange) {
    String[] searchedColumnNames = originalIndex.getColumnNames();
    for (int i = 0; i < candidates.size(); i++) {
      DBIndex candidate = candidates.get(i);
      String[] candidateColumnNames = candidate.getColumnNames();
      if (Arrays.equals(searchedColumnNames, candidateColumnNames)) {
        processRenamed(originalIndex, candidate, ownerChange);
        return i;
      }
    }
    for (int i = 0; i < candidates.size(); i++) {
      DBIndex candidate = candidates.get(i);
      String[] candidateColumnNames = candidate.getColumnNames();
      if (ArrayUtil.equalsIgnoreOrder(searchedColumnNames, candidateColumnNames)) {
        processRenamed(originalIndex, candidate, ownerChange);
        if (!originalIndex.isNameDeterministic() || !candidate.isNameDeterministic())
          ownerChange.addSubChange(new Rename<DBIndex>(originalIndex, candidate.getName()));
        return i;
      }
    }
    return -1;
  }
View Full Code Here

Examples of org.databene.jdbacl.model.DBIndex

  @Test
  public void testUnchanged() {
    // given a table of which the index has not changed
    DBTable table = createTableWithColumns("tbl", 3);
    DBIndex index1 = new DBNonUniqueIndex("idx", true, table, "col1");
    DBIndex index2 = new DBNonUniqueIndex("idx", true, table, "col1");
    // when performing a comparison
    TableChange tableChange = new TableChange(table, null);
    new IndexComparator(new ComparisonConfig("db1", "db2", null)).compareObjects(index1, index2, tableChange);
    // then the result must be empty
    System.out.println(tableChange);
View Full Code Here

Examples of org.databene.jdbacl.model.DBIndex

  @Test
  public void testIndexMadeUnique() {
    // given an index which only changed by becoming unique
    DBTable table = createTableWithColumns("tbl", 3);
    DBIndex index1 = new DBNonUniqueIndex("idx", true, table, "col1");
    DBIndex index2 = new DBUniqueIndex("idx", true, new DBUniqueConstraint(table, "uk1", false, "col1"));
    TableChange tableChange = new TableChange(table, null);
    // when performing a comparison
    new IndexComparator(config).compareObjects(index1, index2, tableChange);
    // then the result must be an IndexUniquenessChange
    System.out.println(tableChange);
View Full Code Here

Examples of org.databene.jdbacl.model.DBIndex

  @Test
  public void testIndexMadeNonUnique() {
    // given an index which was unique before but is not now
    DBTable table = createTableWithColumns("tbl", 3);
    DBIndex index1 = new DBUniqueIndex("idx", true, new DBUniqueConstraint(table, "uk1", false, "col1"));
    DBIndex index2 = new DBNonUniqueIndex("idx", true, table, "col1");
    TableChange tableChange = new TableChange(table, null);
    // when performing a comparison
    new IndexComparator(config).compareObjects(index1, index2, tableChange);
    // then the result must be an IndexUniquenessChange
    System.out.println(tableChange);
View Full Code Here

Examples of org.databene.jdbacl.model.DBIndex

  @Test
  public void testColumnOrderChanged() {
    // given a table with an index of which the column order changed
    DBTable table = createTableWithColumns("tbl", 2);
    DBIndex index1 = new DBNonUniqueIndex("idx", true, table, "col1", "col2");
    DBIndex index2 = new DBNonUniqueIndex("idx", true, table, "col2", "col1");
    TableChange tableChange = new TableChange(table, null);
    // when performing a comparison
    new IndexComparator(config).compareObjects(index1, index2, tableChange);
    // then the result must be a ColumnOrderChange
    System.out.println(tableChange);
View Full Code Here

Examples of org.databene.jdbacl.model.DBIndex

  @Test
  public void testSingleIndexColumnReplaced() {
    // given an index consisting of exactly one column which was replaced in a newer index version
    DBTable table = createTableWithColumns("tbl", 2);
    DBIndex index1 = new DBNonUniqueIndex("idx", true, table, "col1");
    DBIndex index2 = new DBNonUniqueIndex("idx", true, table, "col2");
    TableChange tableChange = new TableChange(table, null);
    // when performing a comparison
    new IndexComparator(config).compareObjects(index1, index2, tableChange);
    // then the result must be deletion of the former index version and creation of the new one
    System.out.println(tableChange);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.