Package org.apache.openjpa.jdbc.schema

Examples of org.apache.openjpa.jdbc.schema.Index


        Column c1 = table.addColumn("c1");
        Column c2 = table.addColumn("c2");
        Table table2 = _schema.addTable("table2");
        Column c3 = table2.addColumn("c3");

        Index idx = table.addIndex("idx");
        try {
            idx.addColumn(c3);
            fail("Allowed addition of column of another table.");
        } catch (RuntimeException re) {
        }

        Column[] cols = idx.getColumns();
        assertEquals(0, cols.length);

        idx.addColumn(c1);
        idx.addColumn(c2);
        cols = idx.getColumns();
        assertEquals(2, cols.length);
        assertEquals(c1, cols[0]);
        assertEquals(c2, cols[1]);

        assertTrue(idx.removeColumn(c1));
        cols = idx.getColumns();
        assertEquals(1, cols.length);
        assertEquals(c2, cols[0]);
        assertTrue(idx.removeColumn(c2));
        cols = idx.getColumns();
        assertEquals(0, cols.length);

        assertTrue(!idx.isUnique());
        idx.setUnique(true);
        assertTrue(idx.isUnique());
    }
View Full Code Here


        Table table = _schema.addTable("table");
        Column c1 = table.addColumn("c1");
        Column c2 = table.addColumn("c2");
        PrimaryKey pk = table.addPrimaryKey("pk");
        pk.addColumn(c1);
        Index idx1 = table.addIndex("idx1");
        idx1.addColumn(c1);
        Index idx2 = table.addIndex("idx2");
        idx2.addColumn(c1);
        idx2.addColumn(c2);

        Table table2 = _schema.addTable("table2");
        Column c3 = table2.addColumn("c3");
        Column c4 = table2.addColumn("c4");
        pk = table2.addPrimaryKey("pk2");
        pk.addColumn(c3);
        ForeignKey fk = table.addForeignKey("fk");
        fk.join(c1, c3);

        table.removeColumn(c1);
        assertNull(table.getPrimaryKey());
        assertNull(table.getIndex("idx1"));
        assertEquals(1, idx2.getColumns().length);
        assertEquals(0, table.getForeignKeys().length);
    }
View Full Code Here

    /**
     * Test that indexes are resolved correctly.
     */
    public void testIndexParsing() {
        Table table = _group.getSchema("SCHEMA1").getTable("TABLE1");
        Index idx = table.getIndex("IDX1");
        assertNotNull(idx);
        assertTrue(idx.isUnique());
        assertEquals(1, idx.getColumns().length);
        assertEquals(table.getColumn("COL2"), idx.getColumns()[0]);
       
        table = _group.getSchema("SCHEMA2").getTable("TABLE2");
        idx = table.getIndex("IDX2");
        assertNotNull(idx);
        assertTrue(!idx.isUnique());
        assertEquals(2, idx.getColumns().length);
        assertEquals(table.getColumn("COL1"), idx.getColumns()[0]);
        assertEquals(table.getColumn("COL2"), idx.getColumns()[1]);
    }
View Full Code Here

    /**
     * Create a new index from the information in the schema metadata.
     */
    protected Index newIndex(ResultSet idxMeta)
        throws SQLException {
        Index idx = new Index();
        idx.setSchemaName(idxMeta.getString("TABLE_SCHEM"));
        idx.setTableName(idxMeta.getString("TABLE_NAME"));
        idx.setColumnName(idxMeta.getString("COLUMN_NAME"));
        idx.setName(idxMeta.getString("INDEX_NAME"));
        idx.setUnique(!idxMeta.getBoolean("NON_UNIQUE"));
        return idx;
    }
View Full Code Here

    /**
     * Create a new index from the information in the schema metadata.
     */
    protected Index newIndex(ResultSet idxMeta)
        throws SQLException {
        Index idx = new Index();
        idx.setSchemaName(idxMeta.getString("TABLE_SCHEM"));
        idx.setTableName(idxMeta.getString("TABLE_NAME"));
        idx.setColumnName(idxMeta.getString("COLUMN_NAME"));
        idx.setName(idxMeta.getString("INDEX_NAME"));
        idx.setUnique(!idxMeta.getBoolean("NON_UNIQUE"));
        return idx;
    }
View Full Code Here

        return pk;
    }

    public Index newIndex(ResultSet idxMeta)
        throws SQLException {
        Index idx = super.newIndex(idxMeta);
        if (swapSchemaAndCatalog)
            idx.setSchemaName(idxMeta.getString("TABLE_CAT"));
        return idx;
    }
View Full Code Here

            Column pkColumn) {
        if (isDB2ZOSV8xOrLater()) {
            // build the index for the sequence tables
            // the index name will the fully qualified table name + _IDX
            Table tab = schema.getTable(table);
            Index idx = tab.addIndex(tab.getFullName() + "_IDX");
            idx.setUnique(true);
            idx.addColumn(pkColumn);
        }
    }
View Full Code Here

    /**
     * Create a new index from the information in the schema metadata.
     */
    protected Index newIndex(ResultSet idxMeta)
        throws SQLException {
        Index idx = new Index();
        idx.setSchemaIdentifier(fromDBName(idxMeta.getString("TABLE_SCHEM"), DBIdentifierType.SCHEMA));
        idx.setTableIdentifier(fromDBName(idxMeta.getString("TABLE_NAME"), DBIdentifierType.TABLE));
        idx.setColumnIdentifier(fromDBName(idxMeta.getString("COLUMN_NAME"), DBIdentifierType.COLUMN));
        idx.setIdentifier(fromDBName(idxMeta.getString("INDEX_NAME"), DBIdentifierType.INDEX));
        idx.setUnique(!idxMeta.getBoolean("NON_UNIQUE"));
        return idx;
    }
View Full Code Here

            // the index name will be the fully qualified table name + _IDX
            Table tab = schema.getTable(table);
            DBIdentifier fullIdxId = tab.getFullIdentifier().clone();
            DBIdentifier unQualifiedName = DBIdentifier.append(fullIdxId.getUnqualifiedName(), "IDX");
            fullIdxId.setName(getValidIndexName(unQualifiedName, tab));
            Index idx = tab.addIndex(fullIdxId);
            idx.setUnique(true);
            idx.addColumn(pkColumn);
        }
    }
View Full Code Here

    /**
     * Create a new index from the information in the schema metadata.
     */
    protected Index newIndex(ResultSet idxMeta)
        throws SQLException {
        Index idx = new Index();
        idx.setSchemaName(idxMeta.getString("TABLE_SCHEM"));
        idx.setTableName(idxMeta.getString("TABLE_NAME"));
        idx.setColumnName(idxMeta.getString("COLUMN_NAME"));
        idx.setName(idxMeta.getString("INDEX_NAME"));
        idx.setUnique(!idxMeta.getBoolean("NON_UNIQUE"));
        return idx;
    }
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.schema.Index

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.