RE: Appropriate place for transaction code?

2007-05-07 Thread Michael.Davis
Thanks, that's helpful. I'll look into Spring.

I will be adding operations that do inserts and updates soon.

Regards,
Michael

 -Original Message-
 From: Glen Mazza [mailto:[EMAIL PROTECTED]
 Sent: Thursday, May 03, 2007 8:53 PM
 To: axis-user@ws.apache.org
 Subject: Re: Appropriate place for transaction code?
 
 
 Reading the third sentence of your email, you said the service is just
 *retrieving* data from the database (i.e. SQL SELECT), is 
 that correct?
 If so, commits would not be a concern for you--you may be able to keep
 your service in application scope[1] and just initialize an instance
 variable to hold the session factory.
 
 Otherwise, I don't know if you're using Spring but the Axis2 Spring
 guide[2] may give you some ideas until someone else can get 
 you a better
 answer.
 
 [1] http://www.developer.com/java/web/article.php/10935_3620661_2
 [2] http://ws.apache.org/axis2/1_2/spring.html
 
 Glen
 
 
 Am Donnerstag, den 03.05.2007, 16:26 -0400 schrieb
 [EMAIL PROTECTED]:
  Hi,
  
  I'm new to Axis. I'm using Axis2 1.1.1.
  
  I'm creating a service that retrieves data from a database. 
 I'm using Hibernate. For those of you not familiar with it, 
 the basic pattern of usage is that you create something 
 called a SessionFactory once when the application starts, and 
 then for each request/response cycle you create a Session. 
 When the response finishes, you commit the session.
  
  In regular web applications I create the session factory in 
 the ApplicationContext. Then I make a servlet filter that 
 creates the session and starts a transaction on the way in, 
 and then commits the transaction and closes the session on 
 the way out.
  
  I'm trying to figure out how to do this in Axis. I created 
 a module called hibernateTransactionModule. I've got two 
 handlers, one for the way in and one for the way out, each 
 attached to a new phase. Right now they're just saying 'hello 
 world' and it works, they do execute when I expect them to.
  
  So I've got three classes:
  
  HibernateTransactionModule implements 
 org.apache.axis2.modules.Module
  HibernateTransactionHandlerBegin extends AbstractHandler 
 implements Handler
  HibernateTransactionHandlerEnd extends AbstractHandler 
 implements Handler
  
  My intuition tells me that 
 HibernateTransactionModule.init() would be the appropriate 
 place to create the hibernate session factory, 
 HibernateTransactionHandlerBegin.invoke() could create a 
 session for a request and put it into the messageContext, and 
 HibernateTransactionHandlerEnd.invoke() could commit the 
 transaction and close the session.
  
  But I can't see a place where I can store the session 
 factory where it can be accessible to the handlers.
  
  One possibility would be to use a static field in 
 HibernateTransactionHandlerBegin but that would be an ugly 
 hack. Any suggestions?
  
  Thanks
  Michael Davis
  www.damaru.com
  
  
 -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  
 
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 
 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Appropriate place for transaction code?

2007-05-07 Thread Michael.Davis
Thanks, that does help!
 
Michael

-Original Message-
From: robert lazarski [mailto:[EMAIL PROTECTED]
Sent: Monday, May 07, 2007 9:44 AM
To: axis-user@ws.apache.org
Subject: Re: Appropriate place for transaction code?


Hi Michael, 

When doing hibernate transactions with web services, one way to do it is to 
have the transaction boundary inside a method that the web service calls. 
Spring does that automagically if you set it up right - but it certainly isn't 
mandatory to use Spring to do hibernate transactions in a web services. 

What you describe by your servlet filter seems to be what spring does in its 
Open Session In View pattern, so on the UI layer you could use the data after 
the session would normally terminate. In this case you probably just need a 
method that you call in a web service that opens and closes the session - 
managed by yourself or spring - since the data would presumably be in an 
OMElement or the chosen databinding, and not using attached hibernate objects. 

HTH,
Robert 


On 5/7/07, [EMAIL PROTECTED]   mailto:[EMAIL PROTECTED] [EMAIL PROTECTED] 
wrote: 

Thanks, that's helpful. I'll look into Spring. 

I will be adding operations that do inserts and updates soon.

Regards,
Michael

 -Original Message-
 From: Glen Mazza [mailto: [EMAIL PROTECTED]  mailto:[EMAIL PROTECTED] ]
 Sent: Thursday, May 03, 2007 8:53 PM
 To: axis-user@ws.apache.org
 Subject: Re: Appropriate place for transaction code?


 Reading the third sentence of your email, you said the service is just 
 *retrieving* data from the database (i.e. SQL SELECT), is
 that correct?
 If so, commits would not be a concern for you--you may be able to keep
 your service in application scope[1] and just initialize an instance 
 variable to hold the session factory.

 Otherwise, I don't know if you're using Spring but the Axis2 Spring
 guide[2] may give you some ideas until someone else can get
 you a better 
 answer.

 [1] http://www.developer.com/java/web/article.php/10935_3620661_2
 [2] http://ws.apache.org/axis2/1_2/spring.html

 Glen


 Am Donnerstag, den 03.05.2007, 16:26 -0400 schrieb
 [EMAIL PROTECTED]  mailto:[EMAIL PROTECTED] :
  Hi,
 
  I'm new to Axis. I'm using Axis2 1.1.1.
 
  I'm creating a service that retrieves data from a database.
 I'm using Hibernate. For those of you not familiar with it, 
 the basic pattern of usage is that you create something
 called a SessionFactory once when the application starts, and
 then for each request/response cycle you create a Session.
 When the response finishes, you commit the session. 
 
  In regular web applications I create the session factory in
 the ApplicationContext. Then I make a servlet filter that
 creates the session and starts a transaction on the way in,
 and then commits the transaction and closes the session on
 the way out.
 
  I'm trying to figure out how to do this in Axis. I created
 a module called hibernateTransactionModule. I've got two 
 handlers, one for the way in and one for the way out, each
 attached to a new phase. Right now they're just saying 'hello
 world' and it works, they do execute when I expect them to.
 
  So I've got three classes:
 
  HibernateTransactionModule implements
 org.apache.axis2.modules.Module
  HibernateTransactionHandlerBegin extends AbstractHandler 
 implements Handler
  HibernateTransactionHandlerEnd extends AbstractHandler
 implements Handler
 
  My intuition tells me that
 HibernateTransactionModule.init() would be the appropriate 
 place to create the hibernate session factory,
 HibernateTransactionHandlerBegin.invoke() could create a
 session for a request and put it into the messageContext, and
 HibernateTransactionHandlerEnd.invoke () could commit the
 transaction and close the session.
 
  But I can't see a place where I can store the session
 factory where it can be accessible to the handlers.
 
  One possibility would be to use a static field in
 HibernateTransactionHandlerBegin but that would be an ugly
 hack. Any suggestions?
 
  Thanks
  Michael Davis
  www.damaru.com
 
 
 -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 


 - 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]  mailto:[EMAIL 
 PROTECTED] 



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






RE: Appropriate place for transaction code?

2007-05-07 Thread Michael.Davis
That's great! Thank you very much.

Michael

 -Original Message-
 From: Hickman, Craig [mailto:[EMAIL PROTECTED]
 Sent: Friday, May 04, 2007 1:18 PM
 To: 'axis-user@ws.apache.org'
 Subject: RE: Appropriate place for transaction code?
 
 
 One way you could do this is to just use Spring's api, or you 
 could inject
 it yourself as in:
 
 Now for specific injection (unrelated to above) of SessionFactory:
 
 ?xml version=1.0 encoding=UTF-8?
 beans
 
 bean id=your name class=org.example.impl.HibernateExample
 property name=sessionFactory ref=sessionFactoryBean/
 /bean
 
 bean id=sessionFactoryBean
 class=org.springframework.orm.hibernate3.annotation.Annotatio
 nSessionFactor
 yBean
 property name=dataSource ref=dataSource/
 property name=annotatedClasses
 list
 valueorg.example.ExampleBean/value
 /list
 /property
 property name=hibernateProperties
 value
 hibernate.dialect=org.hibernate.dialect.HSQLDialect
 hibernate.show_sql=true
 /value
 /property
 /bean
 
 /beans
 
 Also a good article for Session injection:
 
 http://unitils.sourceforge.net/spring_article.html
 
 Also roll your own beans too:
 
  Let's say you wanted to inject the datasource. Create a util 
 class using a
 synchronized singleton and then add your method as private for the
 appContext lookup (this can also be done for your own beans 
 using a factory
 method as well):
 
 private final static DataSource getDataSource() {
   ApplicationContext ctx = new
 ClassPathXmlApplicationContext(WSConstants.APPLICATION_CONTEXT );
   DataSource ds = (DataSource)ctx.getBean(ds);
   
   return ds;
   }
 
 Then add your public method:
 
public ExampleDaoImpl getExampleDS() {
   ExampleDaoImpl dataSupport = new ExampleDaoImpl();
   dataSupport.setDataSource(getDataSource());
   return dataSupport;
   }
 
 ---
 
 Now for injection of your own beans:
 
 Create a bean xml and add this to it and place it in WEB-INF 
 (later use ant
 to place it in build directory and classes, because it will 
 be referenced
 from the classpath using a specialized method):
 
  start of xml --
 ?xml version=1.0 encoding=UTF-8?
 !DOCTYPE beans SYSTEM 
 http://@TLD_HOST_WEB_SERVER@/dtd/spring-beans.dtd;
 beans
 
 !-- The factory bean, which contains a method called create.. --
 bean id=exampleBeanFactory class=com.your
 path.services.core.ExampleBeanFactory/
 
 
 !-- The bean to be created via the factory bean --
 bean id=SsoBO
   factory-bean=exampleBeanFactory
   factory-method=createExampleBO/
   
 /beans
 -- end of xml -
 
 Now create two classes:
 
 
 public interface AbstractBeanFactory {
   
   public ExampleBO createExampleBean();
 
 }
 
 public class ExampleBeanFactory implements AbstractBeanFactory {
   
   
 public ExampleBean createExampleBean(){
 return new ExampleBean();
 }
   
 
 }
 
  //--- utility method
public  Object getBean(String bean) {
 ClassPathResource res = new
 ClassPathResource(beans.xml); // lookup your bean
 XmlBeanFactory factory = new XmlBeanFactory(res);
 Object obj = factory.getBean(bean);
 
 return obj;
 }
 
 
 Then I can create the instance ( I used a service bean helper 
 ), and call
 the utility method in the init:
 
  private ServiceBeanHelper() {
   super();
   
 this.setSsoBO((SsoBO)utils.getBean(WSConstants.EXAMPLE_BEAN
 )); 
   }
 
   
 
 
 
 
 
 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, May 03, 2007 2:26 PM
 To: axis-user@ws.apache.org
 Subject: Appropriate place for transaction code?
 
 Hi,
 
 I'm new to Axis. I'm using Axis2 1.1.1.
 
 I'm creating a service that retrieves data from a database. I'm using
 Hibernate. For those of you not familiar with it, the basic 
 pattern of usage
 is that you create something called a SessionFactory once when the
 application starts, and then for each request/response cycle 
 you create a
 Session. When the response finishes, you commit the session.
 
 In regular web applications I create the session factory in the
 ApplicationContext. Then I make a servlet filter that creates 
 the session
 and starts a transaction on the way in, and then commits the 
 transaction and
 closes the session on the way out.
 
 I'm trying to figure out how to do this in Axis. I created a 
 module called
 hibernateTransactionModule. I've got two handlers, one for 
 the way in and
 one for the way out, each attached to a new phase. Right now 
 they're just
 saying 'hello world' and it works, they do execute when I 
 expect them to.
 
 So I've got three classes

RE: Appropriate place for transaction code?

2007-05-04 Thread Hickman, Craig
One way you could do this is to just use Spring's api, or you could inject
it yourself as in:

Now for specific injection (unrelated to above) of SessionFactory:

?xml version=1.0 encoding=UTF-8?
beans

bean id=your name class=org.example.impl.HibernateExample
property name=sessionFactory ref=sessionFactoryBean/
/bean

bean id=sessionFactoryBean
class=org.springframework.orm.hibernate3.annotation.AnnotationSessionFactor
yBean
property name=dataSource ref=dataSource/
property name=annotatedClasses
list
valueorg.example.ExampleBean/value
/list
/property
property name=hibernateProperties
value
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.show_sql=true
/value
/property
/bean

/beans

Also a good article for Session injection:

http://unitils.sourceforge.net/spring_article.html

Also roll your own beans too:

 Let's say you wanted to inject the datasource. Create a util class using a
synchronized singleton and then add your method as private for the
appContext lookup (this can also be done for your own beans using a factory
method as well):

private final static DataSource getDataSource() {
ApplicationContext ctx = new
ClassPathXmlApplicationContext(WSConstants.APPLICATION_CONTEXT );
DataSource ds = (DataSource)ctx.getBean(ds);

return ds;
}

Then add your public method:

   public ExampleDaoImpl getExampleDS() {
ExampleDaoImpl dataSupport = new ExampleDaoImpl();
dataSupport.setDataSource(getDataSource());
return dataSupport;
}

---

Now for injection of your own beans:

Create a bean xml and add this to it and place it in WEB-INF (later use ant
to place it in build directory and classes, because it will be referenced
from the classpath using a specialized method):

 start of xml --
?xml version=1.0 encoding=UTF-8?
!DOCTYPE beans SYSTEM http://@TLD_HOST_WEB_SERVER@/dtd/spring-beans.dtd;
beans

!-- The factory bean, which contains a method called create.. --
bean id=exampleBeanFactory class=com.your
path.services.core.ExampleBeanFactory/


!-- The bean to be created via the factory bean --
bean id=SsoBO
  factory-bean=exampleBeanFactory
  factory-method=createExampleBO/
  
/beans
-- end of xml -

Now create two classes:


public interface AbstractBeanFactory {

public ExampleBO createExampleBean();

}

public class ExampleBeanFactory implements AbstractBeanFactory {


public ExampleBean createExampleBean(){
return new ExampleBean();
}


}

 //--- utility method
   public  Object getBean(String bean) {
  ClassPathResource res = new
ClassPathResource(beans.xml); // lookup your bean
  XmlBeanFactory factory = new XmlBeanFactory(res);
  Object obj = factory.getBean(bean);
  
  return obj;
  }


Then I can create the instance ( I used a service bean helper ), and call
the utility method in the init:

 private ServiceBeanHelper() {
super();
this.setSsoBO((SsoBO)utils.getBean(WSConstants.EXAMPLE_BEAN
)); 
}

  





-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 
Sent: Thursday, May 03, 2007 2:26 PM
To: axis-user@ws.apache.org
Subject: Appropriate place for transaction code?

Hi,

I'm new to Axis. I'm using Axis2 1.1.1.

I'm creating a service that retrieves data from a database. I'm using
Hibernate. For those of you not familiar with it, the basic pattern of usage
is that you create something called a SessionFactory once when the
application starts, and then for each request/response cycle you create a
Session. When the response finishes, you commit the session.

In regular web applications I create the session factory in the
ApplicationContext. Then I make a servlet filter that creates the session
and starts a transaction on the way in, and then commits the transaction and
closes the session on the way out.

I'm trying to figure out how to do this in Axis. I created a module called
hibernateTransactionModule. I've got two handlers, one for the way in and
one for the way out, each attached to a new phase. Right now they're just
saying 'hello world' and it works, they do execute when I expect them to.

So I've got three classes:

HibernateTransactionModule implements org.apache.axis2.modules.Module
HibernateTransactionHandlerBegin extends AbstractHandler implements Handler
HibernateTransactionHandlerEnd extends AbstractHandler implements Handler

My intuition tells me that HibernateTransactionModule.init() would be the
appropriate place to create the hibernate session factory,
HibernateTransactionHandlerBegin.invoke() 

Re: Appropriate place for transaction code?

2007-05-03 Thread Glen Mazza
Reading the third sentence of your email, you said the service is just
*retrieving* data from the database (i.e. SQL SELECT), is that correct?
If so, commits would not be a concern for you--you may be able to keep
your service in application scope[1] and just initialize an instance
variable to hold the session factory.

Otherwise, I don't know if you're using Spring but the Axis2 Spring
guide[2] may give you some ideas until someone else can get you a better
answer.

[1] http://www.developer.com/java/web/article.php/10935_3620661_2
[2] http://ws.apache.org/axis2/1_2/spring.html

Glen


Am Donnerstag, den 03.05.2007, 16:26 -0400 schrieb
[EMAIL PROTECTED]:
 Hi,
 
 I'm new to Axis. I'm using Axis2 1.1.1.
 
 I'm creating a service that retrieves data from a database. I'm using 
 Hibernate. For those of you not familiar with it, the basic pattern of usage 
 is that you create something called a SessionFactory once when the 
 application starts, and then for each request/response cycle you create a 
 Session. When the response finishes, you commit the session.
 
 In regular web applications I create the session factory in the 
 ApplicationContext. Then I make a servlet filter that creates the session and 
 starts a transaction on the way in, and then commits the transaction and 
 closes the session on the way out.
 
 I'm trying to figure out how to do this in Axis. I created a module called 
 hibernateTransactionModule. I've got two handlers, one for the way in and one 
 for the way out, each attached to a new phase. Right now they're just saying 
 'hello world' and it works, they do execute when I expect them to.
 
 So I've got three classes:
 
 HibernateTransactionModule implements org.apache.axis2.modules.Module
 HibernateTransactionHandlerBegin extends AbstractHandler implements Handler
 HibernateTransactionHandlerEnd extends AbstractHandler implements Handler
 
 My intuition tells me that HibernateTransactionModule.init() would be the 
 appropriate place to create the hibernate session factory, 
 HibernateTransactionHandlerBegin.invoke() could create a session for a 
 request and put it into the messageContext, and 
 HibernateTransactionHandlerEnd.invoke() could commit the transaction and 
 close the session.
 
 But I can't see a place where I can store the session factory where it can be 
 accessible to the handlers.
 
 One possibility would be to use a static field in 
 HibernateTransactionHandlerBegin but that would be an ugly hack. Any 
 suggestions?
 
 Thanks
 Michael Davis
 www.damaru.com
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]