Exemplo n.º 1
0
        public ICriteria EstablishCriteria(IShardedCriteria shardedCriteria)
        {
            CriteriaId critId = shardedCriteria.CriteriaId;
            ICriteria  crit   = null;

            if (criteriaMap.Keys.Contains(critId))
            {
                crit = criteriaMap[critId];
            }
            if (crit == null)
            {
                crit = shardedCriteria.CriteriaFactory.CreateCriteria(EstablishSession());
                criteriaMap.Add(critId, crit);
                ICollection <ICriteriaEvent> critEvents = null;
                if (criteriaEventMap.Keys.Contains(critId))
                {
                    critEvents = criteriaEventMap[critId];
                }
                if (critEvents != null)
                {
                    foreach (ICriteriaEvent critEvent in critEvents)
                    {
                        critEvent.OnEvent(crit);
                    }
                    critEvents.Clear();
                }
            }
            return(crit);
        }
Exemplo n.º 2
0
        public ICriteria GetCriteriaById(CriteriaId id)
        {
            ICriteria value;

            criteriaMap.TryGetValue(id, out value);
            return(value);
        }
Exemplo n.º 3
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }

            if (!(o is CriteriaId))
            {
                return(false);
            }

            CriteriaId criteriaId = (CriteriaId)o;

            if (id != criteriaId.id)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
 /// <summary>
 /// @see Criteria#uniqueResult()
 /// </summary>
 /// <param name="criteriaId"></param>
 /// <returns></returns>
 public object UniqueResult(CriteriaId criteriaId)
 {
     return(criteriaMap[criteriaId].UniqueResult());
 }
Exemplo n.º 5
0
 /// <summary>
 /// @see Criteria#list()
 /// </summary>
 /// <param name="criteriaId"></param>
 /// <returns></returns>
 public IList <object> List(CriteriaId criteriaId)
 {
     return(criteriaMap[criteriaId].List <object>());
 }
Exemplo n.º 6
0
 public void AddCriteriaEvent(CriteriaId id, ICriteriaEvent @event)
 {
     AddEventToMap(criteriaEventMap, id, @event);
 }
Exemplo n.º 7
0
        public void TestAddCriteriaEvent()
        {
            ShardImpl shard = new ShardImpl(new ShardId(1), Stub <ISessionFactoryImplementor>());//new SessionFactoryDefaultMock()

            try
            {
                shard.AddCriteriaEvent(null, null);
                Assert.Fail("expected nre");
            }
            catch (NullReferenceException nre)
            {
                // good
            }

            CriteriaId criteriaId = new CriteriaId(2);

            try
            {
                shard.AddCriteriaEvent(criteriaId, null);
                Assert.Fail("expected nre");
            }
            catch (NullReferenceException nre)
            {
                // good
            }

            ICriteriaEvent ce = Stub <ICriteriaEvent>();//new CriteriaEventDefaultMock()

            try
            {
                shard.AddCriteriaEvent(null, ce);
                Assert.Fail("expected nre");
            }
            catch (NullReferenceException nre)
            {
                // good
            }

            shard.AddCriteriaEvent(criteriaId, ce);
            //Assert.IsNotNull(shard.GetCriteriaEventMap());
            //Assert.Equals(1, shard.getCriteriaEventMap().size());
            //Assert.Equals(1, shard.getCriteriaEventMap().get(criteriaId).size());
            //Assert.AreSame(ce, shard.getCriteriaEventMap().get(criteriaId).get(0));

            // now add another event to the same criteria
            ICriteriaEvent anotherCe = Stub <ICriteriaEvent>();
            //shard.AddCriteriaEvent(criteriaId, anotherCe);
            //Assert.IsNotNull(shard.getCriteriaEventMap());
            //Assert.Equals(1, shard.getCriteriaEventMap().size());
            //Assert.Equals(2, shard.getCriteriaEventMap().get(criteriaId).size());
            //Assert.AreSame(ce, shard.getCriteriaEventMap().get(criteriaId).get(0));
            //Assert.AreSame(anotherCe, shard.getCriteriaEventMap().get(criteriaId).get(1));

            // now add an event to a different criteria
            CriteriaId     anotherCriteriaId = new CriteriaId(3);
            ICriteriaEvent yetAnotherCe      = Stub <ICriteriaEvent>();

            shard.AddCriteriaEvent(anotherCriteriaId, yetAnotherCe);
            //Assert.IsNotNull(shard.getCriteriaEventMap());
            //Assert.Equals(2, shard.getCriteriaEventMap().size());
            //Assert.Equals(2, shard.getCriteriaEventMap().get(criteriaId).size());
            //Assert.AreSame(ce, shard.getCriteriaEventMap().get(criteriaId).get(0));
            //Assert.AreSame(anotherCe, shard.getCriteriaEventMap().get(criteriaId).get(1));
            //Assert.Equals(1, shard.getCriteriaEventMap().get(anotherCriteriaId).size());
            //Assert.AreSame(yetAnotherCe, shard.getCriteriaEventMap().get(anotherCriteriaId).get(0));
        }