コード例 #1
0
        public void PerformCollectionChange(ISession session, string entityName, string propertyName, AuditConfiguration auditCfg, PersistentCollectionChangeData persistentCollectionChangeData, object revision)
        {
            var data = persistentCollectionChangeData.Data;

            session.Save(persistentCollectionChangeData.EntityName, data);
            SessionCacheCleaner.ScheduleAuditDataRemoval(session, data);
        }
コード例 #2
0
        public void Perform(ISession session, string entityName, object id, object data, object revision)
        {
            var auditedEntityName = _auditConfiguration.AuditEntCfg.GetAuditEntityName(entityName);

            var reuseEntityIdentifier = _auditConfiguration.GlobalCfg.AllowIdentifierReuse;
            // Update the end date of the previous row if this operation is expected to have a previous row
            var revisionTypeIsAdded = revisionType(_auditConfiguration, data) == RevisionType.Added;

            if (reuseEntityIdentifier || !revisionTypeIsAdded)
            {
                /*
                 * Constructing a query:
                 * select e from audited_ent e where e.end_rev is null and e.id = :id
                 */
                var qb = new QueryBuilder(auditedEntityName, QueryConstants.MiddleEntityAlias);

                // e.id = :id
                var idMapper = _auditConfiguration.EntCfg[entityName].IdMapper;
                idMapper.AddIdEqualsToQuery(qb.RootParameters, id, _auditConfiguration.AuditEntCfg.OriginalIdPropName, true);

                addEndRevisionNullRestriction(_auditConfiguration, qb);

                var l = qb.ToQuery(session).SetLockMode(QueryConstants.MiddleEntityAlias, LockMode.Upgrade).List();

                updateLastRevision(session, _auditConfiguration, l, id, auditedEntityName, revision, (!reuseEntityIdentifier || !revisionTypeIsAdded));
            }

            // Save the audit data
            session.Save(auditedEntityName, data);
            SessionCacheCleaner.ScheduleAuditDataRemoval(session, data);
        }
コード例 #3
0
        public void PerformCollectionChange(ISession session, string entityName, string propertyName, AuditConfiguration auditCfg, PersistentCollectionChangeData persistentCollectionChangeData, object revision)
        {
            var qb = new QueryBuilder(persistentCollectionChangeData.EntityName, QueryConstants.MiddleEntityAlias);

            var originalIdPropName   = _auditConfiguration.AuditEntCfg.OriginalIdPropName;
            var originalId           = (IDictionary)persistentCollectionChangeData.Data[originalIdPropName];
            var revisionFieldName    = auditCfg.AuditEntCfg.RevisionFieldName;
            var revisionTypePropName = auditCfg.AuditEntCfg.RevisionTypePropName;

            // Adding a parameter for each id component, except the rev number and type.
            foreach (DictionaryEntry originalIdKeyValue in originalId)
            {
                if (!revisionFieldName.Equals(originalIdKeyValue.Key) && !revisionTypePropName.Equals(originalIdKeyValue.Key))
                {
                    qb.RootParameters.AddWhereWithParam(originalIdPropName + "." + originalIdKeyValue.Key, true, "=", originalIdKeyValue.Value);
                }
            }

            var sessionFactory = ((ISessionImplementor)session).Factory;
            var propertyType   = sessionFactory.GetEntityPersister(entityName).GetPropertyType(propertyName);

            if (propertyType.IsCollectionType)
            {
                var collectionPropertyType = (CollectionType)propertyType;
                // Handling collection of components.
                if (collectionPropertyType.GetElementType(sessionFactory) is ComponentType)
                {
                    // Adding restrictions to compare data outside of primary key.
                    foreach (var dataEntry in persistentCollectionChangeData.Data)
                    {
                        if (!originalIdPropName.Equals(dataEntry.Key))
                        {
                            qb.RootParameters.AddWhereWithParam(dataEntry.Key, true, "=", dataEntry.Value);
                        }
                    }
                }
            }

            addEndRevisionNullRestriction(_auditConfiguration, qb);

            var l = qb.ToQuery(session).SetLockMode(QueryConstants.MiddleEntityAlias, LockMode.Upgrade).List();

            if (l.Count > 0)
            {
                updateLastRevision(session, _auditConfiguration, l, originalId, persistentCollectionChangeData.EntityName, revision, true);
            }

            // Save the audit data
            var data = persistentCollectionChangeData.Data;

            session.Save(persistentCollectionChangeData.EntityName, data);
            SessionCacheCleaner.ScheduleAuditDataRemoval(session, data);
        }
コード例 #4
0
        private void updateLastRevision(ISession session, AuditConfiguration auditCfg, IList l,
                                        object id, string auditedEntityName, object revision, bool throwIfNotOneEntry)
        {
            // There should be one entry
            if (l.Count == 1)
            {
                // Setting the end revision to be the current rev
                var previousData         = (IDictionary)l[0];
                var revisionEndFieldName = auditCfg.AuditEntCfg.RevisionEndFieldName;
                previousData[revisionEndFieldName] = revision;

                if (auditCfg.AuditEntCfg.IsRevisionEndTimestampEnabled)
                {
                    // Determine the value of the revision property annotated with @RevisionTimestamp
                    DateTime revisionEndTimestamp;
                    var      revEndTimestampFieldName = auditCfg.AuditEntCfg.RevisionEndTimestampFieldName;
                    var      revEndTimestampObj       = _auditConfiguration.RevisionTimestampGetter.Get(revision);

                    // convert to a DateTime
                    if (revEndTimestampObj is DateTime)
                    {
                        revisionEndTimestamp = (DateTime)revEndTimestampObj;
                    }
                    else
                    {
                        revisionEndTimestamp = new DateTime((long)revEndTimestampObj);
                    }

                    // Setting the end revision timestamp
                    previousData[revEndTimestampFieldName] = revisionEndTimestamp;
                }

                // Saving the previous version
                session.Save(auditedEntityName, previousData);
                SessionCacheCleaner.ScheduleAuditDataRemoval(session, previousData);
            }
            else
            {
                if (throwIfNotOneEntry)
                {
                    throw new InvalidOperationException("Cannot find previous revision for entity " + auditedEntityName + " and id " + id);
                }
            }
        }
 public void SaveRevisionData(ISession session, object revisionData)
 {
     session.Save(_revisionInfoEntityName, revisionData);
     SessionCacheCleaner.ScheduleAuditDataRemoval(session, revisionData);
 }
コード例 #6
0
 public void Perform(ISession session, string entityName, object id, object data, object revision)
 {
     session.Save(_auditConfiguration.AuditEntCfg.GetAuditEntityName(entityName), data);
     SessionCacheCleaner.ScheduleAuditDataRemoval(session, data);
 }