希望这可以帮助。
public void countobjectsinAllOS() {
Connection conn = Factory.Connection.getConnection(ConfigInfo.CE_URI);
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
Iterator<ObjectStoreSet> it = domain.get_ObjectStores().iterator();
int countofos = 0;
while (it.hasNext()) {
ObjectStore os = (ObjectStore)it.next();
String osname = os.get_DisplayName();
System.out.println("Working on Object Store " +osname);
countofos++;
countObjectsInAnOS(osname);
}
System.out.println("\n\n");
//System.out.println("Number of Object Stores found in doamin >>\t" + domain.get_Name() + "\t<< is " + countofos);
}
public void countObjectsInAnOS(String OSName) {
Connection conn = Factory.Connection.getConnection(ConfigInfo.CE_URI);
Domain domain = Factory.Domain.fetchInstance(conn, null, null);
ObjectStore os = Factory.ObjectStore.fetchInstance(domain, OSName, null);
// Create a SearchSQL instance and specify the SQL statement (using the
// helper methods).
SearchSQL sqlObject = new SearchSQL();
sqlObject.setSelectList("*");
//sqlObject.setMaxRecords(10);
sqlObject.setWhereClause("f.This INSUBFOLDER '/'");
sqlObject.setFromClauseInitialValue("Folder", "f", false);
domain.get_ObjectStores();
// Uncomment below lines for Documents
// sqlObject.setSelectList("d.DocumentTitle, d.Id");
// sqlObject.setMaxRecords(20);
// sqlObject.setFromClauseInitialValue("Document", "d", false);
// Check the SQL statement.
//Uncomment to see the SQL
//System.out.println("SQL: " + sqlObject.toString());
// Create a SearchScope instance. (Assumes you have the object store
// object.)
Boolean continuable = new Boolean(true);
// Set the page size (Long) to use for a page of query result data. This value is passed
// in the pageSize parameter. If null, this defaults to the value of
// ServerCacheConfiguration.QueryPageDefaultSize.
Integer myPageSize = new Integer(10);
// Specify a property filter to use for the filter parameter, if needed.
// This can be null if you are not filtering properties.
// PropertyFilter myFilter = new PropertyFilter();
// int myFilterLevel = 1;
// myFilter.setMaxRecursion(myFilterLevel);
// myFilter.addIncludeType(new FilterElement(null, null, null, FilteredPropertyType.ANY, null));
// Set the (Boolean) value for the continuable parameter. This indicates
// whether to iterate requests for subsequent pages of result data when the end of the
// first page of results is reached. If null or false, only a single page of results is
// returned.
// Execute the fetchObjects method using the specified parameters.
//IndependentObjectSet myObjects = search.fetchObjects(sqlObject, myPageSize, myFilter, continuable);
SearchScope searchScope = new SearchScope(os);
RepositoryRowSet rowSet = searchScope.fetchRows(sqlObject, myPageSize, null, continuable);
long count = 0;
Iterator<RepositoryRow> it = rowSet.iterator();
while (it.hasNext()) {
it.next();
count++;
}
//System.out.println("Total number of Documents >>\t\t" + count + "\n\n");
System.out.println("Total number of Folders >>\t\t" + count + "\n\n");
}