예제 #1
0
        public QueryCacheItem GetQueryCacheItem(string collectionName, string query, string lastRequest)
        {
            lock (DBConnectionSync)
            {
                QueryCacheItem result = null;

                if (!TableExists <QueryCacheItem>(DBConnectionSync))
                {
                    DBConnectionSync.CreateTable <QueryCacheItem>();
                }
                else
                {
                    var items = DBConnectionSync.Table <QueryCacheItem>().Where(item => item.collectionName == collectionName && item.query == query);
                    if (items.Count() == 1)
                    {
                        foreach (QueryCacheItem item in items)
                        {
                            result = item;
                        }
                    }
                }

                return(result);
            }
        }
예제 #2
0
        public ICache <T> GetCache <T>(string collectionName) where T : class, new()
        {
            lock (DBConnectionSync)
            {
                if (!TableExists <CollectionTableMap>(DBConnectionSync))
                {
                    DBConnectionSync.CreateTable <CollectionTableMap>();
                }

                CollectionTableMap ctm = new CollectionTableMap
                {
                    CollectionName = collectionName,
                    TableName      = typeof(T).Name
                };

                DBConnectionSync.InsertOrReplace(ctm);

                if (mapCollectionToCache.ContainsKey(collectionName))
                {
                    return(mapCollectionToCache[collectionName] as ICache <T>);
                }

                mapCollectionToCache[collectionName] = new SQLiteCache <T>(collectionName, dbConnectionAsync, DBConnectionSync);
                return(mapCollectionToCache[collectionName] as ICache <T>);
            }
        }
예제 #3
0
        /// <summary>
        /// Clears the storage.
        /// </summary>
        public void clearStorage()
        {
            lock (DBConnectionSync)
            {
                if (TableExists <CollectionTableMap>(DBConnectionSync))
                {
                    List <CollectionTableMap> collections = DBConnectionSync.Table <CollectionTableMap>().ToList();
                    if (collections != null)
                    {
                        foreach (var collection in collections)
                        {
                            string dropQuery = $"DROP TABLE IF EXISTS {collection.TableName}";
                            DBConnectionSync.Execute(dropQuery);
                            GetSyncQueue(collection.CollectionName).RemoveAll();
                            mapCollectionToCache.Remove(collection.CollectionName);
                        }

                        DBConnectionSync.DeleteAll <CollectionTableMap>();

                        // Remove _QueryCache table
                        if (TableExists <QueryCacheItem>(DBConnectionSync))
                        {
                            DBConnectionSync.DeleteAll <QueryCacheItem>();
                        }
                    }
                }
            }
        }
예제 #4
0
        public ISyncQueue GetSyncQueue(string collectionName)
        {
            lock (DBConnectionSync)
            {
                if (!TableExists <PendingWriteAction>(DBConnectionSync))
                {
                    DBConnectionSync.CreateTable <PendingWriteAction>();
                }

                return(new SQLiteSyncQueue(collectionName, DBConnectionSync));
            }
        }
예제 #5
0
        /// <summary>
        /// Gets the collection tables.
        /// </summary>
        /// <returns>The collection tables.</returns>
        public List <string> getCollectionTables()
        {
            lock (DBConnectionSync)
            {
                List <SQLTemplates.TableItem> result = DBConnectionSync.Table <SQLTemplates.TableItem>().OrderByDescending(t => t.name).ToList();
                List <string> collections            = new List <string>();

                foreach (SQLTemplates.TableItem item in result)
                {
                    collections.Add(item.name);
                }

                return(collections);
            }
        }
예제 #6
0
        public bool DeleteQueryCacheItem(QueryCacheItem item)
        {
            lock (DBConnectionSync)
            {
                bool success = false;

                if (TableExists <QueryCacheItem>(DBConnectionSync))
                {
                    int result = DBConnectionSync.Delete(item);

                    if (result != 0)
                    {
                        success = true;
                    }
                }

                return(success);
            }
        }
예제 #7
0
        public bool SetQueryCacheItem(QueryCacheItem item)
        {
            lock (DBConnectionSync)
            {
                bool success = false;

                if (!TableExists <QueryCacheItem>(DBConnectionSync))
                {
                    DBConnectionSync.CreateTable <QueryCacheItem>();
                }

                int result = DBConnectionSync.InsertOrReplace(item);
                if (result != 0)
                {
                    success = true;
                }

                return(success);
            }
        }