コード例 #1
0
        protected void InitOuterJoinFetchSetting(HbmOneToOne oneToOne, OneToOne model)
        {
            FetchMode fetchStyle;
            bool      lazy = true;

            if (!oneToOne.fetchSpecified)
            {
                if (!oneToOne.outerjoinSpecified)
                {
                    //NOTE SPECIAL CASE:
                    // one-to-one constrained=falase cannot be proxied,
                    // so default to join and non-lazy
                    lazy       = model.IsConstrained;
                    fetchStyle = lazy ? FetchMode.Default : FetchMode.Join;
                }
                else
                {
                    fetchStyle = GetFetchStyle(oneToOne.outerjoin);
                }
            }
            else
            {
                fetchStyle = GetFetchStyle(oneToOne.fetch);
            }

            model.FetchMode = fetchStyle;
            model.IsLazy    = lazy;
        }
コード例 #2
0
ファイル: Day8.cs プロジェクト: oparkerj/AdventOfCode
    public override void PartTwo()
    {
        var total = 0;

        var expected = new Dictionary <char, int>
        {
            ['a'] = 8,
            ['b'] = 6,
            ['c'] = 8,
            ['d'] = 7,
            ['e'] = 4,
            ['f'] = 9,
            ['g'] = 7,
        };

        foreach (var entry in Input)
        {
            var possible = new OneToOne <char, char>();
            possible.AddValues("abcdefg");
            possible.AddKeys("abcdefg");

            var(input, output) = entry.SingleSplit(" | ");
            var pattern = input.Spaced().ToList();
            var result  = output.Spaced().ToList();

            foreach (var s in pattern)
            {
                if (s.Length == 2)
                {
                    possible.MustBe(s, "cf");
                }
                else if (s.Length == 3)
                {
                    possible.MustBe(s, "acf");
                }
                else if (s.Length == 4)
                {
                    possible.MustBe(s, "bdcf");
                }
            }

            var actual = pattern.Flatten().Frequencies().ToDictionary();
            possible.ReduceWithFrequencies(expected, actual);

            var map   = possible.Mappings();
            var value = result.Select(s => s.Select(c => map[c]).Sorted().Str())
                        .Select(s => s switch
            {
                "abcefg" => 0,
                "cf" => 1,
                "acdeg" => 2,
                "acdfg" => 3,
                "bcdf" => 4,
                "abdfg" => 5,
                "abdefg" => 6,
                "acf" => 7,
                "abcdefg" => 8,
                "abcdfg" => 9,
                _ => 0
            }).Str().AsInt();
コード例 #3
0
        public void ColumnMappingShouldWorkForChildRecordsets()
        {
            var childReader = new OneToOne <ChildFor109>(new ColumnOverride("Bar", "Foo"));

            var results = Connection().QuerySql("SELECT ID=1; SELECT ParentID=1, Bar=3", Parameters.Empty,
                                                Query.Returns(Some <ParentFor109> .Records)
                                                .ThenChildren(childReader)).First();

            Assert.AreEqual(1, results.Children.Count);
            Assert.AreEqual(3, results.Children[0].Foo);
        }
コード例 #4
0
        public void CanOverrideColumnsInline()
        {
            var mappedRecords = new OneToOne <HasDefaultRecordset>(
                new ColumnOverride <HasDefaultRecordset>("Foo", "ID"));

            var result = Connection().QuerySql(
                "SELECT Foo=1, ID=2",
                null,
                Query.Returns(mappedRecords)).First();

            Assert.AreEqual(1, result.ID);
            Assert.AreEqual(2, result.Beer.ID);
        }
コード例 #5
0
ファイル: OneToOneLinking.cs プロジェクト: lulzzz/OrleansExp
        public override async Task Link()
        {
            if (from.Layer.Values.SelectMany(x => x).Count() != to.Layer.Values.SelectMany(x => x).Count())
            {
                throw new InvalidOperationException("OneToOne must be used between to layers with the same amount of nodes");
            }
            List <IWorkerGrain> unLinkedSender   = new List <IWorkerGrain>();
            List <IWorkerGrain> unLinkedReceiver = new List <IWorkerGrain>();

            foreach (var fromPair in from.Layer)
            {
                if (to.Layer.ContainsKey(fromPair.Key))
                {
                    var receivers = to.Layer[fromPair.Key];
                    int limit     = Math.Min(receivers.Count, fromPair.Value.Count);
                    for (int i = 0; i < limit; ++i)
                    {
                        var strategy = new OneToOne(batchSize);
                        strategy.AddReceiver(receivers[i], true);
                        await fromPair.Value[i].SetSendStrategy(id, strategy);
                    }
                    if (receivers.Count > limit)
                    {
                        unLinkedReceiver.AddRange(receivers.Skip(limit));
                    }
                    else if (fromPair.Value.Count > limit)
                    {
                        unLinkedSender.AddRange(fromPair.Value.Skip(limit));
                    }
                }
                else
                {
                    unLinkedSender.AddRange(fromPair.Value);
                }
            }
            foreach (var toPair in to.Layer)
            {
                if (!from.Layer.ContainsKey(toPair.Key))
                {
                    unLinkedReceiver.AddRange(toPair.Value);
                }
            }
            for (int i = 0; i < unLinkedReceiver.Count; ++i)
            {
                var strategy = new OneToOne(batchSize);
                strategy.AddReceiver(unLinkedReceiver[i], true);
                await unLinkedSender[i].SetSendStrategy(id, strategy);
            }
        }
コード例 #6
0
        // private methods
        private void EnsureTestDataOneToOne(IMongoDatabase database, string collectionName)
        {
            database.DropCollection(collectionName);
            var collection = database.GetCollection <OneToOne>(collectionName);
            var documents  = new OneToOne[]
            {
                new OneToOne {
                    Id = 1, From = 1, To = 2
                },
                new OneToOne {
                    Id = 2, From = 2, To = 3
                },
            };

            collection.InsertMany(documents);
        }
コード例 #7
0
        protected void BindOneToOne(HbmOneToOne oneToOneMapping, OneToOne model)
        {
            model.IsConstrained = oneToOneMapping.constrained;

            model.ForeignKeyType = oneToOneMapping.constrained
                                                                        ? ForeignKeyDirection.ForeignKeyFromParent
                                                                        : ForeignKeyDirection.ForeignKeyToParent;

            InitOuterJoinFetchSetting(oneToOneMapping, model);
            InitLaziness(oneToOneMapping.Lazy, model, true);
            BindForeignKey(oneToOneMapping.foreignkey, model);

            model.ReferencedPropertyName = oneToOneMapping.propertyref;

            model.ReferencedEntityName = GetEntityName(oneToOneMapping, mappings);
            model.PropertyName         = oneToOneMapping.Name;
        }
コード例 #8
0
ファイル: AllToOneLinking.cs プロジェクト: lulzzz/OrleansExp
        public override async Task Link()
        {
            if (to.Layer.Values.SelectMany(x => x).Count() != 1)
            {
                throw new InvalidOperationException("AllToOne must be used when there is a n-to-1 mapping");
            }
            var dest = to.Layer.First();

            foreach (var pair in from.Layer)
            {
                foreach (IWorkerGrain grain in pair.Value)
                {
                    var strategy = new OneToOne(batchSize);
                    strategy.AddReceiver(dest.Value.First(), pair.Key.Equals(dest.Key));
                    await grain.SetSendStrategy(id, strategy);
                }
            }
        }
コード例 #9
0
        public IList <SpanStats> GetSpanList(int gameId)
        {
            var mapping =
                new OneToOne <Game, Country, League, Season, Stage, Team, Team, Period, Period, Period, Period,
                              Period, Period>(
                    (g, c, l, se, st, ht, at, p1, p2, p3, p4, ot, ttl) =>
            {
                g.Country    = c;
                g.League     = l;
                l.CountryId  = c.Id;
                g.Season     = se;
                se.CountryId = c.Id;
                se.LeagueId  = l.Id;
                g.Stage      = st;
                st.CountryId = c.Id;
                st.LeagueId  = l.Id;
                st.SeasonId  = se.Id;
                g.TeamHome   = ht;
                g.TeamAway   = at;
                g.P1         = p1;
                g.P2         = p2;
                g.P3         = p3;
                g.P4         = p4;
                g.OT         = ot;
                g.Total      = ttl;
            });

            var reader = _db.Connection.QuerySql(
                "SELECT Game.Id, DateStart, Country.Id, Country.Title, League.Id, League.Title, Season.Id, Season.Title, Stage.Id, Stage.Title, " +
                "TeamHome.Id, TeamHome.Title, TeamHome.CountryId, TeamAway.Id, TeamAway.Title, TeamAway.CountryId, Game.P1_Home AS " +
                "Home, Game.P1_Away AS Away, Game.P2_Home AS Home, Game.P2_Away AS Away, Game.P3_Home AS Home, Game.P3_Away AS " +
                "Away, Game.P4_Home AS Home, Game.P4_Away AS Away, Game.OT_Home AS Home, Game.OT_Away AS Away, Game.Total_Home AS " +
                "Home, Game.Total_Away AS Away FROM[Games] Game JOIN[Countries] Country ON(Country.Id = Game.CountryId) " +
                "JOIN[Leagues] League ON(League.Id = Game.LeagueId) JOIN[Seasons] Season ON(Season.Id = Game.SeasonId) " +
                "JOIN[Stages] Stage ON(Stage.Id = Game.StageId) JOIN[Teams] TeamHome ON(TeamHome.Id = Game.TeamHomeId) " +
                "JOIN[Teams] TeamAway ON(TeamAway.Id = Game.TeamAwayId) WHERE Game.Id = @Id",
                new { Id = gameId }, Query.ReturnsSingle(mapping));

            return(GetSpanList(reader));
        }
コード例 #10
0
        //@SuppressWarnings({"unchecked"})
        public void AddOneToOneNotOwning(PropertyAuditingData propertyAuditingData, IValue value,
                                         ICompositeMapperBuilder mapper, String entityName)
        {
            OneToOne propertyValue = (OneToOne)value;

            String owningReferencePropertyName = propertyValue.ReferencedPropertyName; // mappedBy
            EntityConfiguration configuration  = mainGenerator.EntitiesConfigurations[entityName];

            if (configuration == null)
            {
                throw new MappingException("An audited relation to a non-audited entity " + entityName + "!");
            }

            IdMappingData ownedIdMapping = configuration.IdMappingData;

            if (ownedIdMapping == null)
            {
                throw new MappingException("An audited relation to a non-audited entity " + entityName + "!");
            }

            String lastPropertyPrefix   = MappingTools.createToOneRelationPrefix(owningReferencePropertyName);
            String referencedEntityName = propertyValue.ReferencedEntityName;

            // Generating the id mapper for the relation
            IIdMapper ownedIdMapper = ownedIdMapping.IdMapper.PrefixMappedProperties(lastPropertyPrefix);

            // Storing information about this relation
            mainGenerator.EntitiesConfigurations[entityName].AddToOneNotOwningRelation(
                propertyAuditingData.Name, owningReferencePropertyName,
                referencedEntityName, ownedIdMapper);

            // Adding mapper for the id
            PropertyData propertyData = propertyAuditingData.getPropertyData();

            mapper.AddComposite(propertyData, new OneToOneNotOwningMapper(owningReferencePropertyName,
                                                                          referencedEntityName, propertyData));
        }
コード例 #11
0
		public void ColumnMappingShouldWorkForChildRecordsets()
		{
			var childReader = new OneToOne<ChildFor109>(new ColumnOverride("Bar", "Foo"));

			var results = Connection().QuerySql("SELECT ID=1; SELECT ParentID=1, Bar=3", Parameters.Empty,
							Query.Returns(Some<ParentFor109>.Records)
								.ThenChildren(childReader)).First();

			Assert.AreEqual(1, results.Children.Count);
			Assert.AreEqual(3, results.Children[0].Foo);
		}
コード例 #12
0
		public void CanOverrideColumnsInline()
		{
			var mappedRecords = new OneToOne<HasDefaultRecordset>(
				new ColumnOverride<HasDefaultRecordset>("Foo", "ID"));

			var result = Connection().QuerySql(
				"SELECT Foo=1, ID=2",
				null,
				Query.Returns(mappedRecords)).First();

			Assert.AreEqual(1, result.ID);
			Assert.AreEqual(2, result.Beer.ID);
		}
コード例 #13
0
        public void Bind(IEnumerable <IEntityPropertyMapping> properties, Table table, IDictionary <string, MetaAttribute> inheritedMetas, Action <Property> modifier, Action <Property> addToModelAction)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (modifier == null)
            {
                throw new ArgumentNullException("modifier");
            }
            if (addToModelAction == null)
            {
                throw new ArgumentNullException("addToModelAction");
            }

            foreach (var entityPropertyMapping in properties)
            {
                Property property = null;

                string propertyName = entityPropertyMapping.Name;

                ICollectionPropertiesMapping collectionMapping;
                HbmManyToOne              manyToOneMapping;
                HbmAny                    anyMapping;
                HbmOneToOne               oneToOneMapping;
                HbmProperty               propertyMapping;
                HbmComponent              componentMapping;
                HbmDynamicComponent       dynamicComponentMapping;
                HbmNestedCompositeElement nestedCompositeElementMapping;
                HbmKeyProperty            keyPropertyMapping;
                HbmKeyManyToOne           keyManyToOneMapping;

                if ((propertyMapping = entityPropertyMapping as HbmProperty) != null)
                {
                    var value = new SimpleValue(table);
                    new ValuePropertyBinder(value, Mappings).BindSimpleValue(propertyMapping, propertyName, true);
                    property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas);
                    BindValueProperty(propertyMapping, property);
                }
                else if ((collectionMapping = entityPropertyMapping as ICollectionPropertiesMapping) != null)
                {
                    var    collectionBinder = new CollectionBinder(Mappings, dialect);
                    string propertyPath     = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName);

                    Mapping.Collection collection = collectionBinder.Create(collectionMapping, entityName, propertyPath, persistentClass,
                                                                            mappedClass, inheritedMetas);

                    mappings.AddCollection(collection);

                    property = CreateProperty(collectionMapping, className, collection, inheritedMetas);
                    BindCollectionProperty(collectionMapping, property);
                }
                else if ((manyToOneMapping = entityPropertyMapping as HbmManyToOne) != null)
                {
                    var value = new ManyToOne(table);
                    BindManyToOne(manyToOneMapping, value, propertyName, true);
                    property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas);
                    BindManyToOneProperty(manyToOneMapping, property);
                }
                else if ((componentMapping = entityPropertyMapping as HbmComponent) != null)
                {
                    string subpath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName);
                    var    value   = CreateNewComponent(table);
                    // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute
                    System.Type reflectedClass = mappedClass == null ? null : GetPropertyType(componentMapping.Class, mappedClass, propertyName, componentMapping.Access);
                    BindComponent(componentMapping, value, reflectedClass, entityName, subpath, componetDefaultNullable, inheritedMetas);
                    property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas);
                    BindComponentProperty(componentMapping, property, value);
                }
                else if ((oneToOneMapping = entityPropertyMapping as HbmOneToOne) != null)
                {
                    var value = new OneToOne(table, persistentClass);
                    BindOneToOne(oneToOneMapping, value);
                    property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas);
                    BindOneToOneProperty(oneToOneMapping, property);
                }
                else if ((dynamicComponentMapping = entityPropertyMapping as HbmDynamicComponent) != null)
                {
                    string subpath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName);
                    var    value   = CreateNewComponent(table);
                    // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute
                    System.Type reflectedClass = mappedClass == null ? null : GetPropertyType(dynamicComponentMapping.Class, mappedClass, propertyName, dynamicComponentMapping.Access);
                    BindComponent(dynamicComponentMapping, value, reflectedClass, entityName, subpath, componetDefaultNullable, inheritedMetas);
                    property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas);
                    BindComponentProperty(dynamicComponentMapping, property, value);
                }
                else if ((anyMapping = entityPropertyMapping as HbmAny) != null)
                {
                    var value = new Any(table);
                    BindAny(anyMapping, value, true);
                    property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas);
                    BindAnyProperty(anyMapping, property);
                }
                else if ((nestedCompositeElementMapping = entityPropertyMapping as HbmNestedCompositeElement) != null)
                {
                    if (component == null)
                    {
                        throw new AssertionFailure("Nested Composite Element without a owner component.");
                    }
                    string subpath = propertyName == null ? null : StringHelper.Qualify(propertyBasePath, propertyName);
                    var    value   = CreateNewComponent(table);
                    // NH: Modified from H2.1 to allow specifying the type explicitly using class attribute
                    System.Type reflectedClass = mappedClass == null ? null : GetPropertyType(nestedCompositeElementMapping.Class, mappedClass, propertyName, nestedCompositeElementMapping.access);
                    BindComponent(nestedCompositeElementMapping, value, reflectedClass, entityName, subpath, componetDefaultNullable, inheritedMetas);
                    property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas);
                }
                else if ((keyPropertyMapping = entityPropertyMapping as HbmKeyProperty) != null)
                {
                    var value = new SimpleValue(table);
                    new ValuePropertyBinder(value, Mappings).BindSimpleValue(keyPropertyMapping, propertyName, componetDefaultNullable);
                    property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas);
                }
                else if ((keyManyToOneMapping = entityPropertyMapping as HbmKeyManyToOne) != null)
                {
                    var value = new ManyToOne(table);
                    BindKeyManyToOne(keyManyToOneMapping, value, propertyName, componetDefaultNullable);
                    property = CreateProperty(entityPropertyMapping, className, value, inheritedMetas);
                }

                if (property != null)
                {
                    modifier(property);
                    property.LogMapped(log);
                    addToModelAction(property);
                }
            }
        }