Search in sources :

Example 96 with ObjectId

use of org.bson.types.ObjectId in project MonjaDB by Kanatoko.

the class MDocumentEditor method setItemInfo.

//--------------------------------------------------------------------------------
private void setItemInfo(TreeItem treeItem, String key, Object value) {
    if (key.equals("_id") && value.getClass() == Double.class) {
        BigDecimal bd = new BigDecimal(((Double) value).doubleValue());
        value = bd.toString();
    }
    treeItem.setText(key + " : " + value);
    if (value instanceof Integer) {
        treeItem.setImage(intImage);
    } else if (value instanceof Double) {
        treeItem.setImage(doubleImage);
    } else if (value instanceof Long) {
        treeItem.setImage(longImage);
    } else if (value instanceof Date) {
        treeItem.setImage(dateImage);
    } else if (value instanceof String) {
        treeItem.setImage(stringImage);
    } else if (value instanceof ObjectId) {
        treeItem.setImage(oidImage);
    } else if (value instanceof Boolean) {
        treeItem.setImage(boolImage);
    } else if (value instanceof Code) {
        treeItem.setImage(jsImage);
    }
}
Also used : ObjectId(org.bson.types.ObjectId) Code(org.bson.types.Code) BigDecimal(java.math.BigDecimal)

Example 97 with ObjectId

use of org.bson.types.ObjectId in project MonjaDB by Kanatoko.

the class MDocumentEditor method updateDocument.

//--------------------------------------------------------------------------------
private void updateDocument() {
    int typeIndex = typeCombo.getSelectionIndex();
    if (typeIndex == -1) {
        return;
    }
    String value = valueText.getText();
    Object newValue = null;
    String updateStr = null;
    switch(typeIndex) {
        case //Double
        0:
            newValue = new Double(value);
            break;
        case //Integer
        1:
            newValue = new Integer(value);
            break;
        case //Long
        2:
            newValue = new Long(value);
            break;
        case //String
        3:
            newValue = value;
            break;
        case //List
        4:
            newValue = dataManager.getDB().eval(value, null);
            break;
        case //Map
        5:
            newValue = dataManager.getDB().eval(value, null);
            break;
        case //Date
        6:
            try {
                SimpleDateFormat df = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy", Locale.ENGLISH);
                //df.set
                newValue = df.parse(value);
            } catch (Exception e) {
                //e.printStackTrace();
                return;
            }
            break;
        case //ObjectId
        7:
            newValue = new ObjectId(value);
            break;
        case //Code
        8:
            newValue = new Code(value);
            break;
        case //Binary not implemented
        9:
            break;
        case //Boolean
        10:
            newValue = new Boolean(value);
            break;
        case //null
        11:
            newValue = null;
            break;
        case //Regex
        12:
            newValue = java.util.regex.Pattern.compile(value + "");
            break;
        case //Symbol
        13:
            //newValue = new Symbol( value );
            break;
        case //Code with scope
        14:
            //newValue = new CodeWScope( value, new BasicDBObject() );
            break;
        case //Timestamp
        15:
            break;
        case //Minkey not supported yet
        16:
            break;
        case //Maxkey not supported yet
        17:
            break;
    }
    dataManager.updateDocument(_id, editingFieldName, newValue);
}
Also used : ObjectId(org.bson.types.ObjectId) SimpleDateFormat(java.text.SimpleDateFormat) Code(org.bson.types.Code)

Example 98 with ObjectId

use of org.bson.types.ObjectId in project beam by apache.

the class MongoDBGridFSIOTest method testSplit.

@Test
public void testSplit() throws Exception {
    PipelineOptions options = PipelineOptionsFactory.create();
    MongoDbGridFSIO.Read<String> read = MongoDbGridFSIO.<String>read().withUri("mongodb://localhost:" + port).withDatabase(DATABASE);
    BoundedGridFSSource src = new BoundedGridFSSource(read, null);
    // make sure 2 files can fit in
    long desiredBundleSizeBytes = (src.getEstimatedSizeBytes(options) * 2L) / 5L + 1000;
    List<? extends BoundedSource<ObjectId>> splits = src.split(desiredBundleSizeBytes, options);
    int expectedNbSplits = 3;
    assertEquals(expectedNbSplits, splits.size());
    SourceTestUtils.assertSourcesEqualReferenceSource(src, splits, options);
    int nonEmptySplits = 0;
    int count = 0;
    for (BoundedSource<ObjectId> subSource : splits) {
        List<ObjectId> result = SourceTestUtils.readFromSource(subSource, options);
        if (result.size() > 0) {
            nonEmptySplits += 1;
        }
        count += result.size();
    }
    assertEquals(expectedNbSplits, nonEmptySplits);
    assertEquals(5, count);
}
Also used : ObjectId(org.bson.types.ObjectId) PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) BoundedGridFSSource(org.apache.beam.sdk.io.mongodb.MongoDbGridFSIO.Read.BoundedGridFSSource) Test(org.junit.Test)

Example 99 with ObjectId

use of org.bson.types.ObjectId in project drill by apache.

the class TestBsonRecordReader method testObjectIdType.

@Test
public void testObjectIdType() throws IOException {
    BsonDocument bsonDoc = new BsonDocument();
    BsonObjectId value = new BsonObjectId(new ObjectId());
    bsonDoc.append("_idKey", value);
    writer.reset();
    bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
    SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
    byte[] readByteArray = mapReader.reader("_idKey").readByteArray();
    assertTrue(Arrays.equals(value.getValue().toByteArray(), readByteArray));
}
Also used : BsonDocument(org.bson.BsonDocument) SingleMapReaderImpl(org.apache.drill.exec.vector.complex.impl.SingleMapReaderImpl) BsonObjectId(org.bson.BsonObjectId) ObjectId(org.bson.types.ObjectId) BsonDocumentReader(org.bson.BsonDocumentReader) BsonObjectId(org.bson.BsonObjectId) Test(org.junit.Test)

Example 100 with ObjectId

use of org.bson.types.ObjectId in project gora by apache.

the class MongoStore method fromMongoString.

private Object fromMongoString(final DocumentFieldType storeType, final String docf, final BSONDecorator easybson) {
    Object result;
    if (storeType == DocumentFieldType.OBJECTID) {
        // Try auto-conversion of BSON data to ObjectId
        // It will work if data is stored as String or as ObjectId
        Object bin = easybson.get(docf);
        if (bin instanceof String) {
            ObjectId id = new ObjectId((String) bin);
            result = new Utf8(id.toString());
        } else {
            result = new Utf8(bin.toString());
        }
    } else if (storeType == DocumentFieldType.DATE) {
        Object bin = easybson.get(docf);
        if (bin instanceof Date) {
            Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.getDefault());
            calendar.setTime((Date) bin);
            result = new Utf8(DatatypeConverter.printDateTime(calendar));
        } else {
            result = new Utf8(bin.toString());
        }
    } else {
        result = easybson.getUtf8String(docf);
    }
    return result;
}
Also used : ObjectId(org.bson.types.ObjectId) Utf8(org.apache.avro.util.Utf8)

Aggregations

ObjectId (org.bson.types.ObjectId)194 Test (org.junit.Test)113 BasicDBObject (com.mongodb.BasicDBObject)46 DBObject (com.mongodb.DBObject)28 Date (java.util.Date)23 Document (org.bson.Document)21 ArrayList (java.util.ArrayList)20 BsonObjectId (org.bson.BsonObjectId)16 StreamRuleMock (org.graylog2.streams.matchers.StreamRuleMock)14 Message (org.graylog2.plugin.Message)13 BasicBSONObject (org.bson.BasicBSONObject)12 List (java.util.List)11 Binary (org.bson.types.Binary)10 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)9 Map (java.util.Map)8 DBRef (com.mongodb.DBRef)7 Code (org.bson.types.Code)7 Stream (org.graylog2.plugin.streams.Stream)7 ImmutableList (com.google.common.collect.ImmutableList)6 BsonDocument (org.bson.BsonDocument)6