コード例 #1
0
        public static SqliteViewStore MakeViewStore(SqliteCouchStore store, string name, bool create)
        {
            var retVal = new SqliteViewStore();

            retVal._dbStorage = store;
            retVal.Name       = name;
            retVal._viewId    = -1;
            retVal._collation = ViewCollation.Unicode;

            if (!create && retVal.ViewID <= 0)
            {
                return(null);
            }

            return(retVal);
        }
コード例 #2
0
 public void Close()
 {
     _dbStorage = null;
     _viewId    = -1;
 }
コード例 #3
0
        internal bool Open()
        {
            if (_isOpen) {
                return true;
            }

            Log.D(TAG, "Opening {0}", Name);

            // Instantiate storage:
            //string storageType = Manager.StorageType ?? "SQLite";
            Storage = new SqliteCouchStore();
            Storage.Delegate = this;

            Log.D(TAG, "Using {0} for db at {1}", Storage.GetType(), Path);
            if (!Storage.Open(Path, Manager)) {
                return false;
            }

            Storage.AutoCompact = AUTO_COMPACT;

            // First-time setup:
            if (PrivateUUID() == null) {
                Storage.SetInfo("privateUUID", Misc.CreateGUID());
                Storage.SetInfo("publicUUID", Misc.CreateGUID());
            }

            var savedMaxRevDepth = _maxRevTreeDepth != 0 ? _maxRevTreeDepth.ToString() : Storage.GetInfo("max_revs");
            int maxRevTreeDepth = 0;
            if (savedMaxRevDepth != null && int.TryParse(savedMaxRevDepth, out maxRevTreeDepth)) {
                MaxRevTreeDepth = maxRevTreeDepth;
            } else {
                MaxRevTreeDepth = DEFAULT_MAX_REVS;
            }

            // Open attachment store:
            string attachmentsPath = AttachmentStorePath;

            try {
                Attachments = new BlobStore(attachmentsPath);
            } catch(Exception e) {
                Log.W(TAG, String.Format("Couldn't open attachment store at {0}", attachmentsPath), e);
                Storage.Close();
                Storage = null;
                return false;
            }
           
            _isOpen = true;
            return true;
        }
コード例 #4
0
ファイル: Database.cs プロジェクト: e42s/couchbase-lite-net
        internal void Open()
        {
            if (_isOpen) {
                return;
            }

            Log.D(TAG, "Opening {0}", Name);

            // Instantiate storage:
            //string storageType = Manager.StorageType ?? "SQLite";
            Storage = new SqliteCouchStore();
            Storage.Delegate = this;

            var encryptionKey = default(SymmetricKey);
            var gotKey = Manager.Shared.TryGetValue("encryptionKey", "", Name, out encryptionKey);
            if (gotKey) {
                Storage.SetEncryptionKey(encryptionKey);
            }

            Log.D(TAG, "Using {0} for db at {1}", Storage.GetType(), Path);
            try {
                Storage.Open(Path, Manager);

                // HACK: Needed to overcome the read connection not getting the write connection
                // changes until after the schema is written
                Storage.Close();
                Storage.Open(Path, Manager);
            } catch(CouchbaseLiteException) {
                Storage.Close();
                Log.W(TAG, "Error creating storage engine");
                throw;
            } catch(Exception e) {
                throw new CouchbaseLiteException("Unknown exception creating storage engine", e) { Code = StatusCode.Exception };
            }

            Storage.AutoCompact = AUTO_COMPACT;

            // First-time setup:
            if (PrivateUUID() == null) {
                Storage.SetInfo("privateUUID", Misc.CreateGUID());
                Storage.SetInfo("publicUUID", Misc.CreateGUID());
            }

            var savedMaxRevDepth = _maxRevTreeDepth != 0 ? _maxRevTreeDepth.ToString() : Storage.GetInfo("max_revs");
            int maxRevTreeDepth = 0;
            if (savedMaxRevDepth != null && int.TryParse(savedMaxRevDepth, out maxRevTreeDepth)) {
                MaxRevTreeDepth = maxRevTreeDepth;
            } else {
                MaxRevTreeDepth = DEFAULT_MAX_REVS;
            }

            // Open attachment store:
            string attachmentsPath = AttachmentStorePath;

            try {
                Attachments = new BlobStore(attachmentsPath, encryptionKey);
            } catch(CouchbaseLiteException) {
                Log.E(TAG, "Error creating blob store at {0}", attachmentsPath);
                Storage.Close();
                Storage = null;
                throw;
            } catch(Exception e) {
                Storage.Close();
                Storage = null;
                throw new CouchbaseLiteException(String.Format("Unknown error creating blob store at {0}", attachmentsPath),
                    e) { Code = StatusCode.Exception };
            }
           
            _isOpen = true;
        }