Posts

Linux Reference Page

##Finding particular text in files Find all the *.java files which contains the string confirmStatus in directory src (relative to the current directory). command$  find ./src -name \*.java | xargs grep -il 'confirmStatus' find commands searches list of files and passes the list to xargs, which in turns split the list and passes the each file name as argument to grep command. ##Change Domain password from Linux smbpasswd -r -U ## Setting up Printer in Ubuntu Linux $ gksudo system-config-printer ## Mounting Share drive in Guest Ubuntu Oracle Virtual Box To mount a shared folder say C:\MyVideos as MySharedVideos sudo mount -t vboxsf  MySharedVideos   /media/siddshare2 where  MySharedVideos  is the shared folder name and /media/siddshare2 is the mount point location. ##  Printing all contents to a single line Where myfile.txt contains some text data which we want to print in a single line. cat myfile.txt | tr -d '\n' > oneline.txt...

JSON Manipulation in Java

JSON stands for Java Script Object Notation, in which essentially we represent data in name:value pair in a string. Example of JSON strin is as follows {    "lastName":"Smith",    "suffix":"Jr",    "city":"Foster City",    "country":"US",    "postalCode":"94404",    "firstName":"John" } Which represent the Data about a user. JSON is a standard notation to exchange data. To process Json String , like converting from Json String to Java or vice versa we have so many different libraries in Java.One of the Most prominent being Jackson, Bellow are the example or Some Use cases for Handling Json in Java. Converting JSON String to Java Object Using Jackson We can use ObjectMapper to convert a JSON String to java Object. ObjectMapper mapper = new ObjectMapper(); UserInfo userInfoObj = mapper.readValue(JSONStringSrc,  UserInfo.class); Where UserInfo Obje...

String Manipulation in Java

Working with String like things in java is very common, and one of the common uses case. While we need to replace a substring inside a long String, we have couple of options in java. Java "String" itself has methods like replace and replaceAll which we can use to replace a substring from the main string. The other option is using StringBuilder  which has method like replace(start, end,str);   Which is better then the formar and we will see the difference in details next. We can also use Pattern and Matcher to replace substring from String like bellow. Pattern p = Pattern.compile(" \\$\\{USERNAME\\ }"); Matcher m = p.matcher(ORIGINAL_STRING); p = Pattern.compile(" \\$\\{USERNAME\\ }"); m = p.matcher(ORIGINAL_STRING); m.replaceAll(USERNAME_VALUE); But the for most of the cases much better and efficient way to replace substring is to use Apache StringUtils Utility Class. I have created some test methods which utilizes the above mentioned dif...

Hibernate Exceptions Errors and Causes

The following section will list the general exception that we get while dealing with hibernate. org.hibernate.ObjectDeletedException:deleted object would be re-saved by cascade when we try to delete the child object and don't remove the association, for instance we loaded a parent object with list of child and then we deleted one of the child object but did not removed the child from the parent. Example, Box gotBox =(Box)dao.load(Box.class, box.getBoxId()); List boxitem = new ArrayList(gotBox.getBoxItems()); BoxItem deleteItem = boxitem.get(0); dao.deletItem(deleteItem.getItemName()); Solution is, remove the transient instance from the parent object(Box) like.   gotBox.getBoxItems().remove(deleteItem); OR use   @Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN) on the child object. ------------------------------------------------------------------------------------------------- No Dialect mapping for JDBC type: -1 We get th...

DB2 Specific Working Titbits

We can find if a table needs to be reorged or not by using the following query. db2 "select tabschema,tabname from SYSIBMADM.ADMINTABINFO where reorg_pending='Y'" To get the information about the Table and Schema from the TBSSPACEID and TableID use the following SQL. SELECT C.TABSCHEMA, C.TABNAME, C.COLNAME FROM SYSCAT.TABLES AS T, SYSCAT.COLUMNS AS C WHERE T.TBSPACEID = 3 AND T.TABLEID = 258 AND C.COLNO = 6 AND C.TABSCHEMA = T.TABSCHEMA AND C.TABNAME = T.TABNAME Selecting or Generating the Next Value for a particular Sequence in DB2. For example say we have a sequece name PAYMENT_TABLE_SEQ,  and we want to check wheather this sequence is working or not we can do it by the following SQL in DB2, values(NEXTVAL FOR PAYMENT_TABLE_SEQ )  Using the above we can generate the next value for a particular Sequence and also make sure that the sequence is working

Effect of Select Strategies in Hibernate How and When

STUDY : Hibernate Common Issues and Tips Effect of Select Strategies in Hibernate (How and When) Hibernate is one of the most popular ORM tools. In my own experience I have found that in the application development life cycle we often get some common hibernate related issues, be it performance related issues or Exception generated by hibernate. I have tried to capture the exception or problems we get while  using hibernate in the data access layer. The overall finding is divided in to different scene's. In Hibernate 3 when we load a particular object from db, only that object is loaded and the associated objects are not loaded.  For example if we have a relationship like      Director   ---> Movies(many) If we now load the director all the movies will not be retrieved from data base . We can control this behavior like whether to load the related objects(movies in this case) using fetching strategies. By default all the related o...

Better JVM in linux : Swapiness

Recently I found interesting issue regarding JVM and Linux Swapiness. I was getting java out of memory while compiling my Java application. I have 8GB/Linux, and I was getting Java out of memory while compiling it alone (Without any other memory intensive job), also the overall build time was rediculously high. I googled and tried some tricks on the machine, after that my build time was significantly better and  most importantly, I did not get any out of memory from JVM. What I did is that I set the swapiness of the system to 10 from 60. Swapiness is a value between 0 to 100 and it's a parameter to the linux kerner to take decision on how aggressively to take processes out of the RAM to Swap Space in the Hard disk. Swapiness with 0 tells the kernel to avoid using Swap as far as possible, but it does not mean Swap wont be used at all. Swapiness with value 100 tells the kernel to use Swap space aggressively. You can check swapiness of your linux system using the followi...