Example usage for com.liferay.portal.kernel.util CalendarUtil getTimestamp

List of usage examples for com.liferay.portal.kernel.util CalendarUtil getTimestamp

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util CalendarUtil getTimestamp.

Prototype

public static Timestamp getTimestamp(Date date) 

Source Link

Usage

From source file:at.graz.meduni.liferay.portlet.bibbox.rdconnect.service.service.persistence.RDConnectEventPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the r d connect events where eventdate = ?.
 *
 * <p>//ww w  .java  2 s.  co  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link at.graz.meduni.liferay.portlet.bibbox.rdconnect.service.model.impl.RDConnectEventModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param eventdate the eventdate
 * @param start the lower bound of the range of r d connect events
 * @param end the upper bound of the range of r d connect events (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching r d connect events
 * @throws SystemException if a system exception occurred
 */
@Override
public List<RDConnectEvent> findByEventdate(Date eventdate, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EVENTDATE;
        finderArgs = new Object[] { eventdate };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_EVENTDATE;
        finderArgs = new Object[] { eventdate, start, end, orderByComparator };
    }

    List<RDConnectEvent> list = (List<RDConnectEvent>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (RDConnectEvent rdConnectEvent : list) {
            if (!Validator.equals(eventdate, rdConnectEvent.getEventdate())) {
                list = null;

                break;
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 3));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_RDCONNECTEVENT_WHERE);

        boolean bindEventdate = false;

        if (eventdate == null) {
            query.append(_FINDER_COLUMN_EVENTDATE_EVENTDATE_1);
        } else {
            bindEventdate = true;

            query.append(_FINDER_COLUMN_EVENTDATE_EVENTDATE_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(RDConnectEventModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindEventdate) {
                qPos.add(CalendarUtil.getTimestamp(eventdate));
            }

            if (!pagination) {
                list = (List<RDConnectEvent>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = new UnmodifiableList<RDConnectEvent>(list);
            } else {
                list = (List<RDConnectEvent>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            FinderCacheUtil.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:at.graz.meduni.liferay.portlet.bibbox.rdconnect.service.service.persistence.RDConnectEventPersistenceImpl.java

License:Open Source License

protected RDConnectEvent getByEventdate_PrevAndNext(Session session, RDConnectEvent rdConnectEvent,
        Date eventdate, OrderByComparator orderByComparator, boolean previous) {
    StringBundler query = null;//  w w  w  . j av a 2s .co m

    if (orderByComparator != null) {
        query = new StringBundler(6 + (orderByComparator.getOrderByFields().length * 6));
    } else {
        query = new StringBundler(3);
    }

    query.append(_SQL_SELECT_RDCONNECTEVENT_WHERE);

    boolean bindEventdate = false;

    if (eventdate == null) {
        query.append(_FINDER_COLUMN_EVENTDATE_EVENTDATE_1);
    } else {
        bindEventdate = true;

        query.append(_FINDER_COLUMN_EVENTDATE_EVENTDATE_2);
    }

    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }

        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);

            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }

        query.append(ORDER_BY_CLAUSE);

        String[] orderByFields = orderByComparator.getOrderByFields();

        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);

            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } else {
        query.append(RDConnectEventModelImpl.ORDER_BY_JPQL);
    }

    String sql = query.toString();

    Query q = session.createQuery(sql);

    q.setFirstResult(0);
    q.setMaxResults(2);

    QueryPos qPos = QueryPos.getInstance(q);

    if (bindEventdate) {
        qPos.add(CalendarUtil.getTimestamp(eventdate));
    }

    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(rdConnectEvent);

        for (Object value : values) {
            qPos.add(value);
        }
    }

    List<RDConnectEvent> list = q.list();

    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}

From source file:at.graz.meduni.liferay.portlet.bibbox.rdconnect.service.service.persistence.RDConnectEventPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of r d connect events where eventdate = &#63;.
 *
 * @param eventdate the eventdate//from w  w w .  j a v  a 2s  .c  o m
 * @return the number of matching r d connect events
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByEventdate(Date eventdate) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_EVENTDATE;

    Object[] finderArgs = new Object[] { eventdate };

    Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if (count == null) {
        StringBundler query = new StringBundler(2);

        query.append(_SQL_COUNT_RDCONNECTEVENT_WHERE);

        boolean bindEventdate = false;

        if (eventdate == null) {
            query.append(_FINDER_COLUMN_EVENTDATE_EVENTDATE_1);
        } else {
            bindEventdate = true;

            query.append(_FINDER_COLUMN_EVENTDATE_EVENTDATE_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindEventdate) {
                qPos.add(CalendarUtil.getTimestamp(eventdate));
            }

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return count.intValue();
}

From source file:br.com.prodevelopment.associado.service.persistence.AssociadoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the associados where dataNascimento = &#63;.
 *
 * <p>//from  w  w w .ja  v a2  s.  c  om
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link br.com.prodevelopment.associado.model.impl.AssociadoModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param dataNascimento the data nascimento
 * @param start the lower bound of the range of associados
 * @param end the upper bound of the range of associados (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching associados
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Associado> findByDT_NASCIMENTO(Date dataNascimento, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_DT_NASCIMENTO;
        finderArgs = new Object[] { dataNascimento };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_DT_NASCIMENTO;
        finderArgs = new Object[] { dataNascimento,

                start, end, orderByComparator };
    }

    List<Associado> list = (List<Associado>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Associado associado : list) {
            if (!Validator.equals(dataNascimento, associado.getDataNascimento())) {
                list = null;

                break;
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 3));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_ASSOCIADO_WHERE);

        boolean bindDataNascimento = false;

        if (dataNascimento == null) {
            query.append(_FINDER_COLUMN_DT_NASCIMENTO_DATANASCIMENTO_1);
        } else {
            bindDataNascimento = true;

            query.append(_FINDER_COLUMN_DT_NASCIMENTO_DATANASCIMENTO_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(AssociadoModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindDataNascimento) {
                qPos.add(CalendarUtil.getTimestamp(dataNascimento));
            }

            if (!pagination) {
                list = (List<Associado>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = new UnmodifiableList<Associado>(list);
            } else {
                list = (List<Associado>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            FinderCacheUtil.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:br.com.prodevelopment.associado.service.persistence.AssociadoPersistenceImpl.java

License:Open Source License

protected Associado getByDT_NASCIMENTO_PrevAndNext(Session session, Associado associado, Date dataNascimento,
        OrderByComparator orderByComparator, boolean previous) {
    StringBundler query = null;/*from  w w  w. j  ava2 s .c  om*/

    if (orderByComparator != null) {
        query = new StringBundler(6 + (orderByComparator.getOrderByFields().length * 6));
    } else {
        query = new StringBundler(3);
    }

    query.append(_SQL_SELECT_ASSOCIADO_WHERE);

    boolean bindDataNascimento = false;

    if (dataNascimento == null) {
        query.append(_FINDER_COLUMN_DT_NASCIMENTO_DATANASCIMENTO_1);
    } else {
        bindDataNascimento = true;

        query.append(_FINDER_COLUMN_DT_NASCIMENTO_DATANASCIMENTO_2);
    }

    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }

        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);

            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }

        query.append(ORDER_BY_CLAUSE);

        String[] orderByFields = orderByComparator.getOrderByFields();

        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);

            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } else {
        query.append(AssociadoModelImpl.ORDER_BY_JPQL);
    }

    String sql = query.toString();

    Query q = session.createQuery(sql);

    q.setFirstResult(0);
    q.setMaxResults(2);

    QueryPos qPos = QueryPos.getInstance(q);

    if (bindDataNascimento) {
        qPos.add(CalendarUtil.getTimestamp(dataNascimento));
    }

    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(associado);

        for (Object value : values) {
            qPos.add(value);
        }
    }

    List<Associado> list = q.list();

    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}

From source file:br.com.prodevelopment.associado.service.persistence.AssociadoPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of associados where dataNascimento = &#63;.
 *
 * @param dataNascimento the data nascimento
 * @return the number of matching associados
 * @throws SystemException if a system exception occurred
 *//*from  ww w.  j  a va  2 s .c  o m*/
@Override
public int countByDT_NASCIMENTO(Date dataNascimento) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_DT_NASCIMENTO;

    Object[] finderArgs = new Object[] { dataNascimento };

    Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if (count == null) {
        StringBundler query = new StringBundler(2);

        query.append(_SQL_COUNT_ASSOCIADO_WHERE);

        boolean bindDataNascimento = false;

        if (dataNascimento == null) {
            query.append(_FINDER_COLUMN_DT_NASCIMENTO_DATANASCIMENTO_1);
        } else {
            bindDataNascimento = true;

            query.append(_FINDER_COLUMN_DT_NASCIMENTO_DATANASCIMENTO_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindDataNascimento) {
                qPos.add(CalendarUtil.getTimestamp(dataNascimento));
            }

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return count.intValue();
}

From source file:br.com.prodevelopment.lapidarios.contato.service.persistence.ContatoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the contatos where companyId = &#63; and dataNascimento = &#63;.
 *
 * <p>/* ww w.j av  a  2 s .  c  om*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link br.com.prodevelopment.lapidarios.contato.model.impl.ContatoModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param companyId the company ID
 * @param dataNascimento the data nascimento
 * @param start the lower bound of the range of contatos
 * @param end the upper bound of the range of contatos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching contatos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Contato> findByC_DTN(long companyId, Date dataNascimento, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_DTN;
        finderArgs = new Object[] { companyId, dataNascimento };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_DTN;
        finderArgs = new Object[] { companyId, dataNascimento,

                start, end, orderByComparator };
    }

    List<Contato> list = (List<Contato>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Contato contato : list) {
            if ((companyId != contato.getCompanyId())
                    || !Validator.equals(dataNascimento, contato.getDataNascimento())) {
                list = null;

                break;
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 3));
        } else {
            query = new StringBundler(4);
        }

        query.append(_SQL_SELECT_CONTATO_WHERE);

        query.append(_FINDER_COLUMN_C_DTN_COMPANYID_2);

        boolean bindDataNascimento = false;

        if (dataNascimento == null) {
            query.append(_FINDER_COLUMN_C_DTN_DATANASCIMENTO_1);
        } else {
            bindDataNascimento = true;

            query.append(_FINDER_COLUMN_C_DTN_DATANASCIMENTO_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(ContatoModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(companyId);

            if (bindDataNascimento) {
                qPos.add(CalendarUtil.getTimestamp(dataNascimento));
            }

            if (!pagination) {
                list = (List<Contato>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = new UnmodifiableList<Contato>(list);
            } else {
                list = (List<Contato>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            FinderCacheUtil.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:br.com.prodevelopment.lapidarios.contato.service.persistence.ContatoPersistenceImpl.java

License:Open Source License

protected Contato getByC_DTN_PrevAndNext(Session session, Contato contato, long companyId, Date dataNascimento,
        OrderByComparator orderByComparator, boolean previous) {
    StringBundler query = null;/* w  w w .j a v a  2 s.c om*/

    if (orderByComparator != null) {
        query = new StringBundler(6 + (orderByComparator.getOrderByFields().length * 6));
    } else {
        query = new StringBundler(3);
    }

    query.append(_SQL_SELECT_CONTATO_WHERE);

    query.append(_FINDER_COLUMN_C_DTN_COMPANYID_2);

    boolean bindDataNascimento = false;

    if (dataNascimento == null) {
        query.append(_FINDER_COLUMN_C_DTN_DATANASCIMENTO_1);
    } else {
        bindDataNascimento = true;

        query.append(_FINDER_COLUMN_C_DTN_DATANASCIMENTO_2);
    }

    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }

        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);

            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }

        query.append(ORDER_BY_CLAUSE);

        String[] orderByFields = orderByComparator.getOrderByFields();

        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);

            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } else {
        query.append(ContatoModelImpl.ORDER_BY_JPQL);
    }

    String sql = query.toString();

    Query q = session.createQuery(sql);

    q.setFirstResult(0);
    q.setMaxResults(2);

    QueryPos qPos = QueryPos.getInstance(q);

    qPos.add(companyId);

    if (bindDataNascimento) {
        qPos.add(CalendarUtil.getTimestamp(dataNascimento));
    }

    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(contato);

        for (Object value : values) {
            qPos.add(value);
        }
    }

    List<Contato> list = q.list();

    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}

From source file:br.com.prodevelopment.lapidarios.contato.service.persistence.ContatoPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of contatos where companyId = &#63; and dataNascimento = &#63;.
 *
 * @param companyId the company ID//w  w  w . j a v a 2 s  .com
 * @param dataNascimento the data nascimento
 * @return the number of matching contatos
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByC_DTN(long companyId, Date dataNascimento) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_DTN;

    Object[] finderArgs = new Object[] { companyId, dataNascimento };

    Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if (count == null) {
        StringBundler query = new StringBundler(3);

        query.append(_SQL_COUNT_CONTATO_WHERE);

        query.append(_FINDER_COLUMN_C_DTN_COMPANYID_2);

        boolean bindDataNascimento = false;

        if (dataNascimento == null) {
            query.append(_FINDER_COLUMN_C_DTN_DATANASCIMENTO_1);
        } else {
            bindDataNascimento = true;

            query.append(_FINDER_COLUMN_C_DTN_DATANASCIMENTO_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(companyId);

            if (bindDataNascimento) {
                qPos.add(CalendarUtil.getTimestamp(dataNascimento));
            }

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(finderPath, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return count.intValue();
}

From source file:br.com.prodevelopment.lapidarios.contato.service.persistence.ContatoPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the contatos where companyId = &#63; and groupId = &#63; and dataNascimento = &#63;.
 *
 * <p>//w  w w . j  av a 2 s. c o  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link br.com.prodevelopment.lapidarios.contato.model.impl.ContatoModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param companyId the company ID
 * @param groupId the group ID
 * @param dataNascimento the data nascimento
 * @param start the lower bound of the range of contatos
 * @param end the upper bound of the range of contatos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching contatos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Contato> findByC_G_DTN(long companyId, long groupId, Date dataNascimento, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_G_DTN;
        finderArgs = new Object[] { companyId, groupId, dataNascimento };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_DTN;
        finderArgs = new Object[] { companyId, groupId, dataNascimento,

                start, end, orderByComparator };
    }

    List<Contato> list = (List<Contato>) FinderCacheUtil.getResult(finderPath, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Contato contato : list) {
            if ((companyId != contato.getCompanyId()) || (groupId != contato.getGroupId())
                    || !Validator.equals(dataNascimento, contato.getDataNascimento())) {
                list = null;

                break;
            }
        }
    }

    if (list == null) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(5 + (orderByComparator.getOrderByFields().length * 3));
        } else {
            query = new StringBundler(5);
        }

        query.append(_SQL_SELECT_CONTATO_WHERE);

        query.append(_FINDER_COLUMN_C_G_DTN_COMPANYID_2);

        query.append(_FINDER_COLUMN_C_G_DTN_GROUPID_2);

        boolean bindDataNascimento = false;

        if (dataNascimento == null) {
            query.append(_FINDER_COLUMN_C_G_DTN_DATANASCIMENTO_1);
        } else {
            bindDataNascimento = true;

            query.append(_FINDER_COLUMN_C_G_DTN_DATANASCIMENTO_2);
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(ContatoModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(companyId);

            qPos.add(groupId);

            if (bindDataNascimento) {
                qPos.add(CalendarUtil.getTimestamp(dataNascimento));
            }

            if (!pagination) {
                list = (List<Contato>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = new UnmodifiableList<Contato>(list);
            } else {
                list = (List<Contato>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            FinderCacheUtil.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}