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);
}
}
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);
}
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);
}
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));
}
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;
}
Aggregations