Package org.apache.ddlutils.model

Examples of org.apache.ddlutils.model.IndexColumn


  }
 
  private void fillIndex(org.apache.ddlutils.model.Index i, Field field) {
    String[] columns = ClassInfo.getColumnNames(field);
    for (String string : columns) {
      IndexColumn ic = new IndexColumn(string);
      i.addColumn(ic);
    }
  }
View Full Code Here


              index.setName(indexName);
              knownIndices.put(indexName, index);
          }
 
          IndexColumn indexColumn = new IndexColumn();
 
          indexColumn.setName((String)values.get("COLUMN_NAME"));
          if (values.containsKey("ORDINAL_POSITION"))
          {
              indexColumn.setOrdinalPosition(((Short)values.get("ORDINAL_POSITION")).intValue());
          }
          index.addColumn(indexColumn);
        }
    }
View Full Code Here

                printIdentifier(getTableName(table));
                print(" (");
   
                for (int idx = 0; idx < index.getColumnCount(); idx++)
                {
                    IndexColumn idxColumn = index.getColumn(idx);
                    Column      col       = table.findColumn(idxColumn.getName());
   
                    if (col == null)
                    {
                        // would get null pointer on next line anyway, so throw exception
                        throw new ModelException("Invalid column '" + idxColumn.getName() + "' on index " + index.getName() + " for table " + table.getName());
                    }
                    if (idx > 0)
                    {
                        print(", ");
                    }
View Full Code Here

        }
        print(" (");

        for (int idx = 0; idx < index.getColumnCount(); idx++)
        {
            IndexColumn idxColumn = index.getColumn(idx);
            Column      col       = table.findColumn(idxColumn.getName());

            if (col == null)
            {
                // would get null pointer on next line anyway, so throw exception
                throw new ModelException("Invalid column '" + idxColumn.getName() + "' on index " + index.getName() + " for table " + table.getName());
            }
            if (idx > 0)
            {
                print(", ");
            }
View Full Code Here

                     index.getName());
        assertFalse(index.isUnique());
        assertEquals(1,
                     index.getColumnCount());

        IndexColumn indexColumn = index.getColumn(0);

        assertEquals("value",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        index = table.getIndex(1);

        assertNull(index.getName());
        assertFalse(index.isUnique());
        assertEquals(2,
                     index.getColumnCount());

        indexColumn = index.getColumn(0);

        assertEquals("when",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        indexColumn = index.getColumn(1);

        assertEquals("id",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        assertEquals(
            "<?xml version=\"1.0\"?>\n<!DOCTYPE database SYSTEM \"" + LocalEntityResolver.DTD_PREFIX + "\">\n" +
            "  <database name=\"test\">\n" +
            "    <table name=\"TableWidthIndex\">\n" +
View Full Code Here

                     index.getName());
        assertTrue(index.isUnique());
        assertEquals(1,
                     index.getColumnCount());

        IndexColumn indexColumn = index.getColumn(0);

        assertEquals("id",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        index = table.getIndex(1);

        assertNull(index.getName());
        assertFalse(index.isUnique());
        assertEquals(1,
                     index.getColumnCount());

        indexColumn = index.getColumn(0);

        assertEquals("when",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        assertEquals(
            "<?xml version=\"1.0\"?>\n<!DOCTYPE database SYSTEM \"" + LocalEntityResolver.DTD_PREFIX + "\">\n" +
            "  <database name=\"test\">\n" +
            "    <table name=\"TableWidthIndices\">\n" +
View Full Code Here

        assertNull(index.getName());
        assertTrue(index.isUnique());
        assertEquals(1,
                     index.getColumnCount());

        IndexColumn indexColumn = index.getColumn(0);

        assertEquals("name",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        // table B
       
        table = model.getTable(1);

        assertEquals("B",
                     table.getName());
        assertEquals("Table B",
                     table.getDescription());
        assertEquals(0, table.getAutoIncrementColumns().length);
        assertEquals(3,
                     table.getColumnCount());
        assertEquals(2,
                     table.getForeignKeyCount());
        assertEquals(1,
                     table.getIndexCount());

        column = table.getColumn(0);

        assertEquals("id",
                     column.getName());
        assertEquals("TIMESTAMP",
                     column.getType());
        assertEquals(Types.TIMESTAMP,
                     column.getTypeCode());
        assertNull(column.getSize());
        assertEquals(0,
                     column.getSizeAsInt());
        assertTrue(column.isPrimaryKey());
        assertTrue(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The primary key of table B",
                     column.getDescription());

        column = table.getColumn(1);

        assertEquals("aid",
                     column.getName());
        assertEquals("INTEGER",
                     column.getType());
        assertEquals(Types.INTEGER,
                     column.getTypeCode());
        assertNull(column.getSize());
        assertEquals(0,
                     column.getSizeAsInt());
        assertFalse(column.isPrimaryKey());
        assertFalse(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The field for the foreign key towards A",
                     column.getDescription());

        column = table.getColumn(2);

        assertEquals("cid",
                     column.getName());
        assertEquals("CHAR",
                     column.getType());
        assertEquals(Types.CHAR,
                     column.getTypeCode());
        assertEquals("32",
                     column.getSize());
        assertEquals(32,
                     column.getSizeAsInt());
        assertFalse(column.isPrimaryKey());
        assertFalse(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The field for the foreign key towards C",
                     column.getDescription());

        fk = table.getForeignKey(0);

        assertNull(fk.getName());
        assertEquals(model.getTable(0),
                     fk.getForeignTable());
        assertEquals("A",
                     fk.getForeignTableName());
        assertEquals(1,
                     fk.getReferenceCount());

        ref = fk.getFirstReference();

        assertEquals(table.getColumn(1),
                     ref.getLocalColumn());
        assertEquals("aid",
                     ref.getLocalColumnName());
        assertEquals(model.getTable(0).getColumn(0),
                     ref.getForeignColumn());
        assertEquals("id",
                     ref.getForeignColumnName());

        fk = table.getForeignKey(1);

        assertNull(fk.getName());
        assertEquals(model.getTable(2),
                     fk.getForeignTable());
        assertEquals("C",
                     fk.getForeignTableName());
        assertEquals(1,
                     fk.getReferenceCount());

        ref = fk.getFirstReference();

        assertEquals(table.getColumn(2),
                     ref.getLocalColumn());
        assertEquals("cid",
                     ref.getLocalColumnName());
        assertEquals(model.getTable(2).getColumn(0),
                     ref.getForeignColumn());
        assertEquals("id",
                     ref.getForeignColumnName());

        index = table.getIndex(0);

        assertNull(index.getName());
        assertFalse(index.isUnique());
        assertEquals(2,
                     index.getColumnCount());

        indexColumn = index.getColumn(0);

        assertEquals("aid",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        indexColumn = index.getColumn(1);

        assertEquals("cid",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        // table C

        table = model.getTable(2);

        assertEquals("C",
                     table.getName());
        assertEquals("Table C",
                     table.getDescription());
        assertEquals(0, table.getAutoIncrementColumns().length);
        assertEquals(2,
                     table.getColumnCount());
        assertEquals(0,
                     table.getForeignKeyCount());
        assertEquals(1,
                     table.getIndexCount());

        column = table.getColumn(0);

        assertEquals("id",
                     column.getName());
        assertEquals("CHAR",
                     column.getType());
        assertEquals(Types.CHAR,
                     column.getTypeCode());
        assertEquals("32",
                     column.getSize());
        assertEquals(32,
                     column.getSizeAsInt());
        assertTrue(column.isPrimaryKey());
        assertTrue(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The primary key of table C",
                     column.getDescription());

        column = table.getColumn(1);

        assertEquals("text",
                     column.getName());
        assertEquals("LONGVARCHAR",
                     column.getType());
        assertEquals(Types.LONGVARCHAR,
                     column.getTypeCode());
        assertNull(column.getSize());
        assertEquals(0,
                     column.getSizeAsInt());
        assertFalse(column.isPrimaryKey());
        assertFalse(column.isRequired());
        assertFalse(column.isAutoIncrement());
        assertNull(column.getDefaultValue());
        assertEquals("The text",
                     column.getDescription());

        index = table.getIndex(0);

        assertEquals("byText",
                     index.getName());
        assertFalse(index.isUnique());
        assertEquals(1,
                     index.getColumnCount());

        indexColumn = index.getColumn(0);

        assertEquals("text",
                     indexColumn.getName());
        assertNull(indexColumn.getSize());

        assertEquals(
            "<?xml version=\"1.0\"?>\n<!DOCTYPE database SYSTEM \"" + LocalEntityResolver.DTD_PREFIX + "\">\n" +
            "  <database name=\"test\">\n" +
            "    <table name=\"A\" description=\"Table A\">\n" +
View Full Code Here

            // --------------------------

            if ( columnDefinition.mIsUnique ) {
                UniqueIndex uniqueIndex = new UniqueIndex();
                uniqueIndex.setName("uidx_" + t.getName() + "_" + c.getName());
                uniqueIndex.addColumn(new IndexColumn(c));
                t.addIndex(uniqueIndex);
            }

            // --------------------------
            // References Constraint
View Full Code Here

TOP

Related Classes of org.apache.ddlutils.model.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.