Package org.springframework.orm.hibernate3

Examples of org.springframework.orm.hibernate3.HibernateTemplate


  public static JdbcTemplate getjt() {   
    return new JdbcTemplate((DataSource) new ClassPathXmlApplicationContext("applicationContext.xml").getBean("ds"));
  }
  public static HibernateTemplate getht(){
    return new HibernateTemplate((SessionFactory)new ClassPathXmlApplicationContext("applicationContext.xml").getBean("sf"));
  }
View Full Code Here


  public List find() throws DaoException {
    return getHelper().findAll(_handledClass);
  }

  public WOJObject find(final Long id) throws DaoException {
        HibernateTemplate t = new HibernateTemplate(getSessionFactory());

        return (WOJObject) t.execute(
            new HibernateCallback() {
                public Object doInHibernate(Session s) throws HibernateException, SQLException {
                    return s.createCriteria(_handledClass).add(Restrictions.eq("id", id)).uniqueResult();
                }
            }
View Full Code Here

    public void setSessionFactory(SessionFactory sessionFactory) {
        _sessionFactory = sessionFactory;
    }
   
    public List findAll(final Class c) {
        HibernateTemplate t = new HibernateTemplate(this._sessionFactory);
       
        return (List)t.execute(
                new HibernateCallback() {
                    public Object doInHibernate(Session s) throws HibernateException, SQLException {
                        return s.createCriteria(c).list();
                    }
                }
View Full Code Here

                }
        );
    }
   
    public void doSave(final WOJObject o) throws DaoException {
        HibernateTemplate t = new HibernateTemplate(this._sessionFactory);
       
        t.execute(
                new HibernateCallback() {
                    public Object doInHibernate(Session s) throws HibernateException, SQLException {
                        s.saveOrUpdate(o);
                        return null;
                    }
View Full Code Here

                }
        );
    }
   
    public void doRemove(final WOJObject o) throws DaoException {
        HibernateTemplate t = new HibernateTemplate(this._sessionFactory);
       
        t.execute(
                new HibernateCallback() {
                    public Object doInHibernate(Session s) throws HibernateException, SQLException {
                        s.delete(o);
                        return null;
                    }
View Full Code Here

    public HibernateProductPointDao(DaoHelper helper) {
        super(helper, ProductPoint.class);
    }

    public ProductPoint get(final Product p, final int years, final int type) {
        HibernateTemplate t = new HibernateTemplate(getSessionFactory());

        return (ProductPoint)t.execute(
            new HibernateCallback() {
                public Object doInHibernate(Session s) throws HibernateException, SQLException {
                    return s.createCriteria(getHandledClass())
                        .add(Restrictions.eq("product", p))
                        .add(Restrictions.eq("years", new Integer(years)))
View Full Code Here

            }
        );
    }
   
    public List get(final Product p, final int type) {
        HibernateTemplate t = new HibernateTemplate(getSessionFactory());

        return (List)t.execute(
            new HibernateCallback() {
                public Object doInHibernate(Session s) throws HibernateException, SQLException {
                    return s.createCriteria(getHandledClass())
                        .add(Restrictions.eq("product", p))
                        .add(Restrictions.eq("type", new Integer(type)))
View Full Code Here

    public String getCurrentVersion() {
        return getCurrentClufVersion().getVersion();
    }

    public ClufVersionImpl getCurrentClufVersion() {
        HibernateTemplate t = new HibernateTemplate(getSessionFactory());
        Number maxId = new Long(0);
        List maxIds = t.find("select max(m.id) from " + ClufVersionImpl.class.getName() + " m");
        if(maxIds != null && maxIds.size() >0) {
            maxId = (Number) maxIds.get(0);
        }
        List foundClufs = t.find("from " + ClufVersionImpl.class.getName() + " c where c.id = ?", maxId);
        if (foundClufs.size() == 0) {
            LOGGER.warn("no current cluf found");
            throw new IllegalStateException("no current cluf found");
        }
        LOGGER.debug("found " + foundClufs.size() + " cluf as current cluf");
View Full Code Here

        LOGGER.debug("found " + foundClufs.size() + " cluf as current cluf");
        return ((ClufVersionImpl)foundClufs.get(0));
    }

    public synchronized ClufImpl getCurrentVersion(String language) {
        HibernateTemplate t = new HibernateTemplate(getSessionFactory());
        ClufVersionImpl version = getCurrentClufVersion();
        List currentCluf = t.find("from " + ClufImpl.class.getName() + " c where c.clufVersion = ? and c.language = ?", new Object[] {version, language});
        if (currentCluf.size() == 0) {
            if ("en".equals(language)) {
                throw new IllegalStateException("no cluf found for "+version.getVersion()+" language=en");
            } else {
                // maybe the language is unknown, let's try with english
                currentCluf = t.find("from " + ClufImpl.class.getName() + " c where c.clufVersion = ? and c.language = ?", new Object[] {version, "en"});
                if (currentCluf.size() == 0) {
                    throw new IllegalStateException("no cluf found for "+version.getVersion()+" language="+language+",en");
                }
            }
        }
View Full Code Here

    public HibernateUserDao(DaoHelper helper) {
        super(helper, UserImpl.class);
    }

    public User findUser(final String login) {
        HibernateTemplate t = new HibernateTemplate(getSessionFactory());
       
        return (User)t.execute(
                new HibernateCallback() {
                    public Object doInHibernate(Session s) throws HibernateException, SQLException {
                      LOGGER.debug("finding user from login " + login);
                     
                      List foundUsers = s.createCriteria(User.class)
View Full Code Here

TOP

Related Classes of org.springframework.orm.hibernate3.HibernateTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.