All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.fluent.hibernate.HibernateObjectQuery Maven / Gradle / Ivy

Go to download

A library to work with Hibernate by fluent API. This library hasn't dependencies except Hibernate dependencies. It requires Java 1.6 and above.

There is a newer version: 0.3.1
Show newest version
package com.github.fluent.hibernate;

import java.util.List;

import org.hibernate.Session;

/**
 * @author DoubleF1re
 * @author V.Ladynev
 */
class HibernateObjectQuery {

    @SuppressWarnings("unchecked")
    public static  T save(final T entity) {
        return HibernateSessionFactory.doInTransaction(new IRequest() {
            @Override
            public T doInTransaction(Session session) {
                return (T) session.save(entity);
            }
        });
    }

    public static  void saveOrUpdate(final T entity) {
        HibernateSessionFactory.doInTransaction(new IRequest() {
            @Override
            public Void doInTransaction(Session session) {
                session.saveOrUpdate(entity);
                return null;
            }
        });
    }

    public static  void saveAll(final List entities) {
        HibernateSessionFactory.doInTransaction(new IRequest() {
            @Override
            public Void doInTransaction(Session session) {
                for (T entity : entities) {
                    session.save(entity);
                }
                return null;
            }
        });
    }

    public static  void saveOrUpdateAll(final List entities) {
        HibernateSessionFactory.doInTransaction(new IRequest() {
            @Override
            public Void doInTransaction(Session session) {
                // TODO need batch update
                for (T entity : entities) {
                    session.saveOrUpdate(entity);
                }
                return null;
            }
        });
    }

    public static  void delete(final T entity) {
        HibernateSessionFactory.doInTransaction(new IRequest() {
            @Override
            public Void doInTransaction(Session session) {
                session.delete(entity);
                return null;
            }
        });
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy