Esempio n. 1
0
        public async Task MappingSingleExplicitAsync_AsParameter()
        {
            var localSession = GetNewSession(KeyspaceName);
            await localSession.UserDefinedTypes.DefineAsync(
                UdtMap.For <Phone>("phone")
                .Map(v => v.Alias, "alias")
                .Map(v => v.CountryCode, "country_code")
                .Map(v => v.Number, "number")
                ).ConfigureAwait(false);

            var phone = new Phone
            {
                Alias       = "home phone",
                Number      = "85 988888888",
                CountryCode = 55
            };

            localSession.Execute(new SimpleStatement("INSERT INTO users (id, main_phone) values (1, ?)", phone));
            var rs    = localSession.Execute("SELECT * FROM users WHERE id = 1");
            var row   = rs.First();
            var value = row.GetValue <Phone>("main_phone");

            Assert.AreEqual(phone, value);
        }
Esempio n. 2
0
        public void MappingCaseSensitiveTest()
        {
            foreach (var protocolVersion in UdtProtocolVersionSupported)
            {
                Cluster.MaxProtocolVersion = protocolVersion;
                var localSession = GetNewSession(KeyspaceName);
                //Cassandra identifiers are lowercased by default
                localSession.UserDefinedTypes.Define(
                    UdtMap.For <Phone>("phone")
                    .SetIgnoreCase(false)
                    .Map(v => v.Alias, "alias")
                    .Map(v => v.CountryCode, "country_code")
                    .Map(v => v.Number, "number")
                    );
                localSession.Execute("INSERT INTO users (id, main_phone) values (101, {alias: 'home phone', number: '123', country_code: 34})");
                var rs    = localSession.Execute("SELECT * FROM users WHERE id = 101");
                var row   = rs.First();
                var value = row.GetValue <Phone>("main_phone");
                Assert.NotNull(value);
                Assert.AreEqual("home phone", value.Alias);
                Assert.AreEqual("123", value.Number);
                Assert.AreEqual(34, value.CountryCode);

                Assert.Throws <InvalidTypeException>(() => localSession.UserDefinedTypes.Define(
                                                         //The name should be forced to be case sensitive
                                                         UdtMap.For <Phone>("PhoNe")
                                                         .SetIgnoreCase(false)));

                Assert.Throws <InvalidTypeException>(() => localSession.UserDefinedTypes.Define(
                                                         UdtMap.For <Phone>("phone")
                                                         .SetIgnoreCase(false)
                                                         //the field is called 'alias' it should fail
                                                         .Map(v => v.Alias, "Alias")
                                                         ));
            }
        }
Esempio n. 3
0
        public void CreateTable_With_Frozen_Value()
        {
            var config = new MappingConfiguration().Define(new Map <UdtAndTuplePoco>()
                                                           .PartitionKey(p => p.Id1)
                                                           .Column(p => p.Id1)
                                                           .Column(p => p.ListMapValue1, cm => cm.WithFrozenValue().WithName("m"))
                                                           .Column(p => p.UdtList1, cm => cm.WithFrozenValue().WithName("l"))
                                                           .TableName("tbl_frozen_value")
                                                           .ExplicitColumns());

            Session.Execute("CREATE TYPE IF NOT EXISTS song (title text, releasedate timestamp, artist text)");
            Session.UserDefinedTypes.Define(UdtMap.For <Song>());
            var table = new Table <UdtAndTuplePoco>(Session, config);

            table.Create();
            var tableMeta = Cluster.Metadata.GetTable(_uniqueKsName, "tbl_frozen_value");

            Assert.AreEqual(3, tableMeta.TableColumns.Length);
            var column = tableMeta.ColumnsByName["l"];

            Assert.AreEqual(ColumnTypeCode.List, column.TypeCode);
            column = tableMeta.ColumnsByName["m"];
            Assert.AreEqual(ColumnTypeCode.Map, column.TypeCode);
        }
 public void MappingOnLowerProtocolVersionTest()
 {
     using (var cluster = Cluster.Builder()
                          .AddContactPoint(TestCluster.InitialContactPoint)
                          .WithMaxProtocolVersion(ProtocolVersion.V2)
                          .Build())
     {
         var localSession = cluster.Connect(KeyspaceName);
         Assert.Throws <NotSupportedException>(() => localSession.UserDefinedTypes.Define(UdtMap.For <Phone>()));
     }
 }
 public static void AddUDTType(this ISession session)
 {
     session.UserDefinedTypes.Define(UdtMap.For <IdentityClaim>());
 }
Esempio n. 6
0
 public void Setup()
 {
     Session.Execute($"CREATE TYPE IF NOT EXISTS {_udtName} (id uuid, title text, artist text)");
     Session.UserDefinedTypes.Define(UdtMap.For <Song>(_udtName));
     Session.Execute($"CREATE TABLE IF NOT EXISTS {_tableName} (id uuid primary key, name text, songs list<frozen<{_udtName}>>, publishingdate timestamp)");
 }
        public void Should_ExecuteSelectsAndInserts_When_UdtWithCollections()
        {
            var localSession = GetNewTemporarySession(KeyspaceName);

            localSession.UserDefinedTypes.Define(UdtMap.For <UdtWithCollections>("udt_collections"));

            var udtList = new List <UdtWithCollections>
            {
                // nulls
                new UdtWithCollections
                {
                    Id = 1
                },

                // collections with elements
                new UdtWithCollections
                {
                    Id               = 2,
                    NullableId       = 4,
                    IntEnumerable    = new [] { 1, 10 },
                    IntEnumerableSet = new [] { 2, 20 },
                    IntIList         = new List <int> {
                        3, 30
                    },
                    IntList = new List <int> {
                        4, 40
                    },
                    IntReadOnlyList = new List <int> {
                        5, 50
                    },
                    NullableIntEnumerable = new int?[] { 6, 60 },
                    NullableIntList       = new List <int?> {
                        7, 70
                    }
                },

                // empty collections
                new UdtWithCollections
                {
                    Id                    = 3,
                    NullableId            = 5,
                    IntEnumerable         = new int[0],
                    IntEnumerableSet      = new int[0],
                    IntIList              = new List <int>(),
                    IntList               = new List <int>(),
                    IntReadOnlyList       = new List <int>(),
                    NullableIntEnumerable = new int?[0],
                    NullableIntList       = new List <int?>()
                }
            };

            var insert = new SimpleStatement("INSERT INTO table_udt_collections (id, udt, udt_list, nullable_id) values (?, ?, ?, ?)", 1, udtList[0], udtList, 100);

            localSession.Execute(insert);
            insert = new SimpleStatement("INSERT INTO table_udt_collections (id, udt, udt_list) values (?, ?, ?)", 2, udtList[1], udtList);
            localSession.Execute(insert);
            insert = new SimpleStatement("INSERT INTO table_udt_collections (id, udt, udt_list) values (?, ?, ?)", 3, udtList[2], udtList);
            localSession.Execute(insert);
            insert = new SimpleStatement("INSERT INTO table_udt_collections (id, udt, udt_list) values (?, ?, ?)", 4, null, null);
            localSession.Execute(insert);

            var rs = localSession.Execute(new SimpleStatement("SELECT * FROM table_udt_collections WHERE id = ?", 1)).ToList();

            CollectionAssert.AreEqual(udtList, rs.Single().GetValue <List <UdtWithCollections> >("udt_list"));
            Assert.AreEqual(udtList[0], rs.Single().GetValue <UdtWithCollections>("udt"));
            Assert.AreEqual(100, rs.Single().GetValue <int?>("nullable_id"));

            var ps = localSession.Prepare("SELECT * FROM table_udt_collections WHERE id = ?");

            rs = localSession.Execute(ps.Bind(2)).ToList();
            CollectionAssert.AreEqual(udtList, rs.Single().GetValue <List <UdtWithCollections> >("udt_list"));
            Assert.AreEqual(udtList[1], rs.Single().GetValue <UdtWithCollections>("udt"));
            Assert.IsNull(rs.Single().GetValue <int?>("nullable_id"));

            rs = localSession.Execute(ps.Bind(3)).ToList();
            CollectionAssert.AreEqual(udtList, rs.Single().GetValue <List <UdtWithCollections> >("udt_list"));
            Assert.AreEqual(udtList[2], rs.Single().GetValue <UdtWithCollections>("udt"));

            rs = localSession.Execute(ps.Bind(4)).ToList();
            Assert.IsNull(rs.Single().GetValue <List <UdtWithCollections> >("udt_list"));
            Assert.IsNull(rs.Single().GetValue <UdtWithCollections>("udt"));
        }
        public void MappingOnLowerProtocolVersionTest()
        {
            Cluster.MaxProtocolVersion = 2;
            var localCluster = Cluster.Builder().AddContactPoint(IpPrefix + "1").Build();
            var localSession = localCluster.Connect("tester");

            try
            {
                Assert.Throws <NotSupportedException>(() => localSession.UserDefinedTypes.Define(UdtMap.For <Phone>()));
            }
            finally
            {
                localCluster.Dispose();
            }
        }
Esempio n. 9
0
        public UdtMapEx(Session session, string cassandrifiedUdtName) : base(typeof(T), cassandrifiedUdtName)
        {
            var udtMap = UdtMap.For <T>(cassandrifiedUdtName);

            session.UserDefinedTypes.Define(udtMap);
        }
Esempio n. 10
0
        public void Initialize <TUser, TRole>(CassandraOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (string.IsNullOrEmpty(options.KeyspaceName))
            {
                throw new InvalidOperationException("Keyspace is null or empty.");
            }

            // Keyspace
            try
            {
                // Attempt to switch to keyspace
                _session.ChangeKeyspace(options.KeyspaceName);
            }
            catch (InvalidQueryException)
            {
                // If failed with InvalidQueryException then keyspace does not exist
                // -> create new one
                _session.CreateKeyspaceIfNotExists(options.KeyspaceName, replication: options.Replication, durableWrites: options.DurableWrites);
                _session.ChangeKeyspace(options.KeyspaceName);
            }

            // User Defined Types
            _session.Execute($"CREATE TYPE IF NOT EXISTS {options.KeyspaceName}.LockoutInfo (EndDate timestamp, Enabled boolean, AccessFailedCount int);");
            _session.Execute($"CREATE TYPE IF NOT EXISTS {options.KeyspaceName}.PhoneInfo (Number text, ConfirmationTime timestamp);");
            _session.Execute($"CREATE TYPE IF NOT EXISTS {options.KeyspaceName}.LoginInfo (LoginProvider text, ProviderKey text, ProviderDisplayName text);");
            _session.Execute($"CREATE TYPE IF NOT EXISTS {options.KeyspaceName}.TokenInfo (LoginProvider text, Name text, Value text);");

            _session.UserDefinedTypes.Define(
                UdtMap.For <LockoutInfo>(),
                UdtMap.For <PhoneInfo>(),
                UdtMap.For <LoginInfo>(),
                UdtMap.For <TokenInfo>());

            // Tables
            var usersTable = new Table <TUser>(_session);

            usersTable.CreateIfNotExists();

            var rolesTable = new Table <TRole>(_session);

            rolesTable.CreateIfNotExists();

            _session.Execute($"CREATE TABLE IF NOT EXISTS {options.KeyspaceName}.userclaims (" +
                             " UserId uuid, " +
                             " Type text, " +
                             " Value text, " +
                             " PRIMARY KEY (UserId, Type, Value));");

            // Materialized views
            CassandraSessionHelper.UsersTableName = usersTable.GetTable().Name;
            CassandraSessionHelper.RolesTableName = rolesTable.GetTable().Name;

            _session.Execute("CREATE MATERIALIZED VIEW IF NOT EXISTS users_by_email AS" +
                             $" SELECT * FROM {options.KeyspaceName}.{CassandraSessionHelper.UsersTableName}" +
                             " WHERE NormalizedEmail IS NOT NULL" +
                             " PRIMARY KEY (NormalizedEmail, Id)");

            _session.Execute("CREATE MATERIALIZED VIEW IF NOT EXISTS users_by_username AS" +
                             $" SELECT * FROM {options.KeyspaceName}.{CassandraSessionHelper.UsersTableName}" +
                             " WHERE NormalizedUserName IS NOT NULL" +
                             " PRIMARY KEY (NormalizedUserName, Id)");

            _session.Execute("CREATE MATERIALIZED VIEW IF NOT EXISTS roles_by_name AS" +
                             $" SELECT * FROM {options.KeyspaceName}.{CassandraSessionHelper.RolesTableName}" +
                             " WHERE NormalizedName IS NOT NULL" +
                             " PRIMARY KEY (NormalizedName, Id)");

            _session.Execute("CREATE MATERIALIZED VIEW IF NOT EXISTS userclaims_by_type_and_value AS" +
                             $" SELECT * FROM {options.KeyspaceName}.userclaims" +
                             " WHERE Type IS NOT NULL AND Value IS NOT NULL" +
                             " PRIMARY KEY ((Type, Value), UserId)");
        }
Esempio n. 11
0
        public void copyData(int fedID, string projectNumber, string projectName)
        {
            OracleConnection oraConn   = DBOperation.Connect();
            ISession         CSSession = CassandraDB.connect();

            CSSession.UserDefinedTypes.Define(UdtMap.For <CSType>(), UdtMap.For <CSPoint>(), UdtMap.For <CSGeometry>(), UdtMap.For <CSMatrix3D>(), UdtMap.For <CSSpatialIndex>(),
                                              UdtMap.For <CSTopoFace>(), UdtMap.For <CSProperty>(), UdtMap.For <CSMaterial>(), UdtMap.For <CSClassification>());

            PreparedStatement modelIns = CSSession.Prepare("Insert into bimrl_federatedmodel (projectnumber, projectname, federatedid, lastupdatedate, maxoctreelevel, projectid, worldbox) "
                                                           + "values (?, ?, ?, ?, ?, ?, ?)");
            PreparedStatement elemInsPrep = CSSession.Prepare("Insert into bimrl_element (federatedmodelid, projectname, projectnumber, elementid, lineno, elementtype, modelid, type, name, longname, "
                                                              + "ownerhistoryid, description, objecttype, tag, container, geometrybody, geometrybody_bbox, geometrybody_bbox_centroid, geometryfootprint, geometryaxis, "
                                                              + "transform, obb_major_axis, obb_major_axis_centroid, obb) "
                                                              + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,  ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,  ?, ?, ?, ?)");

            // Delete existing data first if already exists
            deleteData(fedID);

            string sqlStmt = string.Empty;

            sqlStmt = "Select e.elementid, e.lineno, e.elementtype, e.modelid, e.typeid, e.name, e.longname, e.ownerhistoryid, e.description, e.objecttype, "
                      + "e.tag, e.container, e.geometrybody, e.geometrybody_bbox, e.geometrybody_bbox_centroid, e.geometryfootprint, e.geometryaxis, e.transform_x_axis, e.transform_y_axis, e.transform_z_axis, "
                      + "e.body_major_axis1, e.body_major_axis2, e.body_major_axis3, e.body_major_axis_cnetroid, e.obb, t.elementid, t.ifctype, t.name, t.description, t.ownerhistoryid, "
                      + "t.modelid, t.applicableoccurence, t.tag, t.elementtype, t.predefinedtype, t.assembyplace, t.operationtype, t.constructiontype "
                      + "from bimrl_element_" + fedID.ToString("X4") + " e, bimrl_type_" + fedID.ToString("X4") + " t where t.elementid (+) =e.typeid";

            OracleCommand command = new OracleCommand(sqlStmt, oraConn);

            command.CommandText = sqlStmt;
            command.FetchSize   = 1000;
            OracleDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                CSType bType = new CSType();
                bType.typeid              = reader.GetString(22);
                bType.ifctype             = reader.GetString(23);
                bType.name                = reader.GetString(24);
                bType.description         = reader.GetString(25);
                bType.ownerhistoryid      = reader.GetInt32(26);
                bType.applicableoccurence = SafeGetString(reader, 27);
                bType.tag              = SafeGetString(reader, 28);
                bType.elementtype      = reader.GetString(29);
                bType.predefinedtype   = reader.GetString(30);
                bType.assemblyplace    = reader.GetString(31);
                bType.operationtype    = reader.GetString(32);
                bType.constructiontype = reader.GetString(33);

                List <CSPoint> transf = new List <CSPoint>();
                transf.Add(CSpointFromSdoGeom(reader, 17));
                transf.Add(CSpointFromSdoGeom(reader, 18));
                transf.Add(CSpointFromSdoGeom(reader, 19));
                CSMatrix3D transform = new CSMatrix3D();
                transform.matrix3d = transf;

                List <CSPoint> mjAxis = new List <CSPoint>();
                mjAxis.Add(CSpointFromSdoGeom(reader, 20));
                mjAxis.Add(CSpointFromSdoGeom(reader, 21));
                mjAxis.Add(CSpointFromSdoGeom(reader, 22));
                CSMatrix3D mjAxisMatrix = new CSMatrix3D();
                mjAxisMatrix.matrix3d = mjAxis;

                NetSdoGeometry.SdoGeometry bodyMjAxisCentroid = reader.GetValue(20) as NetSdoGeometry.SdoGeometry;
                NetSdoGeometry.SdoGeometry obb = reader.GetValue(21) as NetSdoGeometry.SdoGeometry;

                BoundStatement boundStmt = elemInsPrep.Bind(fedID, projectName, projectNumber, reader.GetString(0), reader.GetInt32(1), reader.GetString(2), reader.GetInt32(3), bType, SafeGetString(reader, 5), SafeGetString(reader, 6),
                                                            SafeGetValue(reader, 7), SafeGetString(reader, 8), SafeGetString(reader, 9), SafeGetString(reader, 10), SafeGetString(reader, 11), CSgeomFromSdoGeom(reader, 12), CSgeomFromSdoGeom(reader, 13), CSpointFromSdoGeom(reader, 14), CSgeomFromSdoGeom(reader, 15), CSgeomFromSdoGeom(reader, 16),
                                                            transform, mjAxisMatrix, CSpointFromSdoGeom(reader, 23), CSgeomFromSdoGeom(reader, 24));

                CSSession.Execute(boundStmt);
            }
        }
Esempio n. 12
0
        public void MappingOnLowerProtocolVersionTest()
        {
            Cluster.MaxProtocolVersion = 2;
            var localSession = GetNewSession(KeyspaceName);

            Assert.Throws <NotSupportedException>(() => localSession.UserDefinedTypes.Define(UdtMap.For <Phone>()));
        }
Esempio n. 13
0
        static void Main()
        {
            //Zamieniæ to na mysql -- bardzo analogicznie

            Cluster cluster = Cluster.Builder()
                              .AddContactPoint("192.168.100.99")
                              .Build();
            ISession session = cluster.Connect("test_keyspace");


            session.UserDefinedTypes.Define(
                UdtMap.For <Shot>()
                .Map(a => a.id, "Chorobaid")
                .Map(a => a.name, "nazwa")
                .Map(a => a.accessible, "dostêpna")
                .Map(a => a.refund, "refundacjaid")
                );

            session.UserDefinedTypes.Define(
                UdtMap.For <Vaccination>()
                .Map(a => a.id, "id")
                .Map(a => a.name, "Szczepionkanazwa")
                .Map(a => a.pesel_p, "PacjientPesel")
                .Map(a => a.pesel_n, "Pielêgniarkapesel")
                .Map(a => a.pesel_d, "Doktorpesel")
                .Map(a => a.date, "data_wykonania")
                .Map(a => a.obligatory, "obowi¹zkowowe")
                );

            session.UserDefinedTypes.Define(
                UdtMap.For <High_risk>()
                .Map(a => a.id, "Chorobaid")
                .Map(a => a.pesel_p, "PacjientPesel")
                );

            session.UserDefinedTypes.Define(
                UdtMap.For <Patient>()
                .Map(a => a.pesel, "Pesel")
                .Map(a => a.first_name, "imie")
                .Map(a => a.last_name, "nazwisko")
                .Map(a => a.login, "login")
                .Map(a => a.password, "haslo")
                );

            session.UserDefinedTypes.Define(
                UdtMap.For <Nurse>()
                .Map(a => a.pesel, "pesel")
                .Map(a => a.first_name, "imie")
                .Map(a => a.last_name, "nazwisko")
                .Map(a => a.login, "login")
                .Map(a => a.password, "haslo")
                );

            session.UserDefinedTypes.Define(
                UdtMap.For <Doctor>()
                .Map(a => a.pesel, "pesel")
                .Map(a => a.first_name, "imie")
                .Map(a => a.last_name, "nazwisko")
                .Map(a => a.login, "login")
                .Map(a => a.password, "haslo")
                );

            session.UserDefinedTypes.Define(
                UdtMap.For <Ilness>()
                .Map(a => a.id, "id")
                .Map(a => a.name, "nazwa")
                );

            session.UserDefinedTypes.Define(
                UdtMap.For <Refund>()
                .Map(a => a.id, "id")
                .Map(a => a.type_r, "typ_refundacji ")
                );

            //Zamieniæ to na mysql -- bardzo analogicznie



            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }