public Task<IEnumerable<object>> Execute(IDataMapperFactory factory, ConsistencyLevel cl) { IConnection connection; if (null == (connection = _connection)) { lock (_lock) { if (null == (connection = _connection)) { connection = _cluster.GetConnection(null); connection.OnFailure += ConnectionOnOnFailure; Action<IFrameWriter> writer = fw => CQLCommandHelpers.WritePrepareRequest(fw, _cql); Func<IFrameReader, IEnumerable<object>> reader = fr => CQLCommandHelpers.ReadPreparedQuery(fr, connection); InstrumentationToken prepareToken = InstrumentationToken.Create(RequestType.Prepare, _executionFlags, _cql); connection.Execute(writer, reader, _executionFlags, prepareToken).ContinueWith(ReadPreparedQueryInfo).Wait(); _connection = connection; } } } Action<IFrameWriter> execWriter = fw => WriteExecuteRequest(fw, cl, factory); Func<IFrameReader, IEnumerable<object>> execReader = fr => CQLCommandHelpers.ReadRowSet(fr, factory); InstrumentationToken queryToken = InstrumentationToken.Create(RequestType.Query, _executionFlags, _cql); return connection.Execute(execWriter, execReader, _executionFlags, queryToken); }
public ICqlCommand Create(ICluster cluster, IDataMapperFactory factoryIn, IDataMapperFactory factoryOut) { factoryIn.CheckArgumentNotNull("factoryIn"); factoryOut.CheckArgumentNotNull("factoryOut"); return new CqlCommand(cluster, factoryIn, factoryOut); }
public Task<IEnumerable<object>> Execute(ConsistencyLevel cl, IDataMapperFactory factory) { IConnection connection; if (null == (connection = _connection)) { lock (_lock) { if (null == (connection = _connection)) { connection = _cluster.GetConnection(null); connection.OnFailure += ConnectionOnOnFailure; Action<IFrameWriter> writer = fw => CQLCommandHelpers.WritePrepareRequest(fw, _cql); Func<IFrameReader, IEnumerable<object>> reader = fr => CQLCommandHelpers.ReadPreparedQuery(fr, connection); connection.Execute(writer, reader).ContinueWith(ReadPreparedQueryInfo).Wait(); Thread.MemoryBarrier(); _connection = connection; } } } Action<IFrameWriter> execWriter = fw => WriteExecuteRequest(fw, cl, factory); Func<IFrameReader, IEnumerable<object>> execReader = fr => CQLCommandHelpers.ReadRowSet(fr, factory); return connection.Execute(execWriter, execReader); }
public ICqlCommand Create(ICluster cluster, IDataMapperFactory factoryIn, IDataMapperFactory factoryOut) { factoryIn.CheckArgumentNotNull("factoryIn"); factoryOut.CheckArgumentNotNull("factoryOut"); return(new CqlCommand(cluster, factoryIn, factoryOut)); }
public Task<IEnumerable<object>> Execute(ConsistencyLevel cl, IDataMapperFactory factory) { Action<IFrameWriter> writer = fw => WriteExecuteRequest(fw, cl, factory); Func<IFrameReader, IEnumerable<object>> reader = fr => CQLCommandHelpers.ReadRowSet(fr, factory); return _connection.Execute(writer, reader); }
internal static IObservable<object> CreateQuery(IConnection connection, string cql, ConsistencyLevel cl, IDataMapperFactory factory, ExecutionFlags executionFlags) { Action<IFrameWriter> writer = fw => WriteQueryRequest(fw, cql, cl, MessageOpcodes.Query); Func<IFrameReader, IEnumerable<object>> reader = fr => ReadRowSet(fr, factory); InstrumentationToken token = InstrumentationToken.Create(RequestType.Query, executionFlags, cql); Query query = new Query(writer, reader, token, connection); return query; }
internal static IObservable<object> CreateExecuteQuery(IConnection connection, byte[] id, IColumnSpec[] columnSpecs, ConsistencyLevel cl, ExecutionFlags executionFlags, string cql, IDataMapperFactory factory) { Action<IFrameWriter> writer = fw => WriteExecuteRequest(fw, id, columnSpecs, cl, factory); Func<IFrameReader, IEnumerable<object>> reader = fr => ReadRowSet(fr, factory); InstrumentationToken token = InstrumentationToken.Create(RequestType.Prepare, executionFlags, cql); Query query = new Query(writer, reader, token, connection); return query; }
public PreparedQuery(ICluster cluster, ConsistencyLevel?consistencyLevel, ExecutionFlags?executionFlags, IDataMapperFactory factoryIn, IDataMapperFactory factoryOut, string cql) { _cluster = cluster; _consistencyLevel = consistencyLevel; _executionFlags = executionFlags; _factoryIn = factoryIn; _factoryOut = factoryOut; _cql = cql; _connection = null; }
public SystemPeersDiscoveryService(ILogger logger, ICluster cluster, DiscoveryConfig config) { PocoCommand.PocoDataMapperFactory mapper = new PocoCommand.PocoDataMapperFactory(); _peerFactory = mapper.Create<DiscoveredPeer>(null); _logger = logger; _cluster = cluster; _timer = new Timer(config.Interval*1000); _timer.Elapsed += (s, e) => TryDiscover(); _timer.AutoReset = true; TryDiscover(); }
private void WriteExecuteRequest(IFrameWriter frameWriter, ConsistencyLevel cl, IDataMapperFactory factory) { frameWriter.WriteShortByteArray(_id); frameWriter.WriteShort((short) _columnSpecs.Length); IDataSource dataSource = factory.DataSource; foreach (IColumnSpec columnSpec in _columnSpecs) { object data = dataSource.Get(columnSpec); byte[] rawData = columnSpec.Serialize(data); frameWriter.WriteByteArray(rawData); } frameWriter.WriteShort((short) cl); frameWriter.Send(MessageOpcodes.Execute); }
public CqlCommand(ICluster cluster, IDataMapperFactory factoryIn, IDataMapperFactory factoryOut) { _cluster = cluster; _factoryIn = factoryIn; _factoryOut = factoryOut; }
ICqlCommandBuilderBuild ICqlCommandBuilderTo.Set(IDataMapperFactory factory) { _factoryTo = factory; return this; }
ICqlCommandBuilderTo ICqlCommandBuilderFrom.Set(IDataMapperFactory factory) { _factoryFrom = factory; return this; }
ICqlCommandBuilderBuild ICqlCommandBuilderTo.Set(IDataMapperFactory factory) { _factoryTo = factory; return(this); }
ICqlCommandBuilderTo ICqlCommandBuilderFrom.Set(IDataMapperFactory factory) { _factoryFrom = factory; return(this); }
private static void WriteExecuteRequest(IFrameWriter frameWriter, byte[] id, IColumnSpec[] columnSpecs, ConsistencyLevel cl, IDataMapperFactory factory) { Stream stream = frameWriter.WriteOnlyStream; stream.WriteShortByteArray(id); stream.WriteShort((short) columnSpecs.Length); IDataSource dataSource = factory.DataSource; foreach (IColumnSpec columnSpec in columnSpecs) { object data = dataSource.Get(columnSpec); byte[] rawData = columnSpec.Serialize(data); stream.WriteByteArray(rawData); } stream.WriteShort((short) cl); frameWriter.SetMessageType(MessageOpcodes.Execute); }
private static IEnumerable<object> ReadRows(IFrameReader frameReader, IColumnSpec[] columnSpecs, IDataMapperFactory mapperFactory) { Stream stream = frameReader.ReadOnlyStream; int rowCount = stream.ReadInt(); for (int rowIdx = 0; rowIdx < rowCount; ++rowIdx) { IInstanceBuilder instanceBuilder = mapperFactory.CreateBuilder(); foreach (ColumnSpec colSpec in columnSpecs) { byte[] rawData = stream.ReadByteArray(); object data = null != rawData ? colSpec.Deserialize(rawData) : null; instanceBuilder.Set(colSpec, data); } yield return instanceBuilder.Build(); } }
private static IEnumerable<object> ReadRowSet(IFrameReader frameReader, IDataMapperFactory mapperFactory) { if (MessageOpcodes.Result != frameReader.MessageOpcode) { throw new ArgumentException("Unknown server response"); } if (null == mapperFactory) { yield break; } Stream stream = frameReader.ReadOnlyStream; ResultOpcode resultOpcode = (ResultOpcode) stream.ReadInt(); switch (resultOpcode) { case ResultOpcode.Void: yield break; case ResultOpcode.Rows: IColumnSpec[] columnSpecs = ReadColumnSpec(frameReader); foreach (object row in ReadRows(frameReader, columnSpecs, mapperFactory)) { yield return row; } break; case ResultOpcode.SetKeyspace: yield break; case ResultOpcode.SchemaChange: yield break; default: throw new ArgumentException("Unexpected ResultOpcode"); } }