Kuldeept’s Weblog

Just another WordPress.com weblog

  • Categories

  • Archives

Surrogate Key

Posted by kuldeept on September 20, 2008

Surrogate key is a substitution for the natural primary key.

It is just a unique identifier or number for each row that can be used for the primary key to the table. The only requirement for a surrogate primary key is that it is unique for each row in the table.

Data warehouses typically use a surrogate, (also known as artificial or identity key), key for the dimension tables primary keys. They can use sequence generator, or Oracle sequence, or SQL Server Identity values for the surrogate key.

It is useful because the natural primary key (i.e. Customer Number in Customer table) can change and this makes updates more difficult.

Let me give you a simple example:

Employee ‘E1’ belongs to Business Unit ‘BU1’ (that’s what would be in your Employee Dimension). This employee has a transactions on the Business Unit ‘BU1’ But later on the Employee ‘E1’ is shifted from Business Unit ‘BU1’ to Business Unit ‘BU2.’ All the transactions have to belong to the new Business Unit ‘BU2’ but the old one should Belong to the Business Unit ‘BU1.’

If you used the primary key ‘E1’ for your employee within your data warehouse everything would be allocated to Business Unit ‘BU2’ even what actually belongs to ‘BU1.’

If you use surrogate keys, you could create a new record for the Employee ‘E1’ in your Employee Dimension with a new surrogate key.

This way, in your fact table, you have your old data with the SID of the Employee ‘E1’ + ‘BU1.’ All new data would take the SID of the employee ‘E1’ + ‘BU2.’

You could consider Slowly Changing Dimension as an enlargement of your natural key: natural key of the Employee was Employee Code ‘E1’ but for you it becomes Employee Code + Business Unit – ‘E1’ + ‘BU1’ or ‘E1’ + ‘BU2.’ But the difference with the natural key enlargement process, is that you might not have all part of your new key within your fact table, so you might not be able to do the join on the new enlarge key -> so you need another id.


Posted in Data Warehouse | Tagged: | 1 Comment »

Code Leader: Using People, Tools, and Processes to Build Successful Software

Posted by kuldeept on July 15, 2009

Code Leader: Using People, Tools, and Processes to Build Successful Software is written by Patrick Cauldwell Intended audience for this book is experienced developers/architects/Tech Managers. But this is a must read book for all developers/process owners. Author has divided the whole books in three parts: 1. Test Drivern Development and Continous Integration 2. Process for Testing/Source Control & Code Analyss 3. Code Construction (Dependecies, Tracing, Error Handling) I liked Cauldwell explanation on Buy/Build, Using Open Source Application and creating unit/integration tests, source control, analysis tools and tracing capabilities and found it very useful for developers and Managers also who wants to setup software development process for their group. In first section, this book talks about some of the philosophy behind test-driven development, continuous integration, and the main buy vs build decision, not so much how to do TDD or continuous integration. In Second Section, it is all about the processes. Starting with how you know when have you completed some tasks, how to properly do testing, how to use source control and how to use and understand static code analysis. The third section concentrated on how to actually put code together. Author talks about how to develop using interfaces and how to find and limit dependencies. Section three also covers the model-view-presenter pattern of application development, and some good guidance on how to use tracing and how to do error handling. Authour is very concise and to the point but whereever required, he is going a bit into details. Authur is .Net developer, so he has given examples on using .Net technologies but along with it he discussed lots of open source and alternative commercial tools for other development platforms. Author combined process, tools and people, to make a better product. You will find lots of tips in this book, e.g., – Adding a slight delay in you continuous build process to prevent a couple of atomic checkins by one developer all triggering a new build – Setting your acceptable level of code coverage that will trigger a build fail to just below your current level, instead of some ridiculously high level that will result in build failures for weeks to come This book covers all the main concepts for setting up a professional development environment. Most of the practices it talks about are main practices in agile software development.

Posted in Uncategorized | Leave a Comment »

Struts2 and DOJO

Posted by kuldeept on July 15, 2009

Now days everybody is talking about web2.0. Web 2.0 is facilitating communication, information sharing, interoperability and User-centered design. To achieve this user-web interactivity, web based frameworks (Struts2, Spring) and AJAX are key technologies.

Struts2 is a second-generation web based application framework that implements the Model-View-Controller (MVC) design pattern. Struts 2 is built from the ground upon best practices and proven, community-accepted design patterns. Using AJAX, you can increase the user interactivity on web to refresh certain part of web page without submitting complete page every time.

Recently, we worked on Sales Credit Adjustment Request Template for Sales Compensation Team. We have developed SCART application using Struts2 framework and dojo. We have used Struts2 framework to separate the UI (html) and core logic (java code). There were lots of features on this template where we had to update certain part of webpage without submitting the form/complete page. AJAX form submission helped us to achieve this. We have used dojo grid in this project that is a very nice widget provided by dojo framework which allow us to create data in grid format.

We are going to write in brief about Dojo and Struts2’s features that can help us to build more user interactive, scalable and maintainable web-based applications


One of the frameworks that make it easier to use Ajax is the DOJO JavaScript toolkit. This framework provides lots of already built-in widget that allow us to do faster development and enhance the interface and usability of web applications.

Dojo widgets are prepackaged components of JavaScript code; HTML markup and CSS style declarations that can be used to enrich websites with various interactive features that work across browsers:

  • Menus, tabs, and tooltips
  • Sortable tables, dynamic charts, and 2-D vector drawings
  • Animated effects—fades, wipes and slides—facilities for custom animation effects
  • Tree widgets that support drag-and-drop
  • Various forms and routines for validating form input
  • Calendar-based date selector, time selector, and clock

One of the widget that we had used in SCART application is Dojo Grid that expects data in json format and provides nicely build grid with sorting and pagination without any server side coding. This saves a lot of development efforts spent on sorting and pagination. Beside, this allows you to format data in desired format.

See in details about dojo and widgets available:



See in details how Grids works (http://www.sitepen.com/blog/2008/07/14/dojo-12-grid/).


Struts2 is web application framework. Struts2 helps well-designed web applications, as it provided the infrastructure for easily achieving the MVC separation of concerns. This allowed developers with few resources for such architectural niceties to tap into a ready-made best practice solution available to them.

Struts 2 introduce several new architectural features that make the framework cleaner and more flexible. These new features include interceptors for layering cross-cutting concerns away from action logic; annotation-based configuration to reduce or eliminate XML configuration; a powerful expression language, Object-Graph Navigation Language (OGNL), that transverses the entire framework; and a mini-MVC–based tag API that supports modifiable and reusable UI components. Hence, Apache Struts 2 is a dynamic, extensible framework for a complete application development from building, deploying and maintaining.

The high-level design of Struts 2 follows the well-established Model-View-Controller design pattern. The MVC pattern provides a separation of concerns that applies well to web applications. Separation of concerns allows us to manage the complexity of large software systems by dividing them into high-level components.

Struts 2 has lot of features of them are Interceptors. This provides ability to do an action before an event. For example we can write our own validations or any program that needs to be executed much before our main program starts, e.g., login functionality.

Secondly, it also its own tags that helps in minimizing amount of code to be written. For example if we need to construct an object then we need all its fields to be collected and then pass to constructor to get that object initialized. But in struts 2 we need to just give the names of the object fields in the html tags, on submit this itself will create a object this can be captured by just getter setter methods for that object. Even retrieval of the fields of the object is simple.

Furthermore, Struts 2 also has Ajax theme, which helps in implementation of the Ajax features. With the help of the struts.xml we can easily identify what action is done for what and what is the output of that action. With advent of the action methods in the action class we direct each method to each function and return the result appropriately. There is also feature for the CSS implementation with help of the property file. We can just provide the theme name in the property file this will apply for all the struts tags.

Struts 2 also provide validation framework. Our validation can be void with just making the field validate to true in the html forms.  Some key features provided by Struts2 are:

  • Simplified Design – Programming the abstract classes instead of interfaces is one of design problem of struts1 framework that has been resolved in the struts 2 framework. Framework components are tried to keep loosely coupled.
  • Simplified Actions  – Actions are simple POJOs. Any java class with execute() method can be used as an Action class. Even we don’t need to implement interfaces always. Inversion of Control is introduced while developing the action classes.
  • No more ActionForms  – ActionForms feature is no more known to the struts2 framework. Simple JavaBeans flavored actions are used to put properties directly. No need to use all String properties.
  • Simplified testability – Struts 2 Actions are HTTP independent and framework neutral. This enables to test struts applications very easily without resorting to mock objects.
  • Intelligent Defaults – Most configuration elements have a default value, which can be set according to the need. Even there are xml-based default configuration files that can be overridden according to the need.
  • Improved results – Unlike ActionForwards, Struts 2 Results provide flexibility to create multiple types of outputs and in actual it helps to prepare the response.
  • Better Tag features – Struts 2 tags enables to add style sheet-driven markup capabilities, so that we can create consistent pages with less code. Struts 2 tags are more capable and result oriented.
  • Annotations introduced: Applications in struts 2 can use java 5 annotations as an alternative to XML and Java properties configuration. Annotations minimize the use of xml.
  • Stateful Checkboxes – Struts 2 checkboxes do not require special handling for false values.
  • QuickStart – Many changes can be made on the fly without restarting a web container.
  • Easy plugins – Struts 2 extensions can be added by dropping in a JAR. No manual configuration is required!
  • AJAX support – The AJAX theme gives interactive applications a significant boost.
    The framework provides a set of tags to help you ajaxify your applications, even on Dojo. The AJAX features include:
  1. AJAX Client Side Validation
  2. Remote form submission support (works with the submit tag as well)
  3. An advanced div template that provides dynamic reloading of partial HTML
  4. An advanced template that provides the ability to load and evaluate javascript remotely
  5. An AJAX-only tabbed Panel implementation
  6. A rich pub-sub event model
  7. Interactive auto complete tag

Some of the useful links for struts 2




Posted in Java | Leave a Comment »