I appreciate the meaning of POCO:)
I actually read your 'IEditableObject - Another behaviour for your
NHibernate entities' while I was doing my research and what I was
thinking was
a) I don't really want to implement my undo/redo as a series of
IEditable..CancelEdits and
b) This can't make my collections rollback adds/removes..
Thus I decieded to do what I did. I really like the PostSharp approach
and I'll take some more time to read into your IEditableCollection as
that sounds promising and like a proper way to do this thing. However,
I don't feel like what I've done is too far away from being just fine.
While tracing through my code I did find a bug.. that I solved by
uncommenting a line of code.. well kind-off :)
public override string GetEntityName(object entity)
{
var type = entity.GetType();
//if (entity is IProxyTargetAccessor)
type = type.BaseType;
return type.Name;
}
Now, I'll post two tests. The first one passes, the other one fails..
Also, I've made a test application for all this and I'll e-mail the
whole thing to you. What you'll get is the test in the debugger. And
hopefully everything will work out of the box. If anything by now you
should know that spam and poco are my two favourite words :D If it
turns out to be some stu-pid bug that I oversaw, I promise to bet my
life savings on Chelsea winning the Champions League. :)
[Test]
public void Updating_poco_entities_should_work()
{
//fetch POCOs from DB
var mp = new ManagerPool();
var compMan = mp.GetManager<CompanyManager>();
var comp = compMan.GetAll().First();
Assert.IsFalse(comp is IStateTrackable);
comp.Address = "1313 Webfoot Walk, Duckburg, Calisota";
Assert.AreSame(typeof(Company), comp.GetType());
compMan.SaveOrUpdate(comp);
//fetch the entity again from a new session
var mp2 = new ManagerPool();
var comp2 =
mp2.GetManager<CompanyManager>().GetAll().First();
Assert.AreEqual("1313 Webfoot Walk, Duckburg, Calisota",
comp2.Address);
}
[Test]
public void Updating_state_trackable_entities_should_work2()
{
//use an NHibernate.IInterceptor in NHibernate
configuration whoose Instantate method returns proxies with injected
undo/redo functionality.
var mp = new
ManagerPool(Shared.StateManager.NHibernateHelper.Helper);
var compMan = mp.GetManager<CompanyManager>();
var comp = compMan.GetAll().First();
Assert.IsTrue(comp is IStateTrackable);
var statemanager = (comp as IStateTrackable).Originator;
comp.Address = "1313 Webfoot Walk, Duckburg, Calisota";
Assert.IsTrue(statemanager.CanUndo);
Assert.AreEqual(1, statemanager.ActionsCount);
/*IProxyTargetAccessor.DynProxyGetTarget() sometimes
returns the proxy itself, so I added functionality in my proxy
creation process that keeps track of all the actual
target object references (from the time the proxy was
created).
This method undos the whole proxy generation, ie. it
traverses the target object (the proxy with undo/redo f) and setts all
its properties to the target object references.
In doing so I hope get the original object.
To recap, copm is a Castle.Proxies.CompanyProxy and all
its properties are Proxies. comp's target is a Company and the Detach
method returns that exact Company instance
and likewise recursively sets all its properties to
their targets.
However, the Company I get here is obviously not Company
enough.. */
var myComp = statemanager.Detach(comp);
Assert.AreSame(myComp, (comp as
IStateTrackable).ProxyTarget);
Assert.AreSame(typeof(Company), myComp.GetType());
Assert.IsFalse(statemanager.IsStateTrackable(myComp));
//fails here - NHibernate.MappingException : No persister
for: Company
compMan.SaveOrUpdate(myComp);
var mp2 = new ManagerPool();
var comp2 =
mp2.GetManager<CompanyManager>().GetAll().First();
Assert.AreEqual("1313 Webfoot Walk, Duckburg, Calisota",
comp2.Address);
}
On Mar 7, 6:58 pm, Fabio Maulo <[email protected]> wrote:
> Perhaps you may send a POCO of code (in Spanish and in Italian POCO =
> "little bit").
>
>
>
>
>
> On Sat, Mar 5, 2011 at 11:34 PM, H.Alex <[email protected]> wrote:
> > I'm sorry for spaming, but here's the stack trace and to note that,
> > ofcourse, my mappings are ok..
>
> > Test
>
> > 'Indigo.Domain.Tests.StateManager_Fixture.Updating_state_trackable_entities_should_work2'
> > failed: NHibernate.MappingException : No persister for: Company
> > at NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String
> > entityName)
> > at NHibernate.Impl.SessionImpl.GetEntityPersister(String entityName,
> > Object obj)
> > at NHibernate.Engine.ForeignKeys.IsTransient(String entityName,
> > Object entity, Nullable`1 assumed, ISessionImplementor session)
> > at
> > NHibernate.Event.Default.AbstractSaveEventListener.GetEntityState(Object
> > entity, String entityName, EntityEntry entry, ISessionImplementor
> > source)
> > at
>
> > NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent
> > event)
> > at
>
> > NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent
> > event)
> > at NHibernate.Impl.SessionImpl.FireSaveOrUpdate(SaveOrUpdateEvent
> > event)
> > at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
> > Domain\ManagerBase.cs(86,0): at
> > Shared.Domain.ManagerBase`1.SaveOrUpdate(T item)
> > Tests\StateManager_Fixture.cs(192,0): at
>
> > Indigo.Domain.Tests.StateManager_Fixture.Updating_state_trackable_entities_should_work2()
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=en.
>
> --
> Fabio Maulo- Hide quoted text -
>
> - Show quoted text -
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.