@Override protected final void doRun( CDOTransaction transaction, CDOObject object, IProgressMonitor progressMonitor) throws Exception { CDOResourceNode newResourceNode = createNewResourceNode(); newResourceNode.setName(name); if (object instanceof CDOResourceFolder) { ((CDOResourceFolder) object).getNodes().add(newResourceNode); } else { transaction.getRootResource().getContents().add(newResourceNode); } }
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input CDO resource directory"); inputOpt.setArgs(1); inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option repoOpt = OptionBuilder.create(REPO_NAME); repoOpt.setArgName("REPO_NAME"); repoOpt.setDescription("CDO Repository name"); repoOpt.setArgs(1); repoOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(repoOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String repositoryDir = commandLine.getOptionValue(IN); String repositoryName = commandLine.getOptionValue(REPO_NAME); Class<?> inClazz = CdoQueryGetBranchStatements.class .getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName); try { server.run(); CDOSession session = server.openSession(); CDOTransaction transaction = session.openTransaction(); Resource resource = transaction.getRootResource(); { Runtime.getRuntime().gc(); long initialUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log( Level.INFO, MessageFormat.format( "Used memory before query: {0}", MessageUtil.byteCountToDisplaySize(initialUsedMemory))); LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); Set<TextElement> list = ASE2015JavaQueries.getCommentsTagContent(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log( Level.INFO, MessageFormat.format("Query result contains {0} elements", list.size())); LOG.log( Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); Runtime.getRuntime().gc(); long finalUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log( Level.INFO, MessageFormat.format( "Used memory after query: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory))); LOG.log( Level.INFO, MessageFormat.format( "Memory use increase: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory))); } transaction.close(); session.close(); } finally { server.stop(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }