/// <summary> /// Returns a collection of all defined keyspaces names. /// </summary> /// <returns>a collection of all defined keyspaces names.</returns> public ICollection <string> GetKeyspaces() { if (Configuration.MetadataSyncOptions.MetadataSyncEnabled) { //Use local cache return(_keyspaces.Keys); } return(TaskHelper.WaitToComplete(SchemaParser.GetKeyspacesNamesAsync(), _queryAbortTimeout)); }
/// <summary> /// Gets the definition associated with a User Defined Type from Cassandra /// </summary> public Task <UdtColumnInfo> GetUdtDefinitionAsync(string keyspace, string typeName) { if (Configuration.MetadataSyncOptions.MetadataSyncEnabled) { return(!_keyspaces.TryGetValue(keyspace, out var ksMetadata) ? Task.FromResult <UdtColumnInfo>(null) : ksMetadata.GetUdtDefinitionAsync(typeName)); } return(SchemaParser.GetUdtDefinitionAsync(keyspace, typeName)); }
/// <summary> /// Returns the view metadata for the provided view name in the keyspace. /// </summary> /// <param name="keyspace">name of the keyspace within specified view is defined.</param> /// <param name="name">name of view.</param> /// <returns>a MaterializedViewMetadata for the view in the specified keyspace.</returns> public MaterializedViewMetadata GetMaterializedView(string keyspace, string name) { if (Configuration.MetadataSyncOptions.MetadataSyncEnabled) { return(!_keyspaces.TryGetValue(keyspace, out var ksMetadata) ? null : ksMetadata.GetMaterializedViewMetadata(name)); } return(TaskHelper.WaitToComplete(SchemaParser.GetViewAsync(keyspace, name), _queryAbortTimeout * 2)); }
internal Task <TableMetadata> GetTableAsync(string keyspace, string tableName) { if (Configuration.MetadataSyncOptions.MetadataSyncEnabled) { return(!_keyspaces.TryGetValue(keyspace, out var ksMetadata) ? Task.FromResult <TableMetadata>(null) : ksMetadata.GetTableMetadataAsync(tableName)); } return(SchemaParser.GetTableAsync(keyspace, tableName)); }
/// <summary> /// Returns names of all tables which are defined within specified keyspace. /// </summary> /// <param name="keyspace">the name of the keyspace for which all tables metadata should be /// returned.</param> /// <returns>an ICollection of the metadata for the tables defined in this /// keyspace.</returns> public ICollection <string> GetTables(string keyspace) { if (Configuration.MetadataSyncOptions.MetadataSyncEnabled) { return(!_keyspaces.TryGetValue(keyspace, out var ksMetadata) ? new string[0] : ksMetadata.GetTablesNames()); } return(TaskHelper.WaitToComplete(SchemaParser.GetTableNamesAsync(keyspace), _queryAbortTimeout)); }
/// <summary> /// Returns metadata of specified keyspace. /// </summary> /// <param name="keyspace"> the name of the keyspace for which metadata should be /// returned. </param> /// <returns>the metadata of the requested keyspace or <c>null</c> if /// <c>* keyspace</c> is not a known keyspace.</returns> public KeyspaceMetadata GetKeyspace(string keyspace) { if (Configuration.MetadataSyncOptions.MetadataSyncEnabled) { //Use local cache _keyspaces.TryGetValue(keyspace, out var ksInfo); return(ksInfo); } return(TaskHelper.WaitToComplete(SchemaParser.GetKeyspaceAsync(keyspace), _queryAbortTimeout)); }
/// <summary> /// Gets the definition associated with a aggregate from Cassandra /// </summary> /// <returns>The aggregate metadata or null if not found.</returns> public AggregateMetadata GetAggregate(string keyspace, string name, string[] signature) { if (Configuration.MetadataSyncOptions.MetadataSyncEnabled) { return(!_keyspaces.TryGetValue(keyspace, out var ksMetadata) ? null : ksMetadata.GetAggregate(name, signature)); } var signatureString = SchemaParser.ComputeFunctionSignatureString(signature); return(TaskHelper.WaitToComplete(SchemaParser.GetAggregateAsync(keyspace, name, signatureString), _queryAbortTimeout)); }
/// <summary> /// Creates a new instance if the currentInstance is not valid for the given Cassandra version /// </summary> public static SchemaParser GetInstance(Version cassandraVersion, Metadata parent, Func <string, string, Task <UdtColumnInfo> > udtResolver, SchemaParser currentInstance = null) { if (cassandraVersion >= Version40 && !(currentInstance is SchemaParserV3)) { return(new SchemaParserV3(parent, udtResolver)); } if (cassandraVersion >= Version30 && !(currentInstance is SchemaParserV2)) { return(new SchemaParserV2(parent, udtResolver)); } if (cassandraVersion < Version30 && !(currentInstance is SchemaParserV1)) { return(new SchemaParserV1(parent)); } if (currentInstance == null) { throw new ArgumentNullException(nameof(currentInstance)); } return(currentInstance); }
/// <summary> /// Sets the Cassandra version in order to identify how to parse the metadata information /// </summary> /// <param name="version"></param> internal void SetCassandraVersion(Version version) { _schemaParser = SchemaParser.GetInstance(version, this, GetUdtDefinitionAsync, _schemaParser); }
internal Metadata(Configuration configuration, SchemaParser schemaParser) : this(configuration) { _schemaParser = schemaParser; }