SRB:Jargon Tips
From Adapt
Querying MCAT for one item
This will query the MCAT for one item
- queryItem is the SRBMetaDataSet item to query against
- test is the MetaDataCondition test to use
- selectItem is the desired return item
It will return a list of results. See below for examples on using this to list files in a directory.
public static List<String> queryForOneItem( SRBFileSystem sfs, String queryItem, int test, String query, String selectItem ) throws IOException { if ( sfs == null ) throw new NullPointerException("SRBFile is null"); /** * Construct query */ MetaDataCondition[] conditions = { MetaDataSet.newCondition( queryItem, test, query ) }; String[] selectStrings = { selectItem }; MetaDataSelect[] selects = MetaDataSet.newSelection(selectStrings); MetaDataRecordList[] rl = sfs.query( conditions, selects, 300 ); ArrayList<String> results = new ArrayList<String>(); while (rl != null && rl.length > 0) { for (MetaDataRecordList r : rl) { results.add(r.getValue(selectItem).toString()); } if (!rl[rl.length-1].isQueryComplete()) { rl = rl[rl.length-1].getMoreResults(); } else { rl = null; } } return results; }
Listing Files and directories
Here's a shortcut to listing files and directories w/o using srb file, using the metadata hack above
public static List<String> listFilesInDirectory( SRBFileSystem sfs, String directory ) throws IOException { if ( sfs == null || StringUtil.isEmpty(directory)) throw new NullPointerException("SRBFile or directory is null or empty"); String path = (directory.endsWith("/") ? directory.substring(0,directory.length() - 1) : directory); return queryForOneItem(sfs, SRBMetaDataSet.DIRECTORY_NAME, MetaDataCondition.EQUAL, path, SRBMetaDataSet.FILE_NAME); } public static List<String> listDirectoriesInDirectory( SRBFileSystem sfs, String directory ) throws IOException { if ( sfs == null || StringUtil.isEmpty(directory)) throw new NullPointerException("SRBFile or directory is null or empty"); String path = (directory.endsWith("/") ? directory.substring(0,directory.length() - 1) : directory); return queryForOneItem(sfs, SRBMetaDataSet.PARENT_DIRECTORY_NAME, MetaDataCondition.EQUAL, path, SRBMetaDataSet.DIRECTORY_NAME); }
-- Main.MikeSmorul - 07 Dec 2006