Friday, August 24, 2012

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="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/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- Main transaction manager for accessing internal DB -->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
   
    <!-- enable the configuration of transactional behavior based on annotations -->
  <tx:annotation-driven transaction-manager="transactionManager"/>

That's it. Hope it works for other too.

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 skip the cache, re-downloading the entire website.
Escape – Stop.
Alt+Home – Open homepage.

Zooming

Ctrl and +, Ctrl+Mousewheel Up – Zoom in.
Ctrl and -, Ctrl+Mousewheel Down — Zoom out.
Ctrl+0 – Default zoom level.
F11 – Full-screen mode.

Scrolling

Space, Page Down – Scroll down a frame.
Shift+Space, Page Up – Scroll up a frame.
Home – Top of page.
End – Bottom of page.
Middle Click – Scroll with the mouse. (Windows only)

Address Bar

Ctrl+L, Alt+D, F6 – Focus the address bar so you can begin typing.
Ctrl+Enter – Prefix www. and append .com to the text in the address bar, and then load the website. For example, type howtogeek into the address bar and press Ctrl+Enter to open www.howtogeek.com.
Alt+Enter – Open the location in the address bar in a new tab.

Search

Ctrl+K, Ctrl+E – Focus the browser’s built-in search box or focus the address bar if the browser doesn’t have a dedicated search box. (Ctrl+K doesn’t work in IE, Ctrl+E does.)
Alt+Enter – Perform a search from the search box in a new tab.
Ctrl+F, F3 – Open the in-page search box to search on the current page.
Ctrl+G, F3 – Find the next match of the searched text on the page.
Ctrl+Shift+G, Shift+F3 – Find the previous match of the searched text on the page.

History & Bookmarks

Ctrl+H – Open the browsing history.
Ctrl+J – Open the download history.
Ctrl+D – Bookmark the current website.
Ctrl+Shift+Del – Open the Clear Browsing History window.

Other Functions

Ctrl+P – Print the current page.
Ctrl+S – Save the current page to your computer.
Ctrl+O – Open a file from your computer.
Ctrl+U – Open the current page’s source code. (Not in IE.)
F12 – Open Developer Tools. (Requires Firebug extension for Firefox.)


Tuesday, August 7, 2012

Use mySQl setup from your virtual machine

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();
        JarFile jarFile = new JarFile("./lib/dummyJar.jar");
        Enumeration<JarEntry> e = jarFile.entries();
        while (e.hasMoreElements()) {
            xmlFiles.process(e.nextElement());
        }
        System.out.println("List:" + xmlFiles.getList());
    }

    private void process(Object obj) {
        JarEntry entry = (JarEntry)obj;
        String name = entry.getName();
        if(name.endsWith(".xml")) {
            list.add(name);      
        }
    }
}

If you want to know all the files name inside,Just removed the if-else filter, It will add all  the filename into the list.
private void process(Object obj) {
        JarEntry entry = (JarEntry)obj;
        String name = entry.getName();
        list.add(name);        

}


Wednesday, August 1, 2012

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

Friday, July 27, 2012

How to read properties file using ANT

Suppose You have to access some properties (from a file), which are already defined in my build file. To be able to access the properties We can use the build attribute of the property task. 

build.properties

#Release information 
#Thu Oct 14 16:25:12 CEST 2004
build.number=115
release.version=0.4
release.name=framework
 
Ant Example Target

<target name="read.properties">    
  <!-- Read the properties from the release of the framework -->
  <property file="build.properties" prefix="build"/>
  <echo message="${build.build.number}"/>
  <echo message="${build.release.version}"/>
  <echo message="${build.release.name}"/>    
</target> 
 
Output

Buildfile: C:\build.xml
read.properties:
  [echo] 115
  [echo] 0.4
  [echo] framework
BUILD SUCCESSFUL
Total time: 3 seconds

Monday, July 23, 2012

chkconfig Command Examples

chkconfig command is used to setup, view, or change services that are configured to start automatically during the system startup.

chkconfig has five distinct functions: adding new services for management, removing services from management, listing the current startup information for services, changing the startup information for services, and checking the startup state of a particular service.

chkconfig --list [name]
chkconfig --add name
chkconfig --del name
chkconfig [--level levels] name <on|off|reset>
chkconfig [--level levels] name 

OPTIONS

--level levels
Specifies the run levels an operation should pertain to. It is given as a string of numbers from 0 to 7. For example, --level 35 specifies runlevels 3 and 5.
--add name
This option adds a new service for management by chkconfig.
--del name
The service is removed from chkconfig management.
--list name
This option lists all of the services which chkconfig knows about, and whether they are stopped or started in each runlevel. If name is specified, information in only display about service name
 
Example : 

1 .  How to add any scripts in the chkconfig ?

You have to modify the script a little bit to make it work at boot time. Just add the following lines at the beginning of the file

#!/bin/sh
#chkconfig: 2345 80 30 
#description: Service Description


This says that the random script should be started in levels 2, 3, 4, and 5, that its start priority should be 80, and that its stop priority should be 30. You should be able to figure out what the description says; the \ causes the line to be continued. The extra space in front of the line is ignore
Note : There is no space in between '#' and 'chkconfig'.

2.  Copy your scripts into init.d folder.
    copy the scripts file to /etc/init.d.

3. How to add service to the startup

   chkconfig --add service_name

4. How to view status of startup services
     chkconfig --list
     To view particular service : chkconfig --list | grep service_name
   
 5. How to remove a service from startup list
   chkconfig --del service_name

6. How to Turn-on or Turn-off a service for a selected Run level
   Sometimes you might not want to delete the whole service. Instead, you might just want to turn the  flag on or off for a particular run level (for a particular service).
   chkconfig --level 3 service_name on/off 

 7. How to check service startup status from shell script
    create a file check.sh
    vi check.sh
    chkconfig service_name && echo "${service_name} service is configured"
    chkconfig service_name --level 3 && echo "${service_name} service is configured for level 3"
  
   ./check.sh


NOTE:

 - Run level 0 – /etc/rc.d/rc0.d/
 - Run level 1 – /etc/rc.d/rc1.d/
 - Run level 2 – /etc/rc.d/rc2.d/
 - Run level 3 – /etc/rc.d/rc3.d/
 - Run level 4 – /etc/rc.d/rc4.d/
 - Run level 5 – /etc/rc.d/rc5.d/
 - Run level 6 – /etc/rc.d/rc6.d/

 - Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
 - Programs starts with S are used during startup. S for startup.
 - Programs starts with K are used during shutdown. K for kill.
 - There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.


How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...