Пример #1
0
 /**
  * Creates a query, which will return entities satisfying some conditions (specified later),
  * at a given revision.
  * @param c Class of the entities for which to query.
  * @param revision Revision number at which to execute the query.
  * @return A query for entities at a given revision, to which conditions can be added and which
  * can then be executed. The result of the query will be a list of entities (beans), unless a
  * projection is added.
  */
 public IAuditQuery ForEntitiesAtRevision(System.Type c, long revision)
 {
     //throw new NotImplementedException("Query not implemented yet");
     ArgumentsTools.CheckNotNull(revision, "Entity revision");
     ArgumentsTools.CheckPositive(revision, "Entity revision");
     return(new EntitiesAtRevisionQuery(auditCfg, auditReaderImplementor, c, revision));
 }
Пример #2
0
 public DeclaredPersistentProperty(Property property, MemberInfo memberInfo)
 {
     ArgumentsTools.CheckNotNull(property, "property");
     ArgumentsTools.CheckNotNull(memberInfo, "memberInfo");
     Member   = memberInfo;
     Property = property;
 }
Пример #3
0
        public IEnumerable <long> GetRevisions(string entityName, object primaryKey)
        {
            ArgumentsTools.CheckNotNull(primaryKey, "Primary key");

            if (!verCfg.EntCfg.IsVersioned(entityName))
            {
                throw new NotAuditedException(entityName, entityName + " is not versioned!");
            }

            var resultList = CreateQuery().ForRevisionsOfEntity(entityName, false, true)
                             .AddProjection(AuditEntity.RevisionNumber())
                             .Add(AuditEntity.Id().Eq(primaryKey))
                             .GetResultList();

            return(from object revision in resultList select Convert.ToInt64(revision));
        }
Пример #4
0
        public IList GetRevisions(System.Type cls, Object primaryKey)
        {
            // todo: if a class is not versioned from the beginning, there's a missing ADD rev - what then?
            ArgumentsTools.CheckNotNull(cls, "Entity class");
            ArgumentsTools.CheckNotNull(primaryKey, "Primary key");
            CheckSession();

            String entityName = cls.FullName;

            if (!verCfg.EntCfg.IsVersioned(entityName))
            {
                throw new NotAuditedException(entityName, entityName + " is not versioned!");
            }

            return(CreateQuery().ForRevisionsOfEntity(cls, false, true)
                   .AddProjection(AuditEntity.RevisionNumber())
                   .Add(AuditEntity.Id().Eq(primaryKey))
                   .GetResultList());
        }
Пример #5
0
        public long GetRevisionNumberForDate(DateTime date)
        {
            ArgumentsTools.CheckNotNull(date, "Date of revision");
            CheckSession();

            IQuery query = verCfg.RevisionInfoQueryCreator.getRevisionNumberForDateQuery(Session, date);

            try {
                object res = query.UniqueResult();
                if (res == null)
                {
                    throw new RevisionDoesNotExistException(date);
                }

                return((long)res);
            } catch (NonUniqueResultException e) {
                throw new AuditException(e);
            }
        }
Пример #6
0
        public T FindRevision <T>(System.Type revisionEntityClass, long revision)
        {
            ArgumentsTools.CheckNotNull(revision, "Entity revision");
            ArgumentsTools.CheckPositive(revision, "Entity revision");
            CheckSession();

            IQuery query = verCfg.RevisionInfoQueryCreator.getRevisionQuery(Session, revision);

            try {
                object revisionData = query.UniqueResult();

                if (revisionData == null)
                {
                    throw new RevisionDoesNotExistException(revision);
                }

                return((T)revisionData);
            } catch (NonUniqueResultException e) {
                throw new AuditException(e);
            }
        }
Пример #7
0
        public DateTime GetRevisionDate(long revision)
        {
            ArgumentsTools.CheckNotNull(revision, "Entity revision");
            ArgumentsTools.CheckPositive(revision, "Entity revision");
            CheckSession();

            IQuery query = verCfg.RevisionInfoQueryCreator.getRevisionDateQuery(Session, revision);

            try {
                Object timestampObject = query.UniqueResult();
                if (timestampObject == null)
                {
                    throw new RevisionDoesNotExistException(revision);
                }

                // The timestamp object is either a date or a long
                return(timestampObject is DateTime ? (DateTime)timestampObject : new DateTime((long)timestampObject));
            } catch (NonUniqueResultException e) {
                throw new AuditException(e);
            }
        }
Пример #8
0
        public object Find(System.Type cls, object primaryKey, long revision)
        {
            ArgumentsTools.CheckNotNull(primaryKey, "Primary key");
            ArgumentsTools.CheckNotNull(revision, "Entity revision");
            ArgumentsTools.CheckPositive(revision, "Entity revision");
            CheckSession();

            String entityName = cls.FullName;

            if (!verCfg.EntCfg.IsVersioned(entityName))
            {
                throw new NotAuditedException(entityName, entityName + " is not versioned!");
            }

            if (FirstLevelCache.Contains(entityName, revision, primaryKey))
            {
                return(FirstLevelCache[entityName, revision, primaryKey]);
            }

            Object result;

            try
            {
                // The result is put into the cache by the entity instantiator called from the query
                result = CreateQuery().ForEntitiesAtRevision(cls, revision)
                         .Add(AuditEntity.Id().Eq(primaryKey)).GetSingleResult();
            }
            catch (NonUniqueResultException e)
            {
                throw new AuditException(e);
            }
            catch (HibernateException e)
            {//ORIG: NoResultException e
                result = null;
            }

            return(result);
        }
Пример #9
0
        public object Find(string entityName, object primaryKey, long revision, bool includeDeletions)
        {
            ArgumentsTools.CheckNotNull(primaryKey, "Primary key");
            ArgumentsTools.CheckPositive(revision, "Entity revision");

            if (!verCfg.EntCfg.IsVersioned(entityName))
            {
                throw new NotAuditedException(entityName, entityName + " is not versioned!");
            }

            object result;

            if (FirstLevelCache.TryGetValue(entityName, revision, primaryKey, out result))
            {
                return(result);
            }

            // The result is put into the cache by the entity instantiator called from the query
            result = CreateQuery().ForEntitiesAtRevision(entityName, revision, includeDeletions)
                     .Add(AuditEntity.Id().Eq(primaryKey)).GetSingleResult();

            return(result);
        }