if (!values.isEmpty() || mapper.getOptions().isStoreEmpties()) { dbObject.put(name, values);
/** * Ensures (creating if necessary) the index including the field(s) + directions; eg fields = "field1, -field2" ({field1:1, field2:-1}) */ public void ensureIndex(String collName, String name, String fields, boolean unique, boolean dropDupsOnCreate) { BasicDBObject dbFields = parseFieldsString(fields); final BasicDBObjectBuilder keyOpts = new BasicDBObjectBuilder(); if (name != null && name.length() != 0) { keyOpts.add("name", name); } if (unique) { keyOpts.add("unique", true); if (dropDupsOnCreate) { keyOpts.add("dropDups", true); } } final DBCollection dbColl = getCollection(getCollName(collName)); final BasicDBObject opts = (BasicDBObject) keyOpts.get(); if (opts.isEmpty()) { LOGGER.debug("Ensuring index for " + dbColl.getName() + " with keys:" + dbFields); dbColl.createIndex(dbFields); } else { LOGGER.debug("Ensuring index for " + dbColl.getName() + " with keys:" + fields + " and opts:" + opts); dbColl.createIndex(dbFields, opts); } }
/** * Ensures (creating if necessary) the index including the field(s) + directions; eg fields = "field1, -field2" ({field1:1, field2:-1}) */ public void ensureIndex(String collName, String name, String fields, boolean unique, boolean dropDupsOnCreate) { BasicDBObject dbFields = parseFieldsString(fields); final BasicDBObjectBuilder keyOpts = new BasicDBObjectBuilder(); if (name != null && name.length() != 0) { keyOpts.add("name", name); } if (unique) { keyOpts.add("unique", true); if (dropDupsOnCreate) { keyOpts.add("dropDups", true); } } final DBCollection dbColl = getCollection(getCollName(collName)); final BasicDBObject opts = (BasicDBObject) keyOpts.get(); if (opts.isEmpty()) { LOGGER.debug("Ensuring index for " + dbColl.getName() + " with keys:" + dbFields); dbColl.createIndex(dbFields); } else { LOGGER.debug("Ensuring index for " + dbColl.getName() + " with keys:" + fields + " and opts:" + opts); dbColl.createIndex(dbFields, opts); } }
public boolean isEmpty() { return index.isEmpty(); } }
if (!compositeColumns.isEmpty())
public boolean isEmpty() { return update.isEmpty(); } }
public boolean isEmpty() { return index.isEmpty(); } }
public boolean isEmpty() { return fields.isEmpty(); } }
public boolean isEmpty() { return fields.isEmpty(); } }
public boolean isEmpty() { return update.isEmpty(); } }
/** * Method applies the sorting if any to given {@link DBCursor}. * * @param dbCursor {@link DBCursor} to apply sorting to. * @return {@link DBCursor} with sorting. */ @Nonnull public DBCursor apply(@Nonnull final DBCursor dbCursor) { assert dbCursor != null; // Check if sorting should be applied. if (!sortDBObject.isEmpty()) { return dbCursor.sort(sortDBObject); } return dbCursor; }
public WriteResult remove(String description, DBObject query, boolean checkForEmptyQuery) { if (log.isDebugEnabled()) { log.debug("--"+dbCollection.getName()+"-> "+description+" q="+toString(query)); } if (checkForEmptyQuery && (query==null || ((BasicDBObject)query).isEmpty())) { throw new RuntimeException("I assume this is a bug. Protection against deleting the whole collection"); } WriteResult writeResult = dbCollection.remove(query); if (log.isDebugEnabled()) { log.debug("<-"+dbCollection.getName()+"-- "+writeResult); } return writeResult; }
public WriteResult remove(String description, DBObject query, boolean checkForEmptyQuery) { if (log.isDebugEnabled()) { log.debug("--"+dbCollection.getName()+"-> "+description+" q="+toString(query)); } if (checkForEmptyQuery && (query==null || ((BasicDBObject)query).isEmpty())) { throw new RuntimeException("I assume this is a bug. Protection against deleting the whole collection"); } WriteResult writeResult = dbCollection.remove(query); if (log.isDebugEnabled()) { log.debug("<-"+dbCollection.getName()+"-- "+writeResult); } return writeResult; }
private void writeMap(final MappedField mf, final DBObject dbObject, final Map<Object, DBObject> involvedObjects, final String name, final Object fieldValue, final Mapper mapper) { final Map<String, Object> map = (Map<String, Object>) fieldValue; if (map != null) { final BasicDBObject values = new BasicDBObject(); for (final Map.Entry<String, Object> entry : map.entrySet()) { final Object entryVal = entry.getValue(); final Object val; if (entryVal == null) { val = null; } else if (mapper.converters.hasSimpleValueConverter(mf) || mapper.converters.hasSimpleValueConverter(entryVal.getClass())) { val = mapper.converters.encode(entryVal); } else { if (Map.class.isAssignableFrom(entryVal.getClass()) || Collection.class.isAssignableFrom(entryVal.getClass())) { val = mapper.toMongoObject(entryVal, true); } else { val = mapper.toDBObject(entryVal, involvedObjects); } if (!shouldSaveClassName(entryVal, val, mf)) { ((DBObject) val).removeField(Mapper.CLASS_NAME_FIELDNAME); } } final String strKey = mapper.converters.encode(entry.getKey()).toString(); values.put(strKey, val); } if (!values.isEmpty() || mapper.getOptions().storeEmpties) { dbObject.put(name, values); } } }
/** * Check if the majority read concern is supported by this storage engine. * The fact that read concern is supported doesn't it can be used - it also * has to be enabled. * * @return true if the majority read concern is supported */ public boolean isMajorityReadConcernSupported() { if (majorityReadConcernSupported == null) { BasicDBObject stat = getServerStatus(); if (stat.isEmpty()) { LOG.debug("User doesn't have privileges to get server status; falling back to the isMajorityReadConcernEnabled()"); return isMajorityReadConcernEnabled(); } else { if (stat.containsField("storageEngine")) { BasicDBObject storageEngine = (BasicDBObject) stat.get("storageEngine"); majorityReadConcernSupported = storageEngine.getBoolean("supportsCommittedReads"); } else { majorityReadConcernSupported = false; } } } return majorityReadConcernSupported; }
/** * Check if the majority read concern is supported by this storage engine. * The fact that read concern is supported doesn't it can be used - it also * has to be enabled. * * @return true if the majority read concern is supported */ public boolean isMajorityReadConcernSupported() { if (majorityReadConcernSupported == null) { BasicDBObject stat = getServerStatus(); if (stat.isEmpty()) { LOG.debug("User doesn't have privileges to get server status; falling back to the isMajorityReadConcernEnabled()"); return isMajorityReadConcernEnabled(); } else { if (stat.containsField("storageEngine")) { BasicDBObject storageEngine = (BasicDBObject) stat.get("storageEngine"); majorityReadConcernSupported = storageEngine.getBoolean("supportsCommittedReads"); } else { majorityReadConcernSupported = false; } } } return majorityReadConcernSupported; }
/** * Update a object that already exists in the store. The object must exist * already or the update may fail. * * @param key * identifier of the object in the store * @param obj * the object to be inserted */ private void performPut(final K key, final T obj) { // Build the query to select the object to be updated DBObject qSel = new BasicDBObject("_id", key); // Build the update query BasicDBObject qUpdate = new BasicDBObject(); BasicDBObject qUpdateSet = newUpdateSetInstance(obj); if (qUpdateSet.size() > 0) { qUpdate.put("$set", qUpdateSet); } BasicDBObject qUpdateUnset = newUpdateUnsetInstance(obj); if (qUpdateUnset.size() > 0) { qUpdate.put("$unset", qUpdateUnset); } // Execute the update (if there is at least one $set ot $unset if (!qUpdate.isEmpty()) { mongoClientColl.update(qSel, qUpdate, true, false); obj.clearDirty(); } else { LOG.debug("No update to perform, skip {}", key); } }
/** * Ensures (creating if necessary) the index including the field(s) + directions; eg fields = "field1, -field2" ({field1:1, field2:-1}) */ public void ensureIndex(String collName, String name, String fields, boolean unique, boolean dropDupsOnCreate) { BasicDBObject dbFields = parseFieldsString(fields); final BasicDBObjectBuilder keyOpts = new BasicDBObjectBuilder(); if (name != null && name.length() != 0) { keyOpts.add("name", name); } if (unique) { keyOpts.add("unique", true); if (dropDupsOnCreate) { keyOpts.add("dropDups", true); } } final DBCollection dbColl = getCollection(getCollName(collName)); final BasicDBObject opts = (BasicDBObject) keyOpts.get(); if (opts.isEmpty()) { LOGGER.debug("Ensuring index for " + dbColl.getName() + " with keys:" + dbFields); dbColl.createIndex(dbFields); } else { LOGGER.debug("Ensuring index for " + dbColl.getName() + " with keys:" + fields + " and opts:" + opts); dbColl.createIndex(dbFields, opts); } }
if (opts.isEmpty()) { LOG.debug("Ensuring index for " + dbColl.getName() + " with keys:" + fields); dbColl.ensureIndex(fields);
protected <T> void ensureIndex(Class<T> clazz, String name, BasicDBObject fields, boolean unique, boolean dropDupsOnCreate, boolean background, boolean sparse) { BasicDBObjectBuilder keyOpts = new BasicDBObjectBuilder(); if (name != null && name.length() > 0) { keyOpts.add("name", name); } if (unique) { keyOpts.add("unique", true); if (dropDupsOnCreate) keyOpts.add("dropDups", true); } if (background) keyOpts.add("background", true); if (sparse) keyOpts.add("sparse", true); DBCollection dbColl = getCollection(clazz); BasicDBObject opts = (BasicDBObject) keyOpts.get(); if (opts.isEmpty()) { log.debug("Ensuring index for " + dbColl.getName() + " with keys:" + fields); dbColl.ensureIndex(fields); } else { log.debug("Ensuring index for " + dbColl.getName() + " with keys:" + fields + " and opts:" + opts); dbColl.ensureIndex(fields, opts); } //TODO: remove this once using 2.4 driver does this in ensureIndex CommandResult cr = dbColl.getDB().getLastError(); cr.throwOnError(); }