public IFdbDynamicSubspace ByKey(T1 value1, T2 value2, T3 value3, IDynamicKeyEncoder encoder)
 {
     return(FdbSubspace.CreateDynamic(this.Subspace.ConcatKey(this.Encoder.EncodeKey(value1, value2, value3)), encoder));
 }
 public IFdbEncoderSubspace <TNext> ByKey <TNext>(T1 value1, T2 value2, T3 value3, IKeyEncoder <TNext> encoder)
 {
     return(FdbSubspace.CreateEncoder <TNext>(this.Subspace.ConcatKey(this.Encoder.EncodeKey(value1, value2, value3)), encoder));
 }
Exemple #3
0
 public IFdbEncoderSubspace <TNext> ByKey <TNext>(T1 value1, T2 value2, IFdbKeyEncoding encoding)
 {
     return(FdbSubspace.CreateEncoder <TNext>(this.Subspace.ConcatKey(this.Encoder.EncodeKey(value1, value2)), encoding));
 }
            /// <summary>Open a named partition of a specific cluster</summary>
            /// <param name="clusterFile">Path to the 'fdb.cluster' file to use, or null for the default cluster file</param>
            /// <param name="dbName">Name of the database, or "DB" if not specified.</param>
            /// <param name="path">Path of the named partition to open</param>
            /// <param name="readOnly">If true, the database instance will only allow read operations</param>
            /// <param name="cancellationToken">Token used to cancel this operation</param>
            /// <returns>Returns a new database instance that will only be able to read and write inside the specified partition. If the partition does not exist, it will be automatically created</returns>
            public static async Task <IFdbDatabase> OpenNamedPartitionAsync(string clusterFile, string dbName, [NotNull] IEnumerable <string> path, bool readOnly, CancellationToken cancellationToken)
            {
                if (path == null)
                {
                    throw new ArgumentNullException("path");
                }
                var partitionPath = path.ToList();

                if (partitionPath.Count == 0)
                {
                    throw new ArgumentException("The path to the named partition cannot be empty", "path");
                }

                // looks at the global partition table for the specified named partition

                // By convention, all named databases will be under the "/Databases" folder
                FdbDatabase db        = null;
                var         rootSpace = FdbSubspace.Empty;

                try
                {
                    db = await Fdb.OpenInternalAsync(clusterFile, dbName, rootSpace, readOnly : false, cancellationToken : cancellationToken).ConfigureAwait(false);

                    var rootLayer = FdbDirectoryLayer.Create(rootSpace);
                    if (Logging.On)
                    {
                        Logging.Verbose(typeof(Fdb.Directory), "OpenNamedPartitionAsync", String.Format("Opened root layer of database {0} using cluster file '{1}'", db.Name, db.Cluster.Path));
                    }

                    // look up in the root layer for the named partition
                    var descriptor = await rootLayer.CreateOrOpenAsync(db, partitionPath, layer : FdbDirectoryPartition.LayerId, cancellationToken : cancellationToken).ConfigureAwait(false);

                    if (Logging.On)
                    {
                        Logging.Verbose(typeof(Fdb.Directory), "OpenNamedPartitionAsync", String.Format("Found named partition '{0}' at prefix {1}", descriptor.FullName, descriptor));
                    }

                    // we have to chroot the database to the new prefix, and create a new DirectoryLayer with a new '/'
                    rootSpace = FdbSubspace.Copy(descriptor);                     //note: create a copy of the key
                    //TODO: find a nicer way to do that!
                    db.ChangeRoot(rootSpace, FdbDirectoryLayer.Create(rootSpace, partitionPath), readOnly);

                    if (Logging.On)
                    {
                        Logging.Info(typeof(Fdb.Directory), "OpenNamedPartitionAsync", String.Format("Opened partition {0} at {1}, using directory layer at {2}", descriptor.FullName, db.GlobalSpace, db.Directory.DirectoryLayer.NodeSubspace));
                    }

                    return(db);
                }
                catch (Exception e)
                {
                    if (db != null)
                    {
                        db.Dispose();
                    }
                    if (Logging.On)
                    {
                        Logging.Exception(typeof(Fdb.Directory), "OpenNamedPartitionAsync", e);
                    }
                    throw;
                }
            }
 public IFdbEncoderSubspace <TNext> ByKey <TNext>(T value, [NotNull] IKeyEncoder <TNext> encoder)
 {
     return(FdbSubspace.CreateEncoder <TNext>(this.Subspace.ConcatKey(this.Encoder.EncodeKey(value)), encoder));
 }
Exemple #6
0
 public IFdbDynamicSubspace ByKey(T1 value1, T2 value2, IFdbKeyEncoding encoding)
 {
     return(FdbSubspace.CreateDynamic(this.Subspace.ConcatKey(this.Encoder.EncodeKey(value1, value2)), encoding));
 }
        /// <summary>Opens a database on this cluster</summary>
        /// <param name="databaseName">Name of the database. Must be 'DB'</param>
        /// <param name="subspace">Subspace of keys that will be accessed.</param>
        /// <param name="readOnly">If true, the database will only allow read operations.</param>
        /// <param name="ownsCluster">If true, the database will dispose this cluster when it is disposed.</param>
        /// <param name="cancellationToken">Cancellation Token</param>
        /// <returns>Task that will return an FdbDatabase, or an exception</returns>
        /// <exception cref="System.InvalidOperationException">If <paramref name="databaseName"/> is anything other than 'DB'</exception>
        /// <exception cref="System.OperationCanceledException">If the token <paramref name="cancellationToken"/> is cancelled</exception>
        /// <remarks>As of Beta2, the only supported database name is 'DB'</remarks>
        internal async Task <FdbDatabase> OpenDatabaseInternalAsync(string databaseName, FdbSubspace subspace, bool readOnly, bool ownsCluster, CancellationToken cancellationToken)
        {
            ThrowIfDisposed();
            if (string.IsNullOrEmpty(databaseName))
            {
                throw new ArgumentNullException("databaseName");
            }
            if (subspace == null)
            {
                throw new ArgumentNullException("subspace");
            }

            if (Logging.On)
            {
                Logging.Info(typeof(FdbCluster), "OpenDatabaseAsync", String.Format("Connecting to database '{0}' ...", databaseName));
            }

            if (cancellationToken.IsCancellationRequested)
            {
                cancellationToken.ThrowIfCancellationRequested();
            }

            var handler = await m_handler.OpenDatabaseAsync(databaseName, cancellationToken).ConfigureAwait(false);

            if (Logging.On && Logging.IsVerbose)
            {
                Logging.Verbose(typeof(FdbCluster), "OpenDatabaseAsync", String.Format("Connected to database '{0}'", databaseName));
            }

            return(FdbDatabase.Create(this, handler, databaseName, subspace, null, readOnly, ownsCluster));
        }
 public IFdbDynamicSubspace ByKey(T value, [NotNull] IDynamicKeyEncoder encoder)
 {
     return(FdbSubspace.CreateDynamic(this.Subspace.ConcatKey(this.Encoder.EncodeKey(value)), encoder));
 }
Exemple #9
0
 public static IFdbEncoderSubspace <T1, T2> UsingEncoder <T1, T2>([NotNull] this IFdbSubspace subspace, [NotNull] IFdbKeyEncoding encoding)
 {
     Contract.NotNull(subspace, nameof(subspace));
     Contract.NotNull(encoding, nameof(encoding));
     return(FdbSubspace.CopyEncoder <T1, T2>(subspace, encoding));
 }
Exemple #10
0
 public static IFdbEncoderSubspace <T> UsingEncoder <T>([NotNull] this IFdbSubspace subspace, [NotNull] IKeyEncoder <T> encoder)
 {
     Contract.NotNull(subspace, nameof(subspace));
     Contract.NotNull(encoder, nameof(encoder));
     return(FdbSubspace.CopyEncoder <T>(subspace, encoder));
 }
Exemple #11
0
 public static IFdbDynamicSubspace UsingEncoder([NotNull] this IFdbSubspace subspace, [NotNull] IDynamicKeyEncoder encoder)
 {
     Contract.NotNull(subspace, nameof(subspace));
     Contract.NotNull(encoder, nameof(encoder));
     return(FdbSubspace.CopyDynamic(subspace, encoder));
 }
Exemple #12
0
 public static IFdbDynamicSubspace Using([NotNull] this IFdbSubspace subspace, [NotNull] IFdbKeyEncoding encoding)
 {
     Contract.NotNull(subspace, nameof(subspace));
     Contract.NotNull(encoding, nameof(encoding));
     return(FdbSubspace.CopyDynamic(subspace, encoding));
 }
Exemple #13
0
 public static IFdbEncoderSubspace <T1, T2, T3, T4> UsingEncoder <T1, T2, T3, T4>([NotNull] this IFdbSubspace subspace, [NotNull] ICompositeKeyEncoder <T1, T2, T3, T4> encoder)
 {
     Contract.NotNull(subspace, nameof(subspace));
     Contract.NotNull(encoder, nameof(encoder));
     return(FdbSubspace.CopyEncoder <T1, T2, T3, T4>(subspace, encoder));
 }