com.anyframe.appserver.websocket.client.hibernate.GetVo.java Source code

Java tutorial

Introduction

Here is the source code for com.anyframe.appserver.websocket.client.hibernate.GetVo.java

Source

/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  All third-party contributions are
 * distributed under license by Red Hat Inc.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package com.anyframe.appserver.websocket.client.hibernate;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import com.gmes.poc.test.vo.DbProductVO;

public class GetVo {
    private static SessionFactory sessionFactory;
    private static DbProductVO testVo;

    private static SessionFactory getInstanceofSessionFactory() {
        // A SessionFactory is set up once for an application
        if (sessionFactory == null)
            sessionFactory = new Configuration().configure() // configures settings from hibernate.cfg.xml
                    .buildSessionFactory();

        return sessionFactory;
    }

    //   private static DbProductVO getVO() {
    //      // A SessionFactory is set up once for an application
    //      if( testVo == null ) {
    //         testVo = new DbProductVO();
    //         
    //         testVo.setEanCode("1000000");
    //         testVo.setName("U6NHYU67Ae0LuNxG9lNMuHGYGMkm4q");
    //         testVo.setCategoryId("9kiQ8cikf");
    //         testVo.setPrice("51.29");
    //         testVo.setManufacturer("63U0OV7zkvaPQ0SrwOUbZQOR7tZgzJ");
    //         testVo.setNotes("yElKNc7GZIKDEov4Rk2pA84Unyw0kpwg4OKan9qwMpr6zsHiLOFLekNKTgTGAlGmawsCvYB6nFM6bQwA4kPTBVpDwnOoLQrrgCqK1oBX21J2Dyrv9HQqweKJBZBwbKXXUinpArfXGyb0Lqoz9osxdzhLcmKVMEos8veUJruUBth64W0SXW82DOIZgPGLcuTcGbNijUBchhMLiSGX7FXJ2jy3Ej4L81SN3L5e5mKbcTo14pigHAtNouiaK1T2xaGg");
    //         testVo.setDescription(null);
    //         testVo.setImage(null);
    //         
    //      }
    //      return testVo;
    //   }   

    public List<DbProductVO> getVOfromH2(int first, int last) {

        Session session = getInstanceofSessionFactory().openSession();

        // now lets pull events from the database and list them
        session = getInstanceofSessionFactory().openSession();
        List result = session
                .createQuery("from DbProductVO where ean_code >= " + first + " and ean_code < " + (first + last))
                .list();
        return result;

        //      List<DbProductVO> result = new ArrayList<DbProductVO>();
        //      
        //      for( int i = first; i <first+last; i++) {
        //         result.add(getVO());
        //         
        //      }
        //      return result;

    }

}