net.sf.farrago.catalog
Class FarragoCatalogUtil

java.lang.Object
  extended by net.sf.farrago.catalog.FarragoCatalogUtil

public abstract class FarragoCatalogUtil
extends Object

Static utilities for accessing the Farrago catalog.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/catalog/FarragoCatalogUtil.java#59 $
Author:
John V. Sichi

Nested Class Summary
static class FarragoCatalogUtil.BackupData
          Helper class used to represent backup information stored in the backup catalog.
private static class FarragoCatalogUtil.RowCountStat
          Helper class used to represent a specific type of row count statistic
private static class FarragoCatalogUtil.RowCountStatType
          Enumeration of the different type of row count statistics
 
Constructor Summary
FarragoCatalogUtil()
           
 
Method Summary
private static void addKeyCols(List<FemAbstractColumn> keyCols, BitSet keys)
           
private static void addNewPendingRestoreRecord(FarragoRepos repos, BackupTypeEnum type)
           
static void addPendingRestore(FarragoRepos repos)
          Adds or updates records in the system backup catalog, indicating that a partial restore has been completed.
static void addPendingSystemBackup(FarragoRepos repos, String type, Long csn, String startTime)
          Adds new records to the system backup catalog corresponding to a pending backup.
static FemRecoveryReference createRecoveryReference(FarragoRepos repos, RecoveryType recoveryType, CwmModelElement modelElement)
          Creates a new recovery reference for a recoverable action on an object.
static String createTimestamp()
          Creates a timestamp reflecting the current time
static
<OutT extends CwmModelElement,AskT extends OutT>
void
filterTypedModelElements(Collection<? extends CwmModelElement> inCollection, Collection<OutT> outCollection, Class<AskT> type)
          Filters a collection for all CwmModelElements of a given type.
static void generateConstraintIndexName(FarragoRepos repos, FemAbstractUniqueConstraint constraint, CwmSqlindex index)
          Sets the generated name for an index used to implement a constraint.
static void generateConstraintName(FarragoRepos repos, FemAbstractUniqueConstraint constraint)
          Sets the generated name for an anonymous constraint.
private static String generateUniqueConstraintColumnList(FemAbstractUniqueConstraint constraint)
           
static FemAuthId getAuthIdByName(FarragoRepos repos, String authName)
          Finds the FemAuthId for a specified Authorization name.
static FemLocalIndex getClusteredIndex(FarragoRepos repos, CwmClass table)
          Finds the clustered index storing a table's data.
static List<FemLocalIndex> getClusteredIndexes(FarragoRepos repos, CwmClass table)
          Finds all clustered indexes storing a table's data.
static List<FarragoCatalogUtil.BackupData> getCurrentBackupData(FarragoRepos repos)
          Retrieves current backup data stored in the catalog.
static FemLocalIndex getDeletionIndex(FarragoRepos repos, CwmClass table)
          Returns the index corresponding to the internal deletion index
static FemColumnHistogram getHistogram(FemAbstractColumn column, Timestamp labelTimestamp)
          Retrieves the histogram for a column based on a label setting.
static FemColumnHistogram getHistogramForUpdate(FarragoRepos repos, FemAbstractColumn column, boolean createNewHistogram)
          Determines which histogram record should be updated.
static CwmTable getIndexTable(CwmSqlindex index)
          Gets the table on which an index is defined.
static FemLocalTable getIndexTable(FemLocalIndex index)
          Gets the FemLocalTable on which a FemLocalIndex is defined.
static String getJarUrl(FemJar femJar)
          Returns the URL for a jar with all properties expanded.
private static List<Timestamp> getLabelBounds(FemLabel referenceLabel, FarragoRepos repos)
          Retrieves the creation timestamp of the labels that bound a specified label.
private static Timestamp getMaxTimestamp(FemAbstractColumnSet table, FemRowCountStatistics stats)
          Returns the max of the dml and analyze timestamps stored in a row count statistics record.
static
<T extends CwmModelElement>
T
getModelElementByName(Collection<T> collection, String name)
          Searches a collection of CwmModelElements (or a subtype) by name.
static
<T extends CwmModelElement>
T
getModelElementByNameAndType(Collection<? extends CwmModelElement> collection, String name, Class<T> clazz)
          Searches a collection for a CwmModelElement by name and type.
static CwmModelElement getModelElementByNameAndType(Collection collection, String name, RefClass type)
          Deprecated. use typesafe version instead
static Timestamp getNewestLabelCreationTimestamp(FarragoRepos repos)
          Retrieves the creation timestamp of the most recently created label stored in the catalog.
static Long getOldestLabelCsn(FarragoRepos repos)
          Retrieves the csn of the oldest label stored in the catalog.
static Long getPageCount(FemLocalIndex index, Timestamp labelTimestamp)
          Retrieves the page count statistic for a local index, taking into consideration the current label setting.
static FemPrimaryKeyConstraint getPrimaryKey(CwmClassifier table)
          Finds the primary key for a table.
static SqlIdentifier getQualifiedName(CwmModelElement element)
          Constructs a fully qualified name for an object.
static FemRole getRoleByName(FarragoRepos repos, String roleName)
          Looks up a role by name in a catalog.
static FemRoutine getRoutineForOrdering(FemUserDefinedOrdering udo)
          Gets the routine which implements a particular user-defined ordering, or null if the ordering does not invoke a routine.
static int getRoutineParamCount(FemRoutine routine)
          Calculates the number of parameters expected by a routine.
static void getRowCounts(FemAbstractColumnSet table, Timestamp labelTimestamp, Long[] rowCounts)
          Retrieves the current and deleted row counts for an abstract column set, optionally based on a label setting.
static FemLocalSchema getSchemaByName(CwmCatalog catalog, String schemaName)
          Looks up a schema by name in a catalog.
static Properties getStorageOptionsAsProperties(FarragoRepos repos, FemElementWithStorageOptions element)
          Extracts the storage options for an element into a Properties.
static List<CwmStructuralFeature> getStructuralFeatures(CwmClassifier classifier)
          Returns a collection of just the structural features of a classifier, hiding other features such as operations.
static SqlAccessType getTableAllowedAccess(CwmNamedColumnSet table)
          Determines the allowed access for a table
static Collection<FemLocalIndex> getTableIndexes(FarragoRepos repos, CwmClass table)
          Gets the collection of indexes spanning a table.
static List<FemLocalIndex> getUnclusteredIndexes(FarragoRepos repos, CwmClass table)
          Finds all unclustered indexes storing a table's data.
static BitSet getUniqueKeyCols(CwmClassifier table)
          Returns a bitmap with bits set for any column from a table that is part of either a primary key or a unique constraint
static List<FemUniqueKeyConstraint> getUniqueKeyConstraints(CwmClassifier table)
          Finds the unique key constraints for a table.
static FemUser getUserByName(FarragoRepos repos, String userName)
          Looks up a user by name in a catalog.
static boolean hasUniqueKey(CwmClassifier table)
          Determines whether a table contains a unique key
static
<T extends CwmModelElement>
void
indexModelElementsByName(Collection<T> inCollection, Map<String,T> outMap)
          Indexes a collection of model elements by name.
static void initializeCatalog(FarragoRepos repos, CwmCatalog catalog)
          Sets default attributes for a new catalog instance.
static boolean isColumnNullable(FarragoRepos repos, CwmColumn column)
          Determines whether a column may contain null values.
static boolean isDeletionIndex(FemLocalIndex index)
          Determines whether an index implements an internal deletion index.
static boolean isIndexPrimaryKey(FemLocalIndex index)
          Determines whether an index implements its table's primary key.
static boolean isIndexTemporary(CwmSqlindex index)
          Determines whether an index is temporary.
static boolean isIndexUnique(FemLocalIndex index)
          Determines whether an index implements either a primary key or a unique constraint
static boolean isRoutineConstructor(FemRoutine routine)
          Determines whether a routine is a constructor method.
static boolean isRoutineMethod(FemRoutine routine)
          Determines whether a routine is a method.
static boolean isTableFunction(FemRoutine routine)
          Determines whether a UDF has a RETURNS TABLE clause.
static FemGrant newCreationGrant(FarragoRepos repos, FemAuthId grantorAuthId, FemAuthId granteeAuthId, CwmModelElement grantedObject)
          Creates a new grant representing ownership of an object by its creator.
static FemGrant newCreationGrant(FarragoRepos repos, String grantorName, String granteeName, CwmModelElement grantedObject)
          Creates a new grant representing ownership of an object by its creator.
static FemGrant newElementGrant(FarragoRepos repos, FemAuthId grantorAuthId, FemAuthId granteeAuthId, CwmModelElement grantedObject)
          Create a new grant for an element, with AuthId's specified as repository objects.
static FemGrant newElementGrant(FarragoRepos repos, String grantorName, String granteeName, CwmModelElement grantedObject)
          Creates a grant on a specified repos element, with AuthId's specified as strings.
static FemGrant newRoleGrant(FarragoRepos repos, String grantorName, String granteeName, String roleName)
          Creates a new grant on a ROLE with specified role name and associate it to the grantor and grantee auth ids respectively.
static void removeObsoleteStatistics(FemLabel label, FarragoRepos repos, boolean usePreviewRefDelete)
           
private static
<ParentType extends CwmModelElement>
void
removeObsoleteStatisticsFromTable(FarragoRepos repos, Collection<ParentType> parentList, Method statsGetter, Method timestampGetter, Timestamp lowerBound, Timestamp upperBound, boolean onlyLabel, boolean usePreviewRefDelete)
          Removes statistics in between 2 timestamp boundaries, provided the stat is not the only remaining statistic record within the timestamp range.
static void resetRowCounts(FemAbstractColumnSet table)
          Deprecated.  
static void resetRowCounts(FemAbstractColumnSet table, FarragoRepos repos)
          Resets the row counts for a table, creating new row count stat records, as needed.
private static void setNewRowCounts(FemAbstractColumnSet table, FemRowCountStatistics rowCountStats, List<FarragoCatalogUtil.RowCountStat> rowCounts)
          Sets various row counts for an abstract column set.
static void setRoutineSpecification(FarragoRepos repos, FemRoutine routine, FemUserDefinedType typeDef)
          Sets the specification for a routine.
private static boolean timestampInRange(Timestamp lowerBound, Timestamp upperBound, Timestamp timestamp)
          Determines if a specified timestamp is within 2 bounds.
static FemSqltypedElement toFemSqltypedElement(FemAbstractTypedElement element)
          Casts a FemAbstractTypedElement to the FemSqltypedElement interface via a proxy.
static String uniquifyGeneratedName(FarragoRepos repos, RefObject refObj, String name)
          Generated names are normally unique by construction.
static void updateAnnotatedElement(FemAnnotatedElement annotatedElement, String timestamp, boolean isNew)
          Updates system-maintained attributes of an object.
static void updateHistogram(FarragoRepos repos, FemAbstractColumn column, Long distinctValues, boolean distinctValuesEstimated, float samplePercent, long sampleSize, int barCount, long rowsPerBar, long rowsLastBar, List<FemColumnHistogramBar> bars)
           
static void updatePageCount(FemLocalIndex index, Long pageCount)
          Deprecated.  
static void updatePageCount(FemLocalIndex index, Long pageCount, FarragoRepos repos)
          Updates the page count statistic for a local index, creating new index stat records as needed.
static boolean updatePendingBackupData(FarragoRepos repos, boolean backupSucceeded, boolean setEndTimestamp)
          Updates the system backup catalog data depending on whether the last pending backup (if any) succeeded or failed.
static void updateRowCount(FemAbstractColumnSet columnSet, Long rowCount, boolean updateRowCount, boolean updateAnalyzeRowCount)
          Deprecated.  
static void updateRowCount(FemAbstractColumnSet columnSet, Long rowCount, boolean updateRowCount, boolean updateAnalyzeRowCount, FarragoRepos repos)
          Updates the row count statistic for an abstract column set, creating new row count stat records, as needed.
static void updateRowCounts(FemAbstractColumnSet table, List<FarragoCatalogUtil.RowCountStat> rowCounts, FarragoRepos repos)
          Updates various row counts for an abstract column set, creating new row count stat records as needed.
static void updateRowCounts(FemAbstractColumnSet table, long rowCount, long deletedRowCount, FarragoRepos repos)
          Updates the current and deleted row counts for an abstract column set, creating new row count stat records as needed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FarragoCatalogUtil

public FarragoCatalogUtil()
Method Detail

initializeCatalog

public static void initializeCatalog(FarragoRepos repos,
                                     CwmCatalog catalog)
Sets default attributes for a new catalog instance.

Parameters:
repos - repository in which catalog is stored
catalog - catalog to initialize

getRoutineParamCount

public static int getRoutineParamCount(FemRoutine routine)
Calculates the number of parameters expected by a routine. For functions, this is different from the number of parameters defined in the repository, because CWM represents the return type by appending an extra parameter.


isRoutineConstructor

public static boolean isRoutineConstructor(FemRoutine routine)
Determines whether a routine is a constructor method.

Parameters:
routine - routine in question
Returns:
true if routine is a constructor method

isRoutineMethod

public static boolean isRoutineMethod(FemRoutine routine)
Determines whether a routine is a method.

Parameters:
routine - routine in question
Returns:
true if routine is a method

setRoutineSpecification

public static void setRoutineSpecification(FarragoRepos repos,
                                           FemRoutine routine,
                                           FemUserDefinedType typeDef)
Sets the specification for a routine.

Parameters:
repos - repository storing the routine definition
routine - new routine
typeDef - owning type if a method, else null

isIndexTemporary

public static boolean isIndexTemporary(CwmSqlindex index)
Determines whether an index is temporary.

Parameters:
index - the index in question
Returns:
true if temporary

getIndexTable

public static CwmTable getIndexTable(CwmSqlindex index)
Gets the table on which an index is defined.

Parameters:
index - the index in question
Returns:
containing table

getIndexTable

public static FemLocalTable getIndexTable(FemLocalIndex index)
Gets the FemLocalTable on which a FemLocalIndex is defined.

Parameters:
index - the index in question
Returns:
containing table

isIndexPrimaryKey

public static boolean isIndexPrimaryKey(FemLocalIndex index)
Determines whether an index implements its table's primary key.

Parameters:
index - the index in question
Returns:
true if is the primary key index

isIndexUnique

public static boolean isIndexUnique(FemLocalIndex index)
Determines whether an index implements either a primary key or a unique constraint

Parameters:
index - the index in question
Returns:
true if is either the primary key index or a unique constraint index

isDeletionIndex

public static boolean isDeletionIndex(FemLocalIndex index)
Determines whether an index implements an internal deletion index.

Parameters:
index - the index in question
Returns:
true if index is the deletion index

getUniqueKeyConstraints

public static List<FemUniqueKeyConstraint> getUniqueKeyConstraints(CwmClassifier table)
Finds the unique key constraints for a table.

Parameters:
table - the table of interest
Returns:
a list of unique key constraints, or an empty list if none is defined

getPrimaryKey

public static FemPrimaryKeyConstraint getPrimaryKey(CwmClassifier table)
Finds the primary key for a table.

Parameters:
table - the table of interest
Returns:
the PrimaryKey constraint, or null if none is defined

getUniqueKeyCols

public static BitSet getUniqueKeyCols(CwmClassifier table)
Returns a bitmap with bits set for any column from a table that is part of either a primary key or a unique constraint

Parameters:
table - the table of interest
Returns:
bitmap with set bits

addKeyCols

private static void addKeyCols(List<FemAbstractColumn> keyCols,
                               BitSet keys)

hasUniqueKey

public static boolean hasUniqueKey(CwmClassifier table)
Determines whether a table contains a unique key

Parameters:
table - the table of interest
Returns:
true if the table has a unique key

getClusteredIndex

public static FemLocalIndex getClusteredIndex(FarragoRepos repos,
                                              CwmClass table)
Finds the clustered index storing a table's data.

Parameters:
repos - repository storing the table definition
table - the table to access
Returns:
clustered index or null if none

getClusteredIndexes

public static List<FemLocalIndex> getClusteredIndexes(FarragoRepos repos,
                                                      CwmClass table)
Finds all clustered indexes storing a table's data.

Parameters:
repos - repository storing the table definition
table - the table to access
Returns:
list of clustered indexes or an empty list if none

getUnclusteredIndexes

public static List<FemLocalIndex> getUnclusteredIndexes(FarragoRepos repos,
                                                        CwmClass table)
Finds all unclustered indexes storing a table's data.

Parameters:
repos - repository storing the table definition
table - the table to access
Returns:
list of clustered indexes or an empty list if none

getDeletionIndex

public static FemLocalIndex getDeletionIndex(FarragoRepos repos,
                                             CwmClass table)
Returns the index corresponding to the internal deletion index

Parameters:
repos - repository storing the table definition
table - the table to access
Returns:
the deletion index if it exists, otherwise NULL

getTableIndexes

public static Collection<FemLocalIndex> getTableIndexes(FarragoRepos repos,
                                                        CwmClass table)
Gets the collection of indexes spanning a table.

Parameters:
repos - repository storing the table definition
table - the table of interest
Returns:
index collection

generateConstraintIndexName

public static void generateConstraintIndexName(FarragoRepos repos,
                                               FemAbstractUniqueConstraint constraint,
                                               CwmSqlindex index)
Sets the generated name for an index used to implement a constraint.

Parameters:
repos - repos storing index
constraint - the constraint being implemented
index - the index implementing the constraint

generateConstraintName

public static void generateConstraintName(FarragoRepos repos,
                                          FemAbstractUniqueConstraint constraint)
Sets the generated name for an anonymous constraint.

Parameters:
repos - repos storing constraint
constraint - the anonymous constraint

uniquifyGeneratedName

public static String uniquifyGeneratedName(FarragoRepos repos,
                                           RefObject refObj,
                                           String name)
Generated names are normally unique by construction. However, if they exceed the name length limit, truncation could cause collisions. In that case, we use repository object ID's to distinguish them.

Parameters:
repos - repos storing object
refObj - object for which to construct name
name - generated name
Returns:
uniquified name

generateUniqueConstraintColumnList

private static String generateUniqueConstraintColumnList(FemAbstractUniqueConstraint constraint)

getModelElementByName

public static <T extends CwmModelElement> T getModelElementByName(Collection<T> collection,
                                                                  String name)
Searches a collection of CwmModelElements (or a subtype) by name.

Parameters:
collection - the collection to search
name - name of element to find
Returns:
CwmModelElement found, or null if not found

getModelElementByNameAndType

public static <T extends CwmModelElement> T getModelElementByNameAndType(Collection<? extends CwmModelElement> collection,
                                                                         String name,
                                                                         Class<T> clazz)
Searches a collection for a CwmModelElement by name and type.

Parameters:
collection - the collection to search
name - name of element to find
clazz - class which sought object must instantiate
Returns:
CwmModelElement found, or null if not found

getModelElementByNameAndType

public static CwmModelElement getModelElementByNameAndType(Collection collection,
                                                           String name,
                                                           RefClass type)
Deprecated. use typesafe version instead


filterTypedModelElements

public static <OutT extends CwmModelElement,AskT extends OutT> void filterTypedModelElements(Collection<? extends CwmModelElement> inCollection,
                                                                                             Collection<OutT> outCollection,
                                                                                             Class<AskT> type)
Filters a collection for all CwmModelElements of a given type.

Parameters:
inCollection - the collection to search
outCollection - receives matching objects
type - class which sought objects must instantiate
See Also:
Util.filter(List, java.lang.Class)

indexModelElementsByName

public static <T extends CwmModelElement> void indexModelElementsByName(Collection<T> inCollection,
                                                                        Map<String,T> outMap)
Indexes a collection of model elements by name.

Parameters:
inCollection - elements to be indexed
outMap - receives indexed elements; key is name, value is element

getSchemaByName

public static FemLocalSchema getSchemaByName(CwmCatalog catalog,
                                             String schemaName)
Looks up a schema by name in a catalog.

Parameters:
catalog - CwmCatalog to search
schemaName - name of schema to find
Returns:
schema definition, or null if not found

isColumnNullable

public static boolean isColumnNullable(FarragoRepos repos,
                                       CwmColumn column)
Determines whether a column may contain null values. This must be used rather than directly calling CwmColumn.getIsNullable, because a column which is part of a primary key or clustered index may not contain nulls even when its definition says it can.

REVIEW jvs 7-July-2006: The statement above is no longer true; we now store the derived nullability in isNullable, and remember the original declared nullability in isDeclaredNullable. Maybe we should deprecate this method now.

Parameters:
repos - repos storing column definition
column - the column of interest
Returns:
whether nulls are allowed

getRoutineForOrdering

public static FemRoutine getRoutineForOrdering(FemUserDefinedOrdering udo)
Gets the routine which implements a particular user-defined ordering, or null if the ordering does not invoke a routine.

Parameters:
udo - user-defined ordering of interest
Returns:
invoked routine or null

getQualifiedName

public static SqlIdentifier getQualifiedName(CwmModelElement element)
Constructs a fully qualified name for an object.

Parameters:
element - model element
Returns:
qualified identifier

toFemSqltypedElement

public static FemSqltypedElement toFemSqltypedElement(FemAbstractTypedElement element)
Casts a FemAbstractTypedElement to the FemSqltypedElement interface via a proxy.

Parameters:
element - element to cast
Returns:
cast result (a proxy)

getStructuralFeatures

public static List<CwmStructuralFeature> getStructuralFeatures(CwmClassifier classifier)
Returns a collection of just the structural features of a classifier, hiding other features such as operations.

Parameters:
classifier - to access
Returns:
list of structural features

isTableFunction

public static boolean isTableFunction(FemRoutine routine)
Determines whether a UDF has a RETURNS TABLE clause.

Parameters:
routine - UDF
Returns:
true if RETURNS TABLE

getJarUrl

public static String getJarUrl(FemJar femJar)
Returns the URL for a jar with all properties expanded.

Parameters:
femJar - jar to access
Returns:
expanded URL as a string

getAuthIdByName

public static FemAuthId getAuthIdByName(FarragoRepos repos,
                                        String authName)
Finds the FemAuthId for a specified Authorization name.

Parameters:
repos - repository storing the Authorization Id
authName - the input name used for this lookup
Returns:
repository element represents the authorization identifier

getUserByName

public static FemUser getUserByName(FarragoRepos repos,
                                    String userName)
Looks up a user by name in a catalog.

Parameters:
repos - repos storing catalog
userName - name of user to find
Returns:
user definition, or null if not found

getRoleByName

public static FemRole getRoleByName(FarragoRepos repos,
                                    String roleName)
Looks up a role by name in a catalog.

Parameters:
repos - repos storing catalog
roleName - name of role to find
Returns:
role definition, or null if not found

newRoleGrant

public static FemGrant newRoleGrant(FarragoRepos repos,
                                    String grantorName,
                                    String granteeName,
                                    String roleName)
Creates a new grant on a ROLE with specified role name and associate it to the grantor and grantee auth ids respectively. By default, the admin option is set to false. The caller will have to set it on the grant object returned.

Parameters:
repos - repository containing the objects
grantorName - the creator of this grant
granteeName - the receipient of this grant
roleName - the role name of the authorization id to be granted by this new grant
Returns:
new grant object

newElementGrant

public static FemGrant newElementGrant(FarragoRepos repos,
                                       String grantorName,
                                       String granteeName,
                                       CwmModelElement grantedObject)
Creates a grant on a specified repos element, with AuthId's specified as strings.

Parameters:
repos - repository storing the objects
grantorName - the creator of this grant
granteeName - the recipient of this grant
grantedObject - element being granted
Returns:
grant a grant object

newElementGrant

public static FemGrant newElementGrant(FarragoRepos repos,
                                       FemAuthId grantorAuthId,
                                       FemAuthId granteeAuthId,
                                       CwmModelElement grantedObject)
Create a new grant for an element, with AuthId's specified as repository objects.

Parameters:
repos - repository storing the objects
grantorAuthId - the creator of this grant
granteeAuthId - the receipient of this grant
grantedObject - element being granted
Returns:
new grant object

newCreationGrant

public static FemGrant newCreationGrant(FarragoRepos repos,
                                        String grantorName,
                                        String granteeName,
                                        CwmModelElement grantedObject)
Creates a new grant representing ownership of an object by its creator.

Parameters:
repos - repository storing the objects
grantorName - the name of the creator of the grant
granteeName - the name of the grantee of the grant
grantedObject - element being created
Returns:
new grant object

newCreationGrant

public static FemGrant newCreationGrant(FarragoRepos repos,
                                        FemAuthId grantorAuthId,
                                        FemAuthId granteeAuthId,
                                        CwmModelElement grantedObject)
Creates a new grant representing ownership of an object by its creator.

Parameters:
repos - repository storing the objects
grantorAuthId - a FemAuthId representing the creator of the grant
granteeAuthId - a FemAuthId representing the grantee of the grant
grantedObject - element being created
Returns:
new grant object

getTableAllowedAccess

public static SqlAccessType getTableAllowedAccess(CwmNamedColumnSet table)
Determines the allowed access for a table

Parameters:
table - Repository table
Returns:
Access type of the table

getRowCounts

public static void getRowCounts(FemAbstractColumnSet table,
                                Timestamp labelTimestamp,
                                Long[] rowCounts)
Retrieves the current and deleted row counts for an abstract column set, optionally based on a label setting.

Parameters:
table - the abstract column set
labelTimestamp - creation timestamp of the label setting that determines which row counts to retrieve; null if there is no label setting
rowCounts - the row counts to be returned; the first element in the array is the current row count and the second is the deleted row count

getMaxTimestamp

private static Timestamp getMaxTimestamp(FemAbstractColumnSet table,
                                         FemRowCountStatistics stats)
Returns the max of the dml and analyze timestamps stored in a row count statistics record. If both timestamps are null, returns null.

Parameters:
table - the abstract column set corresponding to the row count stats record
stats - the row count stats record
Returns:
maximum of the dml and analyze timestamps or null if both timestamps are null

updateRowCounts

public static void updateRowCounts(FemAbstractColumnSet table,
                                   long rowCount,
                                   long deletedRowCount,
                                   FarragoRepos repos)
Updates the current and deleted row counts for an abstract column set, creating new row count stat records as needed.

Parameters:
table - the abstract column set
rowCount - the current row count
deletedRowCount - the deleted row count
repos - repository

updateRowCounts

public static void updateRowCounts(FemAbstractColumnSet table,
                                   List<FarragoCatalogUtil.RowCountStat> rowCounts,
                                   FarragoRepos repos)
Updates various row counts for an abstract column set, creating new row count stat records as needed.

Parameters:
table - the abstract column set
rowCounts - list of row counts to be updated
repos - repository

updateRowCount

public static void updateRowCount(FemAbstractColumnSet columnSet,
                                  Long rowCount,
                                  boolean updateRowCount,
                                  boolean updateAnalyzeRowCount)
Deprecated. 

Updates the row count statistic for an abstract column set

Parameters:
columnSet - the column set whose row count will be updated
rowCount - number of rows returned by column set
updateRowCount - if true, the FemAbstractColumnSet.setRowCount(Long) property is updated.
updateAnalyzeRowCount - if true, the FemAbstractColumnSet.setLastAnalyzeRowCount(Long) property is updated

updateRowCount

public static void updateRowCount(FemAbstractColumnSet columnSet,
                                  Long rowCount,
                                  boolean updateRowCount,
                                  boolean updateAnalyzeRowCount,
                                  FarragoRepos repos)
Updates the row count statistic for an abstract column set, creating new row count stat records, as needed.

Parameters:
columnSet - the column set whose row count will be updated
rowCount - number of rows returned by column set
updateRowCount - if true, the current row count is updated
updateAnalyzeRowCount - if true, the analyze row count is updated

getPageCount

public static Long getPageCount(FemLocalIndex index,
                                Timestamp labelTimestamp)
Retrieves the page count statistic for a local index, taking into consideration the current label setting.

Parameters:
index - the index whose page count will be retrieved
labelTimestamp - creation timestamp of the label setting that determines which page count to retrieve; null if there is no label setting
Returns:
the page count for the index

updatePageCount

public static void updatePageCount(FemLocalIndex index,
                                   Long pageCount)
Deprecated. 

Updates the page count statistic for a local index in the index record.

Parameters:
index - the index whose page count will be updated
pageCount - number of pages on disk used by index

updatePageCount

public static void updatePageCount(FemLocalIndex index,
                                   Long pageCount,
                                   FarragoRepos repos)
Updates the page count statistic for a local index, creating new index stat records as needed.

Parameters:
index - the index whose page count will be updated
pageCount - number of pages on disk used by index
repos - repository

getHistogram

public static FemColumnHistogram getHistogram(FemAbstractColumn column,
                                              Timestamp labelTimestamp)
Retrieves the histogram for a column based on a label setting.

Parameters:
column - the column
labelTimestamp - the creation timestamp of the label setting; null if there is no label setting
Returns:
the corresponding histogram, if it exists

updateHistogram

public static void updateHistogram(FarragoRepos repos,
                                   FemAbstractColumn column,
                                   Long distinctValues,
                                   boolean distinctValuesEstimated,
                                   float samplePercent,
                                   long sampleSize,
                                   int barCount,
                                   long rowsPerBar,
                                   long rowsLastBar,
                                   List<FemColumnHistogramBar> bars)

getHistogramForUpdate

public static FemColumnHistogram getHistogramForUpdate(FarragoRepos repos,
                                                       FemAbstractColumn column,
                                                       boolean createNewHistogram)
Determines which histogram record should be updated. Either the latest one is reused, or a new one is created, if desired.

Parameters:
repos - repository
column - the column for which the histogram will be created
createNewHistogram - if true and the latest record cannot be updated, then create a new histogram record
Returns:
the histogram record to be updated or null if an existing record cannot be updated and a new one was not created

updateAnnotatedElement

public static void updateAnnotatedElement(FemAnnotatedElement annotatedElement,
                                          String timestamp,
                                          boolean isNew)
Updates system-maintained attributes of an object.

Parameters:
annotatedElement - object to update
timestamp - timestamp to use for creation/modification
isNew - whether object is being created

createTimestamp

public static String createTimestamp()
Creates a timestamp reflecting the current time

Returns:
the timestamp encoded as a string

createRecoveryReference

public static FemRecoveryReference createRecoveryReference(FarragoRepos repos,
                                                           RecoveryType recoveryType,
                                                           CwmModelElement modelElement)
Creates a new recovery reference for a recoverable action on an object.

Parameters:
repos - repository in which object is defined
recoveryType - description of recoverable action
modelElement - object on which recovery would be needed

resetRowCounts

public static void resetRowCounts(FemAbstractColumnSet table)
Deprecated. 

Resets the row counts for a table

Parameters:
table - a column set table

resetRowCounts

public static void resetRowCounts(FemAbstractColumnSet table,
                                  FarragoRepos repos)
Resets the row counts for a table, creating new row count stat records, as needed.

Parameters:
table - a column set table
repos - repository

setNewRowCounts

private static void setNewRowCounts(FemAbstractColumnSet table,
                                    FemRowCountStatistics rowCountStats,
                                    List<FarragoCatalogUtil.RowCountStat> rowCounts)
Sets various row counts for an abstract column set. The counts are reflected both in the abstract column set record as well as the row count statistics record.

Parameters:
table - the abstract column set
rowCountStats - the row count statistics
rowCounts - the row counts to be set

getNewestLabelCreationTimestamp

public static Timestamp getNewestLabelCreationTimestamp(FarragoRepos repos)
Retrieves the creation timestamp of the most recently created label stored in the catalog.

Parameters:
repos - repository
Returns:
creation timestamp of the newest label

getOldestLabelCsn

public static Long getOldestLabelCsn(FarragoRepos repos)
Retrieves the csn of the oldest label stored in the catalog.

Parameters:
repos - repository
Returns:
csn of the oldest label; null if there are no labels

getLabelBounds

private static List<Timestamp> getLabelBounds(FemLabel referenceLabel,
                                              FarragoRepos repos)
Retrieves the creation timestamp of the labels that bound a specified label.

Parameters:
referenceLabel - the label that will be used to determine the boundaries
repos - repository
Returns:
returns the lower and upper bound timestamps; if the specified label is the oldest, then the lowerBound is set to null; if the specified label is the newest, then the upperBound is set to null; therefore, if the specified label is the only label, then both bounds are set to null

removeObsoleteStatistics

public static void removeObsoleteStatistics(FemLabel label,
                                            FarragoRepos repos,
                                            boolean usePreviewRefDelete)

removeObsoleteStatisticsFromTable

private static <ParentType extends CwmModelElement> void removeObsoleteStatisticsFromTable(FarragoRepos repos,
                                                                                           Collection<ParentType> parentList,
                                                                                           Method statsGetter,
                                                                                           Method timestampGetter,
                                                                                           Timestamp lowerBound,
                                                                                           Timestamp upperBound,
                                                                                           boolean onlyLabel,
                                                                                           boolean usePreviewRefDelete)
                                               throws Exception
Removes statistics in between 2 timestamp boundaries, provided the stat is not the only remaining statistic record within the timestamp range. The candidate stats are located by walking through a list of parent objects that reference stats.

Type Parameters:
ParentType - the type of the object that references the stat records
Parameters:
repos - repository
parentList - list of parent objects
statsGetter - method that retrieves the list of stat records from each parent object
timestampGetter - method that retrieves the timestamp from each stats record; null if this is a RowCountStatistics object; row count stats are handled as a special case
lowerBound - the lower bound timestamp boundary
upperBound - the upper bound timestamp boundary
onlyLabel - true if this is the special case where the label being dropped is the only remaining one; in this case, the lowerBound should be null
usePreviewRefDelete - whether to use the repository's preview refDelete feature or just delete the objects
Throws:
Exception

timestampInRange

private static boolean timestampInRange(Timestamp lowerBound,
                                        Timestamp upperBound,
                                        Timestamp timestamp)
Determines if a specified timestamp is within 2 bounds. The bounds are non-inclusive.

Parameters:
lowerBound - the lower bound; if null, then there is no lower bound
upperBound - the upper bound; if null, then there is no upper bound
timestamp - the timestamp; if null, the timestamp represents a very old timestamp and therefore only qualifies if there is no explicit lower bound
Returns:
true if the timestamp is within bounds

getCurrentBackupData

public static List<FarragoCatalogUtil.BackupData> getCurrentBackupData(FarragoRepos repos)
Retrieves current backup data stored in the catalog. Information on the full backup, if it exists, is always returned first, followed by information on the last backup.

Parameters:
repos - repository
Returns:
list containing current backup data

addPendingSystemBackup

public static void addPendingSystemBackup(FarragoRepos repos,
                                          String type,
                                          Long csn,
                                          String startTime)
Adds new records to the system backup catalog corresponding to a pending backup.

Parameters:
repos - repository
type - type of backup
csn - commit sequence number corresponding to the backup
startTime - start time of the backup

updatePendingBackupData

public static boolean updatePendingBackupData(FarragoRepos repos,
                                              boolean backupSucceeded,
                                              boolean setEndTimestamp)
Updates the system backup catalog data depending on whether the last pending backup (if any) succeeded or failed. However, if the data indicates that a partial restore has been done, then nothing is updated.

Parameters:
repos - repository
backupSucceeded - true if the last backup succeeded
setEndTimestamp - if true, record the current timestamp as the ending timestamp when updating pending data to completed
Returns:
true if a partial restore was done

addPendingRestore

public static void addPendingRestore(FarragoRepos repos)
Adds or updates records in the system backup catalog, indicating that a partial restore has been completed.

Parameters:
repos - repository

addNewPendingRestoreRecord

private static void addNewPendingRestoreRecord(FarragoRepos repos,
                                               BackupTypeEnum type)

getStorageOptionsAsProperties

public static Properties getStorageOptionsAsProperties(FarragoRepos repos,
                                                       FemElementWithStorageOptions element)
Extracts the storage options for an element into a Properties. No duplicate property names are allowed. Inline property references (such as ${varname} get expanded on read.

Parameters:
repos - repository reference
element - FemElement we want the options from
Returns:
Properties object populated with the storage options