Search in sources :

Example 1 with Diagnosticable

use of org.apache.derby.iapi.services.diag.Diagnosticable in project derby by apache.

the class D_DiagnosticUtil method diag_conglomid.

/**
 * Given a Database name and conglomid, return diagnositic string.
 * <p>
 * Return a string with diagnostic information about a particular
 * conglomerate, can be called for any type of conglomerate (some types
 * may not return any info though).
 * <p>
 * Can be called from ij to find out info about conglomid 19 in database
 * 'msgdb' by using the following syntax:
 *
 *     values
 *     com.ibm.db2j.protocol.BasicServices.Diagnostic.T_Diagnosticable::
 *     diag_conglomid('msgdb', 19);
 *       maximumdisplaywidth 9000;
 *
 *       CREATE FUNCTION DIAG_CONGLOMID(DBNAME VARCHAR(128), CONGLOMID INT)
 *       RETURNS VARCHAR(32000) RETURNS NULL ON NULL INPUT
 *       EXTERNAL NAME
 *       'org.apache.derby.impl.store.raw.data.D_DiagnosticUtil.diag_conglomid'
 *       LANGUAGE JAVA PARAMETER STYLE JAVA;
 *
 *       values DIAG_CONGLOMID('msgdb', 19);
 *          com.ibm.db2j.protocol.BasicServices.Diagnostic.T_Diagnosticable::
 *          diag_conglomid_print('msgdb', 19);
 *
 * RESOLVE - An interface that takes a table name would be nice.
 *
 * @param db_name   name of the database
 * @param conglomid conglomerate id of the conglomerate to debug
 *
 * @exception  StandardException  Standard exception policy.
 */
public static String diag_conglomid(String db_name, long conglomid) throws StandardException {
    String ret_string = null;
    AccessFactory store_module = null;
    store_module = (AccessFactory) getModuleFromDbName(db_name);
    if (store_module != null) {
        TransactionController tc = store_module.getTransaction(FileContainer.getContextService().getCurrentContextManager());
        ConglomerateController open_table = tc.openConglomerate(conglomid, false, 0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE);
        open_table.debugConglomerate();
        Diagnosticable diag_obj = DiagnosticUtil.findDiagnostic(open_table);
        ret_string = diag_obj.diag();
        open_table.close();
    } else {
        System.out.println("Could not find module for database: " + db_name);
    }
    return (ret_string);
}
Also used : ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) TransactionController(org.apache.derby.iapi.store.access.TransactionController) Diagnosticable(org.apache.derby.iapi.services.diag.Diagnosticable) AccessFactory(org.apache.derby.iapi.store.access.AccessFactory)

Example 2 with Diagnosticable

use of org.apache.derby.iapi.services.diag.Diagnosticable in project derby by apache.

the class T_Diagnosticable method t_001.

/* Private/Protected methods of This class: */
/**
 * Simple test of DiagnosticUtil interfaces.
 * <p>
 * Simple test of DiagnosticUtil.toDiagString() and
 * DiagnosticUtil.findDiagnostic() interfaces.
 *
 * @exception  T_Fail  If test fails for some reason.
 */
private void t_001() throws T_Fail {
    // Create object with also has a diagnostic interface:
    Object diag_obj = new T_DiagTestClass1("object with diag interface");
    // Create an object in a sub-class that doesn't have a D_ class, but
    // its super-class does.
    Object diagSubObj = new T_DiagTestClass1Sub("sub-class");
    // Create object with neither Diagnosticable:
    Object obj = (long) 5;
    // Test just getting a single string back, from each type of object.
    String str = null;
    String expected_str = null;
    Diagnosticable helper_class = null;
    // Here the string should come from the Diagnostic object's diag().
    str = DiagnosticUtil.toDiagString(diag_obj);
    expected_str = "D_T_DiagTestClass1: object with diag interface";
    if (str.compareTo(expected_str) != 0) {
        throw T_Fail.testFailMsg("DiagnosticUtil.toDiagString() failed, got: (" + str + "), expected: (" + expected_str + ").");
    }
    // make sure right class was found.
    helper_class = DiagnosticUtil.findDiagnostic(diag_obj);
    if (!(helper_class instanceof D_T_DiagTestClass1))
        throw T_Fail.testFailMsg("Bad helper class lookup.");
    try {
        str = helper_class.diag();
    } catch (Throwable t) {
        throw T_Fail.testFailMsg("Unexpected exception from helper_class.diag() call");
    }
    if (!str.equals(expected_str)) {
        throw T_Fail.testFailMsg("DiagnosticUtil.toDiagString() failed, got: (" + str + "), expected: (" + expected_str + ").");
    }
    // make sure the Diagnostic class picks up a super-version of the D_ class
    str = DiagnosticUtil.toDiagString(diagSubObj);
    expected_str = "D_T_DiagTestClass1: sub-class";
    if (!str.equals(expected_str)) {
        throw T_Fail.testFailMsg("DiagnosticUtil.toDiagString() failed, got: (" + str + "), expected: (" + expected_str + ").");
    }
    // Here the string should just be the system's default toString.
    str = DiagnosticUtil.toDiagString(obj);
    expected_str = "5";
    if (str.compareTo(expected_str) != 0) {
        throw T_Fail.testFailMsg("DiagnosticUtil.toDiagString() failed, got: (" + str + "), expected: (" + expected_str + ").");
    }
    // check that lookup for this class return correctly returns null,
    // since help class does not exist.
    helper_class = DiagnosticUtil.findDiagnostic(obj);
    if (helper_class != null)
        throw T_Fail.testFailMsg("Bad helper class - should be null.");
}
Also used : Diagnosticable(org.apache.derby.iapi.services.diag.Diagnosticable)

Aggregations

Diagnosticable (org.apache.derby.iapi.services.diag.Diagnosticable)2 AccessFactory (org.apache.derby.iapi.store.access.AccessFactory)1 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)1 TransactionController (org.apache.derby.iapi.store.access.TransactionController)1