Re: Business Logic Javabeans

2002-04-13 Thread @Basebeans.com

Subject: Re: Business Logic Javabeans
From: "David Bolsover" <[EMAIL PROTECTED]>
 ===
Ric

Your proposals for saeparate classes to represent User and Database are very
close to the generally accepted way of doing things in struts.

To expand - In this situation, I would use classes like
***
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class User extends ActionForm
{
  private String userCred = "";
  public void setUserCred(String p_userCred) {
this.userCred = p_userCred;
  }
  public String getUserCred() {
return this.userCred;
  }
}
***
import User;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class UserDAO
{
  private Connection con;
  public UserDAO(Connection con) {
this.con = con;
  }
  public User retrieveUserByUserName(String userName) throws
ObjectNotFoundException {
PreparedStatement ps = null;
ResultSet rs = null;
User user = null;
User user1 = null;
String sql = "SELECT UserCred, UserName, UserFirstName, UserSurname,
UserTitle, UserEmail, UserCompany FROM RealmNames WHERE UserName = ? ";
try {
  if (con.isClosed()) {
throw new IllegalStateException("error.unexpected");
  }
  ps = con.prepareStatement(sql);
  ps.setString(1, userName);
  rs = ps.executeQuery();

  if (rs.next()) {
user = new User();
user.setUserCred(rs.getString("UserCred"));
user.setUserName(rs.getString("UserName"));
user.setUserFirstName(rs.getString("UserFirstName"));
user.setUserSurname(rs.getString("UserSurname"));
user.setUserTitle(rs.getString("UserTitle"));
user.setUserEmail(rs.getString("UserEmail"));
user.setUserCompany(rs.getString("UserCompany"));
return user;
  } else {
throw new ObjectNotFoundException("error.notfound.user");
  }
}
catch (SQLException e) {
  e.printStackTrace();
  throw new RuntimeException("error.unexpected");
}
finally {
  try {
if (ps != null) {
  ps.close();
}
  }
  catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("error.unexpected");
  }
}

  }
}
***
In you Action class just instantiate a new UserDAO (DataAccessObject)
passing a reference to your database connection object and then call the
methods you need.

I usually implement the usual crud (create, retrieve, update and delete)
methods.

happy coding

David
[EMAIL PROTECTED]

"Ric Searle" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]...
> Apologies for the somewhat newbie-esque nature of this post, but I hope
> you can clear up some confusion:
>
> I'm developing my first struts application.  In theory it's very simple
> (at least, I could write in in no time in perl!).  The key elements are:
>
> - User creation / login / session tracking
> - Logged in user can edit a tree-like structure stored in a mySQL
> database.
>
> I'm comfortable(ish) with the role of the controller servlet, and the
> presentation JSP custom tags all look easy to use.  I can even cope with
> form beans to validate and pass around form submission data.  My
> confusion is in how to structure the business-logic side of the
> application.
>
> I *think* that my action servlets should use a "business-logic
> javabean", rather than doing any database manipulation themselves.  Here
> I am struggling with the concept of a javabean, since every tutorial I
> come across talks about them in the context of GUI development.
>
> Am I right in thinking that it's just a normal class that follows some
> naming conventions?  In which case, should I have a class which
> represents a 'User' and a class that represents my 'Database', which has
> an addUser(myUser) method?  I imagine the Database class to be a
> front-end to the SQL.
>
> Any thoughts would be appreciated, particularly if I'm way off the mark!
>
>
>Ric Searle
>Web Application Developer
>--
>Dialogue Communications Ltd, Sheffield, UK
>
>http://www.dialogue.co.uk
>+44 (0) 114 221 0307
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>



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




RE: Business Logic Javabeans

2002-04-11 Thread Sandeep Takhar

I think this depends on the set-up that you have.

the pattern you are referring to is business-delegate
and that is exactly what it does -- delegates.

the book ejb design patterns talks about the pros and
cons.

for us -- it doesn't make a lot of sense.

Sandeep
--- Jay sissom <[EMAIL PROTECTED]>
wrote:
> While I agree that all this work should be done
> during the action, the 
> code that implements your business logic shouldn't
> be directly in the 
> perform method of the action object.  It should be
> in other objects that 
> you call.  This provides for re-use of the business
> logic and seperation 
> between the UI (action objects, form objects, jsp,
> jsp tags) and your 
> business logic.  These other objects don't have to
> conform to the javabean 
> spec if you don't want them to.  Most of the time
> ours does not.
> 
> I think that's what was said earlier, but I wanted
> to clarify a bit.
> 
> This is my opinion only of course.
> 
> Jay
> 
> On Thu, 11 Apr 2002, Oliver Refle wrote:
> 
> > Sorry what i forgot to say, the business logic i
> meant is
> > mainly checking database, adding database entries
> and so on,
> > not changing the values or building a value
> object. This should
> > be done in the action
> > 
> > -Original Message-
> > From: Ric Searle [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, April 11, 2002 12:40 PM
> > To: [EMAIL PROTECTED]
> > Subject: Business Logic Javabeans
> > 
> > 
> > Apologies for the somewhat newbie-esque nature of
> this post, but I hope
> > you can clear up some confusion:
> > 
> > I'm developing my first struts application.  In
> theory it's very simple
> > (at least, I could write in in no time in perl!). 
> The key elements are:
> > 
> > - User creation / login / session tracking
> > - Logged in user can edit a tree-like structure
> stored in a mySQL
> > database.
> > 
> > I'm comfortable(ish) with the role of the
> controller servlet, and the
> > presentation JSP custom tags all look easy to use.
>  I can even cope with
> > form beans to validate and pass around form
> submission data.  My
> > confusion is in how to structure the
> business-logic side of the
> > application.
> > 
> > I *think* that my action servlets should use a
> "business-logic
> > javabean", rather than doing any database
> manipulation themselves.  Here
> > I am struggling with the concept of a javabean,
> since every tutorial I
> > come across talks about them in the context of GUI
> development.
> > 
> > Am I right in thinking that it's just a normal
> class that follows some
> > naming conventions?  In which case, should I have
> a class which
> > represents a 'User' and a class that represents my
> 'Database', which has
> > an addUser(myUser) method?  I imagine the Database
> class to be a
> > front-end to the SQL.
> > 
> > Any thoughts would be appreciated, particularly if
> I'm way off the mark!
> > 
> > 
> >Ric Searle
> >Web Application Developer
> >--
> >Dialogue Communications Ltd, Sheffield, UK
> > 
> >http://www.dialogue.co.uk
> >+44 (0) 114 221 0307
> > 
> > 
> > --
> > To unsubscribe, e-mail:
> >
> 
> > For additional commands, e-mail:
> > 
> > 
> > 
> > --
> > To unsubscribe, e-mail:  
> 
> > For additional commands, e-mail:
> 
> > 
> 
> 
> --
> To unsubscribe, e-mail:  
> 
> For additional commands, e-mail:
> 
> 


__
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




RE: Business Logic Javabeans

2002-04-11 Thread Jay sissom

While I agree that all this work should be done during the action, the 
code that implements your business logic shouldn't be directly in the 
perform method of the action object.  It should be in other objects that 
you call.  This provides for re-use of the business logic and seperation 
between the UI (action objects, form objects, jsp, jsp tags) and your 
business logic.  These other objects don't have to conform to the javabean 
spec if you don't want them to.  Most of the time ours does not.

I think that's what was said earlier, but I wanted to clarify a bit.

This is my opinion only of course.

Jay

On Thu, 11 Apr 2002, Oliver Refle wrote:

> Sorry what i forgot to say, the business logic i meant is
> mainly checking database, adding database entries and so on,
> not changing the values or building a value object. This should
> be done in the action
> 
> -Original Message-
> From: Ric Searle [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, April 11, 2002 12:40 PM
> To: [EMAIL PROTECTED]
> Subject: Business Logic Javabeans
> 
> 
> Apologies for the somewhat newbie-esque nature of this post, but I hope
> you can clear up some confusion:
> 
> I'm developing my first struts application.  In theory it's very simple
> (at least, I could write in in no time in perl!).  The key elements are:
> 
> - User creation / login / session tracking
> - Logged in user can edit a tree-like structure stored in a mySQL
> database.
> 
> I'm comfortable(ish) with the role of the controller servlet, and the
> presentation JSP custom tags all look easy to use.  I can even cope with
> form beans to validate and pass around form submission data.  My
> confusion is in how to structure the business-logic side of the
> application.
> 
> I *think* that my action servlets should use a "business-logic
> javabean", rather than doing any database manipulation themselves.  Here
> I am struggling with the concept of a javabean, since every tutorial I
> come across talks about them in the context of GUI development.
> 
> Am I right in thinking that it's just a normal class that follows some
> naming conventions?  In which case, should I have a class which
> represents a 'User' and a class that represents my 'Database', which has
> an addUser(myUser) method?  I imagine the Database class to be a
> front-end to the SQL.
> 
> Any thoughts would be appreciated, particularly if I'm way off the mark!
> 
> 
>Ric Searle
>Web Application Developer
>--
>Dialogue Communications Ltd, Sheffield, UK
> 
>http://www.dialogue.co.uk
>+44 (0) 114 221 0307
> 
> 
> --
> To unsubscribe, e-mail:
> 
> For additional commands, e-mail:
> 
> 
> 
> --
> To unsubscribe, e-mail:   
> For additional commands, e-mail: 
> 


--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Re: Business Logic Javabeans

2002-04-11 Thread Amitkumar_J_Malhotra


for a good tutorial on javabeans visit the site
www.pdf.coreservlets.com
this is a book available  on-line  in pdf format and the chapter on
javabeans (chapter no -13) is really good ( does not talk in gui context ),
i hope this helps you and think that for a start on javabeans is really
good.

rgds,
amit


--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




RE: Business Logic Javabeans

2002-04-11 Thread Oliver Refle

Sorry what i forgot to say, the business logic i meant is
mainly checking database, adding database entries and so on,
not changing the values or building a value object. This should
be done in the action

-Original Message-
From: Ric Searle [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 11, 2002 12:40 PM
To: [EMAIL PROTECTED]
Subject: Business Logic Javabeans


Apologies for the somewhat newbie-esque nature of this post, but I hope
you can clear up some confusion:

I'm developing my first struts application.  In theory it's very simple
(at least, I could write in in no time in perl!).  The key elements are:

- User creation / login / session tracking
- Logged in user can edit a tree-like structure stored in a mySQL
database.

I'm comfortable(ish) with the role of the controller servlet, and the
presentation JSP custom tags all look easy to use.  I can even cope with
form beans to validate and pass around form submission data.  My
confusion is in how to structure the business-logic side of the
application.

I *think* that my action servlets should use a "business-logic
javabean", rather than doing any database manipulation themselves.  Here
I am struggling with the concept of a javabean, since every tutorial I
come across talks about them in the context of GUI development.

Am I right in thinking that it's just a normal class that follows some
naming conventions?  In which case, should I have a class which
represents a 'User' and a class that represents my 'Database', which has
an addUser(myUser) method?  I imagine the Database class to be a
front-end to the SQL.

Any thoughts would be appreciated, particularly if I'm way off the mark!


   Ric Searle
   Web Application Developer
   --
   Dialogue Communications Ltd, Sheffield, UK

   http://www.dialogue.co.uk
   +44 (0) 114 221 0307


--
To unsubscribe, e-mail:

For additional commands, e-mail:



--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




RE: Business Logic Javabeans

2002-04-11 Thread Oliver Refle

The bean on the GUI has to follow naming conventions, but thats
not the bean used to perform the business logic.

For that bean means only an own java class to seperate the
business logic from the gui(action,jsp).
Partially you can prepare your data in the action classes, but
the normal business should be done in another class which
don't have to follow an conventions if you don't want to
use EJB'S

Oliver

-Original Message-
From: Ric Searle [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 11, 2002 12:40 PM
To: [EMAIL PROTECTED]
Subject: Business Logic Javabeans


Apologies for the somewhat newbie-esque nature of this post, but I hope
you can clear up some confusion:

I'm developing my first struts application.  In theory it's very simple
(at least, I could write in in no time in perl!).  The key elements are:

- User creation / login / session tracking
- Logged in user can edit a tree-like structure stored in a mySQL
database.

I'm comfortable(ish) with the role of the controller servlet, and the
presentation JSP custom tags all look easy to use.  I can even cope with
form beans to validate and pass around form submission data.  My
confusion is in how to structure the business-logic side of the
application.

I *think* that my action servlets should use a "business-logic
javabean", rather than doing any database manipulation themselves.  Here
I am struggling with the concept of a javabean, since every tutorial I
come across talks about them in the context of GUI development.

Am I right in thinking that it's just a normal class that follows some
naming conventions?  In which case, should I have a class which
represents a 'User' and a class that represents my 'Database', which has
an addUser(myUser) method?  I imagine the Database class to be a
front-end to the SQL.

Any thoughts would be appreciated, particularly if I'm way off the mark!


   Ric Searle
   Web Application Developer
   --
   Dialogue Communications Ltd, Sheffield, UK

   http://www.dialogue.co.uk
   +44 (0) 114 221 0307


--
To unsubscribe, e-mail:

For additional commands, e-mail:



--
To unsubscribe, e-mail:   
For additional commands, e-mail: