Package org.apache.openjpa.jdbc.schema

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


            || !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

    /**
     * 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

        }

        // 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;

        DBIdentifier name = DBIdentifier.NULL;
        boolean unq;
        if (_idx != null) {
            name = _idx.getIdentifier();
            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 (DBIdentifier.isNull(name)) {
            if (tmplate != null)
                name = tmplate.getIdentifier();
            else {
                name = cols[0].getIdentifier();
                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.setIdentifier(idx.getIdentifier());
        _idx.setUnique(idx.isUnique());
        if (idx.getColumns() != null && idx.getColumns().length > 1)
            _idx.setColumns(idx.getColumns());
    }
View Full Code Here

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

        Index idx = new Index();
        idx.setIdentifier(getIndexName(DBIdentifier.NULL, table, cols));
        return idx;
    }
View Full Code Here

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

        Index idx = new Index();
        idx.setIdentifier(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.setIdentifier(getIndexName(_versName, table, cols));
        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.