Package org.apache.openjpa.jdbc.schema

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


        }

        // look for an existing index on these columns
        Table table = cols[0].getTable();
        Index[] idxs = table.getIndexes();
        Index exist = null;
        for (int i = 0; i < idxs.length; i++) {
            if (idxs[i].columnsMatch(cols)) {
                exist = idxs[i];
                break;
            }
        }

        // remove existing index?
        if (!_canIdx) {
            if (exist == null)
                return null;
            if (!adapt)
                throw new MetaDataException(_loc.get(prefix + "-index-exists",
                    context));
            table.removeIndex(exist);
            return null;
        }

        // if we have an existing index, merge given info into it
        if (exist != null) {
            if (_idx != null && _idx.isUnique() && !exist.isUnique()) {
                if (!adapt)
                    throw new MetaDataException(_loc.get(prefix
                        + "-index-not-unique", context));
                exist.setUnique(true);
            }
            return exist;
        }

        // if no defaults return null
        MappingRepository repos = (MappingRepository) context.getRepository();
        boolean fill = repos.getMappingDefaults().defaultMissingInfo();
        if (_idx == null && (tmplate == null || (!adapt && !fill)))
            return null;

        String name = null;
        boolean unq;
        if (_idx != null) {
            name = _idx.getName();
            unq = _idx.isUnique();
            // preserve multiple columns if they are specified in the index
            if (_idx.getColumns() != null && _idx.getColumns().length > 1)
                cols = _idx.getColumns();
        } else
            unq = tmplate.isUnique();

        // if no name provided by user info, make one
        if (name == null) {
            if (tmplate != null)
                name = tmplate.getName();
            else {
                name = cols[0].getName();
                name = repos.getDBDictionary().getValidIndexName(name, table);
            }
        }

        Index idx = table.addIndex(name);
        idx.setUnique(unq);
        idx.setColumns(cols);
        return idx;
    }
View Full Code Here


            _idx = null;
            return;
        }

        _canIdx = true;
        _idx = new Index();
        _idx.setName(idx.getName());
        _idx.setUnique(idx.isUnique());
        if (idx.getColumns() != null && idx.getColumns().length > 1)
            _idx.setColumns(idx.getColumns());
    }
View Full Code Here

    /**
     * Return the index to set on the version columns, or null if none.
     */
    public Index getIndex(Version version, Column[] cols, boolean adapt) {
        Index idx = null;
        if (cols.length > 0)
            idx = version.getMappingRepository().getMappingDefaults().
                getIndex(version, cols[0].getTable(), cols);
        return createIndex(version, null, idx, cols, adapt);
    }
View Full Code Here

            || !fm.getJoinForeignKey().isLogical())
            return null;
        if (areAllPrimaryKeyColumns(cols))
            return null;

        Index idx = new Index();
        idx.setName(getIndexName(null, table, cols));
        return idx;
    }
View Full Code Here

            || !vm.getForeignKey().isLogical())
            return null;
        if (areAllPrimaryKeyColumns(cols))
            return null;

        Index idx = new Index();
        idx.setName(getIndexName(name, table, cols));
        return idx;
    }
View Full Code Here

    }

    public Index getIndex(Version vers, Table table, Column[] cols) {
        if (!_indexVers)
            return null;
        Index idx = new Index();
        idx.setName(getIndexName(_versName, table, cols));
        return idx;
    }
View Full Code Here

    }

    public Index getIndex(Discriminator disc, Table table, Column[] cols) {
        if (!_indexDisc)
            return null;
        Index idx = new Index();
        idx.setName(getIndexName(_discName, table, cols));
        return idx;
    }
View Full Code Here

    /**
     * Return the index to set on the discriminator columns, or null if none.
     */
    public Index getIndex(Discriminator discrim, Column[] cols, boolean adapt) {
        Index idx = null;
        if (cols.length > 0)
            idx = discrim.getMappingRepository().getMappingDefaults().
                getIndex(discrim, cols[0].getTable(), cols);
        return createIndex(discrim, null, idx, cols, adapt);
    }
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

        assertTrue(table.removeForeignKey(fk));
        assertTrue(!_schema.getSchemaGroup().isNameTaken("fk"));
        assertEquals(0, table.getForeignKeys().length);

        // index testing
        Index idx = table.addIndex("idx");
        assertTrue(_schema.getSchemaGroup().isNameTaken("idx"));
        assertTrue(!table.isNameTaken("idx"));
        assertEquals(table, idx.getTable());
        Index[] idxs = table.getIndexes();
        assertEquals(1, idxs.length);
        assertEquals(idx, idxs[0]);

        assertEquals(idx, table.getIndex("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.