Posts

Showing posts from August, 2012

What is Liquibase ?

1.  Liquibase is an open source database-independent library for tracking, managing and applying database changes. 2. All changes to the database are stored in XML files and identified by a combination of an "id" and "author" tag as well as the name of the file itself. 3. A list of all applied changes is stored in each database which is consulted on all database updates to determine what new changes need to be applied. 4. Liquibase executes changes based on this XML file to handle different revisions of database structures and data. 5. When you first run a changelog, LiquiBase manages those changelogs by adding two tables into your database. databasechangelog : maintains the database changes that were run. databasechangeloglock : ensures that two machines don't attempt to modify the database at one time. 6. Limitations do exist such that it will not export triggers, stored procedures, functions and packages. Sample changeLog file:  The above is...

How to integrate Liquibase with Spring and Hibernate ?

Image
A sample tutorial on how to integrate Liquibase with Spring and Hibernate. While writing this tutorial, I have added javadoc in the code for better understanding and I believe You already have good knowledge on Spring and Hibernate. The main motto of this tutorial is to give an idea on how you can integrate Liquibase with Spring and Hibernate. If you are new to Liquibase : Click Here To integrate liquibase into your project, you need liquibase jars, So  download it before starting the project. I have created an application named "SHLIntegration". The Structure of the project is as follows : The dependencies are also listed here: Lets start with Employee class : 1. Create Employee class having getter/setter and add proper JPA annotation to each variable as below.   public class Employee {     @Id     @GeneratedValue     @Column(name="EMPLOYEE_ID")     private long id;     @Column...

Some ANT task

1. How to build  project from another build. <target name="project2"             description="Builds project2 project, required depedency">         <!-- Build project2 first  -->         <subant target="dist" verbose="yes" inheritall="false">             <filelist dir="../com.waheed.project2"                       files="build.xml" />         </subant>     </target>   2. How to read SVN revision and write into some file <loadfile property="revision" srcFile="./.svn/entries">         <filterchain>           ...

Spring MVC tutorial

Before Starting, I believe you must have basic idea about JAVA, SPRING and Spring MVC. For Spring MVC : http://waheedtechblog.blogspot.in/2012/08/spring-mvc.html In this tutorial , I will just tell you what are the basic thing that you need to start MVC. Step 1 : Create a class  @Controller public class HelloWorld {        @RequestMapping ( "/hello" )      public String helloWorld() {           return = "Hello World, Spring 3.0!" ;      } } 1 . The class HelloWorld  has the annotation @Controller and @RequestMapping("/hello") . When Spring scans this class, it will recognize this bean as being a Controller bean for processing requests. 2 .The @RequestMapping annotation tells Spring that this Controller should process all requests beginning with /hello in the URL path. Step 2. Mapping Spring MVC in WEB.xml The entry point of Spring 3...

Spring MVC

Image
Spring MVC helps in building flexible and loosely coupled web applications. The Model-view-controller design pattern helps in seperating the business logic, presentation logic and navigation logic. Models are responsible for encapsulating the application data. The Views render response to the user with the help of the model object . Controllers are responsible for receiving the request from the user and calling the back-end services. When a request is sent to the Spring MVC Framework the following sequence of events happen. The DispatcherServlet first receives the request. The DispatcherServlet consults the HandlerMapping and invokes the Controller associated with the request. The Controller process the request by calling the appropriate service methods and returns a ModeAndView object to the DispatcherServlet . The ModeAndView object contains the model data and the view name. ...

Sending Email Via JavaMail API Example

From last one month, My internet device is missing from my terrace. So, Mostly I use mobile to access my mail but accessing mail via mobile is very irritating thing because of the slow bandwidth. To send one single mail I have to wait till the mailbox get opened. This is very simple way to send mail without opening your account. :) This is the example to show you how to use JavaMail API method to send an email via Gmail SMTP server. You need mail.jar library to run this code. import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; /**  * @author abdul  *  */ public class SendEmail {     public static void main(String[] args) {                 final String username="YOUR_USER_NAME"...

Spring Auto-Wiring Beans with @Autowired annotation

In Spring, you can use @Autowired annotation to auto wire bean on the setter method, constructor or a field. There are two ways to can achieve it : 1.Using <context:annotation-config />     Just Add Spring context and <context:annotation-config /> in bean configuration file <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"     xmlns:tx="http://www.springframework.org/schema/tx"     xmlns:context="http://www.springframework.org/schema/context"     xsi:schemaLocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd     http://www.springframework.org/schema/aop     http://www.springframework.org/schema/aop/spring-aop.xsd     http://www.springframework.org/sche...

Error:No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

To solve this problem. You have to do two things: 1. mark the DAO as transactional or function which is doing database call like:   @Transactional    public class EmployeeDaoImpl  extends DaoImpl implements EmployeeDao{  ///// }            OR @Transactional     public long addEmployee(Employee employee) {         System.out.println("Employee:"+employee );         long id = employeeDao.addEmployee(employee);         System.out.println("Id1: " );         return id;     } 2. Enable the annotation driven transcation management in applicationContext.xml (where your beans are defined): <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="ht...

Keyboard Shortcuts That Work in All Web Browsers

Tabs Ctrl+1-8 – Switch to the specified tab, counting from the left. Ctrl+9 – Switch to the last tab. Ctrl+Tab – Switch to the next tab – in other words, the tab on the right. ( Ctrl+Page Up also works, but not in Internet Explorer.) Ctrl+Shift+Tab – Switch to the previous tab – in other words, the tab on the left. ( Ctrl+Page Down also works, but not in Internet Explorer.) Ctrl+W , Ctrl+F4 – Close the current tab. Ctrl+Shift+T – Reopen the last closed tab. Ctrl+T – Open a new tab. Ctrl+N – Open a new browser window. Alt+F4 – Close the current window. (Works in all applications.) Mouse Actions for Tabs Middle Click a Tab – Close the tab. Ctrl+Left Click, Middle Click – Open a link in a background tab. Shift+Left Click – Open a link in a new browser window. Ctrl+Shift+Left Click – Open a link in a foreground tab. Navigation Alt+Left Arrow, Backspace – Back. Alt+Right Arrow, Shift+Backspace – Forward. F5 – Reload. Ctrl+F5 – Reload and...

Use mySQl setup from your virtual machine

Image
Have you ever faced a situation where you want to use your MYSQl from your virtual machine. i,e your MYSQL set up is on the windows and your linux is on VM player and you want to use it rather than installing it again on linux box. If yes, Then here is the solution. My System configuration where I have tested. OS : Windows 7 MYSQL: version 5.5 on windows RHEL 5 on VM player Step: 1 . Open MYSQL workbench 5 2.  Open your MYSQL from server Administrator. 3.  Goto Security -> Users and Privileges 4.  Replace 'localhost' with '%' in limited connectivity to host matching box. And you are done here..:) All credit goes to my Manager..Thanx a lot..:)

List all xml files from the JAR.

Do you want to know which all files are in the jar without extracting it.? This is a small tutorial where I am listing all the xml files. import java.io.IOException; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.jar.JarEntry; import java.util.jar.JarFile; /**  * List the name of all xml which is in given jars  *  * @author abdul  */ public class ListXmlFiles {     /* Stores the xml file name*/     List<String> list = new ArrayList<String>();     public List<String> getList() {         return list;     }     /**      * @param args      * @throws IOException      */     public static void main(String[] args) throws IOException {         ListXmlFiles xmlFiles = new ListXmlFiles();  ...

Windows Command Prompt Tricks You Probably Don’t Know

1. Send a Command’s Output to the Clipboard Note: This will work for any command. Without doing copy and paste the output, We can send the output directly to the clipboard. ipconfig | clip 2. Open Command Prompt From a Folder Do you want to open the command promp within a folder from explorer ? All you have to do is hold shift while right  clicking on a folder and the option will appear in the context menu. 3. Command History We can view our past command  i,e using doskey command. doskey /history 4. Drag and Drop Files to Change the Current Path Another neat trick if you are not a fan of opening a command prompt from the context menu is the ability to drag and drop folders onto the prompt and have it automatically enter the path of the folder. 5. Run Multiple Commands In One Go Want to run multiple command at once?  You can do this by linking them with double ampersands. ipconfig && netstat