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

com.formkiq.server.dao.SystemDaoImpl Maven / Gradle / Ivy

package com.formkiq.server.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.transform.AliasToBeanResultTransformer;
import org.springframework.stereotype.Repository;

import com.formkiq.server.domain.SystemProperty;
import com.formkiq.server.domain.type.SystemPropertyDTO;

/**
 * SystemDao implementation.
 *
 */
@Repository
public class SystemDaoImpl extends AbstractDaoImpl implements SystemDao {

    @Override
    public void delete(final String key) {

        SystemProperty property = getEntityManager().find(SystemProperty.class,
                key);

        if (property != null) {
            getEntityManager().remove(property);
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public List getProperties() {
        String sql = "select p.key as key, p.value as value "
                + " from system_properties p "
                + " order by p.key ";

        Session session = getEntityManager().unwrap(Session.class);
        List list = session.createSQLQuery(sql)
                .setResultTransformer(new AliasToBeanResultTransformer(
                        SystemPropertyDTO.class))
                .list();

        return list;
    }

    @Override
    public String getValue(final String key) {

        SystemProperty property = getEntityManager().find(SystemProperty.class,
                key);

        if (property != null) {
            return property.getValue();
        }

        return null;
    }

    @Override
    public SystemProperty save(final SystemProperty property) {
        getEntityManager().merge(property);
        return property;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy