Thursday, 28 July 2016

Caching Dynamic Content with JSP 2.0

Content caching is one of the most common optimization techniques used in web applications, and it can be implemented easily. For example, you can use a custom JSP tag--let's call it <jc:cache>--to wrap every page fragment that must be cached between <jc:cache> and </jc:cache>. Any custom tag can control when its body (i.e. the wrapped page fragment) is executed, and the dynamic output can be captured. The <jc:cache> tag lets the JSP container (e.g. Tomcat) generate the content only once, storing each cached fragment as a JSP variable in the application scope. Every time the JSP page is executed, the custom tag inserts the cached page fragment without re-executing the JSP code that generated the output. A tag library developed as part of the Jakarta project uses this technique, and it works fine when the cached content doesn't need to be customized for each user or request.

Wednesday, 27 July 2016

Upload Files with JSF and MyFaces

Web browsers provide an easy way for sending files to web applications, but the current versions of the Java web standards (servlets, JSP, and JSF) do not offer any help. Fortunately, there are third-party frameworks, such as Apache Commons File Upload, Apache MyFaces, and Oracle ADF Faces, that implement this feature, exposing simple APIs and custom tags. The first half of this article explains how file uploading works, walking you through the source code of MyFaces and Commons File Upload (the former uses the latter internally). It is helpful to know what happens inside of these open source frameworks in order to use them efficiently, and to be able to modify them if you have to. In the second half of the article, you'll find a sample application that lets users upload files using their web browsers.

Monday, 25 July 2016

Hibernate for Java SE

By now it's easy to see that Hibernate is quickly becoming a popular (if not the most popular) O/R mapper/data integration framework for J2EE. It offers a developer clear, concise, and powerful tools for working with relational databases in the enterprise. But what if you need outside access to those entities that are wrapped up in your J2EE web application? Do you develop separate, yet identical, entities to access your data? Or do you write additional web components to manage the internal access to your data?

At some point, these questions are bound to come up, and for me, it was when my company needed to upload records into our database from multiple vendors in multiple file formats. I thought about the approach I had always taken before, which was to write shell and SQL scripts (and even stored procedures) to upload the data. But because our data model is quite complex, I decided to leverage what existing entities, Spring DAOs, and services outside of our web app I could and develop a custom J2SE command-line data loader.

Wednesday, 20 July 2016

Beware of Functional Programming in Java!

This isn’t going to be a rant about functional programming, which is awesome. This is a warning about some practices that you are very likely going to apply to your code, which are terribly wrong!.

Higher order functions are essential to functional programming, and thus, talking about them will help you be the center of attention at parties.

If you’re writing JavaScript, you’re doing it all the time. For instance:

setTimeout(function() {
    alert('10 Seconds passed');
}, 10000);

Monday, 18 July 2016

Query DynamoDB Items with Java

On this post we will create Tables on a DynamoDB Database the java way. Before getting started we need to have local dynamodb installed since we want to avoid any costs for dynamodb usage.

In case you use docker you can find a local dynamodb image or you can create one on you own as described here. The dynamodb java sdk gives us the ability to create dynamodb tables using java code.
The most basic action is to create a table with a hash key. In this case the email of the user would be the hash key.

Monday, 11 July 2016

Working with the JDBC API for Large Objects

The JDBC API provides the necessary support to work with Large Objects (LOB), such as storing an image file or a large text document in the database. The requirements of data persistence may vary both by its size and type of data content; a LOB can be of these types: BLOB (Binary Large Object), CLOB (Character Large Object), and NCLOB (National Character Large Object). These are the LOB variations supported by the JDBC API. However, there is a difference on how a RDBMS treats and handles LOB objects internally. They are very vendor specific, but at the application level, specifically from JDBC APIs out treatment assumes it to be BLOB or CLOB, or perhaps NCLOB.