public IJoin On(IExpression expression) { CBDebug.MustNotBeNull(Log.To.Query, Tag, nameof(expression), expression); _on = expression; return(this); }
public Parameters SetValue(string name, object value) { CBDebug.MustNotBeNull(Log.To.Query, Tag, nameof(name), name); _freezer.PerformAction(() => _params[name] = value); return(this); }
/// <summary> /// Checks whether or not a document with the given ID has any pending revisions to push /// </summary> /// <param name="documentID">The document ID</param> /// <returns>A bool which represents whether or not the document with the corresponding ID has one or more pending revisions. /// <c>true</c> means that one or more revisions have not been pushed to the remote yet, /// and <c>false</c> means that all revisions on the document have been pushed</returns> /// <exception cref="CouchbaseLiteException">Thrown if no push replication</exception> /// <exception cref="CouchbaseException">Thrown if an error condition is returned from LiteCore</exception> public bool IsDocumentPending([NotNull] string documentID) { CBDebug.MustNotBeNull(WriteLog.To.Sync, Tag, nameof(documentID), documentID); bool isDocPending = false; if (!IsPushing()) { CBDebug.LogAndThrow(WriteLog.To.Sync, new CouchbaseLiteException(C4ErrorCode.Unsupported, CouchbaseLiteErrorMessage.PullOnlyPendingDocIDs), Tag, CouchbaseLiteErrorMessage.PullOnlyPendingDocIDs, true); } DispatchQueue.DispatchSync(() => { var errSetupRepl = SetupC4Replicator(); if (errSetupRepl.code > 0) { CBDebug.LogAndThrow(WriteLog.To.Sync, CouchbaseException.Create(errSetupRepl), Tag, errSetupRepl.ToString(), true); } }); LiteCoreBridge.Check(err => { isDocPending = Native.c4repl_isDocumentPending(_repl, documentID, err); return(isDocPending); }); return(isDocPending); }
/// <inheritdoc /> public bool GetBoolean([NotNull] string key) { CBDebug.MustNotBeNull(WriteLog.To.Query, Tag, nameof(key), key); var index = IndexForColumnName(key); return(index >= 0 && GetBoolean(index)); }
public void Purge(Document document) { CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(document), document); ThreadSafety.DoLocked(() => { CheckOpen(); VerifyDB(document); if (!document.Exists) { var docID = new SecureLogString(document.Id, LogMessageSensitivity.PotentiallyInsecure); Log.To.Database.V(Tag, $"Ignoring purge of non-existent document {docID}"); return; } InBatch(() => { var result = Native.c4doc_purgeRevision(document.c4Doc.RawDoc, null, null); if (result >= 0) { LiteCoreBridge.Check(err => Native.c4doc_save(document.c4Doc.RawDoc, 0, err)); } }); }); }
public static void Copy(string path, string name, [CanBeNull] DatabaseConfiguration config) { CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(path), path); CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(name), name); var destPath = DatabasePath(name, config?.Directory); LiteCoreBridge.Check(err => { var nativeConfig = DBConfig; #if COUCHBASE_ENTERPRISE if (config?.EncryptionKey != null) { var key = config.EncryptionKey; var i = 0; nativeConfig.encryptionKey.algorithm = C4EncryptionAlgorithm.AES256; foreach (var b in key.KeyData) { nativeConfig.encryptionKey.bytes[i++] = b; } } #endif return(Native.c4db_copy(path, destPath, &nativeConfig, err)); }); }
public ISelectResult From([NotNull] string alias) { CBDebug.MustNotBeNull(WriteLog.To.Query, Tag, nameof(alias), alias); _from = $"{alias}."; (Expression as QueryTypeExpression).From(alias); return(this); }
public IDataSource As([NotNull] string alias) { CBDebug.MustNotBeNull(WriteLog.To.Query, Tag, nameof(alias), alias); _as = alias; return(this); }
public IExpression From([NotNull] string alias) { CBDebug.MustNotBeNull(WriteLog.To.Query, Tag, nameof(alias), alias); _from = alias; Reset(); return(this); }
public ILimit Limit(IExpression limit) { CBDebug.MustNotBeNull(Log.To.Query, Tag, nameof(limit), limit); LimitValue = limit; return(this); }
/// <inheritdoc /> public string GetString([NotNull] string key) { CBDebug.MustNotBeNull(WriteLog.To.Query, Tag, nameof(key), key); var index = IndexForColumnName(key); return(index >= 0 ? GetString(index) : null); }
/// <inheritdoc /> public float GetFloat([NotNull] string key) { CBDebug.MustNotBeNull(WriteLog.To.Query, Tag, nameof(key), key); var index = IndexForColumnName(key); return(index >= 0 ? GetFloat(index) : 0.0f); }
/// <inheritdoc /> public DictionaryObject GetDictionary([NotNull] string key) { CBDebug.MustNotBeNull(WriteLog.To.Query, Tag, nameof(key), key); var index = IndexForColumnName(key); return(index >= 0 ? GetDictionary(index) : null); }
/// <inheritdoc /> public DateTimeOffset GetDate([NotNull] string key) { CBDebug.MustNotBeNull(WriteLog.To.Query, Tag, nameof(key), key); var index = IndexForColumnName(key); return(index >= 0 ? GetDate(index) : DateTimeOffset.MinValue); }
public void InBatch(Action action) { CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(action), action); ThreadSafety.DoLocked(() => { CheckOpen(); PerfTimer.StartEvent("InBatch_BeginTransaction"); LiteCoreBridge.Check(err => Native.c4db_beginTransaction(_c4db, err)); PerfTimer.StopEvent("InBatch_BeginTransaction"); var success = true; try { action(); } catch (Exception e) { Log.To.Database.W(Tag, "Exception during InBatch, rolling back...", e); success = false; throw; } finally { PerfTimer.StartEvent("InBatch_EndTransaction"); LiteCoreBridge.Check(err => Native.c4db_endTransaction(_c4db, success, err)); PerfTimer.StopEvent("InBatch_EndTransaction"); } }); PostDatabaseChanged(); }
public ILimit Limit([NotNull] IExpression limit, [CanBeNull] IExpression offset) { CBDebug.MustNotBeNull(WriteLog.To.Query, Tag, nameof(limit), limit); LimitValue = limit; SkipValue = offset; return(this); }
public static void Delete(string name, [CanBeNull] string directory) { CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(name), name); var path = DatabasePath(name, directory); LiteCoreBridge.Check(err => Native.c4db_deleteAtPath(path, err) || err->code == 0); }
internal override void Authenticate(ReplicatorOptionsDictionary options) { CBDebug.MustNotBeNull(Log.To.Sync, Tag, nameof(options), options); var cookie = new Cookie(CookieName, SessionID); options.Cookies.Add(cookie); }
public IExpression Collate([NotNull] ICollation collation) { CBDebug.MustNotBeNull(WriteLog.To.Query, Tag, nameof(collation), collation); var col = Misc.TryCast <ICollation, QueryCollation>(collation); col = new QueryCollation(col); col.SetOperand(this); return(col); }
public void Delete(Document document) { CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(document), document); ThreadSafety.DoLocked(() => { CheckOpen(); Save(document, true); }); }
/// <summary> /// Adds a document ended listener on this replication object (similar to a C# event, but /// with the ability to specify a <see cref="TaskScheduler"/> to schedule the /// handler to run on) /// </summary> /// <param name="scheduler">The <see cref="TaskScheduler"/> to run the <c>handler</c> on /// (<c>null</c> for default)</param> /// <param name="handler">The logic to run during the callback</param> /// <returns>A token to remove the handler later</returns> public ListenerToken AddDocumentReplicationListener([CanBeNull] TaskScheduler scheduler, [NotNull] EventHandler <DocumentReplicationEventArgs> handler) { CBDebug.MustNotBeNull(WriteLog.To.Sync, Tag, nameof(handler), handler); Config.Options.ProgressLevel = ReplicatorProgressLevel.PerDocument; var cbHandler = new CouchbaseEventHandler <DocumentReplicationEventArgs>(handler, scheduler); _documentEndedUpdate.Add(cbHandler); return(new ListenerToken(cbHandler, "repl")); }
public ListenerToken AddChangeListener([CanBeNull] TaskScheduler scheduler, EventHandler <ReplicatorStatusChangedEventArgs> handler) { CBDebug.MustNotBeNull(Log.To.Sync, Tag, nameof(handler), handler); var cbHandler = new CouchbaseEventHandler <ReplicatorStatusChangedEventArgs>(handler, scheduler); _statusChanged.Add(cbHandler); return(new ListenerToken(cbHandler, "repl")); }
public Document Save(MutableDocument document) { CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(document), document); return(ThreadSafety.DoLocked(() => { CheckOpen(); return Save(document, false); })); }
/// <summary> /// Creates a database given a name and some configuration /// </summary> /// <param name="name">The name of the database</param> /// <param name="configuration">The configuration to open it with</param> public Database(string name, DatabaseConfiguration configuration = null) { Name = CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(name), name); Config = configuration?.Freeze() ?? new DatabaseConfiguration(true); Open(); FLSharedKeys *keys = null; ThreadSafety.DoLocked(() => keys = Native.c4db_getFLSharedKeys(_c4db)); _sharedStrings = new SharedStringCache(keys); }
public void DeleteIndex(string name) { CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(name), name); ThreadSafety.DoLockedBridge(err => { CheckOpen(); return(Native.c4db_deleteIndex(c4db, name, err)); }); }
/// <summary> /// Constructs an endpoint given a url. Note that the scheme must be ws or wss /// or an exception will be thrown /// </summary> /// <param name="url">The url </param> /// <exception cref="ArgumentException">Thrown if the url scheme is not ws or wss</exception> public URLEndpoint([NotNull] Uri url) { var urlToUse = CBDebug.MustNotBeNull(Log.To.Sync, Tag, "url", url); if (!urlToUse.Scheme.StartsWith("ws")) { throw new ArgumentException($"Invalid scheme for URLEndpoint url ({urlToUse.Scheme}); must be either ws or wss"); } Url = url; }
public IMutableDictionary Remove(string key) { CBDebug.MustNotBeNull(WriteLog.To.Database, Tag, nameof(key), key); if (_dict.ContainsKey(key)) { _dict.Remove(key); HasChanges = true; } return(this); }
/// <summary> /// Creates an blob given a type and a URL to a file /// </summary> /// <param name="contentType">The binary type of the blob</param> /// <param name="fileUrl">The url to the file to read</param> /// <returns>An instantiated <see cref="Blob" /> object</returns> /// <exception cref="ArgumentNullException">Thrown if <c>fileUrl</c> is <c>null</c></exception> /// <exception cref="ArgumentException">Thrown if fileUrl is not a file based URL</exception> public Blob(string contentType, [NotNull] Uri fileUrl) { CBDebug.MustNotBeNull(Log.To.Database, Tag, nameof(fileUrl), fileUrl); if (!fileUrl.IsFile) { throw new ArgumentException($"{fileUrl} must be a file-based URL", nameof(fileUrl)); } ContentType = contentType; _initialContentStream = File.OpenRead(fileUrl.AbsolutePath); }
/// <summary> /// Creates an blob given a type and a URL to a file /// </summary> /// <param name="contentType">The binary type of the blob</param> /// <param name="fileUrl">The url to the file to read</param> /// <returns>An instantiated <see cref="Blob" /> object</returns> /// <exception cref="ArgumentNullException">Thrown if <c>fileUrl</c> is <c>null</c></exception> /// <exception cref="ArgumentException">Thrown if fileUrl is not a file based URL</exception> public Blob(string contentType, [NotNull] Uri fileUrl) { CBDebug.MustNotBeNull(WriteLog.To.Database, Tag, nameof(fileUrl), fileUrl); if (!fileUrl.IsFile) { throw new ArgumentException(String.Format(CouchbaseLiteErrorMessage.NotFileBasedURL, fileUrl), nameof(fileUrl)); } ContentType = contentType; _initialContentStream = File.OpenRead(fileUrl.AbsolutePath); }
private void SetObject([NotNull] string key, object value) { CBDebug.MustNotBeNull(WriteLog.To.Database, Tag, nameof(key), key); value = DataOps.ToCouchbaseObject(value); var oldValue = _dict.Get(key); if (!_dict.ContainsKey(key) || (value != oldValue && value?.Equals(oldValue) != true)) { _dict[key] = value; HasChanges = true; } }