예제 #1
0
        public LuceneSession(IDocumentMapper <T> mapper, IDocumentModificationDetector <T> detector, IIndexWriter writer, Context context, IQueryable <T> queryable)
        {
            this.mapper    = mapper;
            this.writer    = writer;
            this.context   = context;
            this.queryable = queryable;

            documentTracker = new SessionDocumentTracker(detector);
        }
        public void SetUp()
        {
            mapper = MockRepository.GenerateStrictMock<IDocumentMapper<Record>>();
            detector = MockRepository.GenerateStrictMock<IDocumentModificationDetector<Record>>();
            writer = MockRepository.GenerateStrictMock<IIndexWriter>();
            context = MockRepository.GenerateStub<Context>(null, new object());

            session = new LuceneSession<Record>(mapper, detector, writer, context, null);

            mapper.Expect(m => m.ToKey(Arg<Record>.Is.NotNull))
                .WhenCalled(mi => mi.ReturnValue = new DocumentKey(new Dictionary<IFieldMappingInfo, object> { { new FakeFieldMappingInfo { FieldName = "Id"}, ((Record)mi.Arguments[0]).Id } }))
                .Repeat.Any();
        }
예제 #3
0
        public void SetUp()
        {
            mapper   = MockRepository.GenerateStrictMock <IDocumentMapper <Record> >();
            detector = MockRepository.GenerateStrictMock <IDocumentModificationDetector <Record> >();
            writer   = MockRepository.GenerateStrictMock <IIndexWriter>();
            context  = MockRepository.GenerateStub <Context>(null, new object());

            session = new LuceneSession <Record>(mapper, detector, writer, context, null);

            mapper.Expect(m => m.ToKey(Arg <Record> .Is.NotNull))
            .WhenCalled(mi => mi.ReturnValue = new DocumentKey(new Dictionary <IFieldMappingInfo, object> {
                { new FakeFieldMappingInfo {
                      FieldName = "Id"
                  }, ((Record)mi.Arguments[0]).Id }
            }))
            .Repeat.Any();
        }
예제 #4
0
        /// <summary>
        /// Opens a session for staging changes and then committing them atomically.
        /// </summary>
        /// <param name="lookup">Factory delegate that resolves instances of <typeparamref name="T"/></param>
        /// <param name="documentMapper">Mapper that will convert documents to objects and vice versa.</param>
        /// <param name="documentModificationDetector">Helper to determine when instances of <typeparamref name="T"/> are modified
        ///     and need to be updated in the index when the session is committed.
        /// </param>
        /// <typeparam name="T">The type of object that will be mapped to <c cref="Document"/>.</typeparam>
        public virtual ISession <T> OpenSession <T>(ObjectLookup <T> lookup, IDocumentMapper <T> documentMapper, IDocumentModificationDetector <T> documentModificationDetector)
        {
            perFieldAnalyzer.Merge(documentMapper.Analyzer);

            return(new LuceneSession <T>(
                       documentMapper,
                       documentModificationDetector,
                       IndexWriter,
                       context,
                       CreateQueryable(lookup, context, documentMapper)));
        }
예제 #5
0
 /// <summary>
 /// Opens a session for staging changes and then committing them atomically.
 /// </summary>
 /// <param name="factory">Factory delegate that creates new instances of <typeparamref name="T"/></param>
 /// <param name="documentMapper">Mapper that will convert documents to objects and vice versa.</param>
 /// <param name="documentModificationDetector">Helper to determine when instances of <typeparamref name="T"/> are modified
 ///     and need to be updated in the index when the session is committed.
 /// </param>
 /// <typeparam name="T">The type of object that will be mapped to <c cref="Document"/>.</typeparam>
 public ISession <T> OpenSession <T>(ObjectFactory <T> factory, IDocumentMapper <T> documentMapper, IDocumentModificationDetector <T> documentModificationDetector)
 {
     return(OpenSession(_ => factory(), documentMapper, documentModificationDetector));
 }
예제 #6
0
 public SessionDocumentTracker(IDocumentModificationDetector <T> detector)
 {
     this.detector = detector;
 }
예제 #7
0
 public override ISession <T> OpenSession <T>(ObjectLookup <T> factory, IDocumentMapper <T> documentMapper, IDocumentModificationDetector <T> documentModificationDetector)
 {
     throw new InvalidOperationException("Cannot open sessions in read-only mode.");
 }