Wednesday, September 7, 2011

How to access "internal exception" type in JAVA

how to catch MySQLIntegrityConstraintViolationException exception


Suppose JPA entry is:

@Table(name = "players", uniqueConstraints=@UniqueConstraint(columnNames={"firstname", "lastname"}))


EJB class is:
public void create(Player player) {
try {
em.persist(player);
em.flush();
} catch (Exception e) {
e.printStackTrace();
Throwable t = getLastThrowable(e);
throw new Exception(t);
}
}



/** method to access internal exceptions */

private Throwable getLastThrowable(Exception e) {
Throwable t = null;
for(t = e.getCause(); t.getCause() != null; t = t.getCause());
return t;
}

Tuesday, November 24, 2009

Thursday, October 29, 2009

GloMoSim with Ubuntu

  • Download GloMoSim from here
  • Uncompress glomosim-2.03.tar.gz file
$tar -xzvf glomosim-2.03.tar.gz

  • Set Environment variable
$ gedit ~/.bashrc
Then add following lines
PCC_DIRECTORY=GloMoSim_ROOT/glomosim-2.03/parsec/redhat-7.2
export PCC_DIRECTORY


  • Copy both files pcc and parsecc from glomosim-2.03/parsec/redhat-7.2/bin/ dir and copy into usr/bin dir
$ sudo cp glomosim-2.03/parsec/redhat-7.2/bin/pcc glomosim-2.03/parsec/redhat-7.2/bin/parsecc usr/bin


  • Goto glomosim-2.03/glomosim/main dir and run make.
$ cd glomosim-2.03/glomosim/main
$ make