@Override public void onApplicationStarted() { activatePersistenceProvider(); cursorService = new CursorService<>(entry -> { try { return OBJECT_MAPPER.writeValueAsString(entry); } catch (IOException e) { throw new NuxeoException("Unable to serialize entry"); } }); }
public MongoDBRepository(ConnectionManager cm, MongoDBRepositoryDescriptor descriptor) { super(cm, descriptor.name, descriptor); MongoDBConnectionService mongoService = Framework.getService(MongoDBConnectionService.class); // prefix with repository/ to group repository connection MongoDatabase database = mongoService.getDatabase(REPOSITORY_CONNECTION_PREFIX + descriptor.name); coll = database.getCollection(descriptor.name); countersColl = database.getCollection(descriptor.name + ".counters"); if (Boolean.TRUE.equals(descriptor.nativeId)) { idKey = MONGODB_ID; } else { idKey = KEY_ID; } useCustomId = KEY_ID.equals(idKey); if (idType == IdType.sequence || DEBUG_UUIDS) { Integer sbs = descriptor.sequenceBlockSize; sequenceBlockSize = sbs == null ? 1 : sbs.longValue(); sequenceLeft = 0; } converter = new MongoDBConverter(useCustomId ? null : KEY_ID); cursorService = new CursorService<>(ob -> (String) ob.get(converter.keyToBson(KEY_ID))); initRepository(); }
@Override public void onApplicationStarted() { esClient = getClient(); if (Boolean.parseBoolean(Framework.getProperty(MIGRATION_FLAG_PROP))) { if (!isMigrationDone()) { log.info(String.format( "Property %s is true and migration is not done yet, processing audit migration from SQL to Elasticsearch index", MIGRATION_FLAG_PROP)); // Drop audit index first in case of a previous bad migration ElasticSearchAdmin esa = Framework.getService(ElasticSearchAdmin.class); esa.dropAndInitIndex(getESIndexName()); int batchSize = MIGRATION_DEFAULT_BACTH_SIZE; String batchSizeProp = Framework.getProperty(MIGRATION_BATCH_SIZE_PROP); if (batchSizeProp != null) { batchSize = Integer.parseInt(batchSizeProp); } migrate(batchSize); } else { log.warn(String.format( "Property %s is true but migration is already done, please set this property to false", MIGRATION_FLAG_PROP)); } } else { log.debug(String.format("Property %s is false, not processing any migration", MIGRATION_FLAG_PROP)); } cursorService = new CursorService<>(SearchHit::getSourceAsString); }