com.tivoli.twg.engine
Class TWGDatabaseQuery

java.lang.Object
  extended bycom.tivoli.twg.engine.TWGObject
      extended bycom.tivoli.twg.engine.TWGPersistentObject
          extended bycom.tivoli.twg.engine.TWGDatabaseQuery
All Implemented Interfaces:
TWGGetSetInterface

public class TWGDatabaseQuery
extends TWGPersistentObject
implements TWGGetSetInterface

The TWGDatabaseQuery class is used to define queries on the Director database. These * queries can be saved queries (their definition is retained in the Director persistent store), or non-saved queries which are executed once and not retained. There are two types of saved queries:

Both default and user-defined queries are viewable using the Director inventory query browser.

There are two format options available for all queries:


Field Summary
static int JOIN_FORMAT
          Query format where multiple tables are joined on MANAGED_OBJ_ID when the database query is executed.
static int REPORT_FORMAT
          Query format where each table is queried separately.
 
Fields inherited from class com.tivoli.twg.engine.TWGPersistentObject
CLASS_NAME, SIZEOF_BYTE, SIZEOF_CHAR, SIZEOF_DOUBLE, SIZEOF_FLOAT, SIZEOF_INT, SIZEOF_LONG, SIZEOF_SHORT
 
Constructor Summary
TWGDatabaseQuery()
           
TWGDatabaseQuery(TWGDbQueryParms query_parms)
          Constructor for TWGDatabaseQuery.
 
Method Summary
 void changeQuery(TWGDbQueryParms query_parms)
          The method to change the query definition.
 void Destroy()
          Destroy the TWGDatabaseQuery object.
static TWGDatabaseQuery findQueryByIdString(java.lang.String id)
          Get a reference to a default TWGDatabaseQuery object by id_string.
 java.lang.String[] getAttributeIDList()
          Attribute ID enumeration : this method is expected to return a list of strings containing the String names of the attributes supported for a given object.
 int getAttributeType(java.lang.String id)
          Get type of attribute value for given attribute
 DataValue getAttributeValue(java.lang.String id, java.util.Locale loc)
          Get value of attribute with given ID
 java.lang.String getBundleKey()
          Get the key for the resource bundle for the query name.
 java.lang.String getBundleName()
          Get the name of the resource bundle used by this query for translating the query name for default queries.
protected  java.lang.String getBundleString(java.lang.String bundleKey, java.util.Locale loc)
          Look up a value in the resource bundle
 TWGDatabase getDatabase()
          Get a reference to the database the query is in.
 java.lang.String getDatabaseName()
          Get the database name which the query is in.
 boolean getDefault()
          Is the query a default query
 int getFormat()
          Method to get the query format.
 java.lang.String getGroupName()
          The class method gets the group name that is associated with the database query.
 java.lang.String getIdString()
          Get the id string for the query.
static java.util.Enumeration getIdStrings()
          Get id strings for all the queries that have id strings.
protected  TWGDbQueryReply getMyQueryInfo(java.util.Locale loc)
          The instance method gets a TWGDbQueryReply object which contains information about the query.
protected static int getNumberOfQueries()
          Get the number of existing saved queries.
static TWGDatabaseQuery getQuery(long queryId)
          The class method gets a reference to a TWGDatabaseQuery object.
static TWGDatabaseQuery getQuery(java.lang.Long queryId)
          The class method gets a reference to a TWGDatabaseQuery object.
 java.lang.String getQueryDisplayName()
          Get the display name for the query.
 java.lang.Long getQueryId()
          Get the persistent object id for the query.
protected static java.util.Enumeration getQueryIds()
          Get all the query persistent object ids.
static java.util.Enumeration getQueryObjects()
          Gets an enumeration of all TWGDatabaseQuery objects.
 TWGDbQueryParms getQueryParms()
          Get a the query parameters used to create this query
protected  Vect getSelectedFields()
          Gets list of selected field names for the query.
 StringValueSet getTableClasses()
          Get the list of table class names for the tables used in this query
protected  boolean isCopiedQuery()
          Get whether the query is the copy of a default query.
static void removeQueryByIdString(java.lang.String id_string)
          Remove a TWGDatabaseQuery object from the default queries query by specifying the query id string.
protected  void restoreData(TWGPersistentObjectDictionary dict, boolean do_resolve)
          Restore method for database query object
 void run(TWGDbResultSet trs, Vect reportResultSet, LongValueSet managed_obj_id, java.util.Locale loc)
          Method for running query with passed list of managed object ids.
protected  void saveData(TWGPersistentObjectDictionary dictionary)
          Method for saving persistent object data.
 boolean setAttributeValue(java.lang.String id, DataValue val)
          Set value of attribute with given ID
protected  void setCopiedQuery(boolean isClone)
          Set whether the query is the copy of another one.
protected  void setGroupName(java.lang.String groupName)
          Sets group string value.
protected  void setIdString(java.lang.String idString)
          Sets id string value.
protected  void setQueryDisplayName()
          Set the query display name using default locale as input.
protected  void setQueryDisplayName(java.util.Locale queryLocale)
          Set the query display name.
 java.lang.String toString()
          Convert object to String for debug
 boolean verify()
          Verify the validity of this query Database queries have the validity of tables and columns checked.
protected static void verifyAll()
          Run the verify method for each database query.
 
Methods inherited from class com.tivoli.twg.engine.TWGPersistentObject
enableAsyncWrites, fromPersistID, initialize, isNewPersistentStore, isSaveRequired, PersistID, restore, restoreAll, save, save, setSaveRequired, terminate, toPersistID
 
Methods inherited from class com.tivoli.twg.engine.TWGObject
AllObjects, AllObjects, Delete, DumpTWGObjects, FindObject, isDeleted, isNewObject, isPersistent, isPersistent, isValid, isValid, ObjectID, setDistinctObjectID, SetObjectID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JOIN_FORMAT

public static final int JOIN_FORMAT
Query format where multiple tables are joined on MANAGED_OBJ_ID when the database query is executed. No additional fields are automatically appended to these queries

See Also:
Constant Field Values

REPORT_FORMAT

public static final int REPORT_FORMAT
Query format where each table is queried separately. MANAGED_OBJ_ID and LABEL are included for each row. Each unique value for a column for a managed object is listed once, and null indicator values are added to fill out the shorter columns for the managed objecct.

See Also:
Constant Field Values
Constructor Detail

TWGDatabaseQuery

public TWGDatabaseQuery()

TWGDatabaseQuery

public TWGDatabaseQuery(TWGDbQueryParms query_parms)
                 throws TWGDbException
Constructor for TWGDatabaseQuery.

Parameters:
query_parms - - the query parameters
Throws:
TWGDbException
See Also:
TWGDbQueryParms
Method Detail

getQuery

public static TWGDatabaseQuery getQuery(java.lang.Long queryId)
                                 throws TWGDbQueryNotFoundException
The class method gets a reference to a TWGDatabaseQuery object. This method searches the collection of existing querie objects to find the one that matches the supplied query persistent object id.

Parameters:
queryId - - the persistent object id
Returns:
TWGDatabaseQuery
Throws:
TWGDBException
TWGDbQueryNotFoundException

getQuery

public static TWGDatabaseQuery getQuery(long queryId)
                                 throws TWGDbQueryNotFoundException
The class method gets a reference to a TWGDatabaseQuery object. This method searches the collection of existing querie objects to find the one that matches the supplied query persistent object id.

Parameters:
queryId - - the persistent object id
Returns:
TWGDatabaseQuery
Throws:
TWGDBException
TWGDbQueryNotFoundException

getNumberOfQueries

protected static int getNumberOfQueries()
Get the number of existing saved queries.

Returns:
the number of the query objects.

findQueryByIdString

public static TWGDatabaseQuery findQueryByIdString(java.lang.String id)
Get a reference to a default TWGDatabaseQuery object by id_string. User queries do not have id strings.

Parameters:
id - - id string used to identify default query.
Returns:
TWGDatabaseQuery

getQueryObjects

public static java.util.Enumeration getQueryObjects()
Gets an enumeration of all TWGDatabaseQuery objects.

Returns:
Enumeration

getQueryIds

protected static java.util.Enumeration getQueryIds()
Get all the query persistent object ids.

Returns:
Enumeration

getIdStrings

public static java.util.Enumeration getIdStrings()
Get id strings for all the queries that have id strings.


getSelectedFields

protected Vect getSelectedFields()
                          throws TWGDbException
Gets list of selected field names for the query. The format of the names (Strings) is "table_token_name.column_token_name".

This method is protected as an implementation side effect. Do not call or change. Its interface may be changed in a later release.

Returns:
Vect
Throws:
TWGDbException

setIdString

protected void setIdString(java.lang.String idString)
Sets id string value.

Parameters:
idString - - id string

setGroupName

protected void setGroupName(java.lang.String groupName)
Sets group string value. The Group name is a string that can be used to categorize queries. This can be useful, for to determine all queries used by the inventory browser, for example.

Parameters:
groupName - - group name for query

getIdString

public java.lang.String getIdString()
Get the id string for the query.

Returns:
String

getFormat

public int getFormat()
Method to get the query format.

Returns:
the query format.

getGroupName

public java.lang.String getGroupName()
The class method gets the group name that is associated with the database query. This allows queries to be grouped like the default queries used by by the inventory browser.

Returns:
group name

removeQueryByIdString

public static void removeQueryByIdString(java.lang.String id_string)
Remove a TWGDatabaseQuery object from the default queries query by specifying the query id string.

Parameters:
id_string - - the unique string identification for default queries.

getBundleName

public java.lang.String getBundleName()
Get the name of the resource bundle used by this query for translating the query name for default queries. User queries do not have translated names

Returns:
the bundle name

getBundleKey

public java.lang.String getBundleKey()
Get the key for the resource bundle for the query name. User queries do not use the resource bundle to translate their names

Returns:
the bundle key

getBundleString

protected java.lang.String getBundleString(java.lang.String bundleKey,
                                           java.util.Locale loc)
                                    throws java.util.MissingResourceException
Look up a value in the resource bundle

Parameters:
loc - - locale for the bundle
Returns:
string
Throws:
java.util.MissingResourceException

setQueryDisplayName

protected void setQueryDisplayName(java.util.Locale queryLocale)
Set the query display name.

Parameters:
queryLocale - - Locale for translating the query.

setQueryDisplayName

protected void setQueryDisplayName()
Set the query display name using default locale as input.


getDefault

public boolean getDefault()
Is the query a default query

Returns:
true if the query is default query. otherwise false

getQueryDisplayName

public java.lang.String getQueryDisplayName()
Get the display name for the query.

Returns:
String

getDatabaseName

public java.lang.String getDatabaseName()
Get the database name which the query is in.

Returns:
String

getDatabase

public TWGDatabase getDatabase()
                        throws TWGDbException
Get a reference to the database the query is in.

Returns:
TWGDatabase
Throws:
TWGDbException
See Also:
TWGDatabase

getQueryId

public java.lang.Long getQueryId()
Get the persistent object id for the query.

Returns:
Long

isCopiedQuery

protected boolean isCopiedQuery()
Get whether the query is the copy of a default query.

Returns:
boolean

setCopiedQuery

protected void setCopiedQuery(boolean isClone)
Set whether the query is the copy of another one.

Parameters:
isClone - - true if the query is the copy of the other one. False if not.

getQueryParms

public TWGDbQueryParms getQueryParms()
                              throws TWGDbException
Get a the query parameters used to create this query

Returns:
TWGDbQueryParms
Throws:
TWGDbException - if unable to create a TWGDbQueryParms object
See Also:
TWGDbQueryParms

changeQuery

public void changeQuery(TWGDbQueryParms query_parms)
                 throws TWGDbException
The method to change the query definition.

Throws:
TWGDbException
See Also:
TWGDbQueryParms

run

public void run(TWGDbResultSet trs,
                Vect reportResultSet,
                LongValueSet managed_obj_id,
                java.util.Locale loc)
         throws TWGDbException
Method for running query with passed list of managed object ids.

Parameters:
trs - - output parameter to contain the result set returned after the query running.
reportResultSet - - Vect used as output parameter to contain list of result set and it's meta data for each subquery for each table.
managed_obj_id - - a reference to a LongValueSet object indicating a list managed object ids.
loc - - Locale of the caller console.
Throws:
TWGDbException, - TWGDbException
TWGDbException
See Also:
TWGDbResultSet, com.tivoli.twg.libs.IntSortSet.

getMyQueryInfo

protected TWGDbQueryReply getMyQueryInfo(java.util.Locale loc)
                                  throws TWGDbException
The instance method gets a TWGDbQueryReply object which contains information about the query.

Returns:
TWGDbQueryReply
Throws:
TWGDbException
See Also:
TWGDbQueryReply

getTableClasses

public StringValueSet getTableClasses()
Get the list of table class names for the tables used in this query

Returns:
StringValueSet with the list of table classes

verifyAll

protected static void verifyAll()
Run the verify method for each database query. Destroy any queries that do not verify and notify users that the queries have been deleted. This method is run only when the Director server is running the database initializaion. It should not be called at any other time.


verify

public boolean verify()
Verify the validity of this query Database queries have the validity of tables and columns checked. Other types of queries currently have no checks done.


saveData

protected void saveData(TWGPersistentObjectDictionary dictionary)
                 throws TWGPersistentObjectSaveException
Method for saving persistent object data.

Overrides:
saveData in class TWGPersistentObject
Throws:
TWGPersistentObjectSaveException - thrown to abort save procedure.

restoreData

protected void restoreData(TWGPersistentObjectDictionary dict,
                           boolean do_resolve)
                    throws TWGPersistentObjectRestoreException
Restore method for database query object

Overrides:
restoreData in class TWGPersistentObject
Parameters:
dict - - dictionary containing data to be restored
do_resolve - - true if second pass of restore (do resolve)
Throws:
TWGPersistentObjectRestoreException - if restore aborted

Destroy

public void Destroy()
             throws TWGObjectDestroyException
Destroy the TWGDatabaseQuery object. So this object can't be restored.

Overrides:
Destroy in class TWGPersistentObject
Throws:
TWGObjectDestroyException - if error during destroy

toString

public java.lang.String toString()
Convert object to String for debug

Returns:
String with a textual description of the object.

getAttributeIDList

public java.lang.String[] getAttributeIDList()
Attribute ID enumeration : this method is expected to return a list of strings containing the String names of the attributes supported for a given object. Subclasses of base classes implementing the interface should report additional attributes by adding them to the list returned by the base class.

Specified by:
getAttributeIDList in interface TWGGetSetInterface

getAttributeValue

public DataValue getAttributeValue(java.lang.String id,
                                   java.util.Locale loc)
Get value of attribute with given ID

Specified by:
getAttributeValue in interface TWGGetSetInterface
Parameters:
id - - attribute ID requested
loc - - locale to use for value, if applicable
Returns:
value object, or null if no value

setAttributeValue

public boolean setAttributeValue(java.lang.String id,
                                 DataValue val)
Set value of attribute with given ID

Specified by:
setAttributeValue in interface TWGGetSetInterface
Parameters:
id - - attribute ID to be set
val - - attribute value to be set
Returns:
true if set successful, false if not successful

getAttributeType

public int getAttributeType(java.lang.String id)
Get type of attribute value for given attribute

Specified by:
getAttributeType in interface TWGGetSetInterface
Parameters:
id - - attribute ID
Returns:
DataValue type of attribute, or DataValue.NONE_TYPE if undefined