Example usage for com.liferay.portal.kernel.dao.orm SQLQuery setTimestamp

List of usage examples for com.liferay.portal.kernel.dao.orm SQLQuery setTimestamp

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.dao.orm SQLQuery setTimestamp.

Prototype

public Query setTimestamp(int pos, Timestamp value);

Source Link

Usage

From source file:com.vportal.portlet.vdoc.service.persistence.vdocDocumentFinderImpl.java

License:Open Source License

public List findDocsByPublishedDate(long groupId, String language, Date pubDateFrom, Date pubDateTo, int status,
        int quantity) throws SystemException {
    Session session = null;//ww w .ja v a2s.c  o  m

    try {
        session = openSession();
        String sql = "SELECT * FROM vdocDocument";
        StringBuffer query = new StringBuffer();
        query.append(sql);
        query.append(" WHERE ");
        if (Validator.isNull(String.valueOf(groupId))) {
            return null;
        } else {
            query.append(" vdocDocument.groupId = ? ");
        }

        if (Validator.isNull(language)) {
            return null;
        } else {
            query.append(" AND ");
            query.append(" vdocDocument.language = ? ");
        }

        if (pubDateTo != null) {
            query.append(" AND ");
            query.append(" vdocDocument.publishedDate >= ? ");
        }

        if (pubDateFrom != null) {
            query.append(" AND ");
            query.append("vdocDocument.publishedDate <= ? ");
        }

        if (status == 2 || status == 1 || status == 0) {
            query.append(" AND ");
            query.append("vdocDocument.statusDoc = ? ");
        }

        query.append("ORDER BY ");
        query.append("vdocDocument.publishedDate DESC");
        SQLQuery q = session.createSQLQuery(query.toString());
        q.addEntity("vdocDocument", vdocDocumentImpl.class);
        int queryPos = 0;

        q.setLong(queryPos++, groupId);
        q.setString(queryPos++, language);

        if (pubDateFrom != null)
            q.setTimestamp(queryPos++, new Timestamp(pubDateFrom.getTime()));
        if (pubDateTo != null)
            q.setTimestamp(queryPos++, new Timestamp(pubDateTo.getTime()));

        if (status == 2 || status == 1 || status == 0)
            q.setInteger(queryPos++, status);

        return QueryUtil.list(q, getDialect(), 0, quantity);
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}

From source file:com.vportal.portlet.vdoc.service.persistence.vdocDocumentFinderImpl.java

License:Open Source License

public List findDocbyModifyDate(long groupId, String language, Date modiDateFrom, Date modiDateTo, int status)
        throws SystemException {
    Session session = null;//from ww w.  jav a 2 s .  c o m

    try {
        session = openSession();
        String sql = "SELECT * FROM vdocDocument";
        StringBuffer query = new StringBuffer();
        query.append(sql);
        query.append(" WHERE ");
        if (Validator.isNull(String.valueOf(groupId))) {
            return null;
        } else {
            query.append(" vdocDocument.groupId = ? ");
        }

        if (Validator.isNull(language)) {
            return null;
        } else {
            query.append(" AND ");
            query.append(" vdocDocument.language = ? ");
        }

        if (modiDateTo != null) {
            query.append(" AND ");
            query.append(" vdocDocument.modifiedDate >= ? ");
        }

        if (modiDateFrom != null) {
            query.append(" AND ");
            query.append("vdocDocument.modifiedDate <= ? ");
        }

        if (status == 2 || status == 1 || status == 0) {
            query.append(" AND ");
            query.append("vdocDocument.statusDoc = ? ");
        }

        query.append("ORDER BY ");
        query.append("vdocDocument.modifiedDate DESC");
        SQLQuery q = session.createSQLQuery(query.toString());
        q.addEntity("vdocDocument", vdocDocumentImpl.class);
        int queryPos = 0;

        q.setLong(queryPos++, groupId);
        q.setString(queryPos++, language);

        if (modiDateFrom != null)
            q.setTimestamp(queryPos++, new Timestamp(modiDateFrom.getTime()));
        if (modiDateTo != null)
            q.setTimestamp(queryPos++, new Timestamp(modiDateTo.getTime()));

        if (status == 2 || status == 1 || status == 0)
            q.setInteger(queryPos++, status);

        return q.list();
    } catch (Exception e) {
        throw new SystemException(e);
    } finally {
        closeSession(session);
    }
}