当前位置: 首页>>代码示例>>Java>>正文


Java BSONTimestamp类代码示例

本文整理汇总了Java中org.bson.types.BSONTimestamp的典型用法代码示例。如果您正苦于以下问题:Java BSONTimestamp类的具体用法?Java BSONTimestamp怎么用?Java BSONTimestamp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BSONTimestamp类属于org.bson.types包,在下文中一共展示了BSONTimestamp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createQuery

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
/**
 * Creates the query to execute on the collection.
 *
 * @return the query
 */
private Bson createQuery() {
    // timestamps are used as offsets, saved as a concatenation of seconds and order
	Integer timestamp = 0;
    Integer order = 0;
	if(!start.equals("0")){    	
 	final String[] splitted = start.split("_");
 	timestamp = Integer.valueOf(splitted[0]);
     order = Integer.valueOf(splitted[1]);
	}
	
    Bson query = Filters.and(
            Filters.exists("fromMigrate", false),
            Filters.gt("ts", new BSONTimestamp(timestamp, order)),
            Filters.or(
                    Filters.eq("op", "i"),
                    Filters.eq("op", "u"),
                    Filters.eq("op", "d")
            ),
            Filters.eq("ns", db)
    );

    return query;
}
 
开发者ID:DataReply,项目名称:kafka-connect-mongodb,代码行数:29,代码来源:DatabaseReader.java

示例2: call

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
@Override
public Void call() throws Exception {
    
    final Date now = new Date();
    final Document query = new Document("ns", ns)
        .append("ts", new Document("$gt", new BSONTimestamp((int) (now.getTime() / 1000), 0)));
    
    final MongoCursor<Document> cursor = oplog.find(query)
        .cursorType(CursorType.TailableAwait).iterator();
    
    while (cursor.hasNext()) {
        final Document doc = cursor.next();
        for (final OplogListener listener : listeners) {
            listener.onOplog(doc);
        }
    }

    return null;
}
 
开发者ID:bbonnin,项目名称:mongo2els,代码行数:20,代码来源:OplogTailer.java

示例3: mongoToKettleType

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
protected static int mongoToKettleType( Object fieldValue ) {
  if ( fieldValue == null ) {
    return ValueMetaInterface.TYPE_STRING;
  }

  if ( fieldValue instanceof Symbol || fieldValue instanceof String || fieldValue instanceof Code
        || fieldValue instanceof ObjectId || fieldValue instanceof MinKey || fieldValue instanceof MaxKey ) {
    return ValueMetaInterface.TYPE_STRING;
  } else if ( fieldValue instanceof Date ) {
    return ValueMetaInterface.TYPE_DATE;
  } else if ( fieldValue instanceof Number ) {
    // try to parse as an Integer
    try {
      Integer.parseInt( fieldValue.toString() );
      return ValueMetaInterface.TYPE_INTEGER;
    } catch ( NumberFormatException e ) {
      return ValueMetaInterface.TYPE_NUMBER;
    }
  } else if ( fieldValue instanceof Binary ) {
    return ValueMetaInterface.TYPE_BINARY;
  } else if ( fieldValue instanceof BSONTimestamp ) {
    return ValueMetaInterface.TYPE_INTEGER;
  }

  return ValueMetaInterface.TYPE_STRING;
}
 
开发者ID:pentaho,项目名称:pentaho-mongodb-plugin,代码行数:27,代码来源:MongodbInputDiscoverFieldsImpl.java

示例4: createCursor

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
private DBCursor createCursor() {
  DBCollection oplog = _mongo.getDB("local").getCollection("oplog.rs");
  BSONTimestamp startingTimestamp = getStartingTimestamp();

  DBCursor cursor;
  if (startingTimestamp == null) {
    log.info("Tailing the oplog from the beginning...");
    cursor = oplog.find();
  } else {
    log.info("Tailing the oplog from " + startingTimestamp);
    BasicDBObject query = new BasicDBObject("ts", new BasicDBObject("$gt", startingTimestamp));
    cursor = oplog.find(query);
    cursor.addOption(Bytes.QUERYOPTION_OPLOGREPLAY);
  }

  cursor.addOption(Bytes.QUERYOPTION_NOTIMEOUT);
  cursor.addOption(Bytes.QUERYOPTION_TAILABLE);
  cursor.addOption(Bytes.QUERYOPTION_AWAITDATA);

  return cursor;
}
 
开发者ID:colinmarc,项目名称:zerowing,代码行数:22,代码来源:Tailer.java

示例5: getStartingTimestamp

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
private BSONTimestamp getStartingTimestamp() {
  Get get = new Get(_tailerID);

  Result res;
  try {
    res = _stateTable.get(get);
  } catch (IOException e) {
    log.error("Failed to get a starting timestamp for tailer ID: " + _tailerID);
    return null;
  }

  if (res.isEmpty()) {
    if(ConfigUtil.getSkipBacklog(_conf)) return new BSONTimestamp((int) (System.currentTimeMillis() / 1000L), 0);
    return null;
  } else {
    byte[] raw_optime = res.getValue(STATE_TABLE_COL_FAMILY, STATE_TABLE_COL_QUALIFIER_OPTIME);
    byte[] raw_inc = res.getValue(STATE_TABLE_COL_FAMILY, STATE_TABLE_COL_QUALIFIER_INC);

    _optime = Integer.parseInt(new String(raw_optime));
    _inc = Integer.parseInt(new String(raw_inc));
    _optimeSet = true;
    return new BSONTimestamp(_optime, _inc);
  }
}
 
开发者ID:colinmarc,项目名称:zerowing,代码行数:25,代码来源:Tailer.java

示例6: convert

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
/**
 * convert bson types to java primitives. BasicBSONList, Binary,
 * BSONTimestamp, Code, CodeWScope, MinKey, MaxKey, Symbol, ObjectId
 */
private Object convert(Object o) {
	if (o instanceof BSONTimestamp) {
		return ((BSONTimestamp) o).getTime();
	} else if (o instanceof Symbol || o instanceof Code || o instanceof CodeWScope || o instanceof MinKey
			|| o instanceof MaxKey || o instanceof ObjectId) {
		return o.toString();
	} else if (o instanceof BasicBSONList) {
		List<Object> l = new ArrayList<Object>();
		for (Object item : ((BasicBSONList) o)) {
			l.add(convert(item));
		}

		return l;
	} else {
		return o;
	}
}
 
开发者ID:araqne,项目名称:logdb,代码行数:22,代码来源:MongoFindCommand.java

示例7: checkValue

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
protected void checkValue(Object value) {
	if (value instanceof MObject)
		return;

	if (value == null)
		return;
	if (value instanceof Number)
		return;
	if (value instanceof String)
		return;
	if (value instanceof Boolean)
		return;
	if (value instanceof Character)
		return;
	if (value instanceof ObjectId)
		return;
	if (value instanceof Date)
		return;
	if (value instanceof Pattern)
		return;
	if (value instanceof UUID)
		return;
	if (value instanceof MaxKey || value instanceof MinKey)
		return;
	if (value instanceof byte[])
		return;
	if (value instanceof BSONTimestamp || value instanceof Symbol
		|| value instanceof Code || value instanceof CodeWScope)
		return;

	throw new IllegalArgumentException(getClass().getSimpleName()
		+ " can't store a " + value.getClass().getName());
}
 
开发者ID:judison,项目名称:mongodm,代码行数:34,代码来源:MObject.java

示例8: writeTimestamp

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
@Override
public void writeTimestamp(final BSONTimestamp value) {
    checkPreconditions("writeTimestamp", State.VALUE);

    buffer.write(BSONType.TIMESTAMP.getValue());
    writeCurrentName();
    buffer.writeInt(value.getInc());
    buffer.writeInt(value.getTime());

    setState(getNextState());
}
 
开发者ID:MaOrKsSi,项目名称:HZS.Durian,代码行数:12,代码来源:BSONBinaryWriter.java

示例9: getLegacy

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
/**
 * Returns an <code>ObjectSerializer</code> that mostly conforms to the strict JSON format defined in
 * <a href="http://www.mongodb.org/display/DOCS/Mongo+Extended+JSON", but with a few differences to keep
 * compatibility with previous versions of the driver.  Clients should generally prefer
 * <code>getStrict</code> in preference to this method.
 *
 * @return object serializer
 * @see #getStrict()
 */
public static ObjectSerializer getLegacy() {

    ClassMapBasedObjectSerializer serializer = addCommonSerializers();

    serializer.addObjectSerializer(Date.class, new LegacyDateSerializer(serializer));
    serializer.addObjectSerializer(BSONTimestamp.class, new LegacyBSONTimestampSerializer(serializer));
    serializer.addObjectSerializer(Binary.class, new LegacyBinarySerializer());
    serializer.addObjectSerializer(byte[].class, new LegacyBinarySerializer());
    return serializer;
}
 
开发者ID:MaOrKsSi,项目名称:HZS.Durian,代码行数:20,代码来源:JSONSerializers.java

示例10: getStrict

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
/**
 * Returns an <code>ObjectSerializer</code> that conforms to the strict JSON format defined in
 * <a href="http://www.mongodb.org/display/DOCS/Mongo+Extended+JSON".
 *
 * @return object serializer
 */
public static ObjectSerializer getStrict() {

    ClassMapBasedObjectSerializer serializer = addCommonSerializers();

    serializer.addObjectSerializer(Date.class, new DateSerializer(serializer));
    serializer.addObjectSerializer(BSONTimestamp.class, new BSONTimestampSerializer(serializer));
    serializer.addObjectSerializer(Binary.class, new BinarySerializer(serializer));
    serializer.addObjectSerializer(byte[].class, new ByteArraySerializer(serializer));

    return serializer;
}
 
开发者ID:MaOrKsSi,项目名称:HZS.Durian,代码行数:18,代码来源:JSONSerializers.java

示例11: serialize

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
@Override
public void serialize(Object obj, StringBuilder buf) {
    BSONTimestamp t = (BSONTimestamp) obj;
    BasicDBObject temp = new BasicDBObject();
    temp.put("$ts", Integer.valueOf(t.getTime()));
    temp.put("$inc", Integer.valueOf(t.getInc()));
    serializer.serialize(temp, buf);
}
 
开发者ID:MaOrKsSi,项目名称:HZS.Durian,代码行数:9,代码来源:JSONSerializers.java

示例12: convertFromMongoDbType

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
@Override
public Long convertFromMongoDbType(BSONTimestamp data) {
  int inc = data.getInc();
  if (inc < 0 || inc >= 1000) {
    throw new RuntimeException(
        "Overflow occurs while converting BSONTimestamp into long: " + data);
  }
  return (long) data.getTime() * 1000 + inc;
}
 
开发者ID:tfeng,项目名称:play-plugins,代码行数:10,代码来源:MongoDbTypeConverter.java

示例13: convertToMongoDbType

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
@Override
public BSONTimestamp convertToMongoDbType(String data) {
  Matcher matcher = TIMESTAMP_PATTERN.matcher(data);
  if (!matcher.matches()) {
    throw new RuntimeException("Invalid BSONTimestamp " + data);
  }
  int time = Integer.parseInt(matcher.group(1));
  int inc = Integer.parseInt(matcher.group(2));
  return new BSONTimestamp(time, inc);
}
 
开发者ID:tfeng,项目名称:play-plugins,代码行数:11,代码来源:MongoDbTypeConverter.java

示例14: updateOptime

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
private void updateOptime(BasicDBObject doc) {
  BSONTimestamp ts = (BSONTimestamp) doc.get("ts");
  int optime = ts.getTime(), inc = ts.getInc();

  // only checkpoint every 60 seconds
  if (!_optimeSet || (optime - _optime) >= 60) {
    _optime = optime;
    _inc = inc;
    _optimeSet = true;

    log.info("optime: " + _optime);
    saveOptime();
  }
}
 
开发者ID:colinmarc,项目名称:zerowing,代码行数:15,代码来源:Tailer.java

示例15: gotTimestamp

import org.bson.types.BSONTimestamp; //导入依赖的package包/类
public void gotTimestamp( String name , int time , int inc ){
    _put( name , new BSONTimestamp( time , inc ) );
}
 
开发者ID:MaOrKsSi,项目名称:HZS.Durian,代码行数:4,代码来源:BasicBSONCallback.java


注:本文中的org.bson.types.BSONTimestamp类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。