Esempio n. 1
0
        /// <summary>Opens the directory with the given <paramref name="path"/>.
        /// If the directory does not exist, and if <paramref name="readOnly"/> is false, it is created. Otherwise, this method returns null.
        /// If the <paramref name="layer"/> is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
        /// </summary>
        /// <param name="directory">Parent directory</param>
        /// <param name="trans">Transaction used by the operation</param>
        /// <param name="path">Path to the directory to open or create</param>
        /// <param name="readOnly">If true, do not make any modifications to the database, and return null if the directory does not exist.</param>
        /// <param name="layer">Optional layer ID that is checked with the opened directory.</param>
        /// <returns></returns>
        public static Task <FdbDirectorySubspace> TryCreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, FdbDirectoryPath path, bool readOnly, Slice layer = default)
        {
            Contract.NotNull(directory, nameof(directory));
            Contract.NotNull(trans, nameof(trans));

            return(readOnly ? directory.TryOpenAsync(trans, path, layer) : directory.CreateOrOpenAsync(trans, path, layer));
        }
Esempio n. 2
0
        /// <summary>Creates a directory with the given <paramref name="path"/> (creating parent directories if necessary).
        /// An error is raised if the given directory already exists.
        /// </summary>
        public static Task <FdbDirectorySubspace> CreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, FdbDirectoryPath path, CancellationToken ct)
        {
            Contract.NotNull(directory, nameof(directory));
            Contract.NotNull(db, nameof(db));

            return(db.ReadWriteAsync((tr) => directory.CreateAsync(tr, path, Slice.Nil), ct));
        }
Esempio n. 3
0
        /// <summary>Returns the list of subdirectories of directory at <paramref name="path"/>, if it exists</summary>
        public static Task <List <string> > TryListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, FdbDirectoryPath path, CancellationToken ct)
        {
            Contract.NotNull(directory, nameof(directory));
            Contract.NotNull(db, nameof(db));

            return(db.ReadAsync((tr) => directory.TryListAsync(tr, path), ct));
        }
Esempio n. 4
0
        /// <summary>Removes the directory, its contents, and all subdirectories.
        /// Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
        /// </summary>
        public static Task <bool> TryRemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, FdbDirectoryPath path, CancellationToken ct)
        {
            Contract.NotNull(directory, nameof(directory));
            Contract.NotNull(db, nameof(db));

            return(db.ReadWriteAsync((tr) => directory.TryRemoveAsync(tr, path), ct));
        }
Esempio n. 5
0
        /// <summary>Attempts to move the directory found at <paramref name="oldPath"/> to <paramref name="newPath"/>.
        /// There is no effect on the physical prefix of the given directory, or on clients that already have the directory open.
        /// </summary>
        public static Task <FdbDirectorySubspace> TryMoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, FdbDirectoryPath oldPath, FdbDirectoryPath newPath, CancellationToken ct)
        {
            Contract.NotNull(directory, nameof(directory));
            Contract.NotNull(db, nameof(db));

            return(db.ReadWriteAsync((tr) => directory.TryMoveAsync(tr, oldPath, newPath), ct));
        }
Esempio n. 6
0
        /// <summary>Attempts to open the directory with the given <paramref name="path"/>.</summary>
        public static Task <FdbDirectorySubspace> TryOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, FdbDirectoryPath path, Slice layer, CancellationToken ct)
        {
            Contract.NotNull(directory, nameof(directory));
            Contract.NotNull(db, nameof(db));

            return(db.ReadAsync((tr) => directory.TryOpenAsync(tr, path, layer), ct));
        }
Esempio n. 7
0
        /// <summary>Removes the directory, its contents, and all subdirectories.
        /// Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
        /// </summary>
        public static Task <bool> TryRemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken ct)
        {
            Contract.NotNull(directory, nameof(directory));
            Contract.NotNull(db, nameof(db));
            Contract.NotNull(name, nameof(name));

            return(db.ReadWriteAsync((tr) => directory.TryRemoveAsync(tr, new [] { name }), ct));
        }
		/// <summary>Wrap an existing database with a root directory</summary>
		public FdbDatabasePartition(IFdbDatabase database, IFdbDirectory directory)
		{
			if (database == null) throw new ArgumentNullException("database");
			if (directory == null) throw new ArgumentNullException("directory");

			m_database = database;
			m_directory = directory;
		}
        /// <summary>Opens the directory with the given <paramref name="name"/>.
        /// If the directory does not exist, and if <paramref name="readOnly"/> is false, it is created. Otherwise, this method returns null.
        /// If the <paramref name="layer"/> is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
        /// </summary>
        /// <param name="directory">Parent directory</param>
        /// <param name="trans">Transaction used by the operation</param>
        /// <param name="name">Name of the directory to open or create</param>
        /// <param name="readOnly">If true, do not make any modifications to the database, and return null if the directory does not exist.</param>
        /// <param name="layer">Optional layer ID that is checked with the opened directory.</param>
        /// <returns></returns>
        public static Task <FdbDirectorySubspace> TryCreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, [NotNull] string name, bool readOnly, Slice layer = default(Slice))
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            return(TryCreateOrOpenAsync(directory, trans, new[] { name }, readOnly, layer));
        }
 /// <summary>Change the current global namespace.</summary>
 /// <remarks>Do NOT call this, unless you know exactly what you are doing !</remarks>
 internal void ChangeRoot(FdbSubspace subspace, IFdbDirectory directory, bool readOnly)
 {
     subspace = subspace ?? FdbSubspace.Empty;
     lock (this)            //TODO: don't use this for locking
     {
         m_readOnly        = readOnly;
         m_globalSpace     = subspace;
         m_globalSpaceCopy = subspace.Copy();
         m_directory       = directory == null ? null : new FdbDatabasePartition(this, directory);
     }
 }
Esempio n. 11
0
 /// <summary>Change the current global namespace.</summary>
 /// <remarks>Do NOT call this, unless you know exactly what you are doing !</remarks>
 internal void ChangeRoot(IKeySubspace subspace, IFdbDirectory directory, bool readOnly)
 {
     //REVIEW: rename to "ChangeRootSubspace" ?
     subspace = subspace ?? KeySubspace.Empty;
     lock (this)            //TODO: don't use this for locking
     {
         m_readOnly        = readOnly;
         m_globalSpace     = subspace.Copy(TuPack.Encoding);
         m_globalSpaceCopy = subspace.Copy(TuPack.Encoding);                 // keep another copy
         m_directory       = directory;
     }
 }
 /// <summary>Returns the list of subdirectories of the current directory.</summary>
 public static Task <List <string> > ListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyTransaction trans)
 {
     if (directory == null)
     {
         throw new ArgumentNullException(nameof(directory));
     }
     if (trans == null)
     {
         throw new ArgumentNullException(nameof(trans));
     }
     return(directory.ListAsync(trans));
 }
 /// <summary>Change the current global namespace.</summary>
 /// <remarks>Do NOT call this, unless you know exactly what you are doing !</remarks>
 internal void ChangeRoot(IFdbSubspace subspace, IFdbDirectory directory, bool readOnly)
 {
     //REVIEW: rename to "ChangeRootSubspace" ?
     subspace = subspace ?? FdbSubspace.Empty;
     lock (this)            //TODO: don't use this for locking
     {
         m_readOnly        = readOnly;
         m_globalSpace     = FdbSubspace.CopyDynamic(subspace, TypeSystem.Tuples);
         m_globalSpaceCopy = FdbSubspace.CopyDynamic(subspace, TypeSystem.Tuples);                 // keep another copy
         m_directory       = directory == null ? null : new FdbDatabasePartition(this, directory);
     }
 }
 /// <summary>Returns the list of subdirectories of the current directory.</summary>
 public static Task <List <string> > ListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, CancellationToken ct)
 {
     if (directory == null)
     {
         throw new ArgumentNullException(nameof(directory));
     }
     if (db == null)
     {
         throw new ArgumentNullException(nameof(db));
     }
     return(db.ReadAsync((tr) => directory.ListAsync(tr), ct));
 }
        /// <summary>Removes the directory, its contents, and all subdirectories.
        /// Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
        /// </summary>
        public static Task <bool> TryRemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, IEnumerable <string> path, CancellationToken cancellationToken)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }

            return(db.ReadWriteAsync((tr) => directory.TryRemoveAsync(tr, path), cancellationToken));
        }
        /// <summary>Removes the directory, its contents, and all subdirectories.
        /// Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
        /// </summary>
        public static Task RemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, CancellationToken ct)
        {
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }
            if (db == null)
            {
                throw new ArgumentNullException(nameof(db));
            }

            return(db.ReadWriteAsync((tr) => directory.RemoveAsync(tr), ct));
        }
        /// <summary>Checks if a directory already exists</summary>
        /// <returns>Returns true if the directory exists, otherwise false.</returns>
        public static Task <bool> ExistsAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, IEnumerable <string> path, CancellationToken ct)
        {
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }
            if (db == null)
            {
                throw new ArgumentNullException(nameof(db));
            }

            return(db.ReadAsync((tr) => directory.ExistsAsync(tr, path), ct));
        }
Esempio n. 18
0
        /// <summary>Wrap an existing database with a root directory</summary>
        public FdbDatabasePartition(IFdbDatabase database, IFdbDirectory directory)
        {
            if (database == null)
            {
                throw new ArgumentNullException("database");
            }
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }

            m_database  = database;
            m_directory = directory;
        }
 /// <summary>Returns the list of subdirectories of the sub-directory with the given <paramref name="name"/>.</summary>
 public static Task <List <string> > ListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] string name, CancellationToken cancellationToken)
 {
     if (directory == null)
     {
         throw new ArgumentNullException("directory");
     }
     if (db == null)
     {
         throw new ArgumentNullException("db");
     }
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     return(db.ReadAsync((tr) => directory.ListAsync(tr, new [] { name }), cancellationToken));
 }
 /// <summary>Attempts to create a directory with the given <paramref name="name"/>.</summary>
 public static Task <FdbDirectorySubspace> TryCreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, CancellationToken cancellationToken)
 {
     if (directory == null)
     {
         throw new ArgumentNullException("directory");
     }
     if (db == null)
     {
         throw new ArgumentNullException("db");
     }
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     return(db.ReadWriteAsync((tr) => directory.TryCreateAsync(tr, new [] { name }, Slice.Nil), cancellationToken));
 }
 /// <summary>Returns the list of subdirectories of the sub-directory with the given <paramref name="name"/>.</summary>
 public static Task <List <string> > ListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyTransaction trans, [NotNull] string name)
 {
     if (directory == null)
     {
         throw new ArgumentNullException("directory");
     }
     if (trans == null)
     {
         throw new ArgumentNullException("trans");
     }
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     return(directory.ListAsync(trans, new[] { name }));
 }
 /// <summary>Attempts to create a directory with the given <paramref name="name"/>.
 /// If <paramref name="layer"/> is specified, it is recorded with the directory and will be checked by future calls to open.
 /// </summary>
 public static Task <FdbDirectorySubspace> TryCreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] string name, Slice layer, CancellationToken ct)
 {
     if (directory == null)
     {
         throw new ArgumentNullException(nameof(directory));
     }
     if (db == null)
     {
         throw new ArgumentNullException(nameof(db));
     }
     if (name == null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     return(db.ReadWriteAsync((tr) => directory.TryCreateAsync(tr, new[] { name }, layer), ct));
 }
 /// <summary>Returns the list of subdirectories of directory at <paramref name="path"/>, if it exists</summary>
 public static Task <List <string> > TryListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, IEnumerable <string> path, CancellationToken ct)
 {
     if (directory == null)
     {
         throw new ArgumentNullException(nameof(directory));
     }
     if (db == null)
     {
         throw new ArgumentNullException(nameof(db));
     }
     if (path == null)
     {
         throw new ArgumentNullException(nameof(path));                           //REVIEW: or not?
     }
     return(db.ReadAsync((tr) => directory.TryListAsync(tr, path), ct));
 }
        /// <summary>Opens the sub-directory with the given <paramref name="name"/>.
        /// An error is raised if the directory does not exist, or if a layer is specified and a different layer was specified when the directory was created.
        /// </summary>
        public static Task <FdbDirectorySubspace> OpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyTransaction trans, [NotNull] string name, Slice layer = default(Slice))
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (trans == null)
            {
                throw new ArgumentNullException("trans");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            return(directory.OpenAsync(trans, new[] { name }, layer));
        }
        /// <summary>Creates a directory with the given <paramref name="name"/>.
        /// An error is raised if the given directory already exists.
        /// If <paramref name="layer"/> is specified, it is recorded with the directory and will be checked by future calls to open.
        /// </summary>
        public static Task <FdbDirectorySubspace> CreateAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, [NotNull] string name, Slice layer = default(Slice))
        {
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }
            if (trans == null)
            {
                throw new ArgumentNullException(nameof(trans));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            return(directory.CreateAsync(trans, new[] { name }, layer));
        }
        /// <summary>Attempts to open the directory with the given <paramref name="name"/>.</summary>
        public static Task <FdbDirectorySubspace> TryOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyTransaction trans, [NotNull] string name, Slice layer)
        {
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }
            if (trans == null)
            {
                throw new ArgumentNullException(nameof(trans));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            return(directory.TryOpenAsync(trans, new[] { name }, layer));
        }
        /// <summary>Returns the list of subdirectories of directory at <paramref name="path"/>.</summary>
        public static Task <List <string> > ListAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] IEnumerable <string> path, CancellationToken cancellationToken)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            return(db.ReadAsync((tr) => directory.ListAsync(tr, path), cancellationToken));
        }
        /// <summary>Opens the directory with the given <paramref name="path"/>.
        /// If the directory does not exist, it is created (creating parent directories if necessary).
        /// If layer is specified, it is checked against the layer of an existing directory or set as the layer of a new directory.
        /// </summary>
        public static Task <FdbDirectorySubspace> CreateOrOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbRetryable db, [NotNull] IEnumerable <string> path, Slice layer, CancellationToken ct)
        {
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }
            if (db == null)
            {
                throw new ArgumentNullException(nameof(db));
            }
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            return(db.ReadWriteAsync((tr) => directory.CreateOrOpenAsync(tr, path, layer), ct));
        }
        /// <summary>Attempts to open the directory with the given <paramref name="path"/>.</summary>
        public static Task <FdbDirectorySubspace> TryOpenAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyRetryable db, [NotNull] IEnumerable <string> path, Slice layer, CancellationToken cancellationToken)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            return(db.ReadAsync((tr) => directory.TryOpenAsync(tr, path, layer), cancellationToken));
        }
        /// <summary>Checks if a directory already exists</summary>
        /// <returns>Returns true if the directory exists, otherwise false.</returns>
        public static Task <bool> ExistsAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbReadOnlyTransaction trans, [NotNull] string name)
        {
            if (directory == null)
            {
                throw new ArgumentNullException(nameof(directory));
            }
            if (trans == null)
            {
                throw new ArgumentNullException(nameof(trans));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            return(directory.ExistsAsync(trans, new[] { name }));
        }
        /// <summary>Removes the directory, its contents, and all subdirectories.
        /// Warning: Clients that have already opened the directory might still insert data into its contents after it is removed.
        /// </summary>
        public static Task <bool> TryRemoveAsync([NotNull] this IFdbDirectory directory, [NotNull] IFdbTransaction trans, [NotNull] string name)
        {
            if (directory == null)
            {
                throw new ArgumentNullException("directory");
            }
            if (trans == null)
            {
                throw new ArgumentNullException("trans");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            return(directory.TryRemoveAsync(trans, new[] { name }));
        }
		private MemoryDatabase(IFdbCluster cluster, MemoryDatabaseHandler handler, string name, IFdbSubspace globalSpace, IFdbDirectory directory, bool readOnly, bool ownsCluster)
			: base(cluster, handler, name, globalSpace, directory, readOnly, ownsCluster)
		{
			m_handler = handler;
		}