Sunday, May 27, 2012

Audit trail front end design

I need a centralise work on audit trail front end. I don't want each module to have their own audit trail layout format. Thus I make a generic bean that could store the result and publish it into a generic table that shows pre-data on the left and post-data on the right. Yes, this bean is playing the main role connecting the back-end and front-end.

Besides that, I need flexibility, and I don't want to change my core everytime you have new field introduce in the table. Thus I made another bean to represent that fields in each the table. Instead of table, I would rather say view because each audit trail module will have different representation of a module. e.g. claim module, payroll module, and etc.

Lets reveal the design.


I made an abstract audit header object, and an abstract audit content object. The purpose of making them abstract is to increase its flexibility design when interacting with controller class. Thus the controller class do not care about the type of audit, "I don't even want to know! Please leave me alone." Controller class says.

Each header must come with a content. At least one content. Thus I made a composition associate between audit header and audit content. How? By using the black diamond. I use composition (black diamond) instead of aggregation (white diamond) is because of my way of design. I want each audit must come together with at least a content, otherwise don't render this page.

I use generalization to realize the type of audit. As shown in the picture, the audit header and audit content is realize the claim audit.

If the content are ready to be distribute, the controller class will collect it and put it into a public access Bean object.

As shown in the diagram above, the controller class is the middle man who trigger the request and distribute to JSP page. In JSP page, user still have to tell what type of audit content should the controller class to retrieve.

Saturday, May 19, 2012

High level design of audit trail system

This is the high level architecture design of my audit trail system. Initially I though Hibernate Interceptor could be great help, but when I found out that we are using WAS datasource, there is no way for me to use that in our system. Thus, I need to think a way out. After few weeks of design, POC, and testing, finally I come out this design.



I though this is an audit trail system, but why the design look like a database log? I have this feeling at the design stage. If I make a database log, I understand that the IO transaction will gonna eat up the resources, but we need to judge what is the most important one? Resource cost how much? Data integrity cost how much. It has been a hard time for me to put this consideration when designing the system. Thus I decide to make both.

There are few pieces in this design.

  1. Parameter table - Allow owner to decide which table that gonna need to audit. Just register here and let the audit engine do the rest.
  2. Stored Procedure - The audit trail engine. It read information from parameter table on what is needed to audit, create trigger and tie up with the original table, spawn a new shadow table from original table.
  3. Trigger - Act as database logger.
  4. Shadow table - Contain pre and post data of original table.
  5. Audit trail table - The main table that tells the summary story of shadow table.
I use GUID as the key to link the data across shadow table, original table, and audit trail table together. The GUID was generated from JAVA every time a record is save/update/delete. I put this key together with the BEAN object so that the system know what/which does for each audit trail entry.

The whole thing was made up from 10% work on JAVA, 60% work on Dynamic SQL and 20% work on Stored Procedure. I try not to limit the design only for JAVA, thus a lot of consideration need to think of when designing this shit.

Practice make perfect.

Essay writing is fun and interesting. Remember when I was in primary school, I hate writing just because I am lazy. There was an article mention that if someone not able to write a good essay, this person will lacking of communication skills. Does it true? I don't know. But that is not the reason for me to start writing.

What actually motivate me to start writing is because I feel bore. When I am bore, I read book, after reading, I write down my comment on the reading. As I keep writing, I learn new, the English grammar, new vocabulary, writing style. I started to feel the joy of writing, and reading. And I start writing blog.

To write a good post, I have to keep on practice non stop. No one is number one when first born, keep on learning, practicing, read more, and explore all kind of reading will make someone perfect in writing.

Happy Saturday :o)

Sunday, May 13, 2012

JARs must sit inside WEB-INF/lib

I don't know whether Netbean have this kind of problem or this only happen to Eclipse IDE. Whenever there are jars that required to be link in the project, make sure all these jars are located under WEB-INF/lib folder. Although the build path has already been configure, or you don't even configure your project's build path, I don't care. I don't care whatever reason you have, always remember that you are wrong.

As long as the WEB-INF/lib contains the jars require, it just work. I strongly highlight this to those who are new in web development. Please jot it down!

Good luck.

Connection pool in Tomcat

I like discovery channel, especially on Sunday, I will turn into this channel to watch what are the exciting and interesting news is on the show. Hey! why don't I make my own discovery channel... in JAVA ;) This gonna be more fun and exciting. xD

My solution architect require us to change the JDBC connection to connection pool, how that could be done? So easy, by configuring the datasource name in hibernate. But how is the actual work done in server site? I have no idea because the database we are using is Informix and it is shield by the server admin.

In order for me to carry on the research, I decided to do it using Tomcat. When a new Tomcat server instance is created in Eclipse, look for the context.xml. Put in following code:

< Resource name="jdbc/mydb" auth = "Container" type = "javax.sql.DataSource" maxActive="50" maxIdle="30" maxWait="10000" username="root" password="abcd" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/exercise" />

In web.xml, put following code:

< resource-ref >
      < description > DB Connection < /description >
      < res-ref-name > javax.sql.DataSource < /res-ref-name >
      < res-type > javax.sql.DataSource < /res-type >
      < res-auth > Container < /res-auth >
  < /resource-ref >

That's all about it. To test out the code, make a new JSP test page, put in following code.

1st piece of code is to make a query:
< sql:query var="rs" dataSource="jdbc/mydb" >
select FIRSTNAME from CONTACT

2nd piece of code is to render the output:
< c:forEach var="row" items="${rs.rows}" >
    Foo ${ row.FIRSTNAME }< br/ >
< /c:forEach >

Saturday, May 12, 2012

JDBC isn't a good solution for database programming

Now I realize that JDBC is not a good solution in writing a program that involve database because there are a lot of code need to be done. Basically I just copy and paste the redundant code and reuse back for other purpose. So a new idea coming out to hide this redundant code by creating a wrapper class.

Brilliant right? Not really because this only help a portion of my code. There are more tedious one following up next.

Another issue was I need to handle the association on my own. Meaning that when object_A is referencing object_B like the example shown below:

public class Object_A {
    public Object_B objB;
}

Object_A.Object_B.setFunction_A();
Object_A.Object_B.setFunction_B();
Object_A.Object_B.setFunction_C();
...
...


There are many more code I need to go if my table field consist of 20 fields. This is so terrible.

Sunday, May 6, 2012

Now I know JSP and Servlet can work together

I am going back to the basic. In web development, JAVA code and JSP code are two different thing. Then how JSP code and JAVA code link up together?

The picture above showing Servlet and JSP as separate entity




In order to link them up, we need web.xml. We tell the server once we receive an URL request that look like this:
http://< ip >:< port >/< project >/< path >
The Servlet object will be initialize and do its job. This is how we should instruct the servlet to do its job in the web.xml.
< servlet >
   < servlet-name >My Servlet< /servlet-name >
   < servlet-class >org.huahsin68.MyServlet< /servlet-class >
< /servlet >
< servlet-mapping >
   < servlet-name>My Servlet< /servlet-name >
   < url-pattern>/MyPath/*< /url-pattern>
< /servlet-mapping >
When someone enter http://< ip >:< port >/MyPath. MyServlet object will get execute, and process client's request in doGet() function. In doGet(), the JSP Page will get forward using following code:

req.getRequestDispatcher("/thePage.jsp").forward(req, res);

So, is this basic enough?

Internet is really a wasting time thing in my life.

Internet is really a wasting time thing in my life. It has been a long time I take myself off from the Facebook, after that I control on the chat program usage, and recently I started to control myself on the Internet usage. I started to realize that I have been abuse the usage of the Internet because every time I go online, first thing to do is to turn on the chat program, and then mail client, after that facebook, youtube, and read blog post. I've been feeling so lost and frustrate because there are tons of information pushing into my head. Thus I am thinking set up a security control to lock myself down.

Now I have my initiative to control on the Internet usage. When every time I want to use the Internet, I have a log book jotting down the objective of the Internet usage, and time of usage. For example now I'm writing my journey in this blog, it took about 15mins to complete, and 5mins on reviewing my sentence and English grammar checking.

Doing this will required self discipline, and I'm feeling so great that I could get out from the crowd.