Package org.bson.types

Examples of org.bson.types.BSONTimestamp


            break;
        case BsonConstants.TYPE_INT32:
            value = Integer.valueOf(buffer.readInt());
            break;
        case BsonConstants.TYPE_TIMESTAMP:
            value = new BSONTimestamp(buffer.readInt(), buffer.readInt());
            break;
        case BsonConstants.TYPE_INT64:
            value = Long.valueOf(buffer.readLong());
            break;
        case BsonConstants.TYPE_MAX_KEY:


        setEnumBinding(Item.values(), null);
    }

    @Override
    public Object getValue() {
        return new BSONTimestamp(getIntFieldValue(Item.time), getIntFieldValue(Item.increment));
    }

        return new BSONTimestamp(getIntFieldValue(Item.time), getIntFieldValue(Item.increment));
    }

    @Override
    public void setValue(Object value) {
        BSONTimestamp ts = (BSONTimestamp) value;
        setIntFieldValue(Item.time, ts.getTime());
        setIntFieldValue(Item.increment, ts.getInc());
    }

                }

                // find highest current timestamp
                DBCursor cur = chunks.find().sort(new BasicDBObject("lastmod", -1)).batchSize(-1);
                BasicDBObject chunk = (BasicDBObject) (cur.hasNext() ? cur.next() : null);
                BSONTimestamp ts = (BSONTimestamp) (chunk != null ? chunk.get("lastmod") : null);

                // now infer chunk ranges
                long count = tmpchunks.count();
                result.put("uniqueKeys", count);
                int numChunks = 0;

        return chunk;
    }

    BSONTimestamp getNextTimestamp(BSONTimestamp ts) {
        if (ts == null) {
            return new BSONTimestamp(1000, 0);
        }
        return new BSONTimestamp(ts.getTime(), ts.getInc() + 1);
    }

        if (!firstc.hasNext() || !lastc.hasNext()) {
            return null;
        }
        BasicDBObject first = (BasicDBObject) firstc.next();
        BasicDBObject last = (BasicDBObject) lastc.next();
        BSONTimestamp tsfirst = (BSONTimestamp) first.get("ts");
        BSONTimestamp tslast = (BSONTimestamp) last.get("ts");
        if (tsfirst == null || tslast == null) {
            return null;
        }

        int ftime = tsfirst.getTime();
        int ltime = tslast.getTime();
        int timeDiffSec = ltime - ftime;
        result.put("timeDiff", timeDiffSec);
        result.put("timeDiffHours", Float.valueOf(String.format("%.2f", timeDiffSec / 3600f)));
        result.put("tFirst", new Date(ftime * 1000l));
        result.put("tLast", new Date(ltime * 1000l));
 

        } else if (type.startsWith("Double")) {
            val = new Double(0.0);
        } else if (type.equals("Pattern")) {
            val = Pattern.compile("");
        } else if (type.equals("Timestamp")) {
            val = new BSONTimestamp((int) (System.currentTimeMillis() / 1000), 0);
        } else if (type.equals("Document")) {
            val = new BasicDBObject();
        } else if (type.equals("List")) {
            val = new BasicDBList();
        } else if (type.equals("Null")) {

        } else if (value instanceof ObjectId) {
            ObjectId id = (ObjectId)value;
            value = new org.bson.types.ObjectId(id.getBytes());
        } else if (value instanceof Timestamp) {
            Timestamp ts = (Timestamp)value;
            value = new BSONTimestamp(ts.getTime(), ts.getInc());
        } else if (value instanceof CodeWithScope) {
            CodeWithScope code = (CodeWithScope)value;
            value = new org.bson.types.CodeWScope(code.getCode(), createMongoData(code.getScope()));
        } else if (value instanceof Code) {
            Code code = (Code)value;

        assertThat(value, equalTo(result));

        result = serde.deserializeField(d, serde.columnTypes.get(0), "");
        assertThat(value, equalTo(result));

        BSONTimestamp bts = new BSONTimestamp(((Long) (d.getTime() / 1000L)).intValue(), 1);
        result = serde.deserializeField(bts, serde.columnTypes.get(0), "");
        // BSONTimestamp only takes an int, so the long returned in the Timestamp won't be the same
        assertThat((long) bts.getTime(), equalTo(((Timestamp) result).getTime() / 1000L));

        // Utilizes a timestampWritable because there's no native timestamp type in java for
        // object inspector class to relate to
        ObjectInspector innerInspector =
            PrimitiveObjectInspectorFactory.getPrimitiveObjectInspectorFromClass(TimestampWritable.class);

        }
        return object;
    }

    private Object convertToBSONTimestamp(Timestamp ts) {
        return new BSONTimestamp(ts.getTime(), ts.getInc());
    }

TOP

Related Classes of org.bson.types.BSONTimestamp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.