org.bson.BsonDateTime Java Examples
The following examples show how to use
org.bson.BsonDateTime.
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: MongoAdapterTest.java From calcite with Apache License 2.0 | 7 votes |
@BeforeAll public static void setUp() throws Exception { MongoDatabase database = POLICY.database(); populate(database.getCollection("zips"), MongoAdapterTest.class.getResource("/zips-mini.json")); populate(database.getCollection("store"), FoodmartJson.class.getResource("/store.json")); populate(database.getCollection("warehouse"), FoodmartJson.class.getResource("/warehouse.json")); // Manually insert data for data-time test. MongoCollection<BsonDocument> datatypes = database.getCollection("datatypes") .withDocumentClass(BsonDocument.class); if (datatypes.countDocuments() > 0) { datatypes.deleteMany(new BsonDocument()); } BsonDocument doc = new BsonDocument(); Instant instant = LocalDate.of(2012, 9, 5).atStartOfDay(ZoneOffset.UTC).toInstant(); doc.put("date", new BsonDateTime(instant.toEpochMilli())); doc.put("value", new BsonInt32(1231)); doc.put("ownerId", new BsonString("531e7789e4b0853ddb861313")); datatypes.insertOne(doc); schema = new MongoSchema(database); }
Example #2
Source File: ChronoGraph.java From epcis with Apache License 2.0 | 6 votes |
public HashSet<Long> getTimestampsHashSet() { HashSet<Long> timestampSet = new HashSet<Long>(); Function<BsonDateTime, Long> mapper = new Function<BsonDateTime, Long>() { @Override public Long apply(BsonDateTime val) { return val.getValue(); } }; edges.distinct(Tokens.TIMESTAMP, BsonDateTime.class) .filter(new BsonDocument(Tokens.TIMESTAMP, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull()))) .map(mapper).into(timestampSet); return timestampSet; }
Example #3
Source File: ChronoElement.java From epcis with Apache License 2.0 | 6 votes |
/** * @param timestamp * @param projection * @return TimestampProperties BsonDocument only containing projection keys */ public BsonDocument getTimestampProperties(final Long timestamp, final String[] projection) { BsonDocument bsonProjection = new BsonDocument(); if (projection != null) { for (String string : projection) { bsonProjection.append(string, new BsonBoolean(true)); } } if (this instanceof ChronoVertex) return graph.getVertexEvents().find(new BsonDocument(Tokens.VERTEX, new BsonString(this.id)) .append(Tokens.TIMESTAMP, new BsonDateTime(timestamp))).projection(bsonProjection).first(); else return graph.getEdgeCollection() .find(new BsonDocument(Tokens.ID, new BsonString(this.id + "-" + timestamp))) .projection(bsonProjection).first(); }
Example #4
Source File: UpdateOneTimestampsStrategy.java From kafka-connect-mongodb with Apache License 2.0 | 6 votes |
@Override public WriteModel<BsonDocument> createWriteModel(SinkDocument document) { BsonDocument vd = document.getValueDoc().orElseThrow( () -> new DataException("error: cannot build the WriteModel since" + " the value document was missing unexpectedly") ); BsonDateTime dateTime = new BsonDateTime(Instant.now().toEpochMilli()); return new UpdateOneModel<>( new BsonDocument(DBCollection.ID_FIELD_NAME, vd.get(DBCollection.ID_FIELD_NAME)), new BsonDocument("$set", vd.append(FIELDNAME_MODIFIED_TS, dateTime)) .append("$setOnInsert", new BsonDocument(FIELDNAME_INSERTED_TS, dateTime)), UPDATE_OPTIONS ); }
Example #5
Source File: MongoUtil.java From game-server with MIT License | 6 votes |
public static BsonValue getBsonValue(Object obj) { if (obj instanceof Integer) { return new BsonInt32((Integer) obj); } if (obj instanceof String) { return new BsonString((String) obj); } if (obj instanceof Long) { return new BsonInt64((Long) obj); } if (obj instanceof Date) { return new BsonDateTime(((Date) obj).getTime()); } if (obj instanceof Double || obj instanceof Float) { return new BsonDouble((Double) obj); } return new BsonNull(); }
Example #6
Source File: MongoUtil.java From game-server with MIT License | 6 votes |
public static BsonValue getBsonValue(Object obj) { if (obj instanceof Integer) { return new BsonInt32((Integer) obj); } if (obj instanceof String) { return new BsonString((String) obj); } if (obj instanceof Long) { return new BsonInt64((Long) obj); } if (obj instanceof Date) { return new BsonDateTime(((Date) obj).getTime()); } if (obj instanceof Double || obj instanceof Float) { return new BsonDouble((Double) obj); } return new BsonNull(); }
Example #7
Source File: MongoDBAppender.java From heimdall with Apache License 2.0 | 6 votes |
@Override protected void append(ILoggingEvent e) { ZoneId zoneId = ZoneId.of(this.zoneId); // Offset in milliseconds based on the informed Zone long offset = zoneId.getRules().getOffset(Instant.now()).getTotalSeconds() * 1000; Map<String, Object> objLog = new HashMap<>(); objLog.put("ts", new BsonDateTime(e.getTimeStamp() + offset)); objLog.put("trace", BasicDBObject.parse(e.getFormattedMessage())); objLog.put("level", e.getLevel().toString()); objLog.put("logger", e.getLoggerName()); objLog.put("thread", e.getThreadName()); if (e.hasCallerData()) { StackTraceElement st = e.getCallerData()[0]; String callerData = String.format("%s.%s:%d", st.getClassName(), st.getMethodName(), st.getLineNumber()); objLog.put("caller", callerData); } Map<String, String> mdc = e.getMDCPropertyMap(); if (mdc != null && !mdc.isEmpty()) { objLog.put("mdc", new BasicDBObject(mdc)); } collection.insertOne(new Document(objLog)); }
Example #8
Source File: JavaTimeTest.java From immutables with Apache License 2.0 | 6 votes |
@Test public void localDate() throws IOException { long epoch = System.currentTimeMillis(); LocalDate now = Instant.ofEpochMilli(epoch).atOffset(ZoneOffset.UTC).toLocalDate(); TypeAdapter<LocalDate> adapter = gson.getAdapter(LocalDate.class); // read LocalDate date = adapter.read(Jsons.readerAt(new BsonDateTime(epoch))); check(date).is(now); // write BsonValue bson = writeAndReadBson(now); check(bson.getBsonType()).is(BsonType.DATE_TIME); check(Instant.ofEpochMilli(bson.asDateTime().getValue()).atOffset(ZoneOffset.UTC).toLocalDate()).is(now); }
Example #9
Source File: JavaTimeTest.java From immutables with Apache License 2.0 | 6 votes |
@Test public void localDateTime() throws IOException { LocalDateTime now = LocalDateTime.now(); long epoch = now.toInstant(ZoneOffset.UTC).toEpochMilli(); TypeAdapter<LocalDateTime> adapter = gson.getAdapter(LocalDateTime.class); // read LocalDateTime date = adapter.read(Jsons.readerAt(new BsonDateTime(epoch))); LocalDateTime valueRead = Instant.ofEpochMilli(epoch).atOffset(ZoneOffset.UTC).toLocalDateTime(); check(date).is(now); // write BsonValue bson = writeAndReadBson(valueRead); check(bson.getBsonType()).is(BsonType.DATE_TIME); check(Instant.ofEpochMilli(bson.asDateTime().getValue()).atOffset(ZoneOffset.UTC).toLocalDateTime()).is(valueRead); }
Example #10
Source File: JavaTimeTest.java From immutables with Apache License 2.0 | 6 votes |
@Test public void instant() throws IOException { Instant now = Instant.now(); long epoch = now.toEpochMilli(); TypeAdapter<Instant> adapter = gson.getAdapter(Instant.class); // read Instant date = adapter.read(Jsons.readerAt(new BsonDateTime(epoch))); check(date).is(now); // write BsonValue bson = writeAndReadBson(now); check(bson.getBsonType()).is(BsonType.DATE_TIME); check(Instant.ofEpochMilli(bson.asDateTime().getValue())).is(now); }
Example #11
Source File: JavaTimeTest.java From immutables with Apache License 2.0 | 6 votes |
@Test public void javaUtilDate() throws IOException { Date now = new Date(); long epoch = now.getTime(); TypeAdapter<Date> adapter = GsonCodecs.typeAdapterFromCodec(new DateCodec()); // read Date date = adapter.read(Jsons.readerAt(new BsonDateTime(epoch))); check(date).is(now); // write BsonValue bson = writeAndReadBson(now); check(bson.getBsonType()).is(BsonType.DATE_TIME); check(new Date(bson.asDateTime().getValue())).is(now); }
Example #12
Source File: UpdateOneTimestampsStrategy.java From mongo-kafka with Apache License 2.0 | 6 votes |
@Override public WriteModel<BsonDocument> createWriteModel(final SinkDocument document) { BsonDocument vd = document .getValueDoc() .orElseThrow( () -> new DataException( "Error: cannot build the WriteModel since the value document was missing unexpectedly")); BsonDateTime dateTime = new BsonDateTime(Instant.now().toEpochMilli()); return new UpdateOneModel<>( new BsonDocument(ID_FIELD, vd.get(ID_FIELD)), new BsonDocument("$set", vd.append(FIELD_NAME_MODIFIED_TS, dateTime)) .append("$setOnInsert", new BsonDocument(FIELD_NAME_INSERTED_TS, dateTime)), UPDATE_OPTIONS); }
Example #13
Source File: ChronoGraph.java From epcis with Apache License 2.0 | 6 votes |
public TreeSet<Long> getTimestamps(Long startTime, Long endTime) { TreeSet<Long> timestampSet = new TreeSet<Long>(); Function<BsonDateTime, Long> mapper = new Function<BsonDateTime, Long>() { @Override public Long apply(BsonDateTime val) { return val.getValue(); } }; edgeEvents.distinct(Tokens.TIMESTAMP, BsonDateTime.class) .filter(new BsonDocument(Tokens.TIMESTAMP, new BsonDocument(Tokens.FC.$gt.toString(), new BsonDateTime(startTime)) .append(Tokens.FC.$lt.toString(), new BsonDateTime(endTime)))) .map(mapper).into(timestampSet); Set<Long> vtSet = new TreeSet<Long>(); vertexEvents.distinct(Tokens.TIMESTAMP, BsonDateTime.class) .filter(new BsonDocument(Tokens.TIMESTAMP, new BsonDocument(Tokens.FC.$gt.toString(), new BsonDateTime(startTime)) .append(Tokens.FC.$lt.toString(), new BsonDateTime(endTime)))) .map(mapper).into(timestampSet); timestampSet.addAll(vtSet); return timestampSet; }
Example #14
Source File: ChronoGraph.java From epcis with Apache License 2.0 | 6 votes |
/** * Return non-redundant timestamps of all graph element events * * @return HashSet<Long> timestamps */ public TreeSet<Long> getTimestamps() { TreeSet<Long> timestampSet = new TreeSet<Long>(); Function<BsonDateTime, Long> mapper = new Function<BsonDateTime, Long>() { @Override public Long apply(BsonDateTime val) { return val.getValue(); } }; edgeEvents.distinct(Tokens.TIMESTAMP, BsonDateTime.class) .filter(new BsonDocument(Tokens.TIMESTAMP, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull()))) .map(mapper).into(timestampSet); Set<Long> vtSet = new TreeSet<Long>(); vertexEvents.distinct(Tokens.TIMESTAMP, BsonDateTime.class) .filter(new BsonDocument(Tokens.TIMESTAMP, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull()))) .map(mapper).into(vtSet); timestampSet.addAll(vtSet); return timestampSet; }
Example #15
Source File: ECReportCapture.java From epcis with Apache License 2.0 | 5 votes |
private Map<String, BsonValue> getExtensionMap(List<ECReportMemberField> fields) { Map<String, BsonValue> extMap = new HashMap<String, BsonValue>(); for (int l = 0; l < fields.size(); l++) { ECReportMemberField field = fields.get(l); String key = field.getName(); String value = field.getValue(); String[] valArr = value.split("\\^"); if (valArr.length != 2) { extMap.put(key, new BsonString(value)); continue; } try { String type = valArr[1]; if (type.equals("int")) { extMap.put(key, new BsonInt32(Integer.parseInt(valArr[0]))); } else if (type.equals("long")) { extMap.put(key, new BsonInt64(Long.parseLong(valArr[0]))); } else if (type.equals("double")) { extMap.put(key, new BsonDouble(Double.parseDouble(valArr[0]))); } else if (type.equals("boolean")) { extMap.put(key, new BsonBoolean(Boolean.parseBoolean(valArr[0]))); } else if (type.equals("dateTime")) { extMap.put(key, new BsonDateTime(Long.parseLong(valArr[0]))); } else { extMap.put(key, new BsonString(valArr[0])); } } catch (NumberFormatException e) { extMap.put(key, new BsonString(valArr[0])); } } return extMap; }
Example #16
Source File: TypeConversionTest.java From immutables with Apache License 2.0 | 5 votes |
@Test void parseExceptions() { Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(new BsonBoolean(true)).getNumberValue(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(new BsonBoolean(true)).getLongValue(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(BsonNull.VALUE).getNumberValue(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(BsonNull.VALUE).getNumberType(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(new BsonInt32(42)).getBooleanValue(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(new BsonBoolean(true)).getNumberType(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(new BsonDateTime(42)).getBooleanValue(); }); Assertions.assertThrows(JsonParseException.class, () -> { Parsers.parserAt(new BsonTimestamp(42)).getBooleanValue(); }); }
Example #17
Source File: TypeConversionTest.java From immutables with Apache License 2.0 | 5 votes |
@Test void dateTime() throws IOException { final long epoch = System.currentTimeMillis(); final BsonDateTime value = new BsonDateTime(epoch); check(Parsers.parserAt(value).getIntValue()).is((int) epoch); check(Parsers.parserAt(value).getLongValue()).is(epoch); check(Parsers.parserAt(value).getDoubleValue()).is((double) epoch); check(Parsers.parserAt(value).getDecimalValue()).is(BigDecimal.valueOf(epoch)); check(Parsers.parserAt(value).getBigIntegerValue()).is(BigInteger.valueOf(epoch)); check(Parsers.parserAt(value).getText()).is(Long.toString(epoch)); }
Example #18
Source File: ChronoElement.java From epcis with Apache License 2.0 | 5 votes |
/** * @param timestamp * @return TimestampProperties BsonDocument */ public BsonDocument getTimestampProperties(final Long timestamp) { if (this instanceof ChronoVertex) return graph.getVertexEvents().find(new BsonDocument(Tokens.VERTEX, new BsonString(this.id)) .append(Tokens.TIMESTAMP, new BsonDateTime(timestamp))).first(); else { String[] idArr = this.id.split("\\|"); String outV = idArr[0]; String label = idArr[1]; String inV = idArr[2]; return graph.getEdgeEvents().find(new BsonDocument(Tokens.OUT_VERTEX, new BsonString(outV)) .append(Tokens.LABEL, new BsonString(label)).append(Tokens.TIMESTAMP, new BsonDateTime(timestamp)) .append(Tokens.IN_VERTEX, new BsonString(inV))).projection(Tokens.PRJ_NOT_ID).first(); } }
Example #19
Source File: TupleCodecProviderTest.java From immutables with Apache License 2.0 | 5 votes |
@Test void localDate() { LocalDateHolderCriteria criteria = LocalDateHolderCriteria.localDateHolder; Query query = Query.of(TypeHolder.LocalDateHolder.class) .addProjections(Matchers.toExpression(criteria.value), Matchers.toExpression(criteria.nullable), Matchers.toExpression(criteria.optional)); Path idPath = Visitors.toPath(KeyExtractor.defaultFactory().create(TypeHolder.LocalDateHolder.class).metadata().keys().get(0)); TupleCodecProvider provider = new TupleCodecProvider(query, new MongoPathNaming(idPath, PathNaming.defaultNaming()).toExpression()); Codec<ProjectedTuple> codec = provider.get(ProjectedTuple.class, registry); LocalDate now = LocalDate.now(); final long millisEpoch = now.atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli(); BsonDocument doc = new BsonDocument() .append("id", new BsonString("id1")) .append("value", new BsonDateTime(millisEpoch)) .append("nullable", BsonNull.VALUE) .append("optional", BsonNull.VALUE) .append("array", new BsonArray()) .append("list", new BsonArray()); ProjectedTuple tuple = codec.decode(new BsonDocumentReader(doc), DecoderContext.builder().build()); check(tuple.get(Matchers.toExpression(criteria.value))).is(now); check(tuple.get(Matchers.toExpression(criteria.nullable))).isNull(); check(tuple.get(Matchers.toExpression(criteria.optional))).is(Optional.empty()); }
Example #20
Source File: TypeConversionTest.java From immutables with Apache License 2.0 | 5 votes |
@Test public void dateTime() throws IOException { final long epoch = System.currentTimeMillis(); BsonDateTime value = new BsonDateTime(epoch); check(Jsons.readerAt(value).peek()).is(JsonToken.NUMBER); check(Jsons.readerAt(value).nextInt()).is((int) epoch); check(Jsons.readerAt(value).nextLong()).is(epoch); check(Jsons.readerAt(value).nextDouble()).is((double) epoch); }
Example #21
Source File: DeserialisationTest.java From octarine with Apache License 2.0 | 5 votes |
@Test public void deserialise_date() { Date value = new Date(); Key<Date> dateKey = Key.named("my-value"); BsonDocument doc = new BsonDocument(); doc.put("my-value", new BsonDateTime(value.getTime())); Record record = BsonRecordDeserialiser.builder() .readDate(dateKey) .get() .apply(doc); assertEquals("wrong date value", value, dateKey.get(record).get()); }
Example #22
Source File: MongoWriterUtil.java From epcis with Apache License 2.0 | 5 votes |
public static BsonValue converseType(String value) { String[] valArr = value.split("\\^"); if (valArr.length != 2) { return new BsonString(value); } try { String type = valArr[1]; if (type.equals("int")) { return new BsonInt32(Integer.parseInt(valArr[0])); } else if (type.equals("long")) { return new BsonInt64(Long.parseLong(valArr[0])); } else if (type.equals("double")) { return new BsonDouble(Double.parseDouble(valArr[0])); } else if (type.equals("boolean")) { return new BsonBoolean(Boolean.parseBoolean(valArr[0])); } else if (type.equals("float")) { return new BsonDouble(Double.parseDouble(valArr[0])); } else if (type.equals("dateTime")) { BsonDateTime time = getBsonDateTime(valArr[0]); if (time != null) return time; return new BsonString(value); } else if (type.equals("geoPoint")) { BsonDocument point = getBsonGeoPoint(valArr[0]); if (point == null) return new BsonString(value); return point; } else if (type.equals("geoArea")) { BsonDocument area = getBsonGeoArea(valArr[0]); if (area == null) return new BsonString(value); return area; } else { return new BsonString(value); } } catch (NumberFormatException e) { return new BsonString(value); } }
Example #23
Source File: Converter.java From epcis with Apache License 2.0 | 5 votes |
public static BsonDocument getBaseTimestampEdgeEventDocument(String eID, long timestamp) { BsonDocument base = new BsonDocument(); base.put(Tokens.ID, new BsonString(eID + "-" + timestamp)); base.put(Tokens.EDGE, new BsonString(eID)); base.put(Tokens.TIMESTAMP, new BsonDateTime(timestamp)); base.put(Tokens.TYPE, Tokens.TYPE_TIMESTAMP); return base; }
Example #24
Source File: Converter.java From epcis with Apache License 2.0 | 5 votes |
public static BsonDocument getBaseTimestampVertexEventDocument(String vID, long timestamp) { BsonDocument base = new BsonDocument(); base.put(Tokens.ID, new BsonString(vID + "-" + timestamp)); base.put(Tokens.VERTEX, new BsonString(vID)); base.put(Tokens.TIMESTAMP, new BsonDateTime(timestamp)); base.put(Tokens.TYPE, Tokens.TYPE_TIMESTAMP); return base; }
Example #25
Source File: VertexEvent.java From epcis with Apache License 2.0 | 5 votes |
public Set<VertexEvent> getOutVertexEventSet(final AC tt) { while (true) { try { // db.tEdgeEvents.aggregate([{$match:{"_o":"1","_t":{ $lt : ISODate(0) // }}},{$project:{"_i":1,"_t":1,"_id":0}},{$group:{"_id":"$_i", "_mt": {$min: // "$_t"}}}]) BsonDocument match = new BsonDocument("$match", new BsonDocument(Tokens.OUT_VERTEX, new BsonString(vertex.toString())).append(Tokens.TIMESTAMP, new BsonDocument("$gt", new BsonDateTime(timestamp)))); BsonDocument project = new BsonDocument("$project", new BsonDocument(Tokens.IN_VERTEX, new BsonBoolean(true)) .append(Tokens.TIMESTAMP, new BsonBoolean(true)) .append(Tokens.ID, new BsonBoolean(false))); BsonDocument group = new BsonDocument("$group", new BsonDocument(Tokens.ID, new BsonString("$" + Tokens.IN_VERTEX)).append(Tokens.TIMESTAMP, new BsonDocument("$min", new BsonString("$" + Tokens.TIMESTAMP)))); ArrayList<BsonDocument> aggregateQuery = new ArrayList<BsonDocument>(); aggregateQuery.add(match); aggregateQuery.add(project); aggregateQuery.add(group); HashSet<VertexEvent> ret = new HashSet<VertexEvent>(); Function<BsonDocument, VertexEvent> mapper = new Function<BsonDocument, VertexEvent>() { @Override public VertexEvent apply(BsonDocument d) { String inV = d.getString(Tokens.ID).getValue(); Long t = d.getDateTime(Tokens.TIMESTAMP).getValue(); return new VertexEvent(graph, new ChronoVertex(inV, graph), t); } }; vertex.graph.getEdgeEvents().aggregate(aggregateQuery).map(mapper).into(ret); return ret; } catch (MongoCursorNotFoundException e1) { System.out.println(e1.getErrorMessage()); } } }
Example #26
Source File: VertexEvent.java From epcis with Apache License 2.0 | 5 votes |
public Set<VertexEvent> getInVertexEventSet(final String label, final AC tt) { // db.edges.createIndex({"_outV" : 1, "_label" : 1, "_t" : 1, "_inV" : 1}) BsonDocument query = new BsonDocument(Tokens.IN_VERTEX, new BsonString(vertex.toString())); query.append(Tokens.LABEL, new BsonString(label)); query.append(Tokens.TIMESTAMP, new BsonDocument(tt.toString(), new BsonDateTime(timestamp))); BsonDocument proj = new BsonDocument(Tokens.TIMESTAMP, new BsonBoolean(true)) .append(Tokens.OUT_VERTEX, new BsonBoolean(true)).append(Tokens.ID, new BsonBoolean(false)); HashSet<VertexEvent> ret = new HashSet<VertexEvent>(); Iterator<BsonDocument> x = vertex.graph.getEdgeCollection().find(query).projection(proj).iterator(); HashMap<String, Long> map = new HashMap<String, Long>(); while (x.hasNext()) { BsonDocument d = x.next(); String outV = d.getString(Tokens.OUT_VERTEX).getValue(); Long t = d.getDateTime(Tokens.TIMESTAMP).getValue(); if (map.containsKey(outV)) { if (map.get(outV) > t) map.put(outV, t); } else map.put(outV, t); } map.entrySet().parallelStream().forEach(entry -> { VertexEvent ve = new VertexEvent(graph, entry.getKey() + "-" + entry.getValue()); ret.add(ve); }); return ret; }
Example #27
Source File: VertexEvent.java From epcis with Apache License 2.0 | 5 votes |
public Set<VertexEvent> getOutVertexEventSet(final String label, final AC tt) { // db.edges.createIndex({"_outV" : 1, "_label" : 1, "_t" : 1, "_inV" : 1}) BsonDocument query = new BsonDocument(Tokens.OUT_VERTEX, new BsonString(vertex.toString())); query.append(Tokens.LABEL, new BsonString(label)); query.append(Tokens.TIMESTAMP, new BsonDocument(tt.toString(), new BsonDateTime(timestamp))); BsonDocument proj = new BsonDocument(Tokens.TIMESTAMP, new BsonBoolean(true)) .append(Tokens.IN_VERTEX, new BsonBoolean(true)).append(Tokens.ID, new BsonBoolean(false)); HashSet<VertexEvent> ret = new HashSet<VertexEvent>(); Iterator<BsonDocument> x = vertex.graph.getEdgeEvents().find(query).projection(proj).iterator(); HashMap<String, Long> map = new HashMap<String, Long>(); while (x.hasNext()) { BsonDocument d = x.next(); String inV = d.getString(Tokens.IN_VERTEX).getValue(); Long t = d.getDateTime(Tokens.TIMESTAMP).getValue(); if (map.containsKey(inV)) { if (map.get(inV) > t) map.put(inV, t); } else map.put(inV, t); } map.entrySet().parallelStream().forEach(entry -> { VertexEvent ve = new VertexEvent(graph, entry.getKey() + "-" + entry.getValue()); ret.add(ve); }); return ret; }
Example #28
Source File: MongoQueryUtil.java From epcis with Apache License 2.0 | 5 votes |
static BsonValue converseType(String value) { String[] valArr = value.split("\\^"); if (valArr.length != 2) { return new BsonString(value); } try { String type = valArr[1].trim(); if (type.equals("int")) { return new BsonInt32(Integer.parseInt(valArr[0])); } else if (type.equals("long")) { return new BsonInt64(Long.parseLong(valArr[0])); } else if (type.equals("double")) { return new BsonDouble(Double.parseDouble(valArr[0])); } else if (type.equals("boolean")) { return new BsonBoolean(Boolean.parseBoolean(valArr[0])); } else if (type.equals("regex")) { return new BsonRegularExpression("^" + valArr[0] + "$"); } else if (type.equals("float")) { return new BsonDouble(Double.parseDouble(valArr[0])); } else if (type.equals("dateTime")) { BsonDateTime time = MongoQueryService.getTimeMillis(valArr[0]); if (time != null) return time; return new BsonString(value); } else { return new BsonString(value); } } catch (NumberFormatException e) { return new BsonString(value); } }
Example #29
Source File: ChronoGraph.java From epcis with Apache License 2.0 | 5 votes |
public CachedChronoGraph getSnapshot(Long t) { CachedChronoGraph g = new CachedChronoGraph(); MongoCursor<BsonDocument> c = this.getEdgeEvents().find(new BsonDocument(Tokens.TIMESTAMP, new BsonDateTime(t))) .iterator(); while (c.hasNext()) { BsonDocument doc = c.next(); String outV = doc.getString(Tokens.OUT_VERTEX).getValue(); String label = doc.getString(Tokens.LABEL).getValue(); String inV = doc.getString(Tokens.IN_VERTEX).getValue(); CachedChronoEdge e = g.addEdge(outV, inV, label); e.setProperties(doc); } return g; }
Example #30
Source File: LongInterval.java From epcis with Apache License 2.0 | 5 votes |
public static BsonDocument getTemporalRelationFilterQuery(long left, AC ss, AC se) { BsonDocument filter = new BsonDocument(); if (ss != null) filter.append(Tokens.START, new BsonDocument(ss.toString(), new BsonDateTime(left))); if (se != null) filter.append(Tokens.END, new BsonDocument(se.toString(), new BsonDateTime(left))); return filter; }