@Override public void createCollection(String collectionName) { try { if (!mongoTemplate.collectionExists(collectionName)) { mongoTemplate.createCollection(collectionName); } } catch (UncategorizedMongoDbException ex) { LOG.warn("Failed to create collection {} due to", collectionName, ex); } }
public <T> boolean collectionExists(Class<T> entityClass) { return collectionExists(operations.determineCollectionName(entityClass)); }
public <T> boolean collectionExists(Class<T> entityClass) { return collectionExists(operations.determineCollectionName(entityClass)); }
@Override public void createCollection(String collectionName) { if (StringUtils.isEmpty(collectionName)) { collectionName = clz.getSimpleName(); } if (!mongoTemplate.collectionExists(collectionName)) { mongoTemplate.createCollection(collectionName); } };
@Override public void dropPersonCollection(String collectionName) { if (StringUtils.isEmpty(collectionName)) { collectionName = clz.getSimpleName(); } if (mongoTemplate.collectionExists(collectionName)) { mongoTemplate.dropCollection(collectionName); } };
@PostConstruct public void start() { mongoTemplate.setWriteResultChecking(WriteResultChecking.EXCEPTION); if (!mongoTemplate.collectionExists("history")) { mongoTemplate.createCollection("history"); } Thread thread = new Thread(this); thread.start(); LOGGER.info("Historian collector started"); }
@PostConstruct public void updateMongoSchema() { Preconditions.checkState(StringUtils.isNotBlank(collectionName), "error starting Store, collectionName is null"); logger.info("updating Mongo schema ..."); if (!mongoTemplate.collectionExists(collectionName)) { logger.info("create collection '"+collectionName+"'"); mongoTemplate.createCollection(collectionName); } //tags_idx BasicDBObject keys = new BasicDBObject(F_TAGS, 1); mongoTemplate.getCollection(collectionName).ensureIndex(keys, collectionName+"_tags_idx", false); //hist collection if (keepHistory) { collectionNameHist = collectionName + "_hist"; if (!mongoTemplate.collectionExists(collectionNameHist)) { logger.info("create collection '"+collectionNameHist+"'"); mongoTemplate.createCollection(collectionNameHist); } keys = new BasicDBObject(F_RECORD_FK_ID, 1); mongoTemplate.getCollection(collectionNameHist).ensureIndex(keys, collectionNameHist+"_record_fk_idx", false); } }
@Override public void initializeResources() { if (!mongoTemplate.collectionExists(collectionName)) { mongoTemplate.createCollection(collectionName); } hashingElementManager.upgrade(); upgradeIndexes(); }
@Override public ResourcesValidationResult validateResources() { RESULT result; if (mongoTemplate.collectionExists(collectionName)) { if (hashingElementManager.needsUpgrade() || needsUpgradeIndexes()) { result = ResourcesValidationResult.RESULT.NEEDS_UPGRADE; } else { result = ResourcesValidationResult.RESULT.VALID; } } else { result = ResourcesValidationResult.RESULT.NOT_INITIALIZED; } return new ResourcesValidationResult(result); }