/// <summary>
        /// Add mapping definition(s) for UDTs, specifying how UDTs should be mapped to .NET types and vice versa.
        /// </summary>
        /// <exception cref="ArgumentException" />
        public void Define(params UdtMap[] udtMaps)
        {
            if (udtMaps == null)
            {
                throw new ArgumentNullException("udtMaps");
            }
            var keyspace = _session.Keyspace;

            if (String.IsNullOrEmpty(keyspace))
            {
                throw new ArgumentException("It is not possible to define a mapping when no keyspace is specified.");
            }
            if (_session.BinaryProtocolVersion < 3)
            {
                throw new NotSupportedException("User defined type mapping is supported with C* 2.1+ and protocol version 3+");
            }
            // Add types to both indexes
            foreach (var map in udtMaps)
            {
                var udtDefition = GetDefinition(keyspace, map);
                map.Build(udtDefition);
                TypeCodec.SetUdtMap(udtDefition.Name, map);
                _udtByNetType.AddOrUpdate(map.NetType, map, (k, oldValue) => map);
            }
        }
Example #2
0
        public void Create_With_Frozen_Collection_Value()
        {
            string createQuery = null;
            var    sessionMock = new Mock <ISession>();

            sessionMock
            .Setup(s => s.Execute(It.IsAny <string>()))
            .Returns(() => new RowSet())
            .Callback <string>(q => createQuery = q);
            var definition = new Map <UdtAndTuplePoco>()
                             .PartitionKey(c => c.Id1)
                             .Column(c => c.Id1, cm => cm.WithName("id"))
                             .Column(c => c.UdtList1, cm => cm.WithName("my_list").WithFrozenValue())
                             .Column(c => c.TupleMapValue1, cm => cm.WithName("my_map").WithFrozenValue())
                             .ExplicitColumns()
                             .TableName("tbl1");
            var udtInfo = new UdtColumnInfo("song");

            udtInfo.Fields.Add(new ColumnDesc {
                Name = "title", TypeCode = ColumnTypeCode.Ascii
            });
            udtInfo.Fields.Add(new ColumnDesc {
                Name = "releasedate", TypeCode = ColumnTypeCode.Timestamp
            });
            var udtMap = UdtMap.For <Song>();

            udtMap.Build(udtInfo);
            TypeCodec.SetUdtMap("song", udtMap);
            var table = GetTable <UdtAndTuplePoco>(sessionMock.Object, definition);

            table.Create();
            Assert.AreEqual("CREATE TABLE tbl1 (id uuid, my_list list<frozen<song>>, my_map map<text, frozen<tuple<double, double>>>, PRIMARY KEY (id))", createQuery);
        }