Java Code Examples for com.mongodb.MongoClient#close()
The following examples show how to use
com.mongodb.MongoClient#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegisterActivity.java From medical-data-android with GNU General Public License v3.0 | 6 votes |
@Override protected Integer doInBackground(User... params) { try { MongoClientURI mongoClientURI = new MongoClientURI(Variables.mongo_uri); MongoClient mongoClient = new MongoClient(mongoClientURI); MongoDatabase dbMongo = mongoClient.getDatabase(mongoClientURI.getDatabase()); MongoCollection<Document> coll = dbMongo.getCollection("users"); User local_user = params[0]; if (coll.find(eq("email", local_user.getEmail())).first() != null) { mongoClient.close(); return 1; // Repeated email } Document document = local_user.getRegisterDocument(); coll.insertOne(document); local_user.setId(document.getObjectId("_id").toString()); mongoClient.close(); return 0; //Successfully saved } catch (Exception e) { return 2; // Error } }
Example 2
Source File: ProfileActivity.java From medical-data-android with GNU General Public License v3.0 | 6 votes |
@Override protected Integer doInBackground(User... params) { try { MongoClientURI mongoClientURI = new MongoClientURI(Variables.mongo_uri); MongoClient mongoClient = new MongoClient(mongoClientURI); MongoDatabase dbMongo = mongoClient.getDatabase(mongoClientURI.getDatabase()); MongoCollection<Document> coll = dbMongo.getCollection("users"); User local_user = params[0]; if (!local_user.getEmail().equals(original_email)) { Document user = coll.find(eq("email", local_user.getEmail())).first(); if (user != null) { return 1; // Repeated email } } Document search = new Document("_id", new ObjectId(local_user.getId())); Document replacement = new Document("$set", local_user.getRegisterDocument()); // We update some fields of the documents without affecting the rest coll.updateOne(search, replacement); mongoClient.close(); return 0; //Successfully saved } catch (Exception e) { return 2; // Error } }
Example 3
Source File: MongoWrapperDefaultHandler.java From DBus with Apache License 2.0 | 6 votes |
/** * 根据oid去数据库回查数据 * * @param oid * @return */ private Document fetchData(String schemaName, String tableName, String oid) { Document result = null; DbusDatasource datasource = GlobalCache.getDatasource(); MongoClientURI uri = new MongoClientURI(datasource.getMasterUrl()); MongoClient client = new MongoClient(uri); MongoDatabase database = client.getDatabase(schemaName); MongoCollection<Document> collection = database.getCollection(tableName); MongoCursor<Document> cursor = collection.find(new BasicDBObject().append("_id", new ObjectId(oid))).iterator(); if (cursor.hasNext()) { result = cursor.next(); } else { logger.error("get source data error. schemaName:{}, tableName:{}, oid:{}", schemaName, tableName, oid); } client.close(); return result; }
Example 4
Source File: DFMongoManager.java From dfactor with MIT License | 5 votes |
protected void closePool(int id){ MongoClient cli = null; lockWrite.lock(); try{ cli = mapPool.remove(id); }finally{ lockWrite.unlock(); } if(cli != null){ cli.close(); cli = null; } }
Example 5
Source File: DatabaseTools.java From hvdf with Apache License 2.0 | 5 votes |
public static void dropDatabaseByURI(MongoClientURI uri, String dbName) throws UnknownHostException{ MongoClient client = new MongoClient(uri); DB database = client.getDB(dbName); database.dropDatabase(); client.close(); }
Example 6
Source File: DatabaseTools.java From hvdf with Apache License 2.0 | 5 votes |
public static void dropCollection(MongoClientURI uri, String dbName) throws UnknownHostException{ MongoClient client = new MongoClient(uri); DB database = client.getDB(dbName); database.dropDatabase(); client.close(); }
Example 7
Source File: MongoDBClientSupport.java From brooklyn-library with Apache License 2.0 | 5 votes |
public long getShardCount() { MongoClient client = client(); try { return client.getDB("config").getCollection("shards").getCount(); } finally { client.close(); } }
Example 8
Source File: DatabaseTools.java From socialite with Apache License 2.0 | 5 votes |
public static void dropDatabaseByURI(MongoClientURI uri, String dbName) throws UnknownHostException{ MongoClient client = new MongoClient(uri); MongoDatabase database = client.getDatabase(dbName); database.drop(); client.close(); }
Example 9
Source File: MongoClientDecorator.java From jpa-unit with Apache License 2.0 | 5 votes |
@Override public void afterAll(final TestInvocation invocation) throws Exception { final ExecutionContext context = invocation.getContext(); final MongoClient client = (MongoClient) context.getData(Constants.KEY_MONGO_CLIENT); context.storeData(Constants.KEY_MONGO_CLIENT, null); client.close(); }
Example 10
Source File: DoTestMongoClientProxy.java From uavstack with Apache License 2.0 | 5 votes |
public static void main(String args[]) { ConsoleLogger cl = new ConsoleLogger("test"); cl.setDebugable(true); UAVServer.instance().setLog(cl); UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR, ServerVendor.TOMCAT); MongoClientHookProxy p = new MongoClientHookProxy("test", Collections.emptyMap()); p.doInstallDProxy(null, "testApp"); MongoClient client = new MongoClient(); client.listDatabaseNames().first(); MongoDatabase db = client.getDatabase("apphubDataStore"); db.listCollectionNames().first(); MongoCollection<Document> collection = db.getCollection("test"); collection.listIndexes().first(); Document doc = new Document("name", "Amarcord Pizzeria") .append("contact", new Document("phone", "264-555-0193").append("email", "[email protected]") .append("location", Arrays.asList(-73.88502, 40.749556))) .append("stars", 2).append("categories", Arrays.asList("Pizzeria", "Italian", "Pasta")); collection.insertOne(doc); collection.find().first(); MongoClient client2 = new MongoClient("localhost:27017"); db = client2.getDatabase("apphubDataStore"); db.listCollectionNames().first(); collection = db.getCollection("test"); collection.listIndexes().first(); client.close(); client2.close(); }
Example 11
Source File: PatchCounter.java From repairnator with MIT License | 5 votes |
/** * Has the number of patches or patched builds exceeded the number * we intend them to run for? * @return yes or no (true or false) */ public boolean keepRunning() { if(numberOfPatchesToRunFor == 0) { return true; } MongoClient client = new MongoClient(new MongoClientURI(this.mongodbHost + "/" + this.mongodbName)); MongoDatabase mongo = client.getDatabase(this.mongodbName); boolean run = this.numberOfPatchesToRunFor > numberOfBuildsPatched(mongo); client.close(); return run; // return this.numberOfPatchesToRunFor > numberOfPatches(mongo); }
Example 12
Source File: InferenceExamples.java From rya with Apache License 2.0 | 5 votes |
private static Configuration getConf() throws IOException { // MongoDBIndexingConfigBuilder builder = MongoIndexingConfiguration.builder() // .setUseMockMongo(USE_MOCK).setUseInference(USE_INFER).setAuths("U"); MongoDBIndexingConfigBuilder builder = MongoIndexingConfiguration.builder() .setUseMockMongo(USE_EMBEDDED_MONGO).setUseInference(true).setAuths("U"); if (USE_EMBEDDED_MONGO) { final MongoClient c = EmbeddedMongoFactory.newFactory().newMongoClient(); final Net address = EmbeddedMongoFactory.newFactory().getMongoServerDetails().net(); final String url = address.getServerAddress().getHostAddress(); final String port = Integer.toString(address.getPort()); c.close(); builder.setMongoHost(url).setMongoPort(port); } else { // User name and password must be filled in: builder = builder.setMongoUser(MongoUserName) .setMongoPassword(MongoUserPswd) .setMongoHost(MONGO_INSTANCE_URL) .setMongoPort(MONGO_INSTANCE_PORT); } return builder.setMongoDBName(MONGO_DB) .setMongoCollectionPrefix(MONGO_COLL_PREFIX) .setUseMongoFreetextIndex(true) .setMongoFreeTextPredicates(RDFS.LABEL.stringValue()).build(); }
Example 13
Source File: TransformationQueryTest.java From epcis with Apache License 2.0 | 4 votes |
public void test() throws IOException, InterruptedException { File file = new File(fileBaseLoc + this.getClass().getSimpleName() + "-cache-bfs"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase("epcis"); db.getCollection("EventData").drop(); db.getCollection("edges").drop(); db.getCollection("vertices").drop(); db.getCollection("tEdgeEvents").drop(); db.getCollection("tVertexEvents").drop(); MongoDatabase db2 = client.getDatabase("epcis-data"); db2.getCollection("vertices").drop(); client.close(); for (int i = 0; i < transferCount; i++) { // Insert Event String top = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!DOCTYPE project>\n" + "<epcis:EPCISDocument schemaVersion=\"1.2\"\n" + " creationDate=\"2013-06-04T14:59:02.099+02:00\" xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\"\n" + " xmlns:example=\"http://ns.example.com/epcis\">\n" + " <EPCISBody>\n" + " <EventList>"; String bottom = "</EventList>\n" + " </EPCISBody>\n" + "</epcis:EPCISDocument>"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); String cTime = sdf.format(new Date()); String body = ""; cTime = sdf.format(new Date()); body += "<extension>\n" + " <TransformationEvent>\n" + " <eventTime>" + cTime + "</eventTime>\n" + " <eventTimeZoneOffset>+00:00</eventTimeZoneOffset>\n" + " <inputEPCList>\n" + " <epc>urn:epc:id:sgtin:0000001.000001." + i + "</epc>\n" + " </inputEPCList>\n" + " <outputEPCList>\n" + " <epc>urn:epc:id:sgtin:0000001.000001." + (2 * i + 1) + "</epc>\n" + " <epc>urn:epc:id:sgtin:0000001.000001." + (2 * i + 2) + "</epc>\n" + " </outputEPCList>\n" + " </TransformationEvent>\n" + " </extension>"; EventCapture cap = new EventCapture(); cap.capture(top + body + bottom); Thread.sleep(2000); int length = doTransformationQuery(); System.out.println(i + "\t" + length); bw.write(i + "\t" + length + "\n"); bw.flush(); } bw.close(); }
Example 14
Source File: LocationQueryEmulationTest.java From epcis with Apache License 2.0 | 4 votes |
public void test() throws IOException, InterruptedException, ParserConfigurationException, SAXException, ParseException { File file = new File(fileBaseLoc + this.getClass().getSimpleName() + "-cache-bfs"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase("epcis"); db.getCollection("EventData").drop(); db.getCollection("edges").drop(); db.getCollection("vertices").drop(); db.getCollection("edges").createIndex(new BsonDocument("_outV", new BsonInt32(1)).append("_t", new BsonInt32(1)) .append("_inV", new BsonInt32(1))); client.close(); for (int i = 0; i < transferCount; i++) { // Insert Event String top = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!DOCTYPE project>\n" + "<epcis:EPCISDocument schemaVersion=\"1.2\"\n" + " creationDate=\"2013-06-04T14:59:02.099+02:00\" xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\"\n" + " xmlns:example=\"http://ns.example.com/epcis\">\n" + " <EPCISBody>\n" + " <EventList>"; String bottom = "</EventList>\n" + " </EPCISBody>\n" + "</epcis:EPCISDocument>"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); String cTime = sdf.format(new Date()); String body = ""; Thread.sleep(1000); cTime = sdf.format(new Date()); body += "<ObjectEvent>\n" + " <eventTime>" + cTime + "</eventTime>\n" + " <eventTimeZoneOffset>+00:00</eventTimeZoneOffset>\n" + " <epcList>\n" + " <epc>urn:epc:id:sgtin:0000001.000001.0</epc>\n" + " </epcList>\n" + " <action>OBSERVE</action>\n" + " <bizStep>urn:epcglobal:cbv:bizstep:receiving</bizStep>\n" + " <bizLocation>\n" + " <id>urn:epc:id:sgln:0000001.00001." + i + "</id>\n" + " </bizLocation>\n" + "</ObjectEvent>"; EventCapture cap = new EventCapture(); cap.capture(top + body + bottom); Thread.sleep(1000); double avg = doTransformationQuery(); System.out.println(i + "\t" + avg); bw.write(i + "\t" + avg + "\n"); bw.flush(); } bw.close(); }
Example 15
Source File: TimedSummaryNotifier.java From repairnator with MIT License | 4 votes |
@Override public void run() { while (true) { if (this.intervalHasPassed()) { MongoClient client = new MongoClient( new MongoClientURI(this.mongodbHost + "/" + this.mongodbName)); MongoDatabase mongo = client.getDatabase(this.mongodbName); updateFilters(lastNotificationTime.getTime()); // Number of analyzed builds, rtscanner Iterator<Document> nrOfDocuments = queryDatabase("rtscanner", rtscannerFilter, mongo); int nrOfAnalyzedBuilds = nrOfObjects(nrOfDocuments); // Number of repair attempts, inspector status is everything needed nrOfDocuments = queryDatabase("inspector", repairAttemptsFilter, mongo); int nrOfRepairAttempts = nrOfObjects(nrOfDocuments); // Total number of patches, patches nrOfDocuments = queryDatabase("inspector", patchedBuildsFilter, mongo); int nrOfBuildsWithPatches = nrOfObjects(nrOfDocuments); // Number of patches per tool, patches with an if int[] nrOfPatchesPerTool = new int[repairTools.length]; for (int i = 0; i < repairTools.length; i++) { nrOfDocuments = queryDatabase("patches", toolFilters.get(repairTools[i]), mongo); nrOfPatchesPerTool[i] = nrOfObjects(nrOfDocuments); } Date now = new Date(); String message = createMessage(nrOfAnalyzedBuilds, nrOfRepairAttempts, nrOfBuildsWithPatches, nrOfPatchesPerTool, now); updateLastNotificationTime(now); notifyEngines("Repairnator: Summary email", message); client.close(); } else { try { Thread.sleep(TIME_TO_SLEEP); } catch (InterruptedException e) { } } } }
Example 16
Source File: SendTest.java From medical-data-android with GNU General Public License v3.0 | 4 votes |
@Override protected Boolean doInBackground(Context... params) { Context context = params[0]; SharedPreferences settings = context.getSharedPreferences(Variables.PREFS_NAME, Context.MODE_PRIVATE); int local_tests = settings.getInt("local_tests", 0); Log.v(TAG, "Tests: " + String.valueOf(local_tests)); if (local_tests > 0 && canConnect(context, settings)) { try { MongoClientURI mongoClientURI = new MongoClientURI(Variables.mongo_uri); MongoClient mongoClient = new MongoClient(mongoClientURI); MongoDatabase dbMongo = mongoClient.getDatabase(mongoClientURI.getDatabase()); MongoCollection<Document> coll = dbMongo.getCollection("mobileTests"); boolean isFemale = settings.getBoolean("gender", true); ObjectId user_id = new ObjectId(settings.getString("user_id", "")); Cursor c = getSQLCursor(context, local_tests); c.moveToLast(); for (; local_tests > 0; local_tests--) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(FeedTestContract.dateWithTimezone(c.getString(0))); String date_string = format.format(cal.getTime()); Log.v(TAG, date_string); Date original_date = format.parse(date_string); DateFormat format_day = new SimpleDateFormat("yyyy-MM-dd"); Date today_date = format_day.parse(date_string); Log.v(TAG, today_date.toString()); cal.setTime(today_date); cal.add(Calendar.DATE, 1); // number of days to add Date tomorrow_date = cal.getTime(); // dt is now the new date Log.v(TAG, tomorrow_date.toString()); Document document = getDoc(c, user_id, isFemale, original_date); MongoCursor<Document> it = coll.find(and(and(lt("date", tomorrow_date), gte("date", today_date)), eq("user_id", user_id))).limit(1).iterator(); if (it.hasNext()) { // replace the entire document except for the _id field coll.replaceOne(new Document("_id", it.next().getObjectId("_id")), document); } else { coll.insertOne(document); } c.moveToPrevious(); } mongoClient.close(); deleteSQLEntries(context); } catch (Exception e) { Log.v(TAG, e.toString()); } Variables.saveLocalTests(TAG, settings, local_tests); } boolean start = (local_tests > 0); Log.v(TAG, "Flag: " + (start ? "enabled" : "disabled") + ", Tests: " + String.valueOf(local_tests)); return start; }
Example 17
Source File: AggregationQueryTest2.java From epcis with Apache License 2.0 | 4 votes |
public void test() throws IOException, InterruptedException { File file = new File(fileBaseLoc + this.getClass().getSimpleName() + "-cache-bfs"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase("epcis"); db.getCollection("EventData").drop(); db.getCollection("edges").drop(); db.getCollection("vertices").drop(); db.getCollection("edges").createIndex(new BsonDocument("_outV", new BsonInt32(1)).append("_t", new BsonInt32(1)) .append("_inV", new BsonInt32(1))); client.close(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); String cTime = sdf.format(new Date()); long lastTimeMil = System.currentTimeMillis() + 100000000; for (int i = 0; i < transferCount; i++) { Thread.sleep(1000); cTime = sdf.format(new Date()); String epcParent = String.format("%010d", i + 1); String epcChild = String.format("%010d", i); // urn:epc:id:sscc:0000002.0000000001 String top = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!DOCTYPE project>\n" + "<epcis:EPCISDocument schemaVersion=\"1.2\"\n" + " creationDate=\"2013-06-04T14:59:02.099+02:00\" xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\"\n" + " xmlns:example=\"http://ns.example.com/epcis\">\n" + " <EPCISBody>\n" + " <EventList>"; String bottom = "</EventList>\n" + " </EPCISBody>\n" + "</epcis:EPCISDocument>"; String body = "<AggregationEvent>\n" + " <eventTime>" + cTime + "</eventTime>\n" + " <eventTimeZoneOffset>+00:00</eventTimeZoneOffset>\n" + " <parentID>urn:epc:id:sscc:0000001." + epcParent + "</parentID>\n" + " <childEPCs>\n" + " <epc>urn:epc:id:sscc:0000001." + epcChild + "</epc>\n" + " </childEPCs>\n" + " <action>ADD</action>\n" + " <bizStep>urn:epcglobal:cbv:bizstep:loading</bizStep>\n" + " <!-- TNT Liverpool depot -->\n" + " <bizLocation>\n" + " <id>urn:epc:id:sgln:0000001.00002.1</id>\n" + " </bizLocation>\n" + " </AggregationEvent>"; String lastTime = sdf.format(new Date(lastTimeMil - i)); body += "<AggregationEvent>\n" + " <eventTime>" + lastTime + "</eventTime>\n" + " <eventTimeZoneOffset>+00:00</eventTimeZoneOffset>\n" + " <parentID>urn:epc:id:sscc:0000001." + epcParent + "</parentID>\n" + " <childEPCs>\n" + " <epc>urn:epc:id:sscc:0000001." + epcChild + "</epc>\n" + " </childEPCs>\n" + " <action>DELETE</action>\n" + " <bizStep>urn:epcglobal:cbv:bizstep:loading</bizStep>\n" + " <!-- TNT Liverpool depot -->\n" + " <bizLocation>\n" + " <id>urn:epc:id:sgln:0000001.00002.1</id>\n" + " </bizLocation>\n" + " </AggregationEvent>"; EventCapture cap = new EventCapture(); cap.capture(top + body + bottom); Thread.sleep(3000); int avg = doTransformationQuery(); System.out.println(i + "\t" + avg); bw.write(i + "\t" + avg + "\n"); bw.flush(); } bw.close(); }
Example 18
Source File: AggregationQueryTest.java From epcis with Apache License 2.0 | 4 votes |
public void test() throws IOException, InterruptedException { File file = new File(fileBaseLoc + this.getClass().getSimpleName() + "-cache-bfs"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase("epcis"); db.getCollection("EventData").drop(); db.getCollection("edges").drop(); db.getCollection("vertices").drop(); db.getCollection("edges").createIndex(new BsonDocument("_outV", new BsonInt32(1)).append("_t", new BsonInt32(1)) .append("_inV", new BsonInt32(1))); client.close(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); String cTime = sdf.format(new Date()); long lastTimeMil = System.currentTimeMillis() + 100000000; for (int i = 0; i < transferCount; i++) { Thread.sleep(1000); cTime = sdf.format(new Date()); String epcParent = String.format("%010d", i + 1); String epcChild = String.format("%010d", i); // urn:epc:id:sscc:0000002.0000000001 String top = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!DOCTYPE project>\n" + "<epcis:EPCISDocument schemaVersion=\"1.2\"\n" + " creationDate=\"2013-06-04T14:59:02.099+02:00\" xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\"\n" + " xmlns:example=\"http://ns.example.com/epcis\">\n" + " <EPCISBody>\n" + " <EventList>"; String bottom = "</EventList>\n" + " </EPCISBody>\n" + "</epcis:EPCISDocument>"; String body = "<AggregationEvent>\n" + " <eventTime>" + cTime + "</eventTime>\n" + " <eventTimeZoneOffset>+00:00</eventTimeZoneOffset>\n" + " <parentID>urn:epc:id:sscc:0000001." + epcParent + "</parentID>\n" + " <childEPCs>\n" + " <epc>urn:epc:id:sscc:0000001." + epcChild + "</epc>\n" + " </childEPCs>\n" + " <action>ADD</action>\n" + " <bizStep>urn:epcglobal:cbv:bizstep:loading</bizStep>\n" + " <!-- TNT Liverpool depot -->\n" + " <bizLocation>\n" + " <id>urn:epc:id:sgln:0000001.00002.1</id>\n" + " </bizLocation>\n" + " </AggregationEvent>"; String lastTime = sdf.format(new Date(lastTimeMil - i)); body += "<AggregationEvent>\n" + " <eventTime>" + lastTime + "</eventTime>\n" + " <eventTimeZoneOffset>+00:00</eventTimeZoneOffset>\n" + " <parentID>urn:epc:id:sscc:0000001." + epcParent + "</parentID>\n" + " <childEPCs>\n" + " <epc>urn:epc:id:sscc:0000001." + epcChild + "</epc>\n" + " </childEPCs>\n" + " <action>DELETE</action>\n" + " <bizStep>urn:epcglobal:cbv:bizstep:loading</bizStep>\n" + " <!-- TNT Liverpool depot -->\n" + " <bizLocation>\n" + " <id>urn:epc:id:sgln:0000001.00002.1</id>\n" + " </bizLocation>\n" + " </AggregationEvent>"; EventCapture cap = new EventCapture(); cap.capture(top + body + bottom); Thread.sleep(1000); double avg = doTransformationQuery(); System.out.println(i + "\t" + avg); bw.write(i + "\t" + avg + "\n"); bw.flush(); } bw.close(); }
Example 19
Source File: TransformationQueryTestC.java From epcis with Apache License 2.0 | 4 votes |
public void test() throws IOException, InterruptedException { File file = new File(fileBaseLoc + this.getClass().getSimpleName() + "-cache-bfs"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase("epcis"); db.getCollection("EventData").drop(); db.getCollection("edges").drop(); db.getCollection("vertices").drop(); db.getCollection("edges").createIndex(new BsonDocument("_outV", new BsonInt32(1)).append("_label", new BsonInt32(1)).append("_t", new BsonInt32(1)) .append("_inV", new BsonInt32(1))); client.close(); for (int i = 0; i < transferCount; i++) { // Insert Event String top = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!DOCTYPE project>\n" + "<epcis:EPCISDocument schemaVersion=\"1.2\"\n" + " creationDate=\"2013-06-04T14:59:02.099+02:00\" xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\"\n" + " xmlns:example=\"http://ns.example.com/epcis\">\n" + " <EPCISBody>\n" + " <EventList>"; String bottom = "</EventList>\n" + " </EPCISBody>\n" + "</epcis:EPCISDocument>"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); String cTime = sdf.format(new Date()); String body = ""; cTime = sdf.format(new Date()); body += "<extension>\n" + " <TransformationEvent>\n" + " <eventTime>" + cTime + "</eventTime>\n" + " <eventTimeZoneOffset>+00:00</eventTimeZoneOffset>\n" + " <inputEPCList>\n" + " <epc>urn:epc:id:sgtin:0000001.000001." + i + "</epc>\n" + " </inputEPCList>\n" + " <outputEPCList>\n" + " <epc>urn:epc:id:sgtin:0000001.000001." + (2 * i + 1) + "</epc>\n" + " <epc>urn:epc:id:sgtin:0000001.000001." + (2 * i + 2) + "</epc>\n" + " </outputEPCList>\n" + " </TransformationEvent>\n" + " </extension>"; EventCapture cap = new EventCapture(); cap.capture(top + body + bottom); Thread.sleep(2000); double avg = doTransformationQuery(); System.out.println(i + "\t" + avg); bw.write(i + "\t" + avg + "\n"); bw.flush(); } bw.close(); }
Example 20
Source File: OwnershipTransferQueryEmulationTest.java From epcis with Apache License 2.0 | 4 votes |
public void test() throws IOException, InterruptedException, ParserConfigurationException, SAXException, ParseException { File file = new File(fileBaseLoc + this.getClass().getSimpleName() + "-cache-bfs"); file.createNewFile(); FileWriter fw = new FileWriter(file); BufferedWriter bw = new BufferedWriter(fw); MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase("epcis"); db.getCollection("EventData").drop(); db.getCollection("edges").drop(); db.getCollection("vertices").drop(); db.getCollection("edges").createIndex(new BsonDocument("_outV", new BsonInt32(1)).append("_t", new BsonInt32(1)) .append("_inV", new BsonInt32(1))); client.close(); for (int i = 0; i < transferCount; i++) { // Insert Event String top = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!DOCTYPE project>\n" + "<epcis:EPCISDocument schemaVersion=\"1.2\"\n" + " creationDate=\"2013-06-04T14:59:02.099+02:00\" xmlns:epcis=\"urn:epcglobal:epcis:xsd:1\"\n" + " xmlns:example=\"http://ns.example.com/epcis\">\n" + " <EPCISBody>\n" + " <EventList>"; String bottom = "</EventList>\n" + " </EPCISBody>\n" + "</epcis:EPCISDocument>"; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); String cTime = sdf.format(new Date()); String body = ""; Thread.sleep(1000); cTime = sdf.format(new Date()); body += "<ObjectEvent>\n" + " <eventTime>" + cTime + "</eventTime>\n" + " <eventTimeZoneOffset>+00:00</eventTimeZoneOffset>\n" + " <epcList>\n" + " <epc>urn:epc:id:sgtin:0000001.000001.0</epc>\n" + " </epcList>\n" + " <action>OBSERVE</action>\n" + " <bizStep>urn:epcglobal:cbv:bizstep:receiving</bizStep>\n" + " <bizLocation>\n" + " <id>urn:epc:id:sgln:0000001.00002.1</id>\n" + " </bizLocation>\n" + " <extension>\n" + " <sourceList>\n" + " <source type=\"urn:epcglobal:cbv:sdt:possessing_party\">urn:epc:id:sgln:0000001.00001." + i + "</source>\n" + " </sourceList>\n" + " <destinationList>\n" + " <destination type=\"urn:epcglobal:cbv:sdt:possessing_party\">urn:epc:id:sgln:0000001.00001." + (i + 1) + "</destination>\n" + " </destinationList>\n" + " </extension>\n" + "</ObjectEvent>"; EventCapture cap = new EventCapture(); cap.capture(top + body + bottom); Thread.sleep(1000); double avg = doTransformationQuery(); System.out.println(i + "\t" + avg); bw.write(i + "\t" + avg + "\n"); bw.flush(); } bw.close(); }