Joel Hutters

Greenhorn
+ Follow
since Sep 07, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Joel Hutters

I have been thinking of what's the most appropiate way to call a method in an abstract class from an instance of one of its sub-classes. I'll show you some brief code to get it clear what I mean:

Abstract class

And an example of a sub class...

So if you check the last part of the code, both calls work. I think the most appropiate way of calling the method in the super class is by doing it with help of this but I might be wrong? Please let me know if you have a good explanation.
11 years ago
Frank, you don't need to apologize for the long code example, I guess it's something like that I need

However, when looking at your code examples, it feels like your way of implementing it, is very similar to how I did it before making this thread. Instead of using servlets, I have my front controller which invoke my commands which can be seen as a variant of your "simple" servlets. I guess I will go back to this way of implementing it hmm.

Which layer does the servlets/command belongs to? UI controller? How do you avoid to put to much logic in the servlets/command classes? What I mean is that these are often specific for the view of a web page.

Would you mind showing a how a typical Pojo/domain class looks like or is it as simple as the BlogEntry class? Looks like typical Java Bean to me.

Another question. I use an external API, called IPX for sending SMS-messages from my Blog. There are several lines of code required to be able to send a message, isn't it bad to put this in a command class?

Thank you for still having the energy to answer my posts.
Not really sure if I'm doing it right.

Interesting answers both of you. Going to try to explain how my application looks and maybe you it will be easier for me to understand if you use that as reference?

This is the interface for my BlogEntryDAO...


This is a DTO, or is it not?


Then I implemented my POJO (this is my business object?) that looks something like this...



Hmm, but then you say that my business service doesn't need to use any DTO:s, and that my command object may return my business object to the JSP-page? Do you mean my BlogEntryService object, or another what do you mean by business object. Hmm, I don't know how to get this right...
[ November 01, 2006: Message edited by: Joel Hutters ]
You can use autoReconnect=true on your connection url.
11 years ago
I'm very grateful for your answers Stan James, and I have started to reorganize things in my application now. I still have one questions though. I have a command class that collects request parameters from a web form that adds a new post to my blog. It looks something like this:

The last part sets request attributes, so that the view can redisplay the form, if the validation failed. My question is, considering the layer dependency rules, is it okay to use my DTO here?

Instead of doing this in my command class...

I could do this...

In this example, it's only about two attributes, but for an object with a lot of properties it would save alot of typing. Instead of making several request attributes available for my jsp-page, I could "drop" an entire DTO. But it's maybe a bad practice to create DTO:s if they contain invalid data? When I retrieve data from my data source, I simply set my request attributes with dto:s in my command classes so they view easily can display the data. But this feels like another case, since this is valid data... hmmm

Another example from the code posted above. When I call the create method of the BlogEntryService from my command class I do it like this:

What about doing like this?


Hope you understand what I mean, if you don't please let me know and I'll try to clarify it.

[ October 31, 2006: Message edited by: Joel Hutters ]
[ October 31, 2006: Message edited by: Joel Hutters ]
Thanks for taking time and answering my questions. I think I've got it now, but what about form validation. Feels temptating to put validation logic in my pojos, what do you think about that?
[ October 27, 2006: Message edited by: Joel Hutters ]
Yeah it makes some sense but I'm still wondering a little bit about the POJO. Let's I have a Customer DTO like this one (described before):

Is it then POJO's task to "wrap" the calls to the DAO, and maybe perform some business logic after or before if necessary? How do I organize this stuff, packages and naming conventions etc? Is it a good choice to name it CustomerPOJO, and maybe have it in a package like com.appname.pojo?
As I have it now in my application I have transfer object like this, ok now

No CRUID-methods. But when reading Stan James, and from my own thoughts, it's not a good way to make the calls from my "http-specific" command object to my DAO. I'm confused here, and don't really get the pieces together. Would you, or anyone else like to illustrate an example, simple code or explanation of how to do it "right"?

I would appreciate that very much
Very good explanation, and it sounds to be a good way to go. I guess it doesn't matter if my Command objects are http-specific, as long as I keep them clean and simple.

Something like this might work? With no http-related stuff...


Then regarding complicated things like form-validation. What about having that here as well? Like a validation method the checks the state of the pojo, new word for me, but I like it To keep the code simple I might have a validation helper or something like that?


The DAO knows how to connect to the database, do a query or update, return the results. Let's keep all JDBC knowledge in the data accessor so the business layer doesn't import any java.sql classes. The data accessor has to translate all database things into generic things. Imagine trying to change a data acessor from a database source to a remote web service call source, or a JMS source. Keep its interface very generic.


As it is know I have:
DAOFactory (abstract) -> which create concrete factories like MysqlFactory ect
I can get DAO objects like CustomerDAO, UserDAO etc with help of my concrete DAOFactories. These are interfaces, so they all if implementations like MysqlCustomerDAO. Maybe not very generic but I guess I need to use an OR-mapper to achieve this? Anyway, the important thing is that my business layer communicates with my Data Access layer through a common interface no matter what DBMS.

As it's now I pass value-objects (or is it called transport objects?) from my business layer to the DAO, and the other way around.

Any thoughts?

[ October 25, 2006: Message edited by: Joel Hutters ]
[ October 25, 2006: Message edited by: Joel Hutters ]
Hey!
I'm developing a web-application and I'm using the front controller pattern for simplified request handling and the DAO pattern for a unified data access.
What part of the web-app shall use the DAO pattern?

I had this code in my Command objects from the beginning and it looked something like this...

CustomerAction.java
[CODE]
public class CustomerCommand implements Command {
public String execute(HttpServletRequest req, HttpServletResponse resp) {
String view = "example.jsp"
[ November 12, 2006: Message edited by: Joel Hutters ]
Yeah
I actually implemented a connection pool solution with the built in support dbcp in apache. Works great together with mySQL
Hey all!
I have implemented my own Front Controller solution and it's now time to deal with database connectivity. I have read about some different solutions. First of all a basic questions:

Question 1: How does Driver.getConnection() work?
Does it return a new connection everytime it's invoked?

Solution:
The Front Controller servlet invokes the the Driver.getConnection method in its init() method, and closes it in its destroy() method. The connection is then passed to my Action/Command objects.

Question 2: Does this mean that I only have one database connection for my web-app?

Is this a good solution? I have also read about having something called a BaseDao which is extended by other conrecte Daos' such as UserDao, NewsDao etc. This concrete classes invokes the super method getConnection, does it mean that I will get a new connection for every call?

I'm very confused about how to deal with the connections...
[ October 12, 2006: Message edited by: Joel Hutters ]
Thanks for the advices

I'm reading the book Head First Servlets and JSP and developing an application at the same time. I'm sure I will learn by my mistakes but I wont skip the important reading of the basics.

I got the Properties File working with help of the ResourceBundle class, is that how you do it?
11 years ago
Well, I started studying Servlets and JSP last week so I still have much to learn, and I am aware of that. I mentioned the init in a post earlier in this thread, and I understood what you mean a time after replying to your message,

About putting it in the /etc was a typo by me, I have spent to much time in front of the screen today.

Thanks for explaining the case regarding the method loading the XML-file, I assumed it started at the web-root of my application but I was wrong. I will follow your advice and use the method you described earlier instead. I have much more to learn
[ September 08, 2006: Message edited by: Joel Hutters ]
11 years ago
I'm trying to load my XML file with this in my servlet:

my servlet is located in appfolder/WEB-INF/classes/com.blog.web and the XML-file is located in the root directory appfolder/ of my web-app. All I get is "(No such file or directory)"

[ September 08, 2006: Message edited by: Joel Hutters ]
[ September 08, 2006: Message edited by: Joel Hutters ]
11 years ago