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

io.robe.admin.hibernate.dao.SystemParameterDao Maven / Gradle / Ivy

There is a newer version: 0.5.0.0-1039
Show newest version
package io.robe.admin.hibernate.dao;

import com.google.common.base.Optional;
import javax.inject.Inject;
import io.robe.admin.hibernate.entity.SystemParameter;
import io.robe.hibernate.dao.BaseDao;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.transform.Transformers;

import java.util.List;

public class SystemParameterDao extends BaseDao {

    @Inject
    public SystemParameterDao(SessionFactory sessionFactory) {
        super(sessionFactory);
    }


    public Optional findByKey(String key) {
        Criteria criteria = currentSession().createCriteria(SystemParameter.class);
        criteria.add(Restrictions.eq("key", key));
        return Optional.fromNullable(uniqueResult(criteria));
    }

    public List getAll() {
        Criteria criteria = currentSession().createCriteria(SystemParameter.class);

        criteria.setProjection(
                Projections.distinct(Projections.projectionList()
                        .add(Projections.property("key"), "key").add(Projections.property("value"), "value")));

        criteria.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);

        return list(criteria);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy