Saturday, August 9, 2014

Maven + Hibernate + Setter + Getter


/**
 *
 * @author sakib4
 */
public class InvDclStockCategory  implements java.io.Serializable {
 
    private int id;
    private String description;
     private Date creatDate;
     private Date lastUpdateDate;
     private String inactive;

    public InvDclStockCategory() {
    }

   
    public InvDclStockCategory(int id) {
        this.id = id;
    }
    public InvDclStockCategory(int id, String description, Date creatDate,Date lastUpdateDate , String inactive ) {
       this.id = id;
       this.description = description;
       this.creatDate = creatDate;
       this.lastUpdateDate = lastUpdateDate;
       this.inactive = inactive;
    }
  
    public int getId() {
        return this.id;
    }
   
    public void setId(int id) {
        this.id = id;
    }
    public String getDescription() {
        return this.description;
    }
   
    public void setDescription(String description) {
        this.description = description;
    }
   
   
    public void setCreatDate(Date creatDate) {
        this.creatDate = creatDate;
    }
   
    public Date getCreatDate() {
       return this.creatDate = creatDate;
    }

   
    public Date getLastUpdateDate() {
        return this.lastUpdateDate;
    }
   
    public void setLastUpdateDate(Date lastUpdateDate) {
        this.lastUpdateDate = lastUpdateDate;
    }

    public String getInactive() {
        return this.inactive;
    }
   
    public void setInactive(String inactive) {
        this.inactive = inactive;
    }
   
}

Maven + Hibernate + Select & Result List()

Session session = HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();
            Query q = session.createQuery(hql);
            List resultList = q.list();
            displayResult(resultList);
            session.getTransaction().commit();

private void displayResult(List resultList) {
        Vector<String> tableHeaders = new Vector<String>();
        Vector tableData = new Vector();
        tableHeaders.add("Id");
        tableHeaders.add("Category Name");
        tableHeaders.add("Status");
        tableHeaders.add("LastUpdate Date");

        for (Object o : resultList) {
            InvDclStockCategory Cat = (InvDclStockCategory) o;
            Vector<Object> oneRow = new Vector<Object>();
            oneRow.add(Cat.getId());
            oneRow.add(Cat.getDescription());
            oneRow.add(Cat.getInactive());
            oneRow.add(Cat.getLastUpdateDate());
         
            tableData.add(oneRow);
        }
        resultTable.setModel(new DefaultTableModel(tableData, tableHeaders));

    }

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