internal Mapper(ISession session, MapperFactory mapperFactory, StatementFactory statementFactory, CqlGenerator cqlGenerator) { if (session == null) { throw new ArgumentNullException("session"); } if (mapperFactory == null) { throw new ArgumentNullException("mapperFactory"); } if (statementFactory == null) { throw new ArgumentNullException("statementFactory"); } if (cqlGenerator == null) { throw new ArgumentNullException("cqlGenerator"); } _session = session; _mapperFactory = mapperFactory; _statementFactory = statementFactory; _cqlGenerator = cqlGenerator; if (session.Cluster != null && session.Cluster.Configuration != null) { _queryAbortTimeout = session.Cluster.Configuration.ClientOptions.QueryAbortTimeout; } }
internal Mapper(ISession session, MapperFactory mapperFactory, StatementFactory statementFactory, CqlGenerator cqlGenerator) { _session = session ?? throw new ArgumentNullException(nameof(session)); _mapperFactory = mapperFactory ?? throw new ArgumentNullException(nameof(mapperFactory)); _statementFactory = statementFactory ?? throw new ArgumentNullException(nameof(statementFactory)); _cqlGenerator = cqlGenerator ?? throw new ArgumentNullException(nameof(cqlGenerator)); _queryAbortTimeout = session.Cluster.Configuration.DefaultRequestOptions.QueryAbortTimeout; }
public CqlBatch(MapperFactory mapperFactory, CqlGenerator cqlGenerator, BatchType type) { _mapperFactory = mapperFactory ?? throw new ArgumentNullException(nameof(mapperFactory)); _cqlGenerator = cqlGenerator ?? throw new ArgumentNullException(nameof(cqlGenerator)); _statements = new List <Cql>(); BatchType = type; Options = new CqlQueryOptions(); }
public void GenerateUpdate_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>().TableName("users").PartitionKey(u => u.UserId).Column(u => u.UserAge, cm => cm.WithName("AGE"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateUpdate<ExplicitColumnsUser>(); Assert.AreEqual("UPDATE users SET Name = ?, AGE = ? WHERE UserId = ?", cql); }
public void Create() { var cqlQueries = CqlGenerator.GetCreate(PocoData, Name, KeyspaceName, false); foreach (var cql in cqlQueries) { _session.Execute(cql); } }
public void PrependUpdate_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>().TableName("users").PartitionKey(u => u.UserId)); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New("SET Name = ? WHERE UserId = ?", "New name", Guid.Empty); cqlGenerator.PrependUpdate<ExplicitColumnsUser>(cql); Assert.AreEqual("UPDATE users SET Name = ? WHERE UserId = ?", cql.Statement); }
public void AddSelect_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>().TableName("users").PartitionKey(u => u.UserId).Column(u => u.UserAge, cm => cm.WithName("AGE"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New("WHERE UserId = ?", Guid.Empty); cqlGenerator.AddSelect<ExplicitColumnsUser>(cql); Assert.AreEqual("SELECT UserId, Name, AGE FROM users WHERE UserId = ?", cql.Statement); }
public async Task CreateAsync() { var serializer = _session.Cluster.Metadata.ControlConnection.Serializer.GetCurrentSerializer(); var cqlQueries = CqlGenerator.GetCreate(serializer, PocoData, Name, KeyspaceName, false); foreach (var cql in cqlQueries) { await _session.ExecuteAsync(new SimpleStatement(cql)).ConfigureAwait(false); } }
public void Create() { var serializer = _session.Cluster.Metadata.ControlConnection.Serializer; var cqlQueries = CqlGenerator.GetCreate(serializer, PocoData, Name, KeyspaceName, false); foreach (var cql in cqlQueries) { _session.Execute(cql); } }
public void GenerateUpdate_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>().TableName("users").PartitionKey(u => u.UserId).Column(u => u.UserAge, cm => cm.WithName("AGE"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateUpdate <ExplicitColumnsUser>(); Assert.AreEqual("UPDATE users SET Name = ?, AGE = ? WHERE UserId = ?", cql); }
public void GenerateDelete_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>().TableName("USERS").PartitionKey(u => u.UserId)); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateDelete <ExplicitColumnsUser>(); Assert.AreEqual("DELETE FROM USERS WHERE UserId = ?", cql); }
public void PrependUpdate_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>().TableName("users").PartitionKey(u => u.UserId)); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New("SET Name = ? WHERE UserId = ?", "New name", Guid.Empty); cqlGenerator.PrependUpdate <ExplicitColumnsUser>(cql); Assert.AreEqual("UPDATE users SET Name = ? WHERE UserId = ?", cql.Statement); }
public void AddSelect_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>().TableName("users").PartitionKey(u => u.UserId).Column(u => u.UserAge, cm => cm.WithName("AGE"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New("WHERE UserId = ?", Guid.Empty); cqlGenerator.AddSelect <ExplicitColumnsUser>(cql); Assert.AreEqual("SELECT UserId, Name, AGE FROM users WHERE UserId = ?", cql.Statement); }
public void PrependUpdate_CaseSensitive_Test() { var types = new Cassandra.Mapping.Utils.LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("users") .PartitionKey(u => u.UserId) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New(@"SET ""Name"" = ? WHERE ""UserId"" = ?", "New name", Guid.Empty); cqlGenerator.PrependUpdate<ExplicitColumnsUser>(cql); Assert.AreEqual(@"UPDATE ""users"" SET ""Name"" = ? WHERE ""UserId"" = ?", cql.Statement); }
public void GenerateUpdate_CaseSensitive_Test() { var types = new Cassandra.Mapping.Utils.LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("users") .PartitionKey(u => u.UserId) .Column(u => u.UserAge, cm => cm.WithName("AGE")) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateUpdate<ExplicitColumnsUser>(); Assert.AreEqual(@"UPDATE ""users"" SET ""Name"" = ?, ""AGE"" = ? WHERE ""UserId"" = ?", cql); }
public void GenerateInsert_CaseSensitive_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("USERS") .PartitionKey(u => u.UserId) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateInsert <ExplicitColumnsUser>(true, new object[0], out object[] queryParameters); Assert.AreEqual(@"INSERT INTO ""USERS"" (""Name"", ""UserAge"", ""UserId"") VALUES (?, ?, ?)", cql); }
public void GenerateInsert_Without_Nulls_Should_Throw_When_Value_Length_Dont_Match_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); Assert.Throws <ArgumentException>(() => cqlGenerator.GenerateInsert <ExplicitColumnsUser>(false, new object[] { Guid.NewGuid() }, out object[] queryParameters)); }
public void GenerateInsert_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateInsert <ExplicitColumnsUser>(true, new object[0], out object[] queryParameters); Assert.AreEqual(@"INSERT INTO USERS (ID, Name, UserAge) VALUES (?, ?, ?)", cql); }
public void GenerateDelete_CaseSensitive_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID")) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateDelete <ExplicitColumnsUser>(); Assert.AreEqual(@"DELETE FROM ""USERS"" WHERE ""ID"" = ?", cql); }
protected internal override string GetCql(out object[] values) { var pocoData = _mapperFactory.PocoDataFactory.GetPocoData <TEntity>(); var queryIdentifier = $"INSERT LINQ ID {Table.KeyspaceName}/{Table.Name}"; var getBindValues = _mapperFactory.GetValueCollector <TEntity>(queryIdentifier); //get values first to identify null values var pocoValues = getBindValues(_entity); //generate INSERT query based on null values (if insertNulls set) var cqlGenerator = new CqlGenerator(_mapperFactory.PocoDataFactory); //Use the table name from Table<TEntity> instance instead of PocoData var tableName = CqlInsert <TEntity> .CqlIdentifierHelper.EscapeTableNameIfNecessary(pocoData, Table.KeyspaceName, Table.Name); return(cqlGenerator.GenerateInsert <TEntity>( _insertNulls, pocoValues, out values, _ifNotExists, _ttl, _timestamp, tableName)); }
public CqlBatch(MapperFactory mapperFactory, CqlGenerator cqlGenerator) { if (mapperFactory == null) { throw new ArgumentNullException("mapperFactory"); } if (cqlGenerator == null) { throw new ArgumentNullException("cqlGenerator"); } _mapperFactory = mapperFactory; _cqlGenerator = cqlGenerator; _statements = new List <Cql>(); }
public void PrependUpdate_CaseSensitive_Test() { var types = new Cassandra.Mapping.Utils.LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("users") .PartitionKey(u => u.UserId) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New(@"SET ""Name"" = ? WHERE ""UserId"" = ?", "New name", Guid.Empty); cqlGenerator.PrependUpdate <ExplicitColumnsUser>(cql); Assert.AreEqual(@"UPDATE ""users"" SET ""Name"" = ? WHERE ""UserId"" = ?", cql.Statement); }
public void GenerateUpdate_CaseSensitive_Test() { var types = new Cassandra.Mapping.Utils.LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("users") .PartitionKey(u => u.UserId) .Column(u => u.UserAge, cm => cm.WithName("AGE")) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateUpdate <ExplicitColumnsUser>(); Assert.AreEqual(@"UPDATE ""users"" SET ""Name"" = ?, ""AGE"" = ? WHERE ""UserId"" = ?", cql); }
public void AddSelect_CaseSensitive_Test() { var types = new Cassandra.Mapping.Utils.LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("users") .PartitionKey(u => u.UserId) .Column(u => u.UserAge, cm => cm.WithName("AGE")) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New(@"WHERE ""UserId"" = ?", Guid.Empty); cqlGenerator.AddSelect <ExplicitColumnsUser>(cql); Assert.AreEqual(@"SELECT ""UserId"", ""Name"", ""AGE"" FROM ""users"" WHERE ""UserId"" = ?", cql.Statement); }
public CqlBatch(MapperFactory mapperFactory, CqlGenerator cqlGenerator, BatchType type) { if (mapperFactory == null) { throw new ArgumentNullException("mapperFactory"); } if (cqlGenerator == null) { throw new ArgumentNullException("cqlGenerator"); } _mapperFactory = mapperFactory; _cqlGenerator = cqlGenerator; _statements = new List <Cql>(); BatchType = type; Options = new CqlQueryOptions(); }
public void GenerateInsert_Without_Nulls_First_Value_Null_Test() { var types = new LookupKeyedCollection <Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map <ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var values = new object[] { null, "name", 100 }; var cql = cqlGenerator.GenerateInsert <ExplicitColumnsUser>(false, values, out object[] queryParameters); Assert.AreEqual(@"INSERT INTO USERS (Name, UserAge) VALUES (?, ?)", cql); CollectionAssert.AreEqual(values.Where(v => v != null), queryParameters); cql = cqlGenerator.GenerateInsert <ExplicitColumnsUser>(false, values, out queryParameters, true); Assert.AreEqual(@"INSERT INTO USERS (Name, UserAge) VALUES (?, ?) IF NOT EXISTS", cql); CollectionAssert.AreEqual(values.Where(v => v != null), queryParameters); }
public CqlClient(ISession session, MapperFactory mapperFactory, StatementFactory statementFactory, CqlGenerator cqlGenerator) { if (session == null) { throw new ArgumentNullException("session"); } if (mapperFactory == null) { throw new ArgumentNullException("mapperFactory"); } if (statementFactory == null) { throw new ArgumentNullException("statementFactory"); } if (cqlGenerator == null) { throw new ArgumentNullException("cqlGenerator"); } _session = session; _mapperFactory = mapperFactory; _statementFactory = statementFactory; _cqlGenerator = cqlGenerator; }
public void AddSelect_CaseSensitive_Test() { var types = new Cassandra.Mapping.Utils.LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("users") .PartitionKey(u => u.UserId) .Column(u => u.UserAge, cm => cm.WithName("AGE")) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = Cql.New(@"WHERE ""UserId"" = ?", Guid.Empty); cqlGenerator.AddSelect<ExplicitColumnsUser>(cql); Assert.AreEqual(@"SELECT ""UserId"", ""Name"", ""AGE"" FROM ""users"" WHERE ""UserId"" = ?", cql.Statement); }
public void GenerateDelete_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>().TableName("USERS").PartitionKey(u => u.UserId)); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateDelete<ExplicitColumnsUser>(); Assert.AreEqual("DELETE FROM USERS WHERE UserId = ?", cql); }
public void GenerateInsert_CaseSensitive_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("USERS") .PartitionKey(u => u.UserId) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); object[] queryParameters; var cql = cqlGenerator.GenerateInsert<ExplicitColumnsUser>(true, new object[0], out queryParameters); Assert.AreEqual(@"INSERT INTO ""USERS"" (""UserId"", ""Name"", ""UserAge"") VALUES (?, ?, ?)", cql); }
public void GenerateInsert_Without_Nulls_Should_Throw_When_Value_Length_Dont_Match_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); object[] queryParameters; Assert.Throws<ArgumentException>(() => cqlGenerator.GenerateInsert<ExplicitColumnsUser>(false, new object[] { Guid.NewGuid()}, out queryParameters)); }
public void GenerateInsert_Without_Nulls_First_Value_Null_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var values = new object[] { null, "name", 100 }; object[] queryParameters; var cql = cqlGenerator.GenerateInsert<ExplicitColumnsUser>(false, values, out queryParameters); Assert.AreEqual(@"INSERT INTO USERS (Name, UserAge) VALUES (?, ?)", cql); CollectionAssert.AreEqual(values.Where(v => v != null), queryParameters); cql = cqlGenerator.GenerateInsert<ExplicitColumnsUser>(false, values, out queryParameters, true); Assert.AreEqual(@"INSERT INTO USERS (Name, UserAge) VALUES (?, ?) IF NOT EXISTS", cql); CollectionAssert.AreEqual(values.Where(v => v != null), queryParameters); }
public void GenerateInsert_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID"))); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); object[] queryParameters; var cql = cqlGenerator.GenerateInsert<ExplicitColumnsUser>(true, new object[0], out queryParameters); Assert.AreEqual(@"INSERT INTO USERS (ID, Name, UserAge) VALUES (?, ?, ?)", cql); }
public void GenerateDelete_CaseSensitive_Test() { var types = new LookupKeyedCollection<Type, ITypeDefinition>(td => td.PocoType); types.Add(new Map<ExplicitColumnsUser>() .TableName("USERS") .PartitionKey("ID") .Column(u => u.UserId, cm => cm.WithName("ID")) .CaseSensitive()); var pocoFactory = new PocoDataFactory(types); var cqlGenerator = new CqlGenerator(pocoFactory); var cql = cqlGenerator.GenerateDelete<ExplicitColumnsUser>(); Assert.AreEqual(@"DELETE FROM ""USERS"" WHERE ""ID"" = ?", cql); }
public CqlBatch(MapperFactory mapperFactory, CqlGenerator cqlGenerator) : this(mapperFactory, cqlGenerator, BatchType.Logged) { }