package com.acme.model.domain.sc.dao;


import com.acme.structure.BaseEntity;
import com.acme.structure.dao.MainDao;

import java.util.Collection;

import javax.persistence.EntityManager;
import javax.persistence.Query;


public class SCDao
{
    MainDao dao = null;

    public SCDao()
    {
        dao = new MainDao();
    }

    public Collection<BaseEntity> findServicesForList(EntityManager manager)
    {
        StringBuilder queryString = new StringBuilder();
        queryString.append("SELECT new com.acme.model.domain.sc.entity.Service(s.id, s.code, s.name) \n").append("FROM Service s \n").append("ORDER BY s.name \n");

        Query query = manager.createQuery(queryString.toString());

        return query.getResultList();
    }

    public Collection<BaseEntity> findServiceGroupsForList(EntityManager manager)
    {
        StringBuilder queryString = new StringBuilder();
        queryString.append("SELECT new com.acme.model.domain.sc.entity.ServiceGroup(s.id, s.name) \n").append("FROM ServiceGroup s \n").append("ORDER BY s.name \n");

        Query query = manager.createQuery(queryString.toString());

        return query.getResultList();
    }

    public Collection<BaseEntity> findTablesForList(EntityManager manager)
    {
        StringBuilder queryString = new StringBuilder();
        queryString.append("SELECT new com.acme.model.domain.sc.entity.Table(t.id, t.name) \n").append("FROM Table t \n").append("ORDER BY t.name \n");

        Query query = manager.createQuery(queryString.toString());

        return query.getResultList();
    }
}
