Example usage for org.hibernate.type CalendarType CalendarType

List of usage examples for org.hibernate.type CalendarType CalendarType

Introduction

In this page you can find the example usage for org.hibernate.type CalendarType CalendarType.

Prototype

public CalendarType() 

Source Link

Usage

From source file:br.gov.jfrj.siga.wf.relatorio.RelTempoDoc.java

License:Open Source License

/**
 * Retorna os docs no perodo indicado, ordenadas pelo tempo de
 * demora, podendo estar ou no finalizados.
 * /*from  w  w  w. j a v  a  2  s  . c  o m*/
 * Exemplo da query:
 * 
 * SELECT PI.START_,PI.END_,VI.STRINGVALUE_,PI.ID_ FROM
 * SIGAWF.JBPM_PROCESSINSTANCE PI, (SELECT DISTINCT PROCESSINSTANCE_,
 * STRINGVALUE_ FROM SIGAWF.JBPM_VARIABLEINSTANCE WHERE NAME_ LIKE 'doc_%'
 * AND STRINGVALUE_ LIKE '%-_' AND STRINGVALUE_ IS NOT NULL) VI, (SELECT *
 * FROM SIGAWF.JBPM_PROCESSDEFINITION WHERE NAME_ = 'Contratao: fase de
 * anlise') PD WHERE PI.PROCESSDEFINITION_=PD.ID_ AND PI.END_ IS NOT NULL
 * AND PI.ID_ = VI.PROCESSINSTANCE_ AND (PI.START_ >= To_Date('01/03/2011')
 * and PI.START_ <= To_Date('31/03/2011')) AND (PI.END_ >=
 * To_Date('01/03/2011') and PI.END_ <= To_Date('31/05/2011')) ;
 * 
 * 
 * @param dataInicial
 * @param dataFinal
 * @param dataFinalAte
 * @param dataFinalDe
 * @param incluirAbertos 
 * @return
 */
private Set<Doc> consultarDocs(String nomeProcedimento, Date dataInicialDe, Date dataInicialAte,
        Date dataFinalDe, Date dataFinalAte, Boolean incluirAbertos) {
    SQLQuery query = null;
    if (incluirAbertos) {
        query = (SQLQuery) WfDao.getInstance().getSessao()
                .createSQLQuery(getSQLConsultarDocumentosFinalizadosEAbertosNoPeriodo());
    } else {
        query = (SQLQuery) WfDao.getInstance().getSessao()
                .createSQLQuery(getSQLConsultarDocumentosFinalizadosNoPeriodo());
    }

    query.addScalar("START_", new CalendarType());
    query.addScalar("END_", new CalendarType());
    query.addScalar("STRINGVALUE_", new StringType());
    query.addScalar("ID_", new LongType());

    dataInicialAte = inclusiveData(dataInicialAte);
    dataFinalAte = inclusiveData(dataFinalAte);

    query.setString("nomeProcedimento", nomeProcedimento);
    query.setDate("dataInicialDe", dataInicialDe);
    query.setDate("dataInicialAte", dataInicialAte);
    query.setDate("dataFinalDe", dataFinalDe);
    query.setDate("dataFinalAte", dataFinalAte);
    List<Object[]> resultado = query.list();
    Set<Doc> docs = new TreeSet<Doc>(new DocComparator());
    for (Object[] o : resultado) {
        Doc s = new Doc();
        Calendar inicio = (Calendar) o[0];
        Calendar fim = (Calendar) o[1];
        s.setNumeroDoc(o[2].toString());
        s.setInicio(inicio);
        s.setFim(fim);
        s.setProcessInstanceID((Long) (o[3]));
        docs.add(s);
    }

    return docs;
}

From source file:br.gov.jfrj.siga.wf.relatorio.RelTempoDocDetalhado.java

License:Open Source License

private Set<Tarefa> consultarTarefas(String nomeProcedimento, Date dataInicialDe, Date dataInicialAte,
        Date dataFinalDe, Date dataFinalAte, Boolean incluirAbertos) {
    // ArrayList<Tarefa> tarefas = new ArrayList<Tarefa>();
    // Tarefa t1 = new Tarefa();
    // Tarefa t2 = new Tarefa();
    ///* w w w  . ja  va 2  s  .  c  o m*/
    // t1.setNome("t1");
    // t1.setDataFim("01/01/2000");
    // t1.setDataInicio("01/01/2000");
    // t1.setDuracao("5 seg");
    //
    // t2.setNome("t2");
    // t2.setDataFim("01/01/1999");
    // t2.setDataInicio("01/01/1888");
    // t2.setDuracao("5 seg");
    //
    // tarefas.add(t1);
    // tarefas.add(t2);
    // return tarefas;

    // String sql =
    // "SELECT PI.START_,PI.END_,VI.STRINGVALUE_,PI.ID_ FROM JBPM_PROCESSINSTANCE PI, (SELECT DISTINCT PROCESSINSTANCE_, STRINGVALUE_ FROM JBPM_VARIABLEINSTANCE WHERE NAME_ LIKE 'doc_%' AND STRINGVALUE_ LIKE '%-_' AND STRINGVALUE_ IS NOT NULL) VI, (SELECT ID_ FROM JBPM_PROCESSDEFINITION WHERE NAME_ = :nomeProcedimento) PD WHERE PI.PROCESSDEFINITION_=PD.ID_ AND PI.END_ IS NOT NULL AND PI.ID_ = VI.PROCESSINSTANCE_ AND  (PI.START_ >= :dataInicialDe and PI.START_ <= :dataInicialAte) AND (PI.END_ >= :dataFinalDe and PI.END_ <= :dataFinalAte)";

    SQLQuery query = null;
    if (incluirAbertos) {
        query = (SQLQuery) WfDao.getInstance().getSessao()
                .createSQLQuery(getSQLConsultarDocumentosFinalizadosEAbertosNoPeriodo());
    } else {
        query = (SQLQuery) WfDao.getInstance().getSessao()
                .createSQLQuery(getSQLConsultarDocumentosFinalizadosNoPeriodo());
    }

    query.addScalar("stringvalue_", new StringType());
    query.addScalar("pd_name", new StringType());
    query.addScalar("p_start", new CalendarType());
    query.addScalar("p_end", new CalendarType());
    query.addScalar("t_name", new StringType());
    query.addScalar("t_create", new CalendarType());
    query.addScalar("t_end", new CalendarType());

    query.setString("nomeProcedimento", nomeProcedimento);
    query.setDate("dataInicialDe", dataInicialDe);
    query.setDate("dataInicialAte", dataInicialAte);
    query.setDate("dataFinalDe", dataFinalDe);
    query.setDate("dataFinalAte", dataFinalAte);

    List<Object[]> resultado = query.list();
    Set<Tarefa> tarefas = new TreeSet<Tarefa>(new TarefaComparator());
    for (Object[] o : resultado) {
        Tarefa t = new Tarefa();
        t.setDataInicioProcedimento((Calendar) o[2]);
        t.setDataFimProcedimento((Calendar) o[3]);
        t.setNumeroDocumento((String) o[0]);
        t.setNome((String) o[4]);
        t.setDataInicio((Calendar) o[5]);
        t.setDataFim((Calendar) o[6]);

        tarefas.add(t);

    }
    // Set<Doc> secs = new TreeSet<Doc>(new DocComparator());
    // for (Object[] o : resultado) {
    // Doc s = new Doc();
    // Calendar inicio = (Calendar) o[0];
    // Calendar fim = (Calendar) o[1];
    // s.setNumeroDoc(o[2].toString());
    // s.setInicio(inicio);
    // s.setFim(fim);
    // s.setProcessInstanceID((Long) (o[3]));
    // secs.add(s);
    // }
    //
    return tarefas;

}

From source file:lt.emasina.resthub.server.factory.DataFactory.java

License:Open Source License

public CcData getData(final Session session, final DataHandler handler) throws Exception {
    final Query q = handler.getQuery();
    final SQLQuery query = getPagedSQLQuery(session, handler);

    for (MdColumn c : q.getColumns()) {
        switch (c.getType()) {
        case BLOB:
            query.addScalar(c.getName(), new BlobType());
            break;
        case CLOB:
            query.addScalar(c.getName(), new ClobType());
            break;
        case DATE:
            query.addScalar(c.getName(), new CalendarType());
            break;
        case NUMBER:
            query.addScalar(c.getName(), new BigDecimalType());
            break;
        case STRING:
            query.addScalar(c.getName(), new StringType());
            break;
        }//from w  ww  . j a va2  s.  c om
    }

    if (log.isDebugEnabled()) {
        log.debug(query.getQueryString());
    }

    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<CcData> loopRows = executor.submit(new Callable<CcData>() {

        @Override
        @SuppressWarnings("unchecked")
        public CcData call() throws Exception {
            CcData cc = new CcData();
            for (Object o : query.list()) {
                cc.addRow(q, o);
            }
            return cc;
        };
    });

    try {

        return loopRows.get(q.getTimeOut(), TimeUnit.SECONDS);

    } catch (ExecutionException | InterruptedException ex) {
        throw ex;
    } catch (TimeoutException ex) {
        throw new ServerErrorException(Status.SERVER_ERROR_GATEWAY_TIMEOUT, ex);
    }

}