Tuesday, September 25, 2012

Maven POM configuration for Axis2 and Spring

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>example</artifactId>
        <groupId>example</groupId>
        <version>0.0.1</version>
    </parent>
    <groupId>example</groupId>
    <artifactId>services</artifactId>
    <version>0.0.1</version>
    <name>Services</name>
    <description>The component will be exposed as the  service operations.</description>
    <url>http://maven.apache.org</url>
    <packaging>aar</packaging>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>target</directory>
                            <followSymlinks>false</followSymlinks>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.axis2</groupId>
                <artifactId>axis2-aar-maven-plugin</artifactId>
                <extensions>true</extensions>
                <version>1.5</version>
                <configuration>
                    <servicesXmlFile>META-INF/services.xml</servicesXmlFile>
                    <aarName>examplews</aarName>
                    <includeDependencies>true</includeDependencies>
                    <fileSets>
                        <fileSet>
                            <directory>META-INF</directory>
                            <outputDirectory>META-INF</outputDirectory>
                            <includes>
                                <include>services.xml</include>
                            </includes>
                        </fileSet>
                        <fileSet>
                            <directory>servicewsdl</directory>
                            <outputDirectory>META-INF</outputDirectory>
                            <includes>
                                <include>examplewsdata.xsd</include>
                                <include>examplews.wsdl</include>
                            </includes>
                        </fileSet>
                    </fileSets>
                </configuration>
                <goals>
                    <goal>aar</goal>
                </goals>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.4.2</version>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
   
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-mock</artifactId>
            <version>2.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-dao</artifactId>
            <version>2.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>2.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-hibernate3</artifactId>
            <version>2.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-adb</artifactId>
            <version>1.5.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-spring</artifactId>
            <version>1.5.1</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.2.2</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.9</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.2</version>
        </dependency>
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.4.GA</version>
        </dependency>
    </dependencies>
</project>

Monday, September 19, 2011

Identifying the state of hibernate objects practically

Emp instance=new Emp(); /* creating the transient object using the new operator which is not attached to database , which has to be saved in db usinh save or saveorupdate method of session object from sessionfactory */
instance.setEmpno(new Integer("111111"));
instance.setEname("sandeep");
instance.setJob("SE");
instance.setMgr(new Integer(6));
instance.setSal(546545646.89898);
instance.setHiredate(new Date());
com.DeptHome deptHome=new com.DeptHome();
Dept dept2=deptHome.findById(40);/* userdefined method findById persist object which is attached with session need to update not to save*/
instance.setDept(dept2);

empHome.attachDirty(instance);/*user defined method conatins save method of session object to save instance to db*/


------------------------------------------------------------
Emp emp=empHome.findById(7942);/* findById is user defined method to retrive the emp object using the emp id hence emp object is persist object attached to session which can be modified and save into database using the saveorupdate method of session object */

emp.setEname("hariesh");
empHome.attachsaveorupdate(emp);

org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at com.EmpHome.attachsaveorupdate(EmpHome.java:137)
at com.EmpHome.main(EmpHome.java:76)


Solution
This Exception will arise in different scenario of save and saveOrupdate method of hibernate.
if Object is transient , need to save may occur this exception
Conditions.
1. Flushing the data before committing the object may lead to clear all object pending for persist.
2. If object has primary key which is auto generated and you are forcing has assigned key may cause the exception.
3. if you are cleaning the object before committing the object to database may lead this exception.
4. Zero or Incorrect ID:
Hibernate excepts an primary or id of null (not initialize while saving) has per point 2 to mean the object was not saved. If you set the ID to zero or something else, Hibernate will try to update instead of insert, or it lead may to throw this exception.
5.
Object Doesn’t Exist: This is the most easy to determine : has the object get deleted somehow? If so, trying to delete once again it will throw this exception.
6.
Object is Stale: Hibernate caches objects from the session. If the object was modified, and Hibernate doesn’t know about it, it will throw this exception — note the StaleStateException part of the exception.

so after committing the object to database need to flush or clear or clean it ,not before.

Friday, August 19, 2011

Different and best Swings Look and feel Themes


Here is the code

package com.gui;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class MainGUI extends JPanel implements ActionListener {

private static final long serialVersionUID = 1L;
private JButton jbmMetal = new JButton("Metal");
private JButton jbnMotif = new JButton("Motif");
private JButton jbnWindows = new JButton("Windows");
private JButton jbnliquid = new JButton("Liquid");
private JButton jbnstick = new JButton("Stick");
private JButton tatto = new JButton("JTatto Aluminium");
private JButton acryltatto = new JButton("JTatto Acryl");
private JButton Aerotatto = new JButton("JTatto Aero");
private JButton beristeintatto = new JButton("JTatto Bernstein");
private JButton lunatatto = new JButton("JTatto Luna");
private JButton minttatto = new JButton("JTatto mint");
private JButton smarttatto = new JButton("JTatto Smart");
private JButton hifitatto = new JButton("JTatto HiFi");
private JButton quaqua = new JButton("QuaQua");
public MainGUI() {
add(jbmMetal);
add(jbnMotif);
add(jbnWindows);
add(jbnliquid);
add(jbnstick);
add(tatto);
add(acryltatto);
add(Aerotatto);
add(beristeintatto);
add(lunatatto);
add(minttatto);
add(smarttatto);
add(hifitatto);
add(quaqua);
jbmMetal.addActionListener(this);
jbnMotif.addActionListener(this);
jbnWindows.addActionListener(this);
jbnliquid.addActionListener(this);
jbnstick.addActionListener(this);
tatto.addActionListener(this);
acryltatto.addActionListener(this);
Aerotatto.addActionListener(this);
beristeintatto.addActionListener(this);
lunatatto.addActionListener(this);
minttatto.addActionListener(this);
smarttatto.addActionListener(this);
hifitatto.addActionListener(this);
quaqua.addActionListener(this);
}


public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
String laf = "";
if (source == jbmMetal)
laf = "javax.swing.plaf.metal.MetalLookAndFeel";
else if (source == jbnMotif)
laf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
else if (source == jbnWindows)
laf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
else if (source == jbnliquid)
laf = "com.birosoft.liquid.LiquidLookAndFeel";
else if (source == jbnstick)
laf = "com.lipstikLF.LipstikLookAndFeel";
else if (source == tatto)
laf = "com.jtattoo.plaf.aluminium.AluminiumLookAndFeel";
else if (source == acryltatto)
laf = "com.jtattoo.plaf.acryl.AcrylLookAndFeel";
else if (source == Aerotatto)
laf = "com.jtattoo.plaf.aero.AeroLookAndFeel";
else if (source == beristeintatto)
laf = "com.jtattoo.plaf.bernstein.BernsteinLookAndFeel";
else if (source == lunatatto)
laf = "com.jtattoo.plaf.luna.LunaLookAndFeel";
else if (source == minttatto)
laf = "com.jtattoo.plaf.mint.MintLookAndFeel";
else if (source == smarttatto)
laf = "com.jtattoo.plaf.smart.SmartLookAndFeel";
else if (source == hifitatto)
laf = "com.jtattoo.plaf.hifi.HiFiLookAndFeel";
else if (source == quaqua)
laf = "ch.randelshofer.quaqua.QuaquaLookAndFeel";

try {
UIManager.setLookAndFeel(laf);
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception excep) {
}
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("Look and Feel Test");
frame.setSize(500, 300);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Container contentPane = frame.getContentPane();
contentPane.add(new MainGUI());
frame.setVisible(true);
Calculator calculator = new Calculator();
}


}

4 third party jars need to download

liquidlnf.jar
lipstikLF-1.1.jar
JTattoo.jar
quaqua.jar
quaqua-filechooser-only.jar

Wednesday, August 10, 2011

Converting audio/video files using ffmpeg

ffmpeg command can be used to convert the audio/video from one format to another format

Common ffmpeg Parameters
  • -i - Path\Filename of source file
  • -y - Overwrite the existing output file without prompting
  • -an - Disable audio
Video Related ffmpeg Parameters
  • -aspect - Set Aspect Ratio for the video (4:3, 16:9 or 1.3333, 1.7777)
  • -r - Set frame rate in Hz for the video
  • -s - Set video resolution size (Width x Height)
  • -sameq - Use same video quality as source
Audio Related ffmpeg Parameters
  • -ar - Set audio sampling rate (in Hz)
  • -acodec - Force audio codec, example mp3
  • -vol - Change audio volume (256=normal)
  • -ab - Set audio bit rate (in bits/s)
Syntax
ffmpeg Command

Video
  • Converting MOV to FLV using FFMPEG:
    ffmpeg -i movie.mov movie.flv
  • Converting Mpeg to FLV using FFMPEG:
    ffmpeg -i movie.mpeg movie.flv
  • Converting AVI to FLV using FFMPEG - convert movie.avi to movie.flv and resize the video resolution to 500×500:
    ffmpeg -i movie.avi -s 500×500 movie.flv
  • Converting 3GP to FLV using FFMPEG - convert movie.3gp to movie.flv, keep the original file settings and disable the audio content:
    ffmpeg -i movie.3gp -sameq -an movie.flv
  • Converting MPEG to 3GP using FFMPEG:
    ffmpeg -i movie.mpeg -ab 8.85k -acodec libamr_wb -ac 1 -ar 16000 -vcodec h263 -s qcif movie2.3gp
Audio

  • Converting aac to mp3 using FFMPEG with MetaData - convert audio.aac to audio.mp3 with an audio rate of 22.05 Khz and audio BitRate of 32Khz, and will copy the metadata from .aac file to .mp3 file:
    ffmpeg -i audio.aac -ar 22050 -ab 32 -map_meta_data audio.mp3:audio.aac audio.mp3
  • Converting WMV to MP3 using FFMPEG
    ffmpeg -i audio.wmv audio.mp3
  • Converting WMV to FLV using FFMPEG - convert audio.wmv to audio.flv, generating only audio content:
    ffmpeg -i audio.wmv audio.flv
  • Converting AMR to MP3 using FFMPEG - convert audio.amr to audio.mp3, with an audio rate of 22.05 Khz:
    ffmpeg -i audio.amr -ar 22050 audio.mp3
  • Converting aac to mp3 using FFMPEG - convert audio.aac to audio.mp3, with an audio rate of 22.05 Khz and audio BitRate or 32Khz:
    ffmpeg -i audio.aac -ar 22050 -ab 32 audio.mp3
FFmpeg download

http://ffmpeg.arrozcru.org/autobuilds/


convert avi to flv like in youtube

ffmpeg -i video_origine.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv video_finale.flv





Tuesday, April 5, 2011

How to hide closed project in eclipse

Eclipse comes with a cool tiny feature t
hat many of us not know. You may want to Hide all those closed projects from your workspace in Project Explorer tab. Simply follow following steps and do this is few seconds!



Click on Customize view a pop will open

select the closed project and then say ok.
Three Steps hide the closed projects..