public final class IndexHelper
extends java.lang.Object
DMOSorter
instance appropriate to an index-driven query's
sort phrase
It is anticipated that the lists of index names returned by some of the
methods in this class will be used for purposes of serialization of
index resources via a LockManager
. Therefore, unless otherwise
noted, these lists will be sorted in ascending, alphabetical order, to
help prevent deadlocks in situations where all such indexes will be locked
by a particular context. That is, if all contexts acquiring locks on these
indexes are careful to do so in the same order, deadlocks should not occur.
Modifier and Type | Class and Description |
---|---|
private static class |
IndexHelper.EntityIndexKey
A hashable key which encapsulates a DMO entity and a boolean indicating
unique vs.
|
private static class |
IndexHelper.PropertyKey
A hashable key which encapsulates a DMO entity and property name.
|
private static class |
IndexHelper.SortKey
A hashable key which encapsulates a DMO entity and a sort phrase.
|
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<Database,IndexHelper> |
cache
Cache of instances, mapped by database
|
private Database |
database
Primary (non-dirty) database with which this helper is associated
|
private java.util.Map<IndexHelper.SortKey,java.lang.String> |
indexBySort
Map of sort clauses to index names
|
private java.util.Map<IndexHelper.EntityIndexKey,java.util.List<java.lang.String>> |
indexesByEntity
Map of entity keys to lists of all index names
|
private java.util.Map<IndexHelper.PropertyKey,java.util.List<java.lang.String>> |
indexesByProperty
Map of property names to lists of indexes containing them
|
private java.util.Map<IndexHelper.EntityIndexKey,java.util.Map<java.lang.String,java.util.List<java.lang.String>>> |
indexMapsByEntity
Map of entity keys to maps of index names to index property names
|
private static java.util.logging.Logger |
LOG
Logger
|
private java.util.Map<java.lang.String,P2JIndex> |
primaryIndexByEntity
Map of entity to primary index
|
private java.util.Map<IndexHelper.EntityIndexKey,java.util.Set<java.lang.String>> |
propsByEntity
Map of entity keys to indexed properties
|
private java.util.Map<IndexHelper.SortKey,DMOSorter> |
sorters
Map of sort clauses to
DMOSorter objects |
static java.lang.String |
WHOLE_INDEX_PREFIX
Prefix for index information string.
|
Modifier | Constructor and Description |
---|---|
private |
IndexHelper(Database database)
Private constructor.
|
Modifier and Type | Method and Description |
---|---|
static IndexHelper |
get(Database database)
Get an instance of this class for the given database.
|
java.util.Set<java.lang.String> |
getIndexedProperties(java.lang.String entity,
boolean unique)
Retrieve the set of all property names for a particular DMO entity,
which represent database columns that participate in an index on the
entity's backing table, or the subset which represent database columns
that participate in a unique index.
|
java.util.List<java.lang.String> |
getIndexesForEntity(java.lang.String entity,
boolean unique)
Retrieve a list of all index names associated with the table represented
by the given DMO entity name, or the sublist which represents unique
indexes only.
|
java.util.List<java.lang.String> |
getIndexesForProperty(java.lang.String entity,
java.lang.String property)
Retrieve a list of the names of all indexes in which the database
column associated with the given DMO property participates.
|
java.lang.String |
getIndexForSort(RecordBuffer buffer,
java.lang.String sort)
Given a sort phrase from an index-driven query, return the name of the
index represented by the sort phrase.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getIndexMapForEntity(java.lang.String entity,
boolean unique)
Retrieve a mapping of index names to their component property names, for
indexes associated with the table represented by the given DMO entity
name.
|
P2JIndex |
getPrimaryIndex(java.lang.String entity)
Retrieve primary index of given database table.
|
DMOSorter |
getSorterForSortPhrase(RecordBuffer buffer,
java.lang.String sort)
Retrieve a
DMOSorter instance which is able to sort DMO
instances according to the sort criteria specified by the given sort
phrase. |
private java.util.Set<java.lang.String> |
lookupIndexedProperties(java.lang.String entity,
boolean unique)
Collect the set of all indexed property names associated with the table
represented by the given DMO entity name.
|
private java.util.List<java.lang.String> |
lookupIndexesForDMO(java.lang.String entity,
boolean unique)
Collect a list of all index names associated with the table represented
by the given DMO entity name.
|
private java.util.List<java.lang.String> |
lookupIndexesForProperty(java.lang.String entity,
java.lang.String property)
Collect a list of the names of all indexes in which the database
column associated with the given DMO property participates.
|
private java.lang.String |
lookupIndexForSort(RecordBuffer buffer,
java.lang.String sort)
Given a sort phrase from an index-driven query, find the name of the
index represented by the sort phrase.
|
private java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
lookupIndexMapForDMO(java.lang.String entity,
boolean unique)
Generate a mapping of index names to their component property names, for
indexes associated with the table represented by the given DMO entity
name.
|
public static final java.lang.String WHOLE_INDEX_PREFIX
private static final java.util.logging.Logger LOG
private static final java.util.Map<Database,IndexHelper> cache
private final Database database
private final java.util.Map<IndexHelper.SortKey,java.lang.String> indexBySort
private final java.util.Map<IndexHelper.PropertyKey,java.util.List<java.lang.String>> indexesByProperty
private final java.util.Map<IndexHelper.SortKey,DMOSorter> sorters
DMOSorter
objectsprivate final java.util.Map<IndexHelper.EntityIndexKey,java.util.List<java.lang.String>> indexesByEntity
private final java.util.Map<java.lang.String,P2JIndex> primaryIndexByEntity
private final java.util.Map<IndexHelper.EntityIndexKey,java.util.Map<java.lang.String,java.util.List<java.lang.String>>> indexMapsByEntity
private final java.util.Map<IndexHelper.EntityIndexKey,java.util.Set<java.lang.String>> propsByEntity
private IndexHelper(Database database)
get(com.goldencode.p2j.persist.Database)
.database
- Database for which index information is needed.public static IndexHelper get(Database database)
database
- Database for which index information is needed.public java.util.List<java.lang.String> getIndexesForProperty(java.lang.String entity, java.lang.String property) throws PersistenceException
entity
- A DMO entity name which represents a database table.property
- A DMO property which represents a database column.null
.PersistenceException
- if there is any error querying index metadata from the JDBC
driver of the associated database.public java.lang.String getIndexForSort(RecordBuffer buffer, java.lang.String sort) throws PersistenceException
buffer
- Record buffer which contains information about the DMO entity
associated with the sort phrase.sort
- A sort phrase which includes one or more DMO property
references, each qualified by a DMO alias and followed by a
keyword indicating sort direction.null
if no matching index can be found.PersistenceException
- if there is any error querying index metadata from the JDBC
driver of the associated database.public P2JIndex getPrimaryIndex(java.lang.String entity) throws PersistenceException
entity
- A DMO entity name which represents a database table.PersistenceException
- if there is any error in retrieving primary index or more than one primary index
is found.public DMOSorter getSorterForSortPhrase(RecordBuffer buffer, java.lang.String sort) throws PersistenceException
DMOSorter
instance which is able to sort DMO
instances according to the sort criteria specified by the given sort
phrase.buffer
- Record buffer which contains information about the DMO entity
associated with the sort phrase.sort
- A sort phrase which includes one or more DMO property
references, each qualified by a DMO alias and followed by a
keyword indicating sort direction.PersistenceException
- if there is any error querying index metadata from the JDBC
driver of the associated database.public java.util.List<java.lang.String> getIndexesForEntity(java.lang.String entity, boolean unique) throws PersistenceException
entity
- A DMO entity name which represents a database table.unique
- If true
, only unique indexes are returned; if
false
, all indexes are returned.null
.PersistenceException
- if there is any error querying index metadata from the JDBC
driver of the associated database.public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getIndexMapForEntity(java.lang.String entity, boolean unique) throws PersistenceException
entity
- A DMO entity name which represents a database table.unique
- If true
, only unique indexes are returned; if
false
, only non-unique indexes are returned.unique
parameter. The map may
be empty, but it will never by null
. The property
names will not be wrapped in any functions. The map will
iterate in ascending alphabetical order by index name.PersistenceException
- if there is any error querying index metadata from the JDBC
driver of the associated database.public java.util.Set<java.lang.String> getIndexedProperties(java.lang.String entity, boolean unique) throws PersistenceException
Note: the returned set will not include the reserved primary
key property id
.
entity
- A DMO entity name which represents a database table.unique
- If true
, only properties associated with unique
indexes are returned; if false
, all indexed
properties are returned.null
.PersistenceException
- if there is any error querying index metadata from the JDBC
driver of the associated database.private java.util.List<java.lang.String> lookupIndexesForDMO(java.lang.String entity, boolean unique) throws PersistenceException
entity
- A DMO entity name which represents a database table.unique
- If true
, only unique indexes are returned; if
false
, all indexes are returned.null
if none are found.PersistenceException
- if there is any error querying index metadata from the JDBC
driver of the associated database.private java.util.Map<java.lang.String,java.util.List<java.lang.String>> lookupIndexMapForDMO(java.lang.String entity, boolean unique) throws PersistenceException
entity
- A DMO entity name which represents a database table.unique
- If true
, only unique indexes are returned; if
false
, only non-unique indexes are returned.unique
parameter. The map may
be empty, but it will never by null
. The property
names will not be wrapped in any functions. The map will
iterate in ascending alphabetical order by index name.PersistenceException
- if there is any error querying index metadata from the JDBC
driver of the associated database.private java.util.List<java.lang.String> lookupIndexesForProperty(java.lang.String entity, java.lang.String property) throws PersistenceException
entity
- A DMO entity name which represents a database table.property
- A DMO property which represents a database column.null
if none are found.PersistenceException
- if there is any error querying index metadata from the JDBC
driver of the associated database.private java.lang.String lookupIndexForSort(RecordBuffer buffer, java.lang.String sort) throws PersistenceException
DMOSorter
instance is created and cached by the sort clause, for
later retrieval using the
getSorterForSortPhrase(RecordBuffer, String)
method.buffer
- Record buffer which contains information about the DMO entity
associated with the sort phrase.sort
- A sort phrase which includes one or more DMO property
references, each qualified by a DMO alias and followed by a
keyword indicating sort direction.null
if no matching index can be found.PersistenceException
- if there is any error querying index metadata from the JDBC
driver of the associated database.private java.util.Set<java.lang.String> lookupIndexedProperties(java.lang.String entity, boolean unique) throws PersistenceException
Note: the returned set will not include the reserved primary
key property id
.
entity
- A DMO entity name which represents a database table.unique
- If true
, only properties associated with unique
indexes are returned; if false
, all indexed
properties are returned.null
if none are found.PersistenceException
- if there is any error querying index metadata from the JDBC
driver of the associated database.