Skip to content

Commit

Permalink
removed unnecessary generic stuff
Browse files Browse the repository at this point in the history
git-svn-id: https://nhcontrib.svn.sourceforge.net/svnroot/nhcontrib/trunk@1654 d7b3437e-3345-0410-94a8-cbd290e69f67
  • Loading branch information
rogerkratz committed Feb 3, 2011
1 parent 62b7331 commit c70f626
Show file tree
Hide file tree
Showing 34 changed files with 178 additions and 486 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,20 @@ private bool FillPropertyData(MemberInfo property,

// check if a property is declared as not audited to exclude it
// useful if a class is audited but some properties should be excluded
var unVer = _metaDataStore.MemberMeta<NotAuditedAttribute>(property);
if (unVer != null)
if (_metaDataStore.MemberMeta<NotAuditedAttribute>(property) != null)
{
return false;
}
// if the optimistic locking field has to be unversioned and the current property
// is the optimistic locking field, don't audit it
if (_globalCfg.DoNotAuditOptimisticLockingField)
if (_globalCfg.DoNotAuditOptimisticLockingField &&
_persistentPropertiesSource.VersionedProperty != null &&
_persistentPropertiesSource.VersionedProperty.Name.Equals(mappedPropertyName))
{
if (_persistentPropertiesSource.VersionedProperty != null)
{
if (_persistentPropertiesSource.VersionedProperty.Name.Equals(mappedPropertyName))
return false;
}
return false;
}

// Checking if this property is explicitly audited or if all properties are.
//AuditedAttribute aud = property.getAnnotation(typeof(AuditedAttribute));
var aud = _metaDataStore.MemberMeta<AuditedAttribute>(property);
if (aud != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ public EntityInstantiator(AuditConfiguration verCfg, IAuditReaderImplementor ver
/// <param name="versionsEntity">An entry in the versions table, from which data should be mapped.</param>
/// <param name="revision">Revision at which this entity was read.</param>
/// <returns>An entity instance, with versioned properties set as in the versionsEntity map, and proxies created for collections.</returns>
public object CreateInstanceFromVersionsEntity(string entityName, IDictionary<string,object> versionsEntity, long revision)
public object CreateInstanceFromVersionsEntity(string entityName, IDictionary versionsEntity, long revision)
{
const string typeKey = "$type$";

if (versionsEntity == null)
{
return null;
}

object type;
string name = null;
if(versionsEntity.TryGetValue("$type$", out type))
if(versionsEntity.Contains(typeKey))
{
name = verCfg.EntCfg.GetEntityNameForVersionsEntityName((string)type);
name = verCfg.EntCfg.GetEntityNameForVersionsEntityName((string)versionsEntity[typeKey]);
}

if (name != null)
Expand All @@ -48,7 +49,7 @@ public object CreateInstanceFromVersionsEntity(string entityName, IDictionary<st

// First mapping the primary key
var idMapper = verCfg.EntCfg[entityName].GetIdMapper();
var originalId = DictionaryWrapper<string,object>.Wrap((IDictionary)versionsEntity[verCfg.AuditEntCfg.OriginalIdPropName]);
var originalId = (IDictionary)versionsEntity[verCfg.AuditEntCfg.OriginalIdPropName];

var primaryKey = idMapper.MapToIdFromMap(originalId);

Expand Down Expand Up @@ -81,9 +82,9 @@ public object CreateInstanceFromVersionsEntity(string entityName, IDictionary<st
return ret;
}

public void AddInstancesFromVersionsEntities(String entityName, IList addTo, IEnumerable<IDictionary<string, object>> versionsEntities, long revision)
public void AddInstancesFromVersionsEntities(String entityName, IList addTo, IEnumerable<IDictionary> versionsEntities, long revision)
{
foreach (IDictionary<string,object> versionsEntity in versionsEntities)
foreach (var versionsEntity in versionsEntities)
{
addTo.Add(CreateInstanceFromVersionsEntity(entityName, versionsEntity, revision));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -16,12 +17,14 @@ namespace NHibernate.Envers.Entities.Mapper
/**
///@author Simon Duduica, port of Envers omonyme class by Adam Warski (adam at warski dot org)
*/
public class ComponentPropertyMapper : IPropertyMapper, ICompositeMapperBuilder {
public class ComponentPropertyMapper : IPropertyMapper, ICompositeMapperBuilder
{
private readonly PropertyData propertyData;
private readonly MultiPropertyMapper _delegate;
private readonly String componentClassName;

public ComponentPropertyMapper(PropertyData propertyData, String componentClassName) {
public ComponentPropertyMapper(PropertyData propertyData, String componentClassName)
{
this.propertyData = propertyData;
this._delegate = new MultiPropertyMapper();
this.componentClassName = componentClassName;
Expand All @@ -44,7 +47,7 @@ public bool MapToMapFromEntity(ISessionImplementor session, IDictionary<String,
return _delegate.MapToMapFromEntity(session, data, newObj, oldObj);
}

public void MapToEntityFromMap(AuditConfiguration verCfg, Object obj, IDictionary<String, Object> data,
public void MapToEntityFromMap(AuditConfiguration verCfg, Object obj, IDictionary data,
Object primaryKey, IAuditReaderImplementor versionsReader, long revision)
{
if (data == null || obj == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -33,7 +34,7 @@ public interface IPropertyMapper
* @param versionsReader VersionsReader for reading relations
* @param revision Revision at which the object is read, for reading relations
*/
void MapToEntityFromMap(AuditConfiguration verCfg, Object obj, IDictionary<String,object> data, Object primaryKey,
void MapToEntityFromMap(AuditConfiguration verCfg, object obj, IDictionary data, object primaryKey,
IAuditReaderImplementor versionsReader, long revision);

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using NHibernate.Envers.Exceptions;


namespace NHibernate.Envers.Entities.Mapper.Id
{
public abstract class AbstractCompositeIdMapper : AbstractIdMapper , ISimpleIdMapperBuilder
public abstract class AbstractCompositeIdMapper : AbstractIdMapper , ISimpleIdMapperBuilder
{
protected IDictionary<PropertyData, SingleIdMapper> ids;
protected System.Type compositeIdClass;
Expand All @@ -22,7 +22,7 @@ public void Add(PropertyData propertyData)
ids.Add(propertyData, new SingleIdMapper(propertyData));
}

public override object MapToIdFromMap(IDictionary<string, object> data)
public override object MapToIdFromMap(IDictionary data)
{
object ret;
try
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using NHibernate.Envers.Tools.Query;

Expand Down Expand Up @@ -61,9 +62,9 @@ public void AddNamedIdEqualsToQuery(Parameters parameters, String prefix, bool e
public abstract IList<QueryParameterData> MapToQueryParametersFromId(object obj);
public abstract void MapToMapFromId(IDictionary<string, object> data, object obj);
public abstract void MapToMapFromEntity(IDictionary<string, object> data, object obj);
public abstract void MapToEntityFromMap(object obj, IDictionary<string, object> data);
public abstract void MapToEntityFromMap(object obj, IDictionary data);
public abstract object MapToIdFromEntity(object data);
public abstract object MapToIdFromMap(IDictionary<string, object> data);
public abstract object MapToIdFromMap(IDictionary data);
public abstract IIdMapper PrefixMappedProperties(string prefix);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using System.Collections;
using System.Collections.Generic;
using NHibernate.Envers.Tools.Reflection;
using NHibernate.Util;
using NHibernate.Envers.Exceptions;
using System.Reflection;

namespace NHibernate.Envers.Entities.Mapper.Id
{
public class EmbeddedIdMapper : AbstractCompositeIdMapper , ISimpleIdMapperBuilder
public class EmbeddedIdMapper : AbstractCompositeIdMapper, ISimpleIdMapperBuilder
{
private readonly PropertyData idPropertyData;

Expand Down Expand Up @@ -35,7 +35,7 @@ public override void MapToMapFromEntity(IDictionary<string, object> data, Object
MapToMapFromId(data, getter.Get(obj));
}

public override void MapToEntityFromMap(object obj, IDictionary<string, object> data)
public override void MapToEntityFromMap(object obj, IDictionary data)
{
if (data == null || obj == null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Envers.Query;
using NHibernate.Envers.Tools.Query;

namespace NHibernate.Envers.Entities.Mapper.Id
{
/**
* @author Simon Duduica, port of Envers omonyme class by Adam Warski (adam at warski dot org)
*/
public interface IIdMapper
{
void MapToMapFromId(IDictionary<String, Object> data, Object obj);

void MapToMapFromEntity(IDictionary<String, Object> data, Object obj);

void MapToEntityFromMap(Object obj, IDictionary<string,object> data);

Object MapToIdFromEntity(Object data);

Object MapToIdFromMap(IDictionary<string,object> data);
void MapToMapFromId(IDictionary<string, object> data, object obj);
void MapToMapFromEntity(IDictionary<string, object> data, object obj);
void MapToEntityFromMap(object obj, IDictionary data);
object MapToIdFromEntity(object data);
object MapToIdFromMap(IDictionary data);

/**
* Creates a mapper with all mapped properties prefixed. A mapped property is a property which
* is directly mapped to values (not composite).
* @param prefix Prefix to add to mapped properties
* @return A copy of the current property mapper, with mapped properties prefixed.
*/
IIdMapper PrefixMappedProperties(String prefix);
IIdMapper PrefixMappedProperties(string prefix);

/**
* @param obj Id from which to map.
* @return A set parameter data, needed to build a query basing on the given id.
*/
IList<QueryParameterData> MapToQueryParametersFromId(Object obj);
IList<QueryParameterData> MapToQueryParametersFromId(object obj);

/**
* Adds query statements, which contains restrictions, which express the property that the id of the entity
Expand All @@ -43,7 +33,7 @@ public interface IIdMapper
* @param prefix1 First alias of the entity + prefix to add to the properties.
* @param prefix2 Second alias of the entity + prefix to add to the properties.
*/
void AddIdsEqualToQuery(Parameters parameters, String prefix1, String prefix2);
void AddIdsEqualToQuery(Parameters parameters, string prefix1, string prefix2);

/**
* Adds query statements, which contains restrictions, which express the property that the id of the entity
Expand All @@ -55,7 +45,7 @@ public interface IIdMapper
* of the equation.
* @param prefix2 Second alias of the entity + prefix to add to the properties.
*/
void AddIdsEqualToQuery(Parameters parameters, String prefix1, IIdMapper mapper2, String prefix2);
void AddIdsEqualToQuery(Parameters parameters, string prefix1, IIdMapper mapper2, string prefix2);

/**
* Adds query statements, which contains restrictions, which express the property that the id of the entity
Expand All @@ -65,7 +55,7 @@ public interface IIdMapper
* @param prefix Prefix to add to the properties (may be null).
* @param equals Should this query express the "=" relation or the "<>" relation.
*/
void AddIdEqualsToQuery(Parameters parameters, Object id, String prefix, bool equals);
void AddIdEqualsToQuery(Parameters parameters, object id, string prefix, bool equals);

/**
* Adds query statements, which contains named parameters, which express the property that the id of the entity
Expand All @@ -75,6 +65,6 @@ public interface IIdMapper
* @param prefix Prefix to add to the properties (may be null).
* @param equals Should this query express the "=" relation or the "<>" relation.
*/
void AddNamedIdEqualsToQuery(Parameters parameters, String prefix, bool equals);
void AddNamedIdEqualsToQuery(Parameters parameters, string prefix, bool equals);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Envers.Exceptions;
using NHibernate.Util;

namespace NHibernate.Envers.Entities.Mapper.Id
{

/**
* @author Catalina Panait, port of Envers omonyme class by Adam Warski (adam at warski dot org)
*/
public class MultipleIdMapper : AbstractCompositeIdMapper, ISimpleIdMapperBuilder
{
public MultipleIdMapper(System.Type compositeIdClass)
Expand All @@ -22,52 +16,58 @@ public override void MapToMapFromId(IDictionary<String, Object> data, Object obj
foreach (IIdMapper idMapper in ids.Values)
{
idMapper.MapToMapFromEntity(data, obj);
}
}
}
}

public override void MapToMapFromEntity(IDictionary<String, Object> data, Object obj)
{
MapToMapFromId(data, obj);
}

public override void MapToEntityFromMap(Object obj, IDictionary<String, Object> data) {
foreach (IIdMapper idMapper in ids.Values) {
idMapper.MapToEntityFromMap(obj,data);
}
}
public override void MapToEntityFromMap(Object obj, IDictionary data)
{
foreach (IIdMapper idMapper in ids.Values)
{
idMapper.MapToEntityFromMap(obj,data);
}
}

public override IIdMapper PrefixMappedProperties(String prefix)
{
MultipleIdMapper ret = new MultipleIdMapper(compositeIdClass);
MultipleIdMapper ret = new MultipleIdMapper(compositeIdClass);

foreach (PropertyData propertyData in ids.Keys) {
String propertyName = propertyData.Name;
ret.ids.Add(propertyData, new SingleIdMapper(new PropertyData(prefix + propertyName, propertyData)));
}
foreach (PropertyData propertyData in ids.Keys) {
String propertyName = propertyData.Name;
ret.ids.Add(propertyData, new SingleIdMapper(new PropertyData(prefix + propertyName, propertyData)));
}

return ret;
}
return ret;
}

public override Object MapToIdFromEntity(Object data)
{
if (data == null) {
return null;
}

Object ret;
try {
ret = Activator.CreateInstance(compositeIdClass );
//ret = Thread.currentThread().getContextClassLoader().loadClass(compositeIdClass).newInstance();
} catch (Exception e) {
throw new AuditException(e);
}

foreach (SingleIdMapper mapper in ids.Values) {
mapper.MapToEntityFromEntity(ret, data);
}

return ret;
}
if (data == null)
{
return null;
}

Object ret;
try
{
ret = Activator.CreateInstance(compositeIdClass );
}
catch (Exception e)
{
throw new AuditException(e);
}

foreach (SingleIdMapper mapper in ids.Values)
{
mapper.MapToEntityFromEntity(ret, data);
}

return ret;
}

public override IList<QueryParameterData> MapToQueryParametersFromId(Object obj)
{
Expand All @@ -82,10 +82,7 @@ public override IList<QueryParameterData> MapToQueryParametersFromId(Object obj)
ret.Add(new QueryParameterData(propertyData.Key, propertyData.Value));
}


return ret;
}


}
}
Loading

0 comments on commit c70f626

Please sign in to comment.