List of usage examples for com.mongodb Mongo Mongo
@Deprecated
public Mongo()
From source file:org.jwebsocket.plugins.stockticker.service.StocktickerService.java
License:Apache License
/** * *//*from ww w.ja va2 s .c om*/ public StocktickerService() { try { mConnection = new Mongo(); mCollectionUser = mConnection.getDB("StockTicker").getCollection("Users"); mCollectionTicker = mConnection.getDB("StockTicker").getCollection("Tickers"); mCollectionPurchasing = mConnection.getDB("StockTicker").getCollection("Purchasing"); createCollection(); } catch (UnknownHostException ex) { Logger.getLogger(StocktickerService.class.getName()).log(Level.SEVERE, null, ex); } catch (MongoException ex) { Logger.getLogger(StocktickerService.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(StocktickerService.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.mediawiki.importer.XmlDumpReader.java
License:Open Source License
/** * Initialize a processor for a MediaWiki XML dump stream. * Events are sent to a single DumpWriter output sink, but you * can chain multiple output processors with a MultiWriter. * @param inputStream Stream to read XML from. * @param writer Output sink to send processed events to. *//*from w w w . j a v a 2 s . c o m*/ public XmlDumpReader(InputStream inputStream, DumpWriter writer) { input = inputStream; this.writer = writer; buffer = new char[4096]; len = 0; hasContent = false; //by philipp.staender try { //open connection to monogdb an get collections Mongo m = new Mongo(); System.out.println("Initialisiere mongodb Datenbank '" + this.mongodbDatabasename + "'"); m.dropDatabase(this.mongodbDatabasename); DB db = m.getDB(this.mongodbDatabasename); System.out.println("Setze Indizes in mongodb collections..."); this.mongodbArticles = db.getCollection("articles"); this.mongodbArticles.ensureIndex("title"); if (XmlDumpReader.generateTextIndizes) { this.mongodbTextindexes = db.getCollection("textindex"); this.mongodbTextindexes.ensureIndex("title"); this.mongodbTextindexes.ensureIndex("article"); this.mongodbTextindexes.ensureIndex("links"); this.mongodbTextindexes.ensureIndex("sections.subtitle"); } } catch (Exception e) { System.err.println("Fehler beim Initialisieren der mongodb: " + e.getMessage()); System.err.println("Applikation wird beendet"); System.exit(0); } //open connection to mysql String dbURL = "jdbc:mysql://" + this.mysqlHost + ":" + this.mysqlPort + "/" + this.mysqlDatabase; try { this.mysqlConnection = (Connection) DriverManager.getConnection(dbURL, this.mysqlUsername, this.mysqlPassword); //Prepare tables for database System.out.println("Initialisiere notwendige Tabellen in mysql Datenbank '" + this.mysqlDatabase + "'"); Statement stmt = (Statement) this.mysqlConnection.createStatement(); String sql = "DROP TABLE IF EXISTS `articles`;"; stmt.executeUpdate(sql); sql = "CREATE TABLE IF NOT EXISTS `articles` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `MongoID` varchar(255) NOT NULL, `Title` varchar(255) NOT NULL, `Redirect` varchar(255) NOT NULL, `Comment` text NOT NULL, `Content` longtext NOT NULL, `Links` text NOT NULL, PRIMARY KEY (`ID`), KEY `ArticleTitle` (`Title`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; stmt.executeUpdate(sql); if (XmlDumpReader.generateTextIndizes) { sql = "DROP TABLE IF EXISTS `textindex`;"; stmt.executeUpdate(sql); sql = "CREATE TABLE IF NOT EXISTS `textindex` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `ArticleID` int(11) NOT NULL, `MongoID` varchar(255) DEFAULT NULL, `Sort` int(11) NOT NULL, `Title` varchar(255) DEFAULT NULL, `Text` longtext, `Links` text NOT NULL, PRIMARY KEY (`ID`), KEY `ArticleID` (`ArticleID`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;"; stmt.executeUpdate(sql); } } catch (SQLException ex) { // handle any errors System.err.println("Fehler beim Initialisieren der mysql Datenbank..."); System.err.println("SQLException: " + ex.getMessage()); System.err.println("SQLState: " + ex.getSQLState()); System.err.println("VendorError: " + ex.getErrorCode()); System.err.println("Applikation wird beendet"); System.exit(0); } }
From source file:org.ossmeter.factoid.cocomo.CocomoFactoid.java
License:Open Source License
public static void main(String[] args) throws Exception { Mongo mongo = new Mongo(); DB db = mongo.getDB("Xtext"); CocomoFactoid f = new CocomoFactoid(); f.adapt(db);//from w w w. j av a2s .c om f.measure(null, null, new Factoids(db)); System.out.println(FactoidCategory.valueOf("asdasdasdd")); }
From source file:org.ossmeter.metricprovider.downloadcounter.github.GitHubDownloadCounterMetricProvider.java
License:Open Source License
public static void main(String[] args) { Date d = new Date(); GitHubDownloadCounterMetricProvider provider = new GitHubDownloadCounterMetricProvider(); Project p1 = (Project) provider.createGitHubProject("mojombo", "grit"); try {// www .j av a2 s .co m Mongo mongo; mongo = new Mongo(); PongoFactory.getInstance().getContributors().add(new OsgiPongoFactoryContributor()); Platform platform = new Platform(mongo); provider.measure(p1, new ProjectDelta(p1, d, platform), new DownloadCounter()); } catch (UnknownHostException e) { e.printStackTrace(); } }
From source file:org.ossmeter.platform.admin.LoggingInformation.java
License:Open Source License
@SuppressWarnings({ "rawtypes", "unchecked" }) @Get("json")/*from ww w . j a v a2s . c o m*/ public String represent() { @SuppressWarnings("unchecked") Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes() .get("org.restlet.http.headers"); if (responseHeaders == null) { responseHeaders = new Series(Header.class); getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders); } responseHeaders.add(new Header("Access-Control-Allow-Origin", "*")); responseHeaders.add(new Header("Access-Control-Allow-Methods", "GET")); try { Mongo mongo = new Mongo(); DB db = mongo.getDB("logging"); DBCollection col = db.getCollection("log"); ObjectMapper mapper = new ObjectMapper(); ArrayNode results = mapper.createArrayNode(); DBCursor cursor = col.find(); try { while (cursor.hasNext()) { DBObject p = cursor.next(); p.removeField("_id"); p.removeField("thread"); p.removeField("host"); p.removeField("class"); results.add(mapper.readTree(p.toString())); } } catch (JsonProcessingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { cursor.close(); } mongo.close(); return results.toString(); } catch (UnknownHostException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return null; }
From source file:org.ossmeter.platform.app.example.App.java
License:Open Source License
@Override public Object start(IApplicationContext context) throws Exception { // Add projects to the DB here Mongo mongo = new Mongo(); PongoFactory.getInstance().getContributors().add(new OsgiPongoFactoryContributor()); Platform platform = new Platform(mongo); // Project pongo = ProjectCreationUtil.createSvnProject("pongo", "http://pongo.googlecode.com/svn/trunk"); // platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(pongo); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("xText", "news.eclipse.org", "eclipse.modeling.tmf", true, "exquisitus", "flinder1f7", 80, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("epsilon", "news.eclipse.org", "eclipse.epsilon", true, "exquisitus", "flinder1f7", 80, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("thunderbird", "news.mozilla.org", "mozilla.support.thunderbird", false, null, null, 80, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("eclipsePlatform", "news.eclipse.org", "eclipse.platform", true, "exquisitus", "flinder1f7", 80, 10000); Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("BIRT", "news.eclipse.org", "eclipse.birt", true, "exquisitus", "flinder1f7", 80, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("SiriusForum", "news.eclipse.org", "eclipse.sirius", true, "exquisitus", "flinder1f7", 80, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("toolsEmf", "news.eclipse.org", "eclipse.tools.emf", true, "exquisitus", "flinder1f7", 80, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("Log4J", "news.gmane.org", "gmane.comp.jakarta.log4j.user", false, null, null, 119, 10000); // Project pdb = ProjectCreationUtil.createProjectWithNewsGroup("tomcat-user", "news.gmane.org", "gmane.comp.jakarta.tomcat.user", false, null, null, 119, 10000); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("epsilon", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "epsilon", null); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("eclipse", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "platform", null); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("modelinggmtamw", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "GMT", "AMW"); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("modelinggmt", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "GMT", null); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("xText", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "TMF", "Xtext"); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("fedora", "https://bugzilla.redhat.com/xmlrpc.cgi", "Fedora", "acpi"); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("bugzilla", "https://bugzilla.redhat.com/xmlrpc.cgi", "Bugzilla", null); // Url: https://bugs.eclipse.org/bugs/xmlrpc.cgi // Product: MDT.Papyrus // Components: Core, Diagram, Others, Table, Views // addSampleProjectWithBugTrackingSystem("MDT-Papyrus", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "MDT.Papyrus", "Core", platform); // addSampleProjectWithBugTrackingSystem("TMF-Xtext", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "TMF", "Xtext", platform); // Project pdb = ProjectCreationUtil.createProjectWithBugTrackingSystem("epsilon", "https://bugs.eclipse.org/bugs/xmlrpc.cgi", "epsilon", null); // Project pdb = ProjectCreationUtil.createGitProject("rascal", "file:///Users/jurgenv/Workspaces/Rascal/rascal"); pdb.getExecutionInformation().setMonitor(true); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(pdb); platform.getProjectRepositoryManager().getProjectRepository().sync(); System.err.println(platform.getBugTrackingSystemManager().getBugTrackingSystemManagers()); mongo.close();//w w w .j a va 2 s . com // Start the application return null; // return new OssmeterApplication().start(context); }
From source file:org.ossmeter.platform.app.example.DemoApp.java
License:Open Source License
public void run(IMetricProviderManager metricProviderManager, PlatformVcsManager platformVcsManager, PlatformCommunicationChannelManager communicationChannelManager, PlatformBugTrackingSystemManager bugTrackingSystemManager) throws Exception { // TODO: The platform needs to have been started for the API to work. mongo = new Mongo(); PongoFactory.getInstance().getContributors().add(new OsgiPongoFactoryContributor()); Platform platform = new Platform(mongo); // platform.setMetricProviderManager(metricProviderManager); // platform.setPlatformVcsManager(platformVcsManager); // platform.setPlatformCommunicationChannelManager(communicationChannelManager); // platform.setPlatformBugTrackingSystemManager(bugTrackingSystemManager); AdminApplication app = new AdminApplication(); while (true) { try {/*from ww w.j av a2s . co m*/ Thread.sleep(50000000); } catch (Exception e) { throw e; } } }
From source file:org.ossmeter.platform.app.example.ResetApp.java
License:Open Source License
public static void main(String[] args) throws Exception { Mongo mongo = new Mongo(); mongo.dropDatabase("ossmeter"); mongo.dropDatabase("pdb_values"); mongo.dropDatabase("pongo"); mongo.dropDatabase("fedora"); mongo.dropDatabase("epsilon"); mongo.dropDatabase("Epsilon"); mongo.dropDatabase("hamcrest"); mongo.dropDatabase("jMonkeyEngine"); mongo.dropDatabase("thunderbird"); mongo.dropDatabase("fedora"); mongo.dropDatabase("saf"); mongo.dropDatabase("mojambo-grit"); mongo.dropDatabase("emf"); mongo.dropDatabase("xText"); mongo.dropDatabase("toolsEmf"); mongo.dropDatabase("eclipsePlatform"); mongo.dropDatabase("pdb_values"); mongo.dropDatabase("pongo"); mongo.dropDatabase("modelinggmt"); mongo.dropDatabase("eclipse"); mongo.dropDatabase("modelinggmtamw"); mongo.dropDatabase("Log4J"); mongo.dropDatabase("BIRT"); mongo.dropDatabase("SiriusForum"); }
From source file:org.ossmeter.platform.communicationchannel.nntp.local.NNTPDownloader.java
License:Open Source License
public void downloadMessages(NntpNewsGroup newsgroup) throws Exception { final long startTime = System.currentTimeMillis(); long previousTime = startTime; previousTime = printTimeMessage(startTime, previousTime, "Download started"); NNTPClient nntpClient = NntpUtil.connectToNntpServer(newsgroup); NewsgroupInfo newsgroupInfo = NntpUtil.selectNewsgroup(nntpClient, newsgroup); int lastArticleChecked = newsgroupInfo.getFirstArticle(); previousTime = printTimeMessage(startTime, previousTime, "First message in newsgroup:\t" + lastArticleChecked); int lastArticle = newsgroupInfo.getLastArticle(); previousTime = printTimeMessage(startTime, previousTime, "Last message in newsgroup:\t" + lastArticle); previousTime = printTimeMessage(startTime, previousTime, "Articles in newsgroup:\t" + newsgroupInfo.getArticleCount()); System.err.println();//from w ww . ja v a 2 s . co m Mongo mongo = new Mongo(); DB db = mongo.getDB(newsgroup.getName() + "LocalStorage"); Messages dbMessages = new Messages(db); NewsgroupData newsgroupData = dbMessages.getNewsgroup().findOneByName(newsgroup.getName()); if (newsgroupData != null) { int newsgroupLastArticleChecked = Integer.parseInt(newsgroupData.getLastArticleChecked()); if (newsgroupLastArticleChecked > lastArticleChecked) { lastArticleChecked = newsgroupLastArticleChecked; } previousTime = printTimeMessage(startTime, previousTime, "Last article checked set to:\t" + lastArticleChecked); } else { newsgroupData = new NewsgroupData(); newsgroupData.setName(newsgroup.getName()); newsgroupData.setUrl(newsgroup.getUrl()); newsgroupData.setAuthenticationRequired(newsgroup.getAuthenticationRequired()); newsgroupData.setUsername(newsgroup.getUsername()); newsgroupData.setPassword(newsgroup.getPassword()); newsgroupData.setPort(newsgroup.getPort()); newsgroupData.setInterval(newsgroup.getInterval()); newsgroupData.setFirstArticle(lastArticleChecked + ""); dbMessages.getNewsgroup().add(newsgroupData); } int retrievalStep = RETRIEVAL_STEP; while (lastArticleChecked < lastArticle) { if (lastArticleChecked + retrievalStep > lastArticle) { retrievalStep = lastArticle - lastArticleChecked; } Article[] articles = NntpUtil.getArticleInfo(nntpClient, lastArticleChecked + 1, lastArticleChecked + retrievalStep); if (articles.length > 0) { Article lastArticleRetrieved = articles[articles.length - 1]; lastArticleChecked = lastArticleRetrieved.getArticleNumber(); newsgroupData.setLastArticleChecked(lastArticleChecked + ""); } previousTime = printTimeMessage(startTime, previousTime, "downloaded:\t" + articles.length + " nntp articles"); previousTime = printTimeMessage(startTime, previousTime, "downloading contents\t"); for (Article article : articles) { ArticleData articleData = new ArticleData(); articleData.setUrl(newsgroup.getUrl()); articleData.setArticleNumber(article.getArticleNumber()); articleData.setArticleId(article.getArticleId()); articleData.setDate(article.getDate()); articleData.setFrom(article.getFrom()); articleData.setSubject(article.getSubject()); for (String referenceId : article.getReferences()) articleData.getReferences().add(referenceId); articleData.setBody(NntpUtil.getArticleBody(nntpClient, article.getArticleNumber())); dbMessages.getArticles().add(articleData); } dbMessages.sync(); previousTime = printTimeMessage(startTime, previousTime, "stored:\t" + dbMessages.getArticles().size() + " / " + newsgroupInfo.getArticleCount() + " nntp articles sofar"); System.err.println(); } nntpClient.disconnect(); dbMessages.sync(); previousTime = printTimeMessage(startTime, previousTime, "stored:\t" + dbMessages.getArticles().size() + " / " + newsgroupInfo.getArticleCount() + " nntp articles"); }
From source file:org.ossmeter.platform.osgi.ExampleProjectCreator.java
License:Open Source License
public static void main(String[] args) throws Exception { Mongo mongo = new Mongo(); Platform platform = new Platform(mongo); Project project = new Project(); project.setName("Foo"); project.setShortName("Foo"); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(project); project = new Project(); project.setName("Bar"); project.setShortName("Bar"); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(project); project = new Project(); project.setName("Whizz"); project.setShortName("Whizz"); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(project); project = new Project(); project.setName("Baz"); project.setShortName("Baz"); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(project); project = new Project(); project.setName("Boop"); project.setShortName("Boop"); platform.getProjectRepositoryManager().getProjectRepository().getProjects().add(project); platform.getProjectRepositoryManager().getProjectRepository().getSchedulingInformation() .add(new SchedulingInformation()); platform.getProjectRepositoryManager().getProjectRepository().sync(); mongo.close();/*from w w w.jav a 2s. c om*/ }