Database database = (Database) cl.newInstance();
database.setProperty("create-database", "true");
DatabaseManager.registerDatabase(database);
Collection root = DatabaseManager.getCollection(XmldbURI.LOCAL_DB, "admin", "");
CollectionManagementService mgmt = (CollectionManagementService) root.getService("CollectionManagementService", "1.0");
Collection collection = mgmt.createCollection("protected");
IndexQueryService idxConf = (IndexQueryService) collection.getService("IndexQueryService", "1.0");
idxConf.configureCollection(COLLECTION_CONFIG);
XMLResource hamlet = (XMLResource) collection.createResource("hamlet.xml", "XMLResource");
hamlet.setContent(new File("samples/shakespeare/hamlet.xml"));
collection.storeResource(hamlet);
mgmt = (CollectionManagementService) collection.getService("CollectionManagementService", "1.0");
TestDataGenerator generator = new TestDataGenerator("xdb", DOCUMENT_COUNT);
for (int i = 0; i < COLLECTION_COUNT; i++) {
Collection currentColl = mgmt.createCollection("test" + i);
System.out.println("Generating " + DOCUMENT_COUNT + " files...");
File[] files = generator.generate(currentColl, generateXQ);
for (int j = 0; j < files.length; j++) {
XMLResource resource = (XMLResource) currentColl.createResource("xdb" + j + ".xml", "XMLResource");
resource.setContent(files[j]);