Friday, March 26, 2010

I was playing around with Spring 3.0 and the new Spring Expression Language SpEL the last couple of days and ran across a few issues. First the Spring documentation is a little lacking in this area so I am going to share what I have found.

The problem that I was working to solve was that we store our properties files outside of the War file and use a context property to point to the directory where the file is located. In Spring 2.5.6 this was a little complicated but with Spring 3.x it’s much easier when you use SpEL.

With SpEL you can access several types of properties right out of the box. Here is a list of the ones that I know about. (systemProperties, systemEnvironment, contextAttributes, contextParameters)

The key one for my use was finding the contextParameters. What I do is to setup a parameter name in my context xml file for Tomcat.

<Context className="org.apache.catalina.core.StandardContext" cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper" cookies="true" crossContext="true" debug="0"
docBase="C:\Data\etc\eclipse\projectName1\web" mapperClass="org.apache.catalina.core.StandardContextMapper"
path="/projectName1" privileged="false" reloadable="false" swallowOutput="false" useNaming="true"
workDir="work\Standalone\localhost\projectName1" wrapperClass="org.apache.catalina.core.StandardWrapper">
<Parameter name="config.home" override="true" value="C:\Data\etc\eclipse\projectName1\properties"/>
</Context>

Now in my application context xml file I can access this parameter with the SpEL command.

#{contextParameters['config.home']}

So to load up my application’s properties file it’s as easy as using the property loader like this…


<util:properties id="appProperties" location="file:#{contextParameters['config.home']}/myApplication.properties">
</util:properties>

Now the properties can be used anywhere in your application as necessary. This seems fairly simple but I searched the web and the latest Spring docs without success to find this information. I dug into the Spring source last night to location exactly what I needed to make this work like I wanted. I hope that this helps someone else and yes I’m going to put in a Jira to get the Spring docs updated to include the values list above.
Brian

Tuesday, January 26, 2010

Book Review: Oracle SQL Recipes - A Problem Solution Approach

Book Review: Oracle SQL Recipes - A Problem Solution Approach
Author: Grant Allen, Bob Bryla, Darl Kuhn
Publisher: Apress Inc
ISBN: 978-1-4302-2509-6

I haven’t been reviewing Oracle SQL books since for the last several years my primary focus has been in the Java realm. However, I still love working directly with databases especially Oracle so I was looking forward to when this book was release and I had high hopes. Luckily the book delivers in fact I wish that I had a book just like this when I started to work with Oracle 12 years ago. It would have made the learning curve much smaller.

As most books about any technical subject they start out with the simple and head toward the more advanced. This book uses the same approach so if you’re already knowledgeable about SQL you can probably skip the first 2-3 chapters. From there the book ramps up the complexity. This is where SQL starts to get really fun. The book covers many aspects of SQL programming that I have encountered over the years. Validating data between tables, dealing with NULLs, manipulating data in and between types, REGEX are just part of what this book covers. In fact I was working today and ran across a problem where I was developing new Java loaders for some large data sets. I need to compare both tables that are located on different databases to make sure that my code is working the same as the old code. I remembered a section from the book (3-9) that shows how to compare two tables and find the differences quickly. This allowed me to implement a check on several tables in just a few minutes. Otherwise I was going to write a Java program to check and compare the data in the objects which would have taken hours to write. This is a good reminder that we should all use the right tool for the job and in many cases dealing with data using SQL is much simpler than other approaches.

I’m not saying that this book has everything that you would ever need in a SQL book but it’s a great place to start. I would highly recommend this book to add to your library of must have SQL books along with about anything from Joe Celko.