コード例 #1
0
        public long GetNextSequence(XPClassInfo classInfo)
        {
            if (classInfo == null)
            {
                throw new ArgumentNullException("classInfo");
            }
            var ci = classInfo;

            seq = euow.GetObjectByKey<Sequence>(ci.FullName, true);
            if (seq == null)
            {
                throw new InvalidOperationException(string.Format("Sequence for the {0} type was not found.", ci.FullName));
            }

            var nextSequence = seq.NextSequence;
            seq.NextSequence++;
            euow.FlushChanges();
            return nextSequence;
        }
コード例 #2
0
        public static void RegisterSequences(IEnumerable<ITypeInfo> persistentTypes)
        {
            if (persistentTypes != null)
            {
                using (var uow = new UnitOfWork(DefaultDataLayer))
                {
                    var sequenceList = new XPCollection<Sequence>(uow);
                    var typeToExistsMap = new Dictionary<string, bool>();
                    foreach (Sequence seq in sequenceList)
                    {
                        typeToExistsMap[seq.TypeName] = true;
                    }

                    foreach (ITypeInfo typeInfo in persistentTypes)
                    {
                        var ti = typeInfo;
                        if (typeToExistsMap.ContainsKey(ti.FullName))
                        {
                            continue;
                        }
                        while (ti.Base != null && ti.Base.IsPersistent)
                        {
                            ti = ti.Base;
                        }

                        var typeName = ti.FullName;
                        if (ti.IsInterface && ti.IsPersistent)
                        {
                            var generatedEntityType = XpoTypesInfoHelper.GetXpoTypeInfoSource().GetGeneratedEntityType(ti.Type);
                            if (generatedEntityType != null)
                            {
                                typeName = generatedEntityType.FullName;
                            }
                        }

                        if (typeToExistsMap.ContainsKey(typeName))
                        {
                            continue;
                        }
                        if (ti.IsPersistent)
                        {
                            typeToExistsMap[typeName] = true;
                            var seq = new Sequence(uow);
                            seq.TypeName = typeName;
                            seq.NextSequence = 1;
                        }
                    }

                    uow.CommitChanges();
                }
            }
        }