protected ReaderBase(TableDefinitionWrapper table, Func <Document, TEntity> projectionFunc)
        {
            this.Table          = table;
            this.ProjectionFunc = projectionFunc;

            this._entityWrapperCreator = doc => new EntityWrapper(doc, this.EntityType, this.Table.ToDocumentConversionFunctor, this.Table.EntityKeyGetter);
        }
Example #2
0
        /// <summary>
        /// Creates an instance of DataTable class for the specified entity
        /// with predefined HashKey value. The table contents and queries will be cached using
        /// the provided ITableCache implementation.
        /// The provided AWS SDK's Table object is used for all communications with DynamoDb.
        /// </summary>
        public DataTable <TEntity> GetTable <TEntity>(object hashKeyValue, Func <ITableCache> cacheImplementationFactory, Table tableDefinition)
        {
            var entityType = typeof(TEntity);

            var tableWrapper = TableWrappers.GetOrAdd
                               (
                new Tuple <Type, object>(entityType, hashKeyValue),
                t =>
            {
                // if cache is not provided, then passing a fake implementation
                var cacheImplementation =
                    cacheImplementationFactory == null
                        ?
                    FakeCacheImplementation
                        :
                    cacheImplementationFactory();

                var wrapper = new TableDefinitionWrapper
                              (
                    tableDefinition,
                    entityType,
                    hashKeyValue,
                    cacheImplementation,
                    this.ConsistentRead
                              );
                wrapper.OnLog += this.OnLog;
                return(wrapper);
            }
                               );

            if (tableWrapper.TableDefinition != tableDefinition)
            {
                throw new InvalidOperationException("You shouldn't pass different Table instances for the same entityType/hashKeyValue pair");
            }

            // this is to avoid situation, when the same DataContext instance is being used for table creation and then for cached data access.
            if
            (
                (tableWrapper.Cache == FakeCacheImplementation)
                &&
                (cacheImplementationFactory != null)
            )
            {
                throw new InvalidOperationException("You're trying to get a DataTable<T> instance first without caching and then with cache implementation specified. This is not supported. For creating DynamoDb tables, please, use another separate instance of DataContext");
            }

            return(new DataTable <TEntity>(tableWrapper));
        }
Example #3
0
        protected ReaderBase(TableDefinitionWrapper table, Func <Document, TEntity> projectionFunc)
        {
            this.Table          = table;
            this.ProjectionFunc = projectionFunc;

            // choosing a wrapper for the entity depending on whether it's inherited from EntityBase
            if (typeof(EntityBase).IsAssignableFrom(this.EntityType))
            {
                // then using a TransparentProxy
                this._entityWrapperCreator = doc => new EntityProxy(doc, this.EntityType, this.Table.KeyNames);
            }
            else
            {
                // unobtrusive mode - using EntityWrapper
                this._entityWrapperCreator = doc => new EntityWrapper(doc, this.EntityType, this.Table.ToDocumentConversionFunctor, this.Table.EntityKeyGetter);
            }
        }
Example #4
0
 /// <summary>
 /// ctor used for iterating through a search result
 /// </summary>
 private SearchReader(TableDefinitionWrapper table, Search search, Func <Document, TEntity> projectionFunc)
     :
     base(table, projectionFunc)
 {
     this._search = search;
 }
Example #5
0
 internal DataTable(TableDefinitionWrapper tableWrapper) : base(new QueryProvider(tableWrapper))
 {
     this._tableWrapper = tableWrapper;
 }
 internal QueryProvider(TableDefinitionWrapper tableWrapper)
 {
     this.CustomizationHooks = new CustomizationHooks();
     this._tableWrapper      = tableWrapper;
 }
Example #7
0
 /// <summary>
 /// ctor used for iterating through an array taken from cache
 /// </summary>
 public DocArrayReader(TableDefinitionWrapper table, IEnumerable <Document> docs, Func <Document, TEntity> projectionFunc)
     :
     base(table, projectionFunc)
 {
     this._docsEnumerator = docs.GetEnumerator();
 }
 /// <summary>
 /// ctor, that iterates through a single document
 /// </summary>
 public SingleDocReader(TableDefinitionWrapper table, Document singleDoc, Func <Document, TEntity> projectionFunc)
     :
     base(table, projectionFunc)
 {
     this._singleDoc = singleDoc;
 }
 internal QueryProvider(TableDefinitionWrapper tableWrapper)
 {
     this._tableWrapper = tableWrapper;
 }