public static List<MongoIndex> parse(ListIndexesIterable<Document> indexes) { ImmutableList.Builder<MongoIndex> builder = ImmutableList.builder(); for (Document index : indexes) { // TODO: v, ns, sparse fields Document key = (Document) index.get("key"); String name = index.getString("name"); boolean unique = index.getBoolean("unique", false); if (key.containsKey("_fts")) { // Full Text Search continue; } builder.add(new MongoIndex(name, parseKey(key), unique)); } return builder.build(); }
/** * Creates new {@link AggregationOptions} given {@link DBObject} containing aggregation options. * * @param document must not be {@literal null}. * @return the {@link AggregationOptions}. * @since 2.0 */ public static AggregationOptions fromDocument(Document document) { Assert.notNull(document, "Document must not be null!"); boolean allowDiskUse = document.getBoolean(ALLOW_DISK_USE, false); boolean explain = document.getBoolean(EXPLAIN, false); Document cursor = document.get(CURSOR, Document.class); Collation collation = document.containsKey(COLLATION) ? Collation.from(document.get(COLLATION, Document.class)) : null; return new AggregationOptions(allowDiskUse, explain, cursor, collation); }
private MongoColumnHandle buildColumnHandle(Document columnMeta) { String name = columnMeta.getString(FIELDS_NAME_KEY); String typeString = columnMeta.getString(FIELDS_TYPE_KEY); boolean hidden = columnMeta.getBoolean(FIELDS_HIDDEN_KEY, false); Type type = typeManager.getType(TypeSignature.parseTypeSignature(typeString)); return new MongoColumnHandle(name, type, hidden); }
boolean indexExists = false; for (Document document : collection.listIndexes()) { if (MongoDbGrokPatternService.INDEX_NAME.equals(document.getString("name")) && document.getBoolean("unique")) { indexExists = true; break;
boolean committed = element.getBoolean("committed"); boolean rolledback = element.getBoolean("rolledback"); boolean readonly = element.getBoolean("readonly"); boolean completed = element.getBoolean("completed"); boolean heuristic = element.getBoolean("heuristic");
@Override public void upgrade() { if (clusterConfigService.get(MigrationCompleted.class) != null) { LOG.debug("Migration already done."); return; } // Do not overwrite an existing default index config boolean defaultDone = clusterConfigService.get(DefaultIndexSetConfig.class) != null; final ImmutableSet.Builder<String> builder = ImmutableSet.builder(); final FindIterable<Document> documents = collection.find(exists(FIELD_DEFAULT)).sort(ascending(FIELD_CREATION_DATE)); for (final Document document : documents) { final ObjectId id = document.getObjectId(FIELD_ID); final String idString = id.toHexString(); final boolean isDefault = firstNonNull(document.getBoolean(FIELD_DEFAULT), false); if (!defaultDone && isDefault) { defaultDone = true; clusterConfigService.write(DefaultIndexSetConfig.create(idString)); } final long modifiedCount = collection.updateOne(eq(FIELD_ID, id), unset(FIELD_DEFAULT)).getMatchedCount(); if (modifiedCount > 0) { LOG.info("Removed <default> field from index set <{}> ({})", document.getString(FIELD_TITLE), idString); builder.add(idString); } else { LOG.error("Couldn't remove <default> field from index set <{}> ({})", document.getString(FIELD_TITLE), idString); } } clusterConfigService.write(MigrationCompleted.create(builder.build())); }
private void createLocksIndexIfNecessary() { String databaseName = CommonUtils.getApplication(this.endpoint).replaceAll("\\W", "_"); MongoDatabase database = this.mongoClient.getDatabase(databaseName); MongoCollection<Document> locks = database.getCollection(CONSTANTS_TB_LOCKS); ListIndexesIterable<Document> lockIndexList = locks.listIndexes(); boolean transactionIndexExists = false; MongoCursor<Document> lockCursor = null; try { lockCursor = lockIndexList.iterator(); while (transactionIndexExists == false && lockCursor.hasNext()) { Document document = lockCursor.next(); Boolean unique = document.getBoolean("unique"); Document key = (Document) document.get("key"); boolean globalExists = key.containsKey(CONSTANTS_FD_GLOBAL); boolean lengthEquals = key.size() == 1; transactionIndexExists = lengthEquals && globalExists; if (transactionIndexExists && (unique == null || unique == false)) { throw new IllegalStateException(); } } } finally { IOUtils.closeQuietly(lockCursor); } if (transactionIndexExists == false) { Document index = new Document(CONSTANTS_FD_GLOBAL, 1); locks.createIndex(index, new IndexOptions().unique(true)); } }
private void createTransactionsGlobalTxKeyIndexIfNecessary() { String databaseName = CommonUtils.getApplication(this.endpoint).replaceAll("\\W", "_"); MongoDatabase database = this.mongoClient.getDatabase(databaseName); MongoCollection<Document> transactions = database.getCollection(CONSTANTS_TB_TRANSACTIONS); ListIndexesIterable<Document> transactionIndexList = transactions.listIndexes(); boolean transactionIndexExists = false; MongoCursor<Document> transactionCursor = null; try { transactionCursor = transactionIndexList.iterator(); while (transactionIndexExists == false && transactionCursor.hasNext()) { Document document = transactionCursor.next(); Boolean unique = document.getBoolean("unique"); Document key = (Document) document.get("key"); boolean globalExists = key.containsKey(CONSTANTS_FD_GLOBAL); boolean lengthEquals = key.size() == 1; transactionIndexExists = lengthEquals && globalExists; if (transactionIndexExists && (unique == null || unique == false)) { throw new IllegalStateException(); } } } finally { IOUtils.closeQuietly(transactionCursor); } if (transactionIndexExists == false) { Document index = new Document(CONSTANTS_FD_GLOBAL, 1); transactions.createIndex(index, new IndexOptions().unique(true)); } }
public void recover(TransactionRecoveryCallback callback) { MongoCursor<Document> transactionCursor = null; try { String application = CommonUtils.getApplication(this.endpoint); String databaseName = application.replaceAll("\\W", "_"); MongoDatabase mdb = this.mongoClient.getDatabase(databaseName); MongoCollection<Document> transactions = mdb.getCollection(CONSTANTS_TB_TRANSACTIONS); FindIterable<Document> transactionItr = transactions.find(Filters.eq("coordinator", true)); for (transactionCursor = transactionItr.iterator(); transactionCursor.hasNext();) { Document document = transactionCursor.next(); boolean error = document.getBoolean("error"); String targetApplication = document.getString("system"); long expectVersion = document.getLong("version"); long actualVersion = this.versionManager.getInstanceVersion(targetApplication); if (error == false && actualVersion > 0 && actualVersion <= expectVersion) { continue; // ignore } callback.recover(this.reconstructTransactionArchive(document)); } } catch (RuntimeException error) { logger.error("Error occurred while recovering transaction.", error); } catch (Exception error) { logger.error("Error occurred while recovering transaction.", error); } finally { IOUtils.closeQuietly(transactionCursor); } }
for (transactionCursor = transactionItr.iterator(); transactionCursor.hasNext();) { Document document = transactionCursor.next(); boolean error = document.getBoolean("error");
XidFactory compensableXidFactory = this.beanFactory.getCompensableXidFactory(); boolean propagated = document.getBoolean("propagated"); String propagatedBy = document.getString("propagated_by"); boolean compensable = document.getBoolean("compensable"); boolean coordinator = document.getBoolean("coordinator"); int compensableStatus = document.getInteger("status");
collation = collation.caseLevel(source.getBoolean("caseLevel")); collation = collation.numericOrdering(source.getBoolean("numericOrdering")); collation = collation.backwards(source.getBoolean("backwards")); collation = collation.normalization(source.getBoolean("normalization"));
String bxid = element.getString(CONSTANTS_FD_BRANCH); boolean coordinatorFlag = element.getBoolean("coordinator"); boolean tried = element.getBoolean("tried"); boolean confirmed = element.getBoolean("confirmed"); boolean cancelled = element.getBoolean("cancelled"); String serviceId = element.getString("serviceId"); boolean simplified = element.getBoolean("simplified"); String confirmableKey = element.getString("confirmable_key"); String cancellableKey = element.getString("cancellable_key");
/** * Creates new {@link AggregationOptions} given {@link DBObject} containing aggregation options. * * @param document must not be {@literal null}. * @return the {@link AggregationOptions}. * @since 2.0 */ public static AggregationOptions fromDocument(Document document) { Assert.notNull(document, "Document must not be null!"); boolean allowDiskUse = document.getBoolean(ALLOW_DISK_USE, false); boolean explain = document.getBoolean(EXPLAIN, false); Document cursor = document.get(CURSOR, Document.class); Collation collation = document.containsKey(COLLATION) ? Collation.from(document.get(COLLATION, Document.class)) : null; return new AggregationOptions(allowDiskUse, explain, cursor, collation); }
collation = collation.caseLevel(source.getBoolean("caseLevel")); collation = collation.numericOrdering(source.getBoolean("numericOrdering")); collation = collation.backwards(source.getBoolean("backwards")); collation = collation.normalization(source.getBoolean("normalization"));
@Override public boolean isValid(LoginSessionToken loginSessionToken) { Document document = loginSessionCollection.find(new Document().append("_id", loginSessionToken.getValue())).first(); if (document == null) { return false; } return document.getBoolean("valid") != null ? document.getBoolean("valid") : false; }
@Test public void testIsMaster() throws Exception { Document isMaster = db.runCommand(new Document("isMaster", Integer.valueOf(1))); assertThat(isMaster.getBoolean("ismaster")).isTrue(); assertThat(isMaster.getDate("localTime")).isInstanceOf(Date.class); assertThat(isMaster.getInteger("maxBsonObjectSize")).isGreaterThan(1000); assertThat(isMaster.getInteger("maxMessageSizeBytes")).isGreaterThan(isMaster.getInteger("maxBsonObjectSize")); }
public TodoItem(final Document document) { _id = document.getObjectId("_id"); _text = document.getString("text"); if (document.containsKey("checked")) { _checked = document.getBoolean("checked"); } else { _checked = false; } }
private Boolean isCollectionCapped() { // A non-capped collection does not return a "capped" key/value, so we have to deal with null here Boolean result = endpoint.getMongoDatabase().runCommand(createCollStatsCommand()).getBoolean(CAPPED_KEY); return result != null ? result : false; }
public void setMetadataDoc(Document doc) { setId(doc.getString("pid")); setLinked(doc.getBoolean("linked", false)); setLabel(doc.getString("label")); setType(PayloadType.valueOf(doc.getString("payloadType"))); setContentType(doc.getString("contentType")); lastModified = doc.getDate("lastModified"); getBackend().setId(doc.getString("payloadId")); }