List of usage examples for com.mongodb.client.model IndexOptions IndexOptions
IndexOptions
From source file:com.sitewhere.schedule.persistence.mongodb.MongoScheduleManagement.java
License:Open Source License
/** * Ensure that expected collection indexes exist. * /* w w w . java 2 s.c om*/ * @throws SiteWhereException */ protected void ensureIndexes() throws SiteWhereException { getMongoClient().getSchedulesCollection().createIndex(new Document(MongoSchedule.PROP_TOKEN, 1), new IndexOptions().unique(true)); getMongoClient().getScheduledJobsCollection().createIndex(new Document(MongoScheduledJob.PROP_TOKEN, 1), new IndexOptions().unique(true)); }
From source file:com.sitewhere.tenant.persistence.mongodb.MongoTenantManagement.java
License:Open Source License
/** * Ensure that expected collection indexes exist. * //w w w. jav a 2 s . c om * @throws SiteWhereException */ protected void ensureIndexes() throws SiteWhereException { getMongoClient().getTenantsCollection().createIndex(new Document(MongoTenant.PROP_TOKEN, 1), new IndexOptions().unique(true)); getMongoClient().getTenantsCollection().createIndex(new Document(MongoTenant.PROP_AUTH_TOKEN, 1), new IndexOptions().unique(true)); }
From source file:com.sitewhere.user.persistence.mongodb.MongoUserManagement.java
License:Open Source License
/** * Ensure that expected collection indexes exist. * /*from w ww. j a v a 2s .co m*/ * @throws SiteWhereException */ protected void ensureIndexes() throws SiteWhereException { getMongoClient().getUsersCollection().createIndex(new Document("username", 1), new IndexOptions().unique(true)); getMongoClient().getAuthoritiesCollection().createIndex(new Document("authority", 1), new IndexOptions().unique(true)); }
From source file:com.telefonica.iot.cygnus.backends.mongo.MongoBackendImpl.java
License:Open Source License
/** * Creates a collection for STH, given its name, if not exists in the given database. Time-based limits are set, * if possible.//from w ww .jav a 2 s . c o m * @param dbName * @param collectionName * @param dataExpiration * @throws Exception */ @Override public void createCollection(String dbName, String collectionName, long dataExpiration) throws Exception { LOGGER.debug("Creating Mongo collection=" + collectionName + " at database=" + dbName); MongoDatabase db = getDatabase(dbName); // create the collection try { db.createCollection(collectionName); } catch (Exception e) { if (e.getMessage().contains("collection already exists")) { LOGGER.debug("Collection already exists, nothing to create"); } else { throw e; } // if else } // try catch // ensure the _id.origin index, if possible try { if (dataExpiration != 0) { BasicDBObject keys = new BasicDBObject().append("_id.origin", 1); IndexOptions options = new IndexOptions().expireAfter(dataExpiration, TimeUnit.SECONDS); db.getCollection(collectionName).createIndex(keys, options); } // if } catch (Exception e) { throw e; } // try catch }
From source file:com.telefonica.iot.cygnus.backends.mongo.MongoBackendImpl.java
License:Open Source License
/** * Creates a collection for plain MongoDB, given its name, if not exists in the given database. Size-based limits * are set, if possible. Time-based limits are also set, if possible. * @param dbName// w w w.ja v a 2 s . c o m * @param collectionName * @param collectionsSize * @param maxDocuments * @throws Exception */ @Override public void createCollection(String dbName, String collectionName, long collectionsSize, long maxDocuments, long dataExpiration) throws Exception { MongoDatabase db = getDatabase(dbName); // create the collection, with size-based limits if possible try { if (collectionsSize != 0 && maxDocuments != 0) { CreateCollectionOptions options = new CreateCollectionOptions().capped(true) .sizeInBytes(collectionsSize).maxDocuments(maxDocuments); LOGGER.debug("Creating Mongo collection=" + collectionName + " at database=" + dbName + " with " + "collections_size=" + collectionsSize + " and max_documents=" + maxDocuments + " options"); db.createCollection(collectionName, options); } else { LOGGER.debug("Creating Mongo collection=" + collectionName + " at database=" + dbName); db.createCollection(collectionName); } // if else } catch (Exception e) { if (e.getMessage().contains("collection already exists")) { LOGGER.debug("Collection already exists, nothing to create"); } else { throw e; } // if else } // try catch // ensure the recvTime index, if possible try { if (dataExpiration != 0) { BasicDBObject keys = new BasicDBObject().append("recvTime", 1); IndexOptions options = new IndexOptions().expireAfter(dataExpiration, TimeUnit.SECONDS); db.getCollection(collectionName).createIndex(keys, options); } // if } catch (Exception e) { throw e; } // try catch }
From source file:io.djigger.collector.accessors.stackref.AbstractAccessor.java
License:Open Source License
private void createTimestampIndexWithTTL(MongoCollection<Document> collection, String attribute, Long ttl) { IndexOptions options = new IndexOptions(); options.expireAfter(ttl, TimeUnit.SECONDS); createTimestampIndexWithOptions(collection, attribute, options); }
From source file:io.djigger.collector.accessors.stackref.AbstractAccessor.java
License:Open Source License
private void createTimestampIndex(MongoCollection<Document> collection, String attribute) { IndexOptions options = new IndexOptions(); createTimestampIndexWithOptions(collection, attribute, options); }
From source file:io.gravitee.am.repository.mongodb.oauth2.MongoAccessTokenRepository.java
License:Apache License
@PostConstruct public void init() { accessTokenCollection = mongoOperations.getCollection("access_tokens", AccessTokenMongo.class); // one field index accessTokenCollection.createIndex(new Document(FIELD_TOKEN, 1)).subscribe(new LoggableIndexSubscriber()); accessTokenCollection.createIndex(new Document(FIELD_CLIENT_ID, 1)) .subscribe(new LoggableIndexSubscriber()); // two fields index accessTokenCollection.createIndex(new Document(FIELD_CLIENT_ID, 1).append(FIELD_SUBJECT, 1)) .subscribe(new LoggableIndexSubscriber()); accessTokenCollection.createIndex(new Document(FIELD_CLIENT_ID, 1).append(FIELD_REQUESTED_SCOPES, 1)) .subscribe(new LoggableIndexSubscriber()); accessTokenCollection.createIndex(new Document(FIELD_CLIENT_ID, 1).append(FIELD_GRANT_TYPE, 1)) .subscribe(new LoggableIndexSubscriber()); accessTokenCollection/*from ww w. ja v a2s .com*/ .createIndex( new Document(FIELD_CLIENT_ID, 1).append(FIELD_REQUESTED_PARAMETERS + "." + FIELD_NONCE, 1)) .subscribe(new LoggableIndexSubscriber()); // three fields index (with subject) accessTokenCollection .createIndex( new Document(FIELD_CLIENT_ID, 1).append(FIELD_SUBJECT, 1).append(FIELD_REQUESTED_SCOPES, 1)) .subscribe(new LoggableIndexSubscriber()); accessTokenCollection .createIndex(new Document(FIELD_CLIENT_ID, 1).append(FIELD_SUBJECT, 1).append(FIELD_GRANT_TYPE, 1)) .subscribe(new LoggableIndexSubscriber()); accessTokenCollection .createIndex(new Document(FIELD_CLIENT_ID, 1).append(FIELD_SUBJECT, 1) .append(FIELD_REQUESTED_PARAMETERS + "." + FIELD_NONCE, 1)) .subscribe(new LoggableIndexSubscriber()); // three fields index (without subject) accessTokenCollection.createIndex( new Document(FIELD_CLIENT_ID, 1).append(FIELD_REQUESTED_SCOPES, 1).append(FIELD_GRANT_TYPE, 1)) .subscribe(new LoggableIndexSubscriber()); accessTokenCollection .createIndex(new Document(FIELD_CLIENT_ID, 1).append(FIELD_REQUESTED_SCOPES, 1) .append(FIELD_REQUESTED_PARAMETERS + "." + FIELD_NONCE, 1)) .subscribe(new LoggableIndexSubscriber()); accessTokenCollection .createIndex(new Document(FIELD_CLIENT_ID, 1).append(FIELD_GRANT_TYPE, 1) .append(FIELD_REQUESTED_PARAMETERS + "." + FIELD_NONCE, 1)) .subscribe(new LoggableIndexSubscriber()); // four fields index accessTokenCollection .createIndex(new Document(FIELD_CLIENT_ID, 1).append(FIELD_REQUESTED_SCOPES, 1) .append(FIELD_GRANT_TYPE, 1).append(FIELD_SUBJECT, 1)) .subscribe(new LoggableIndexSubscriber()); accessTokenCollection .createIndex(new Document(FIELD_CLIENT_ID, 1).append(FIELD_REQUESTED_SCOPES, 1) .append(FIELD_GRANT_TYPE, 1).append(FIELD_REQUESTED_PARAMETERS + "." + FIELD_NONCE, 1)) .subscribe(new LoggableIndexSubscriber()); // max fields index accessTokenCollection .createIndex(new Document(FIELD_CLIENT_ID, 1).append(FIELD_REQUESTED_SCOPES, 1) .append(FIELD_GRANT_TYPE, 1).append(FIELD_SUBJECT, 1) .append(FIELD_REQUESTED_PARAMETERS + "." + FIELD_NONCE, 1)) .subscribe(new LoggableIndexSubscriber()); // expire after index accessTokenCollection .createIndex(new Document(FIELD_RESET_TIME, 1), new IndexOptions().expireAfter(0L, TimeUnit.SECONDS)) .subscribe(new LoggableIndexSubscriber()); }
From source file:io.gravitee.am.repository.mongodb.oauth2.MongoAuthorizationCodeRepository.java
License:Apache License
@PostConstruct public void init() { authorizationCodeCollection = mongoOperations.getCollection("authorization_codes", AuthorizationCodeMongo.class); authorizationCodeCollection.createIndex(new Document(FIELD_CODE, 1)) .subscribe(new LoggableIndexSubscriber()); authorizationCodeCollection// w ww . j a va 2s . co m .createIndex(new Document(FIELD_RESET_TIME, 1), new IndexOptions().expireAfter(0l, TimeUnit.SECONDS)) .subscribe(new LoggableIndexSubscriber()); }
From source file:io.gravitee.am.repository.mongodb.oauth2.MongoRefreshTokenRepository.java
License:Apache License
@PostConstruct public void init() { refreshTokenCollection = mongoOperations.getCollection("refresh_tokens", RefreshTokenMongo.class); refreshTokenCollection.createIndex(new Document(FIELD_TOKEN, 1)).subscribe(new LoggableIndexSubscriber()); refreshTokenCollection// w w w.j a va 2 s . co m .createIndex(new Document(FIELD_RESET_TIME, 1), new IndexOptions().expireAfter(0L, TimeUnit.SECONDS)) .subscribe(new LoggableIndexSubscriber()); }