Sunday, August 13, 2017

JPA - Tips

###  Orphan Removal and  CascadeType

JPA 2 supports an additional and more aggressive remove cascading mode which can be specified using the orphanRemoval element of the @OneToOne and @OneToMany annotations:

@Entity  
class User{ 
  @OneToOne(orphanRemoval=true) 
  private PhoneNum phoneNum;  
}

The difference between the two settings is in the response to disconnecting a relationship. For example, such as when setting the address field to null or to another Address object.

  • If orphanRemoval=true is specified the disconnected Address instance is automatically removed. This is useful for cleaning up dependent objects (e.g.PhoneNum) that should not exist without a
    reference from an owner object (e.g. User).
  • If only cascade=CascadeType.REMOVE is specified no automatic action is taken since disconnecting a relationship is not a remove
    operation.

Saturday, July 29, 2017

Java - Random Helpful Tips

  • Ternary Operator
This  will to reduce line number of  code . 
condition ? ifConditionTrueWhatShouldHappen : ifConditionFalseWhatShouldHappen
 This can  be use instead of ,Normal if  and  else .


  •  Substring
    •     public String substring(int startIndex) : 
   This method returns new String object containing the substring of the given string from specified     startIndex (inclusive). 

    •     public String substring(int startIndex, int endIndex):  
  This method returns new String object containing the substring of the given string from specified     startIndex   to    endIndex (exclusive).
  Index starts  from 0  .Returns index where found, or -1 if not found 
ex :-  
String text = "Here there everywhere";
int a =text.indexOf("there");   // a is 5
int b =text.indexOf("er"); // b is 1 
int c =text.indexOf("eR"); // c is -1, "eR" is not found
  •  For Checking Null
    if(foo != null && foo.bar()) {
       someStuff();
    }
    will use short-circuit evaluation, meaning it ends if the first condition of a logical AND is false.            
  •  The && and || operators "short-circuit", meaning they don't evaluate the right hand side if it isn't        necessary. The & and | operators, when used as logical operators, always evaluate both sides.


  • Variable Arguments (Varargs) in Java
     
  • There can be only one variable argument in a method.
  • Variable argument (varargs) must be the last argument.
  • ex:-
    // Java program to demonstrate varargs
    class Test1
    {
        // A method that takes variable number of intger
        // arguments.
        static void fun(int ...a)
        {
            System.out.println("Number of arguments: " + a.length);
            // using for each loop to display contents of a
            for (int i: a)
                System.out.print(i + " ");
            System.out.println();
        }
        // Driver code
        public static void main(String args[])
        {
            // Calling the varargs method with different number
            // of parameters
            fun(100);         // one parameter
            fun(1, 2, 3, 4);  // four parameters
            fun();            // no parameter
        }
    }

Friday, July 7, 2017

How to Read Out Loud ,Pdf File etc and Listen to Them Later

If  we  able  to  convert    pdf  files   that  we  have  to read  ,to  audio  files ,It  will  be  great   help  to our   studies .


You  can   use   Adobe  Reader    to  read  out  loud , pdf   files  .But  I    there  is  no direct   way  to convert  those   files  to  MP3  files to  listen  later  .










You  can   use these   steps  in  this  web  page  to use    this  useful  method   Link - Simple Ways on How to Convert PDF to MP3 without any Fuss  .



There  is  other  softwares also ,  But   most  of  them  have  to  pay  to  pay  if  we  convert  them  to  MP3 file  , Watch  this video  .  So  i  think   earlier  way  will  be help most .






Hope   this will  help  to  your   studies . Try  it .

Tuesday, May 30, 2017

How to use CMD to recover files from virus infected storage media

If    your data lost or inaccessible due to virus attacks,  you   can  use CMD (command  prompt)   to  recover  those   files . 

#  First  open  cmd .
#  Then  type        ATTRIB  -H  -R  -S   /S    /D  J:\*.*        in  cmd .   Letter  "J"  in that  should  replace  from  your  drive  name  letter .
#  Then , you  will  able  to  view  your   files  that  inaccessible  due  to  virus  attack .
#  Some  times   you  may  get   error  saying , "ATTRIB  is not  recognized as an internal or external command ........"  etc  , Then edit 
  1. Right click My Computer> Properties> Advanced System Settings  or  search   for "Environment variables"  in  find  option .
  2. In the Advanced System Settings Tab, click on Environment variables and look for Path in System variables
  3. Click Edit and add C:\Windows\System32  at the end of the already  have path  variable . MAKE SURE YOU DON'T DELETE THE REST OF THE STRING


Wednesday, May 10, 2017

Components to be created in Spring MVC application.

1.Add maven dependencies  in  porm.xml

2.Add DispatcherServlet in web.xml

3.Configure view-resolver in spring-servlet.xml

4.Create the controller with handler  mappings

5.Finally write the JSP

Monday, April 24, 2017

Data Access Object (DAO)

# The Data Access Object (DAO) support in Spring is aimed at making it easy to
  work with data access technologies like JDBC,   Hibernate, JPA (our one JPA) or JDO in a consistent way

# The best way to guarantee that your Data Access Objects (DAOs) or
  repositories provide exception translation is to use the @Repository annotation

# Any DAO or repository implementation will need to access to a persistence resource,
 depending on the persistence technology used; for example, a JDBC-based repository will
 need access to a JDBC DataSource; a JPA - based repository will need access to an EntityManager.
 The easiest way to accomplish this is to have this resource dependency injected using one of
 the @Autowired,, @Inject,@Resource or @PersistenceContext annotations.

 @Autowired
 EntityManager em;

# return em.createNativeQuery(sql).getResultList();

# Query query = em.createNativeQuery(sql);
  BigDecimal exChangeRate = (BigDecimal)query.getSingleResult();

Some interesting things to explore more

 Here  some  some  things  to  study  more ,     How Google Search works               https://developers.google.com/search/docs/fundamental...