Brian Enochson

Greenhorn
+ Follow
since Apr 12, 2011
Brian likes ...
Oracle Spring Java
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 Brian Enochson

Where are your text files located in your project or better said in the war? Or are you placing them on the file system outside of the war? They need to be located in the classpath so in the WEB-INF/classes or for instance in a maven project in the src/main/resources directory.

Failing this, you can try this.getClass().getClassLoader().getResourceAsStream("/myfile.txt") with the '/' in front of the file name. This, I believe, looks in the directory where "this" is located which is the location of the class doing the lookup.

7 years ago
Yes, I guess it could be considered hackish if it is a solution not standard in one or the other framework so you are correct.

Read this about CDI and Spring http://java.dzone.com/articles/why-cdi-won%E2%80%99t-replace-spring. I think, at least for me, shows why you may want CDI and Spring in a single application. Granted, I realize normal architectural principles would make it seem not likely you have your JMS code and JSF code in different layers. But, I have done exactly as shown in the link. I had my Web application using JSF for the presentation and portion of its backend functionality involved posting to a JMS queue. As the author states, Spring makes using JMS almost trivial compared to the alternative.

So is this a reason (or use case) where you would use CDI and Spring together?

I really wish someone could jump in who has gone down this route but any users of CDI I have talked to have started using it now and were not users of Spring anyway so they are not having the conflict we are having!
9 years ago
JSF
Hi, this is an interesting question and one I have also looked into without a definite answer. I have read most places where Spring and CDI should not co-exist. I am not convinced this is the final answer and have seen implementations like this (look in the answer, it shows defining a producer which bridges CDI and Spring) http://stackoverflow.com/questions/4144039/injecting-a-spring-bean-using-cdi-inject.

As for a reason I could imagine an existing Spring context file where you would want to reuse this within your application. Also, though I do not have enough experience to know which classes this might be, there are Spring classes that you would want to use and could not be integrated without having the Spring context.

Finally, a reason for having spring might be using AOP constructs for a cross cutting concerns and not covered by CDI.

I would love to hear from anyone with enough experience with CDI and Spring who can add to this conversation and expound on their experience.

Brian


9 years ago
JSF
A common free one used in the Java world is Apache Database Connection Pool (DBCP). http://commons.apache.org/dbcp. This is specifically for pooling of data sources and builds on the common pool library which provides generic object pooling functionality.

DBCP has a couple of versions, 1.4 is for Java 6 and 1.3 for Java 5 and earlier. It comes with a good set of examples and there is plenty of reference material on the web.

As to your post, were you looking for a recommendation then I can say I have used this before. If you need examples of how to use it, I would look first in the examples.

Brian
Not sure if this really belongs in the JDBC section or in the beginning Java section, I will let someone else decide that...

What you are asking is basically if your design would work. I can only start out with these simple tips, hopefully this will help. This is not easy to answer in my view.

1) You will want to keep your UI (Swing) code separate from all others. For instance, an SQL class should return a type of error but not actually display it using Swing. Don't mix responsibilities.

2) Your classes mirroring the entities in the DB are what are called bean classes. They should be simple data carriers with getter and setters. Some people argue about this point, at least for a beginner makes sense. Since they are data carriers they should have no other logic.

3) Next you should have a database access classes (often called DAO or data access objects) that handle all the database interaction. They create and return single objects from #2, or arrays or lists of them. They know how to create, read, update and delete (CRUD) data.

4) Next you have some service classes that use the different DAO classes to perform the actual logic in your application. They are the middleware between your GUI and your DAOs. They would have methods like . Note that services can use other services also.

5) Finally your have your UI code that takes user input, calls out to services and gets the bean classes (from #2) and knows how to display them. It doesn't have any other logic, just the user interaction.

I hope this answer made some sense and will help you organize your application. Build it a little bit at a time and in an iterative fashion, testing often and you should be able to keep the complexity under control.

Good luck!

Brian

Also retrieving a blob takes special handling. Here is some example code I have used, there are probably many examples out there if you want to Google them. And Paul is right, you want to use the Oracle JDBC Driver if your application is always going to use Oracle.




Brian
Also, try changing the compare method by switching the o1 and o2 around in the return statement. That should give you a clue of what is happening.

Like this:


9 years ago
Bud,
You are getting this error because any class that implements the interface Comparable has to implement the method ;

Your compareTo method will return 1 of 3 values. 0 if the object passed in is equal to yours, 1 if your object is considered greater than the passed in object and -1 if it is less than. What you need to decide what is the criteria for the comparison. In your case, I would use size. Therefore your compareTo method might look like this:

9 years ago
Hi, without confusing the answer too much could we expand this to just not Camel but other options such as Mule? From a design standpoint, Spring Integration and Mule seem very similar. Not sure where Camel fits into this.

Sorry to jump in on your question Steve, if this does not fit I could start a new thread, but it seemed to be very similar to the question I was going to ask.

Brian
9 years ago
DZONE has a refcard for Richfaces at http://refcardz.dzone.com/refcardz/richfaces.

Also, I am going to get the book from Apress called Practical Richfaces for an upcoming project. http://www.apress.com/9781430210559

Brian
9 years ago
JSF
This has been covered. https://coderanch.com/t/303346/JDBC/java/find-number-rows-resultset.

What you can also do is a select count with an identical where clause to your where used for the actual select?

Lastly, instead of using an array where you need to allocate it, add your results from your result set to an ArrayList as it will grow dynamically.

Brian

Are you asking if you can integrate Spring core (and not specifically asking about Spring MVC) for dependency injection while using JSF2 and Primefaces? If so the answer is yes. You can load the spring context in your web.xml using the spring class ContextLoaderListener. You need to set a context param in the web.xml stating where the spring configuration file(s) is/are located. Primefaces integration is as easy as adding the jar for primefaces into your application.

This link covers what you need to do very well. http://technology-for-human.blogspot.com/2010/12/jsf-2-with-spring-3-basics-part-1-of-2.html

Brian
9 years ago
Congratulations on the book coming out, can't wait to order it.
9 years ago