/** * @return the new _id field if an insert/upsert was performed */ public Object getNewId() { return wr.getUpsertedId(); }
/** * Gets the _id value of an upserted document that resulted from this write. Note that for MongoDB servers prior to version 2.6, * this method will return null unless the _id of the upserted document was of type ObjectId. * * @return the value of the _id of an upserted document */ public Object getUpsertedId() { return writeResult.getUpsertedId(); }
/** * @return the new _id field if an insert/upsert was performed */ public Object getNewId() { return wr.getUpsertedId(); }
private void addAutoGeneretedKeys(WriteResult result) throws TranslatorException { Table table = this.visitor.mongoDoc.getTargetTable(); int cols = table.getPrimaryKey().getColumns().size(); if (cols != 1) { //restrict to only primary keys based upon id return; } Class<?>[] columnDataTypes = new Class<?>[cols]; String[] columnNames = new String[cols]; //this is typically expected to be an int/long, but we'll be general here. we may eventual need the type logic off of the metadata importer for (int i = 0; i < cols; i++) { columnDataTypes[i] = table.getPrimaryKey().getColumns().get(i).getJavaType(); columnNames[i] = table.getPrimaryKey().getColumns().get(i).getName(); } if (!columnNames[0].equals(MongoDBMetadataProcessor.ID)) { return; } GeneratedKeys generatedKeys = this.executionContext.getCommandContext().returnGeneratedKeys(columnNames, columnDataTypes); List<Object> vals = new ArrayList<Object>(columnDataTypes.length); for (int i = 0; i < columnDataTypes.length; i++) { Object value = this.executionFactory.retrieveValue(result.getUpsertedId(), columnDataTypes[i], this.mongoDB, columnNames[i], columnNames[i]); vals.add(value); } generatedKeys.addKey(vals); } }