public final class P2JIndex
extends java.lang.Object
An index is described at two levels:
This class contains several static convenience methods:
normalizeUniqueIndexes(java.util.List<com.goldencode.p2j.persist.P2JIndex>)
: Given a list of indexes for the
same table, this method identifies the minimal set of unique indexes
which define the least common denominator, unique indexes for a
table. It also normalizes any index which contains all of the
components of any of these by marking it as unique.
nonRedundantIndexes(java.util.List<com.goldencode.p2j.persist.P2JIndex>)
: Given a list of indexes for the same
table, this method identifies the sub-list of indexes which are not
redundant with one another. For our purposes here, an index is
considered redundant with another, if both indexes have the same
number of components, where each component appears in the same order
and has the same name as its counterpart.
Modifier and Type | Field and Description |
---|---|
private java.util.List<P2JIndexComponent> |
components
List of index components
|
private java.lang.String |
name
Name of index
|
private boolean |
primary
Is this the primary index for its table?
|
private java.lang.String |
table
Name of table with which index is associated
|
private boolean |
unique
Does this index define a unique constraint for its table?
|
private boolean |
word
Is this a word index?
|
Constructor and Description |
---|
P2JIndex(P2JIndex index)
Copy constructor.
|
P2JIndex(java.lang.String table,
java.lang.String name,
boolean unique)
Convenience constructor.
|
P2JIndex(java.lang.String table,
java.lang.String name,
boolean unique,
boolean primary,
boolean word)
Convenience constructor.
|
Modifier and Type | Method and Description |
---|---|
P2JIndexComponent |
addComponent(java.lang.String name)
Add an index component to the index definition.
|
P2JIndexComponent |
addComponent(java.lang.String name,
boolean ignoreCase)
Add an index component to the index definition.
|
P2JIndexComponent |
addComponent(java.lang.String name,
boolean descending,
boolean isChar,
boolean ignoreCase,
boolean abbreviated)
Add an index component to the index definition.
|
void |
compact()
Reclaim a bit of memory once all components have been added and this object will no longer
be changed.
|
java.util.Iterator<P2JIndexComponent> |
components()
Get an iterator on all
P2JIndexComponent s in this index. |
java.util.Iterator<P2JIndexComponent> |
components(boolean omitTrailingPK)
Get an iterator on the
P2JIndexComponent s in this index, optionally omitting a
trailing primary key component, if present and if the index is non-unique. |
private boolean |
containsAll(P2JIndex index)
Indicate whether this index contains all of the components of the
specified index.
|
boolean |
equals(java.lang.Object o)
Implement a very loose test for equivalence, whereby
o is
considered equivalent to this object as long as both instances contain
exactly the same set of component names, in the same order. |
P2JIndexComponent |
getComponent(int position)
Get the index component at the specified position.
|
java.util.List<P2JIndexComponent> |
getLeadingComponents(int size)
Return up to
size leading components of this index. |
java.lang.String |
getName()
Get name of this index.
|
java.util.LinkedHashSet<java.lang.String> |
getNameSet(P2JDialect dialect)
Return the set of index component names for this index.
|
java.lang.String |
getOrderByClause(Database database,
java.lang.String dmoAlias,
java.lang.Class dmoClass)
Get order by clause for given index of database.
|
java.lang.String |
getTable()
Get table name associated with this index.
|
int |
hashCode()
Overridden implementation to ensure consistency with our specialized
equals(java.lang.Object) method implementation. |
boolean |
isPrimary()
Indicate whether this index is the primary index for its table (only
meaningful for Progress indexes).
|
boolean |
isUnique()
Indicate whether this index is unique.
|
boolean |
isWord()
Indicate whether this index is a word index (only meaningful for
Progress indexes).
|
boolean |
leadsWith(P2JIndex index)
Test whether this index leads with components of the same name as the
specified index.
|
static void |
main(java.lang.String[] args)
Test harness.
|
static java.util.List<P2JIndex> |
nonRedundantIndexes(java.util.List<P2JIndex> indexes)
Given a list of index descriptors, assemble a list of those which are
not redundant with one another.
|
static java.util.List<P2JIndex> |
normalizeUniqueIndexes(java.util.List<P2JIndex> indexes)
Given a list of indexes, identify the minimal set of unique indexes
which define the least common denominator, unique constraints for a
table.
|
(package private) void |
setTable(java.lang.String table)
Set the table with which this index is associated.
|
(package private) void |
setUnique(boolean unique)
Set the unique flag within this index.
|
int |
size()
Get the number of components in this index.
|
java.lang.String |
toString()
Get a string representation of the internal state of this object,
primarily for debugging purposes.
|
private final java.lang.String name
private final boolean primary
private final boolean word
private final java.util.List<P2JIndexComponent> components
private java.lang.String table
private boolean unique
public P2JIndex(java.lang.String table, java.lang.String name, boolean unique)
table
- Name of the table with which the index is associated.name
- Index name.unique
- true
if this index defines a unique constraint
for its table, else false
.public P2JIndex(java.lang.String table, java.lang.String name, boolean unique, boolean primary, boolean word)
table
- Name of the table with which the index is associated.name
- Index name.unique
- true
if this index defines a unique constraint
for its table, else false
.primary
- true
if this index is the primary index for its
table, else false
.word
- true
if this index is a word index, else
false
.public P2JIndex(P2JIndex index)
index
- Instance to copy.public static java.util.List<P2JIndex> normalizeUniqueIndexes(java.util.List<P2JIndex> indexes)
Conversely, if Index 2 and Index 3 are not explicitly defined as being unique in a Progress schema, they are nevertheless implicitly unique because they include column A, which requires each tuple to contain a unique value for column A. Thus, as a useful side effect, this method normalizes such indexes by marking them unique, regardless of whether the unique flag was applied in the originating Progress schema.
indexes
- A list of indexes for a common table.java.lang.IllegalArgumentException
- if indexes
contains index descriptors for
different tables.public static java.util.List<P2JIndex> nonRedundantIndexes(java.util.List<P2JIndex> indexes)
indexes
- List of indexes which contain possible redundancies.indexes
which contains no redundancies.public java.lang.String getTable()
public java.lang.String getName()
public boolean isUnique()
true
if unique, else false
.public boolean isPrimary()
true
if primary, else false
.public boolean isWord()
true
if a word index, else false
.public P2JIndexComponent addComponent(java.lang.String name)
false
.name
- Name of the index field which defines this index component.P2JIndexComponent
object.public P2JIndexComponent addComponent(java.lang.String name, boolean ignoreCase)
false
, and assumes that the component
is a character type, since ignoreCase
can go either way.name
- Name of the index field which defines this index component.ignoreCase
- true
if this component represents a character
field AND case is ignored when sorting index, else
false
.P2JIndexComponent
object.public P2JIndexComponent addComponent(java.lang.String name, boolean descending, boolean isChar, boolean ignoreCase, boolean abbreviated)
name
- Name of the index field which defines this index component.descending
- true
if this component sorts naturally in
descending order; false
to sort in ascending
order.isChar
- true
if this component represents a character
field.ignoreCase
- true
if this component represents a character
field AND case is ignored when sorting index, else
false
.abbreviated
- true
if this component is abbreviated, else
false
.P2JIndexComponent
object.public int size()
public void compact()
public P2JIndexComponent getComponent(int position)
position
- 0-based position of the desired index component.position
.java.lang.ArrayIndexOutOfBoundsException
- if position
is invalid.public java.util.Iterator<P2JIndexComponent> components()
P2JIndexComponent
s in this index.public java.util.Iterator<P2JIndexComponent> components(boolean omitTrailingPK)
P2JIndexComponent
s in this index, optionally omitting a
trailing primary key component, if present and if the index is non-unique.omitTrailingPK
- true
to omit the trailing primary key component, if present and the
index is non-unique; else false
.public java.util.List<P2JIndexComponent> getLeadingComponents(int size)
size
leading components of this index. If
size
is larger than the number of components in the index,
all components are returned. The order of components is preserved in
the returned list.size
- Number of leading components to return.size
components of the
index.public java.lang.String getOrderByClause(Database database, java.lang.String dmoAlias, java.lang.Class dmoClass)
database
- Database.dmoAlias
- Alias qualifier which represents DMO in sort phrase.dmoClass
- DMO implementation class.public boolean leadsWith(P2JIndex index)
index
- Index with which to compare this index' components.true
if and only if this index contains all
of the components of index
as its leading
components, and these components appear in the same order in
both indexes; false
otherwise.public java.util.LinkedHashSet<java.lang.String> getNameSet(P2JDialect dialect)
dialect
- Optional P2J database dialect.
public boolean equals(java.lang.Object o)
o
is
considered equivalent to this object as long as both instances contain
exactly the same set of component names, in the same order. Table name,
index name, and component sort direction and abbreviation support are
ignored for this test.equals
in class java.lang.Object
o
- An object instance, presumably a P2JIndex
object,
to test for equivalence with this object.true
if o
tests as equivalent to
this object, using the criteria specified above, else
false
.public int hashCode()
equals(java.lang.Object)
method implementation. Note that only the index
component names are taken into account; all other index and index
component data is ignored for purposes of this calculation.hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
void setTable(java.lang.String table)
table
- Name of table.void setUnique(boolean unique)
unique
- true
to indicate that this index is unique;
false
to indicate it is not.private boolean containsAll(P2JIndex index)
index
- Index whose components are checked against those in this
index.true
if this object contains all components of
index
; else false
.public static void main(java.lang.String[] args)
args
- Not used.