Transaction/Reflection
using System;
using System.Reflection;
namespace test
{
public class Controller
{
//...
public XmlDocument execute(XmlDocument oXml)
{
//this method receive a Xml string, materializes an instance of an object and invoke a method requested in this Xml (through Reflection)
//in this case the instance created is a Person object and the method called is add(save a object in a Relational DataBase)
}
}
}
using System;
using System.EnterpriseServices;
namespace test
{
public class Client : ServicedComponent
{
//...
}
}
using System;
using System.EnterpriseServices;
namespace test
{
[Transaction(TransactionOption.Required)]
public class Person : Client
{
//...
public void add(Object oObj)
{
PersistenceBroker broker = new PersistenceBroker();
Person person;
Address address;
try
{
person = (Person)oObj;
address = person.getAddress();
broker.add(person);
address.setIdClient(person.getIdClient());
address.add(address);
ContextUtil.SetComplete()
}
catch(Exception err)
{
ContextUtil.SetAbort()
throw new Exception(err.Message, err);
}
}
}
}
using System;
using System.EnterpriseServices;
namespace test
{
[Transaction(TransactionOption.Required)]
public class Address : ServicedComponent
{
//...
public void add(Object oObj)
{
PersistenceBroker broker = new PersistenceBroker();
Address address;
try
{
address = (Address)oObj;
broker.add(address);
ContextUtil.SetComplete()
}
catch(Exception err)
{
ContextUtil.SetAbort()
throw new Exception(err.Message, err);
}
}
}
}
using System;
using System.Reflection;
using System.EnterpriseServices;
namespace test
{
[Transaction(TransactionOption.Supported)]
public class PersistenceBroker
{
//...
public void add(Object oObj)
{
//through reflection this method creates a string with INSERT command and
//with ADO .Net this command is executed
}
}
}
This code seems that Ok, but after invocation of the method the object instanced doesnât exist anymore and I need the ID's returned in this object passed by reference.
Look if I don't use ContextUtil (or [AutoComplete]) in the Person and Address classes this error doesn't appear.
Fabio Ferreira Balota
__________________
Fabio Ferreira Balota
|