Saturday, August 9, 2014

Maven + Hibernate Session Delete

 Session session = HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();     
   
                Student userAdd =  (Student)session.get(Student.class, Id);
             
                session.delete(userAdd);
                session.getTransaction().commit();
                session.close();

Maven + Hibernate Session Update

      Session session = HibernateUtil.getSessionFactory().openSession();
          session.beginTransaction();     
 InvDclStockCategory cat = InvDclStockCategory)session.get(InvDclStockCategory.class, Id);
  
                cat.setDescription(Name);
                cat.setInactive(Status);
                
                session.update(cat);
                session.getTransaction().commit();
                session.close();

Maven + Hibernate Session Save

Session session = HibernateUtil.getSessionFactory().openSession();
          session.beginTransaction();     
 
                InvDclStockCategory cat = new InvDclStockCategory();
  
                cat.setDescription(Name);
                cat.setInactive(Status);
                session.save(cat);
                session.getTransaction().commit();
                session.close();
               

Maven + Hibernate Mappings + Auto Increment Sequence Uses

 <!-- hbm.xml files settings -->

<hibernate-mapping>
    <class name="com.datacraft.mavenproject1.InvDclStockCategory" table="inv_dcl_stock_category" schema="public">
        <id name="id" type="int">
            <column name="id" />
               
             <generator class="sequence">
                 <param name="sequence">inv_dcl_stock_category_id_seq</param>
             </generator>
         
        </id>
        <property name="description" type="string">
            <column name="description" length="255" />
        </property>
      
        <property name="inactive" type="string">
            <column name="inactive" />
        </property>
        <property name="creatDate" type="date">
            <column name="create_date" length="13"  />
        </property>
        <property name="lastUpdateDate" type="date">
            <column name="last_update_date" length="13" />
        </property>
    </class>

Thursday, June 26, 2014

Java Regular Expressions common matching symbols

Regular Expression                              Description                                      Example

. Matches any single character          (“..”, “a%”) – true(“..”, “.a”) – true
                                                                                                (“..”, “a”) – false

^xxx     Matches xxx regex at the beginning of the line        (“^a.c.”, “abcd”) – true
                                                                                         (“^a”, “ac”) – false

xxx$   Matches regex xxx at the end of the line   (“..cd$”, “abcd”) – true(“a$”, “a”) – true
                                                                               (“a$”, “aca”) – false

[abc] Can match any of the letter a, b or c. [] are known as character classes.
                                                        (“^[abc]d.”, “ad9″) – true(“[ab].d$”, “bad”) – true
                                                        (“[ab]x”, “cx”) – false

[abc][12] Can match a, b or c followed by 1 or 2  
                                              (“[ab][12].”, “a2#”) – true(“[ab]..[12]“, “acd2″) – true
                                               (“[ab][12]“, “c2″) – false

[^abc] When ^ is the first character in [], it negates the pattern,
                                                                             matches anything except a, b or c
                                          (“[^ab][^12].”, “c3#”) – true(“[^ab]..[^12]“, “xcd3″) – true
                                          (“[^ab][^12]“, “c2″) – false

[a-e1-8] Matches ranges between a to e or 1 to 8
                                                           (“[a-e1-3].”, “d#”) – true(“[a-e1-3]“, “2″) – true
                                                           (“[a-e1-3]“, “f2″) – false

xx|yy  Matches regex xx or yy (“x.|y”, “xa”) – true(“x.|y”, “y”) – true
                                                      (“x.|y”, “yz”) – false


Wednesday, June 25, 2014

Java Interface OOP Concept

package java_mysql;

/**
 *
 * @author sakib
 */
public interface MySQL_Interface {
 
 
  public  String Insert_Store_Procedure(String Table_Fields,String Table_Name,String DB_Name);
 
  public  String Update_Store_Procedure(String Table_Fields,String Table_Name,String DB_Name);
 
  public  String Delete_Store_Procedure(int Table_Field,String Table_Name,String DB_Name);
 
  public  String Select_Store_Procedure(String Table_Fields,String Table_Name);
 
  public  String Create_Table(String Table_Fields,String Table_Name);
 
  public  String Insert_Trigger(String DB_Table_Fields,String Table_Name );
 
  public  String Update_Trigger(String DB_Table_Fields,String Trigger_Name );
 
  public  String Delete_Trigger(String DB_Table_Fields,String Trigger_Name );
 
   
}

Tuesday, June 10, 2014

Junit test for testing methods of Java

package junit_test;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Sakib
 */
public class UtilsTest {
 
    public UtilsTest() {
    }
 
    @BeforeClass
    public static void setUpClass() {
    }
 
    @AfterClass
    public static void tearDownClass() {
    }
 
    @Before
    public void setUp() {
    }
 
    @After
    public void tearDown() {
    }

        /**
     * Test of percentage calculate, of class Utils.
     */
    @Test
    public void testgetPercent() {
     
        double rate = 10;
        double amount = 500;
        double expResult = 50;
        double result = Utils.percentage(rate,amount);
        assertEquals(expResult, result,2);
          }
 
}
Result :Test Passed