All pastes #491504 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-05-16 18:24 UTC
rendered paste body
/**
 * [PERSISTENT] Delete all items of all item types.  No items can
 * have any special delete rules.
 * @param dsICM - Connected Datastore object.
 **/
public static void deleteItems(DKDatastoreICM dsICM)
throws DKException, Exception{
  System.out.println("Deleting All Items...");

  // List all Item Types
  DKDatastoreDefICM dsDefICM = (DKDatastoreDefICM)dsICM.datastoreDef();
  String[] itemTypeNames = dsDefICM.listEntityNames();
        
  System.out.println("'"+itemTypeNames.length+"' Item Types Found.");
  for(int i=0; i<itemTypeNames.length; i++){
    deleteItems(dsICM,itemTypeNames[i]);
  }
        
  System.out.println("Deleted All Items.");
}//end deleteItems(DKDatatoreICM dsICM)

/**
 * [PERSISTENT] Delete all items of the specified Item Type.
 * @param ds            Connected Datastore object.
 * @param itemTypeName  Item Type Name for which to delete all 
 *                      items of.
 **/
public static void deleteItems(dkAbstractDatastore ds, String itemTypeName) throws DKException, Exception{
  System.out.println("Deleting All Items of Type '"+itemTypeName+"'...");

  // Validate Inputs
  if(ds==null) throw new Exception("Invalid datastore object parameter.  Found 'null'.");
  if(ds.isConnected()==false) throw new Exception("Invalid datastore object parameter.  Object has not been connected.");  

  int count = 0; // used to count number of items deleted.
                
  // Build the query string to look like: "/<ItemType>"
  String queryString = "/"+itemTypeName;

  // Evaluate Query
  DKNVPair parms[] = new DKNVPair[2];
  // Only the Pid Information will be needed to delete.
  parms[0] = new DKNVPair(DKConstant.DK_CM_PARM_RETRIEVE,    new Integer(DKConstant.DK_CM_CONTENT_IDONLY)); 
  parms[1] = new DKNVPair(DKConstant.DK_CM_PARM_END,         null);
  DKResults results = (DKResults)ds.evaluate(queryString, DKConstant.DK_CM_XQPE_QL_TYPE, parms); // Evaluate Query
        
  // Process Results
  if (results != null) {
    dkIterator iter = results.createIterator();
    
    // Use multi-item delete   
    dsICM.deleteObjects(results); 
  }//end if (results != null) {
                
  System.out.println("Deleted All '"+count+"' Items of Type '"+itemTypeName+"'.");
}//end deleteItems(dkAbstractDatastore ds, String itemTypeName)