/// <summary> /// Builds the execute stored procedure operation. /// </summary> /// <param name="streamName">Name of the stream.</param> /// <param name="configType">The serialization configuration type identifiers.</param> /// <param name="serializationKind">The <see cref="SerializationKind"/>.</param> /// <param name="serializationFormat">The <see cref="SerializationFormat"/>.</param> /// <param name="compressionKind">The <see cref="CompressionKind"/>.</param> /// <param name="unregisteredTypeEncounteredStrategy">The <see cref="UnregisteredTypeEncounteredStrategy"/>.</param> /// <returns>Operation to execute stored procedure.</returns> public static ExecuteStoredProcedureOp BuildExecuteStoredProcedureOp( string streamName, IdentifiedType configType, SerializationKind serializationKind, SerializationFormat serializationFormat, CompressionKind compressionKind, UnregisteredTypeEncounteredStrategy unregisteredTypeEncounteredStrategy) { var sprocName = Invariant($"[{streamName}].[{nameof(GetIdAddIfNecessarySerializerRepresentation)}]"); var parameters = new List <ParameterDefinitionBase>() { new InputParameterDefinition <int>(nameof(InputParamName.ConfigTypeWithoutVersionId), Tables.TypeWithoutVersion.Id.SqlDataType, configType.IdWithoutVersion), new InputParameterDefinition <int>(nameof(InputParamName.ConfigTypeWithVersionId), Tables.TypeWithVersion.Id.SqlDataType, configType.IdWithVersion), new InputParameterDefinition <string>(nameof(InputParamName.SerializationKind), Tables.SerializerRepresentation.SerializationKind.SqlDataType, serializationKind.ToString()), new InputParameterDefinition <string>(nameof(InputParamName.SerializationFormat), Tables.SerializerRepresentation.SerializationFormat.SqlDataType, serializationFormat.ToString()), new InputParameterDefinition <string>(nameof(InputParamName.CompressionKind), Tables.SerializerRepresentation.CompressionKind.SqlDataType, compressionKind.ToString()), new InputParameterDefinition <string>(nameof(InputParamName.UnregisteredTypeEncounteredStrategy), Tables.SerializerRepresentation.SerializationKind.SqlDataType, unregisteredTypeEncounteredStrategy.ToString()), new OutputParameterDefinition <int>(nameof(OutputParamName.Id), Tables.SerializerRepresentation.Id.SqlDataType), }; var result = new ExecuteStoredProcedureOp(sprocName, parameters); return(result); }
/// <summary> /// Initializes a new instance of the <see cref="SqlServerStreamConfig"/> class. /// </summary> /// <param name="name">Name of the stream.</param> /// <param name="accessKinds">Access the stream has.</param> /// <param name="defaultConnectionTimeout">Default timeout to use when connecting to SQL Server.</param> /// <param name="defaultCommandTimeout">Default timeout to use when running a command on SQL Server.</param> /// <param name="defaultSerializerRepresentation">Default <see cref="SerializerRepresentation"/> to use (used for identifier serialization).</param> /// <param name="defaultSerializationFormat">Default <see cref="SerializationFormat"/> to use.</param> /// <param name="allLocators">All <see cref="ISqlServerLocator"/>'s.</param> public SqlServerStreamConfig( string name, StreamAccessKinds accessKinds, TimeSpan defaultConnectionTimeout, TimeSpan defaultCommandTimeout, SerializerRepresentation defaultSerializerRepresentation, SerializationFormat defaultSerializationFormat, IReadOnlyCollection <ISqlServerLocator> allLocators) { name.MustForArg(nameof(name)).NotBeNullNorWhiteSpace(); accessKinds.MustForArg(nameof(accessKinds)).NotBeEqualTo(StreamAccessKinds.None); defaultConnectionTimeout.TotalMilliseconds.MustForArg(Invariant($"{nameof(defaultConnectionTimeout)}.{nameof(TimeSpan.TotalMilliseconds)}")).BeGreaterThanOrEqualTo(0d); defaultCommandTimeout.TotalMilliseconds.MustForArg(Invariant($"{nameof(defaultCommandTimeout)}.{nameof(TimeSpan.TotalMilliseconds)}")).BeGreaterThanOrEqualTo(0d); defaultSerializerRepresentation.MustForArg(nameof(defaultSerializerRepresentation)).NotBeNull(); defaultSerializationFormat.MustForArg(nameof(defaultSerializationFormat)).NotBeEqualTo(SerializationFormat.Invalid); allLocators.MustForArg(nameof(allLocators)).NotBeNullNorEmptyEnumerableNorContainAnyNulls(); this.Name = name; this.AccessKinds = accessKinds; this.DefaultConnectionTimeout = defaultConnectionTimeout; this.DefaultCommandTimeout = defaultCommandTimeout; this.DefaultSerializerRepresentation = defaultSerializerRepresentation; this.DefaultSerializationFormat = defaultSerializationFormat; this.AllLocators = allLocators; }
public IdentifiedSerializerRepresentation GetIdAddIfNecessarySerializerRepresentation( SqlServerLocator resourceLocator, SerializerRepresentation serializerRepresentation = null, SerializationFormat serializationFormat = SerializationFormat.String) { var localSerializerRepresentation = serializerRepresentation ?? this.DefaultSerializerRepresentation; var found = this.serializerRepresentationToIdentifiedSerializerMap.TryGetValue(serializerRepresentation, out var result); if (found) { return(result); } else { var id = this.Execute( new GetOrAddIdentifiedSerializerRepresentationOp(resourceLocator, localSerializerRepresentation, serializationFormat)); var item = new IdentifiedSerializerRepresentation(id, localSerializerRepresentation, serializationFormat); this.serializerRepresentationIdToIdentifiedSerializerMap.TryAdd(item.Id, item); this.serializerRepresentationToIdentifiedSerializerMap.TryAdd(item.SerializerRepresentation, item); var newFound = this.serializerRepresentationToIdentifiedSerializerMap.TryGetValue(serializerRepresentation, out var newResult); newFound.MustForOp("failedToFindSerializationRepresentationAfterAdding").BeTrue(); return(newResult); } }
/// <summary> /// Initializes a new instance of the <see cref="IdentifiedSerializerRepresentation"/> class. /// </summary> /// <param name="id">The serializer representation identifier.</param> /// <param name="serializerRepresentation">The serializer description.</param> /// <param name="serializationFormat">The serialization format.</param> public IdentifiedSerializerRepresentation( int id, SerializerRepresentation serializerRepresentation, SerializationFormat serializationFormat) { serializerRepresentation.MustForArg(nameof(serializerRepresentation)).NotBeNull(); serializationFormat.MustForArg(nameof(serializationFormat)).NotBeEqualTo(SerializationFormat.Invalid); this.Id = id; this.SerializerRepresentation = serializerRepresentation; this.SerializationFormat = serializationFormat; }
/// <summary> /// Gets the serializer representation from identifier (first by cache and then by database). /// </summary> /// <param name="sqlServerLocator">The resource locator.</param> /// <param name="serializerRepresentationId">The serializer representation identifier.</param> /// <returns>IdentifiedSerializerRepresentation.</returns> public IdentifiedSerializerRepresentation GetSerializerRepresentationFromId( SqlServerLocator sqlServerLocator, int serializerRepresentationId) { var found = this.serializerRepresentationIdToIdentifiedSerializerMap.TryGetValue(serializerRepresentationId, out var result); if (found) { return(result); } else { var storedProcOp = StreamSchema.Sprocs.GetSerializerRepresentationFromId.BuildExecuteStoredProcedureOp( this.Name, serializerRepresentationId); var sqlProtocol = this.BuildSqlOperationsProtocol(sqlServerLocator); var sprocResult = sqlProtocol.Execute(storedProcOp); SerializationKind serializationKind = sprocResult .OutputParameters[nameof(StreamSchema .Sprocs.GetSerializerRepresentationFromId.OutputParamName .SerializationKind)] .GetValueOfType <SerializationKind>(); int configTypeWithVersionId = sprocResult .OutputParameters[nameof(StreamSchema .Sprocs.GetSerializerRepresentationFromId.OutputParamName .ConfigTypeWithVersionId)] .GetValueOfType <int>(); CompressionKind compressionKind = sprocResult .OutputParameters[nameof(StreamSchema .Sprocs.GetSerializerRepresentationFromId.OutputParamName .CompressionKind)] .GetValueOfType <CompressionKind>(); SerializationFormat serializationFormat = sprocResult .OutputParameters[nameof(StreamSchema .Sprocs.GetSerializerRepresentationFromId.OutputParamName .SerializationFormat)] .GetValueOfType <SerializationFormat>(); var configType = this.GetTypeById(sqlServerLocator, configTypeWithVersionId, true); var rep = new SerializerRepresentation(serializationKind, configType.WithVersion, compressionKind); var item = new IdentifiedSerializerRepresentation(serializerRepresentationId, rep, serializationFormat); this.serializerRepresentationIdToIdentifiedSerializerMap.TryAdd(item.Id, item); this.serializerRepresentationToIdentifiedSerializerMap.TryAdd(item.SerializerRepresentation, item); var newFound = this.serializerRepresentationIdToIdentifiedSerializerMap.TryGetValue(serializerRepresentationId, out var newResult); newFound.MustForOp("failedToFindSerializationRepresentationAfterAdding").BeTrue(); return(newResult); } }
/// <summary> /// Initializes a new instance of the <see cref="SqlStream"/> class. /// </summary> /// <param name="name">The name of the stream.</param> /// <param name="defaultConnectionTimeout">The default connection timeout.</param> /// <param name="defaultCommandTimeout">The default command timeout.</param> /// <param name="defaultSerializerRepresentation">Default serializer description to use.</param> /// <param name="defaultSerializationFormat">Default serializer format.</param> /// <param name="serializerFactory">The factory to get a serializer to use for objects.</param> /// <param name="resourceLocatorProtocol">The protocols for getting locators.</param> public SqlStream( string name, TimeSpan defaultConnectionTimeout, TimeSpan defaultCommandTimeout, SerializerRepresentation defaultSerializerRepresentation, SerializationFormat defaultSerializationFormat, ISerializerFactory serializerFactory, IResourceLocatorProtocols resourceLocatorProtocol) : base(name, serializerFactory, defaultSerializerRepresentation, defaultSerializationFormat, resourceLocatorProtocol) { name.MustForArg(nameof(name)).NotBeNullNorWhiteSpace(); defaultSerializerRepresentation.MustForArg(nameof(defaultSerializerRepresentation)).NotBeNull(); serializerFactory.MustForArg(nameof(serializerFactory)).NotBeNull(); resourceLocatorProtocol.MustForArg(nameof(resourceLocatorProtocol)).NotBeNull(); this.StreamRepresentation = new StreamRepresentation(this.Name); this.DefaultConnectionTimeout = defaultConnectionTimeout; this.DefaultCommandTimeout = defaultCommandTimeout; var allLocators = this.ResourceLocatorProtocols.Execute(new GetAllResourceLocatorsOp()); this.singleLocator = allLocators.Count == 1 ? allLocators.Single().ConfirmAndConvert <SqlServerLocator>() : null; }