Example: Program to query the collection object

 

This sample program illustrates how to query the data stored in the collection object using the Java™ classes shipped in the ColSrv.jar file in the QIBM/ProdData/OS400/CollectionServices/lib directory path.

By using the code examples, you agree to the terms of the Code license and disclaimer information.

 

Java sample code

import com.ibm.iseries.collectionservices.*; 
class testmco2 {
  public static void main( String argv[] )
  {
    String    objectName = null;     String    libraryName = null;     String    repoName = null;     MgtcolObj mco = null;     int       repoHandle = 0;     int       argc = argv.length;     MgtcolObjAttributes               attr = null;     MgtcolObjRepositoryEntry               repoE = null;     MgtcolObjCollectionEntry               collE = null;     int       i,j; 
    if ( argc <  3 )
    {
      System.out.println("testmco2  objectName libraryName repoName");       System.exit(1);     }

    objectName  = argv[0];     libraryName = argv[1];     repoName    = argv[2]; 
    if ( ! objectName.equals( "*ACTIVE" ) )
      mco = new MgtcolObj( objectName, libraryName );     else       try       {
        mco = MgtcolObj.rtvActive();       } catch ( Exception e)
      {
        System.out.println("rtvActive(): Exception " + e );         System.exit(1);       }
    System.out.println("Object name = " + mco.getName() );     System.out.println("Library name = " + mco.getLibrary() ); 
    try     {
      attr = mco.rtvAttributes( "MCOA0100" );     } catch ( Exception e)
    {
      System.out.println("rtvAttributes(): MCOA0100: Exception " +
e );       System.exit(1);     }

    System.out.println("MCOA0100:  Object " + mco.getLibrary() + "/" + mco.getName() );     System.out.println("   size = " + attr.size + " retention = " + attr.retentionPeriod +
                       " interval = " + attr.dftInterval + " time created = " + attr.timeCreated +
                       " time updated = " + attr.timeUpdated );     System.out.println("   serial = " + attr.logicalPSN + " active = " + attr.isActive +
                       " repaired = " + attr.isRepaired + " summary = " + attr.sumStatus +
                       " repo count = " + attr.repositoryCount );     if ( attr.repositoryInfo != null )
      for(i = 0; i < attr.repositoryCount; i++ )
      {
        repoE = attr.repositoryInfo[ i ];         System.out.println("      name = " + repoE.name + " category = " + repoE.categoryName +
             " size = " + repoE.size );         for( j = 0; j < repoE.collectionInfo.length; j++ )
        {
          collE = repoE.collectionInfo[ j ];           System.out.println("         startTime = " + collE.startTime + " endTime = " + collE.endTime +
               " interval = " + collE.interval );         }
      }

    try     {
      attr = mco.rtvAttributes( "MCOA0200" );     } catch ( Exception e)
    {
      System.out.println("rtvAttributes(): MCOA0200: Exception " + e );       System.exit(1);     }

    System.out.println("MCOA0200: Object " + mco.getLibrary() + "/" + mco.getName() );     System.out.println("   size = " + attr.size + " retention = " + attr.retentionPeriod +
                       " interval = " + attr.dftInterval + " time created = " + attr.timeCreated +
                       " time updated = " + attr.timeUpdated );     System.out.println("   serial = " + attr.logicalPSN + " active = " + attr.isActive +
                       " repaired = " + attr.isRepaired + " summary = " + attr.sumStatus +
                       " repo count = " + attr.repositoryCount );     if ( attr.repositoryInfo != null )
      for(i = 0; i < attr.repositoryCount; i++ )
      {
 repoE = attr.repositoryInfo[ i ];  System.out.println("      name = " + repoE.name + " category = " + repoE.categoryName +
      " size = " + repoE.size );  for( j = 0; j < repoE.collectionInfo.length; j++ )
 {
   collE = repoE.collectionInfo[ j ];    System.out.println("         startTime = " + collE.startTime + " endTime = " + collE.endTime +
        " interval = " + collE.interval );       
 }
      }

    if ( repoName.equals("NONE") )
        return; 
    try     {
      mco.open();     } catch ( Exception e)
    {
      System.out.println("open(): Exception " + e );       System.exit(1);     }

    try     {
      repoHandle = mco.openRepository( repoName, "MCOD0100" );     } catch ( Exception e)
    {
      System.out.println("openRepository(): Exception " + e );       mco.close();       System.exit(1);     }
    System.out.println("repoHandle = " + repoHandle ); 
    MgtcolObjReadOptions  readOptions = new MgtcolObjReadOptions();     MgtcolObjRecInfo recInfo = new MgtcolObjRecInfo(); 
    readOptions.option = MgtcolObjReadOptions.READ_NEXT;     readOptions.recKey = null;     readOptions.offset = 0;     readOptions.length = 0; 
    while ( recInfo.recStatus == MgtcolObjRecInfo.RECORD_OK )
    {
      try       {
        mco.readData( repoHandle, readOptions, recInfo, null );       } catch ( Exception e)
      {
        System.out.println("readData(): Exception " + e );         mco.close();         System.exit(1);       }

      if( recInfo.recStatus == MgtcolObjRecInfo.RECORD_OK )
      {
        System.out.print("Type = " + recInfo.recType );         System.out.print(" Key = " + recInfo.recKey );         System.out.println(" Length = " + recInfo.recLength );       }

    }/* while ... */

    mco.closeRepository( repoHandle );     mco.close(); 
  }/* main() */

}/* class testmco2 */

 

Parent topic:

Example: Implementing user-defined categories