com.mongodb.BasicDBObject.isEmpty()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中com.mongodb.BasicDBObject.isEmpty()方法的一些代码示例,展示了BasicDBObject.isEmpty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BasicDBObject.isEmpty()方法的具体详情如下:
包路径:com.mongodb.BasicDBObject
类名称:BasicDBObject
方法名:isEmpty

BasicDBObject.isEmpty介绍

暂无

代码示例

代码示例来源:origin: MorphiaOrg/morphia

if (!values.isEmpty() || mapper.getOptions().isStoreEmpties()) {
  dbObject.put(name, values);

代码示例来源:origin: ltsopensource/light-task-scheduler

/**
 * 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);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

/**
 * 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);
  }
}

代码示例来源:origin: com.effektif/effektif-mongo

public boolean isEmpty() {
  return index.isEmpty();
 }
}

代码示例来源:origin: Impetus/Kundera

if (!compositeColumns.isEmpty())

代码示例来源:origin: com.effektif/effektif-mongo

public boolean isEmpty() {
  return update.isEmpty();
 }
}

代码示例来源:origin: effektif/effektif

public boolean isEmpty() {
  return index.isEmpty();
 }
}

代码示例来源:origin: effektif/effektif

public boolean isEmpty() {
  return fields.isEmpty();
 }
}

代码示例来源:origin: com.effektif/effektif-mongo

public boolean isEmpty() {
  return fields.isEmpty();
 }
}

代码示例来源:origin: effektif/effektif

public boolean isEmpty() {
  return update.isEmpty();
 }
}

代码示例来源:origin: com.tomtom.speedtools/mongodb

/**
 * 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;
}

代码示例来源:origin: com.effektif/effektif-mongo

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

代码示例来源:origin: effektif/effektif

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

代码示例来源:origin: com.google.code.morphia/morphia

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

代码示例来源:origin: org.apache.jackrabbit/oak-store-document

/**
 * 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;
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * 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;
}

代码示例来源:origin: apache/gora

/**
 * 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);
 }
}

代码示例来源:origin: com.github.ltsopensource/lts-core

/**
 * 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);
  }
}

代码示例来源:origin: com.google.code.morphia/morphia

if (opts.isEmpty()) {
 LOG.debug("Ensuring index for " + dbColl.getName() + " with keys:" + fields);
 dbColl.ensureIndex(fields);

代码示例来源:origin: com.google.code.maven-play-plugin.com.google.code.morphia/morphia

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

相关文章