Example usage for com.liferay.portal.kernel.dao.orm QueryUtil ALL_POS

List of usage examples for com.liferay.portal.kernel.dao.orm QueryUtil ALL_POS

Introduction

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

Prototype

int ALL_POS

To view the source code for com.liferay.portal.kernel.dao.orm QueryUtil ALL_POS.

Click Source Link

Usage

From source file:au.com.example.service.persistence.FooPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the foos.
 *
 * <p>//w ww . ja  v a2 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 au.com.example.model.impl.FooModelImpl}. 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 start the lower bound of the range of foos
 * @param end the upper bound of the range of foos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of foos
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Foo> findAll(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_ALL;
        finderArgs = FINDER_ARGS_EMPTY;
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
        finderArgs = new Object[] { start, end, orderByComparator };
    }

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

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

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

            query.append(_SQL_SELECT_FOO);

            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

            sql = query.toString();
        } else {
            sql = _SQL_SELECT_FOO;

            if (pagination) {
                sql = sql.concat(FooModelImpl.ORDER_BY_JPQL);
            }
        }

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

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

                Collections.sort(list);

                list = new UnmodifiableList<Foo>(list);
            } else {
                list = (List<Foo>) 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:au.com.permeance.liferay.portlet.documentlibrary.service.impl.DLFolderExportZipHelper.java

License:Open Source License

/**
 * Export folder to ZIP writer.//  www  .j  a v  a2  s. c  o  m
 * 
 * @param groupId group id
 * @param repositoryId source repository containing folder to export
 * @param folder source folder to export
 * @param folderPath source folder path to export
 * @param serviceContext service context
 * @param zipWriter destination ZIP writer
 * 
 * @throws PortalException
 * @throws SystemException
 * @throws RemoteException
 */
public static void exportFolderToZipWriter(long groupId, long repositoryId, Folder folder, String folderPath,
        ServiceContext serviceContext, ZipWriter zipWriter) throws PortalException, SystemException {

    // Export file entries in folder to ZIP writer

    List<FileEntry> fileEntryList = DLAppServiceUtil.getFileEntries(folder.getRepositoryId(),
            folder.getFolderId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (FileEntry fileEntry : fileEntryList) {
        try {
            exportFileEntryToZipWriter(fileEntry, folderPath, zipWriter);
        } catch (Exception e) {
            String msg = "Error exporting file entry to ZIP file : " + e.getMessage();
            s_log.error(msg, e);
            throw new PortalException(msg, e);
        }
    }

    // Export sub-folders in folder to ZIP writer

    List<Folder> subFolderList = DLAppServiceUtil.getFolders(folder.getRepositoryId(), folder.getFolderId(),
            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (Folder subFolder : subFolderList) {
        String subFolderName = subFolder.getName();
        String subFolderPath = folderPath + subFolderName + StringPool.FORWARD_SLASH;
        exportFolderToZipWriter(groupId, repositoryId, subFolder, subFolderPath, serviceContext, zipWriter);
    }
}

From source file:au.com.permeance.liferay.portlet.documentlibrary.service.impl.DLFolderUsageHelper.java

License:Open Source License

/**
 * Visit Folder.//from w w  w.  j  a va  2 s  . c o  m
 * 
 * @param repositoryId repository containing folder
 * @param folder folder
 * @param folderPath folder path
 * @param serviceContext service context
 * @param folderUsageCollector folder usage collector
 * 
 * @throws PortalException 
 * @throws SystemException
 */
public static void calculateFolderUsage(long repositoryId, Folder folder, String folderPath,
        ServiceContext serviceContext, DLFolderUsageCollector folderUsageCollector)
        throws PortalException, SystemException {

    // Visit file entries in folder

    if (s_log.isDebugEnabled()) {
        s_log.debug("calculating usage for folder " + folder.getFolderId() + "/" + folder.getName());
    }

    List<FileEntry> fileEntryList = DLAppServiceUtil.getFileEntries(folder.getRepositoryId(),
            folder.getFolderId(), QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (FileEntry fileEntry : fileEntryList) {
        try {
            calculateFileEntryUsage(fileEntry, folderPath, folderUsageCollector);
            folderUsageCollector.incrementFileCount();
        } catch (Exception e) {
            String msg = "Error visiting file entry " + fileEntry.getFileEntryId() + " : " + e.getMessage();
            s_log.error(msg, e);
            throw new PortalException(msg, e);
        }
    }

    // Visit sub-folders

    List<Folder> subFolderList = DLAppServiceUtil.getFolders(folder.getRepositoryId(), folder.getFolderId(),
            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

    for (Folder subFolder : subFolderList) {
        String subFolderName = subFolder.getName();
        String subFolderPath = folderPath + subFolderName + StringPool.FORWARD_SLASH;
        calculateFolderUsage(repositoryId, subFolder, subFolderPath, serviceContext, folderUsageCollector);
        folderUsageCollector.incrementFolderCount();
    }
}

From source file:au.com.redbarn.liferay.property.modifier.PropertyModifierStartupAction.java

License:Open Source License

/**
 * Clears the desired portal preferences (hard coded: ldap.auth.enabled, ldap.auth.required).
 * /* w  w  w  . java 2  s.c om*/
 * @throws SystemException
 */
private void clearPreferences() throws SystemException {

    List<PortalPreferences> portalPreferencesList = PortalPreferencesLocalServiceUtil
            .getPortalPreferenceses(QueryUtil.ALL_POS, QueryUtil.ALL_POS);

    for (PortalPreferences portalPreferences : portalPreferencesList) {
        log.info(portalPreferences.getPreferences());

        String prefs = portalPreferences.getPreferences();
        String newPrefs = prefs;

        final String LDAP_AUTH_ENABLED = "ldap.auth.enabled";

        if (prefs.contains(LDAP_AUTH_ENABLED)) {
            newPrefs = clearPreference(LDAP_AUTH_ENABLED, portalPreferences, prefs);
        }

        final String LDAP_AUTH_REQUIRED = "ldap.auth.required";

        if (prefs.contains(LDAP_AUTH_REQUIRED)) {
            newPrefs = clearPreference(LDAP_AUTH_REQUIRED, portalPreferences, newPrefs);
        }

        PortalPreferencesLocalServiceUtil.updatePreferences(portalPreferences.getOwnerId(),
                portalPreferences.getOwnerType(), newPrefs);
    }
}

From source file:bean.ControllerApproveSDW.java

public String getCashOnHand(long userId) throws SystemException {
    String location = "";
    List<Organization> userOrg = OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS,
            QueryUtil.ALL_POS);//from  w  w w.  ja va 2 s .c o m
    for (Organization o : userOrg) {
        if (o.getType().equals("location")) {
            if (OrganizationLocalServiceUtil.hasUserOrganization(userId, o.getOrganizationId())) {
                location = o.getName();
                break;
            }
        }
    }
    if (location.equals("Main")) {
        return "111103020";
    } else if (location.equals("Satellite")) {
        return "111103030";
    } else if (location.equals("Satellite - LPC")) {
        return "111103050";
    } else if (location.equals("Drugstore") || location.equals("Botica")) {
        return "111103010";
    } else {
        return null;
    }
}

From source file:bean.ControllerApproveSDW.java

public boolean isSameOrg(long sender, long receiver) throws SystemException {
    List<Organization> userOrg = OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS,
            QueryUtil.ALL_POS);/*from ww w  .ja  va  2s  . c  o m*/
    for (Organization o : userOrg) {
        if (o.getType().equals("location")) {
            if (OrganizationLocalServiceUtil.hasUserOrganization(sender, o.getOrganizationId())
                    && OrganizationLocalServiceUtil.hasUserOrganization(receiver,
                            o.getOrganizationId()) == true) {
                //System.out.println("parehas sa " + o.getName() + " - true");
                return true;
            } else {
                //System.out.println("parehas sa " + o.getName() + " - false");
            }
        }
    }
    return false;
}

From source file:bean.ControllerCollection.java

public Integer getLocation(long userId) throws SystemException {
    String location = "";
    List<Organization> userOrg = OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS,
            QueryUtil.ALL_POS);/*from  ww w.j av a2 s .c om*/
    for (Organization o : userOrg) {
        if (o.getType().equals("location")) {
            if (OrganizationLocalServiceUtil.hasUserOrganization(userId, o.getOrganizationId())) {
                location = o.getName();
                break;
            }
        }
    }
    if (location.equals("Main")) {
        return 0;
    } else if (location.equals("Satellite")) {
        return 1;
    } else if (location.equals("Satellite - LPC")) {
        return 2;
    } else if (location.equals("Drugstore") || location.equals("Botica")) {
        return 0;
    } else {
        return null;
    }
}

From source file:bean.DisbursementTicketList.java

public boolean isSameOrg(long sender, long receiver) throws SystemException {
    List<Organization> userOrg = OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS,
            QueryUtil.ALL_POS);/*from w  w  w.ja  v a2  s .  c  om*/
    for (Organization o : userOrg) {
        if (o.getType().equals("location")) {
            if (OrganizationLocalServiceUtil.hasUserOrganization(sender, o.getOrganizationId())
                    && OrganizationLocalServiceUtil.hasUserOrganization(receiver,
                            o.getOrganizationId()) == true) {
                //                    System.out.println("parehas sa " + o.getName() + " - true");
                return true;
            } else {
                //System.out.println("parehas sa " + o.getName() + " - false");
            }
        }
    }
    return false;
}

From source file:bean.PortalData.java

public void init() throws SystemException {
    if (FacesContext.getCurrentInstance().isPostback() == false) {
        beanclear();/*from w  ww  .java  2s . c o  m*/

        setPortletLock((PortletLock) getCustomEntityManagerFactory().getLportalMemOrgEntityManagerFactory()
                .createEntityManager()
                .createQuery("" + "SELECT pl " + "FROM PortletLock " + "pl WHERE pl.systemName = :systemName")
                .setParameter("systemName", "FINANCE AND ACCOUNTING").getResultList().get(0));
        setOrganization(OrganizationLocalServiceUtil.getOrganizations(QueryUtil.ALL_POS, QueryUtil.ALL_POS));
        setCurrentUserId(getLiferayFacesContext().getUser().getUserId());
        setMemberUserList(
                getCustomEntityManagerFactory().getLportalMemOrgEntityManagerFactory().createEntityManager()
                        .createQuery("" + "SELECT mu " + "FROM CoopMemberUser mu").getResultList());

        setUserGroupRoles(UserGroupRoleLocalServiceUtil.getUserGroupRoles(getCurrentUserId()));

        try {
            setUserSchedule((UserSchedule) getCustomEntityManagerFactory()
                    .getLportalMemOrgEntityManagerFactory().createEntityManager()
                    .createQuery("" + "SELECT us " + "FROM UserSchedule us " + "WHERE us.userId = :userId")
                    .setParameter("userId", getCurrentUserId()).getResultList().get(0));
        } catch (Exception e) {

        }

        try {
            setApprover((CoopFinApprover) getCustomEntityManagerFactory().getFinancialDbEntityManagerFactory()
                    .createEntityManager()
                    .createQuery("" + "SELECT a " + "FROM CoopFinApprover a " + "WHERE a.userId = :userId")
                    .setParameter("userId", getCurrentUserId()).getResultList().get(0));
        } catch (Exception e) {

        }

        try {
            if (getPortletLock().getStatus()) {
                try {
                    for (int i = 0; i < getMemberUserList().size(); i++) {
                        if (getMemberUserList().get(i).getUserId().longValue() == getCurrentUserId()) {
                            if (getCustomDate().getCurrentDate().getDay() == 0) {
                                getCustomDate().getCurrentDateFrom()
                                        .setHours(getUserSchedule().getSunFrom().getHours());
                                getCustomDate().getCurrentDateFrom()
                                        .setMinutes(getUserSchedule().getSunFrom().getMinutes());
                                getCustomDate().getCurrentDateFrom()
                                        .setSeconds(getUserSchedule().getSunFrom().getSeconds());

                                getCustomDate().getCurrentDateTo()
                                        .setHours(getUserSchedule().getSunTo().getHours());
                                getCustomDate().getCurrentDateTo()
                                        .setMinutes(getUserSchedule().getSunTo().getMinutes());
                                getCustomDate().getCurrentDateTo()
                                        .setSeconds(getUserSchedule().getSunTo().getSeconds());
                            } else if (getCustomDate().getCurrentDate().getDay() == 1) {
                                getCustomDate().getCurrentDateFrom()
                                        .setHours(getUserSchedule().getMonFrom().getHours());
                                getCustomDate().getCurrentDateFrom()
                                        .setMinutes(getUserSchedule().getMonFrom().getMinutes());
                                getCustomDate().getCurrentDateFrom()
                                        .setSeconds(getUserSchedule().getMonFrom().getSeconds());

                                getCustomDate().getCurrentDateTo()
                                        .setHours(getUserSchedule().getMonTo().getHours());
                                getCustomDate().getCurrentDateTo()
                                        .setMinutes(getUserSchedule().getMonTo().getMinutes());
                                getCustomDate().getCurrentDateTo()
                                        .setSeconds(getUserSchedule().getMonTo().getSeconds());
                            } else if (getCustomDate().getCurrentDate().getDay() == 2) {
                                getCustomDate().getCurrentDateFrom()
                                        .setHours(getUserSchedule().getTueFrom().getHours());
                                getCustomDate().getCurrentDateFrom()
                                        .setMinutes(getUserSchedule().getTueFrom().getMinutes());
                                getCustomDate().getCurrentDateFrom()
                                        .setSeconds(getUserSchedule().getTueFrom().getSeconds());

                                getCustomDate().getCurrentDateTo()
                                        .setHours(getUserSchedule().getTueTo().getHours());
                                getCustomDate().getCurrentDateTo()
                                        .setMinutes(getUserSchedule().getTueTo().getMinutes());
                                getCustomDate().getCurrentDateTo()
                                        .setSeconds(getUserSchedule().getTueTo().getSeconds());
                            } else if (getCustomDate().getCurrentDate().getDay() == 3) {
                                getCustomDate().getCurrentDateFrom()
                                        .setHours(getUserSchedule().getWedFrom().getHours());
                                getCustomDate().getCurrentDateFrom()
                                        .setMinutes(getUserSchedule().getWedFrom().getMinutes());
                                getCustomDate().getCurrentDateFrom()
                                        .setSeconds(getUserSchedule().getWedFrom().getSeconds());

                                getCustomDate().getCurrentDateTo()
                                        .setHours(getUserSchedule().getWedTo().getHours());
                                getCustomDate().getCurrentDateTo()
                                        .setMinutes(getUserSchedule().getWedTo().getMinutes());
                                getCustomDate().getCurrentDateTo()
                                        .setSeconds(getUserSchedule().getWedTo().getSeconds());
                            } else if (getCustomDate().getCurrentDate().getDay() == 4) {
                                getCustomDate().getCurrentDateFrom()
                                        .setHours(getUserSchedule().getThuFrom().getHours());
                                getCustomDate().getCurrentDateFrom()
                                        .setMinutes(getUserSchedule().getThuFrom().getMinutes());
                                getCustomDate().getCurrentDateFrom()
                                        .setSeconds(getUserSchedule().getThuFrom().getSeconds());

                                getCustomDate().getCurrentDateTo()
                                        .setHours(getUserSchedule().getThuTo().getHours());
                                getCustomDate().getCurrentDateTo()
                                        .setMinutes(getUserSchedule().getThuTo().getMinutes());
                                getCustomDate().getCurrentDateTo()
                                        .setSeconds(getUserSchedule().getThuTo().getSeconds());
                            } else if (getCustomDate().getCurrentDate().getDay() == 5) {
                                getCustomDate().getCurrentDateFrom()
                                        .setHours(getUserSchedule().getFriFrom().getHours());
                                getCustomDate().getCurrentDateFrom()
                                        .setMinutes(getUserSchedule().getFriFrom().getMinutes());
                                getCustomDate().getCurrentDateFrom()
                                        .setSeconds(getUserSchedule().getFriFrom().getSeconds());

                                getCustomDate().getCurrentDateTo()
                                        .setHours(getUserSchedule().getFriTo().getHours());
                                getCustomDate().getCurrentDateTo()
                                        .setMinutes(getUserSchedule().getFriTo().getMinutes());
                                getCustomDate().getCurrentDateTo()
                                        .setSeconds(getUserSchedule().getFriTo().getSeconds());
                            } else if (getCustomDate().getCurrentDate().getDay() == 6) {
                                getCustomDate().getCurrentDateFrom()
                                        .setHours(getUserSchedule().getSatFrom().getHours());
                                getCustomDate().getCurrentDateFrom()
                                        .setMinutes(getUserSchedule().getSatFrom().getMinutes());
                                getCustomDate().getCurrentDateFrom()
                                        .setSeconds(getUserSchedule().getSatFrom().getSeconds());

                                getCustomDate().getCurrentDateTo()
                                        .setHours(getUserSchedule().getSatTo().getHours());
                                getCustomDate().getCurrentDateTo()
                                        .setMinutes(getUserSchedule().getSatTo().getMinutes());
                                getCustomDate().getCurrentDateTo()
                                        .setSeconds(getUserSchedule().getSatTo().getSeconds());
                            }

                            System.out.print("101 " + getCustomDate().getCurrentDateFrom());
                            System.out.print("101 " + getCustomDate().getCurrentDate());
                            System.out.print("101 " + getCustomDate().getCurrentDateTo());

                            if (getCustomDate().getCurrentDate()
                                    .compareTo(getCustomDate().getCurrentDateFrom()) >= 0
                                    && getCustomDate().getCurrentDate()
                                            .compareTo(getCustomDate().getCurrentDateTo()) < 0) {
                                setShowContent(true);
                                break;
                            }
                        } else {
                            setMessage("You do not have the roles required to access this portlet.");
                        }
                    }
                } catch (Exception e) {
                    setMessage("You do not have the roles required to access this portlet.");
                }

                try {
                    setUserLocations(null);
                    for (Organization o : getOrganization()) {
                        if (o.getType().equals("location") && o.getName().equals("Main")) {
                            try {
                                if (OrganizationLocalServiceUtil.hasUserOrganization(
                                        getApprover().getUserId().longValue(), o.getOrganizationId())) {
                                    setUserLocation(0);
                                    getUserLocations().add(getUserLocation());
                                }
                            } catch (Exception e) {
                                System.out.print("portalData().init()-0 " + e);
                            }
                        }
                        if (o.getType().equals("location") && o.getName().equals("Satellite")) {
                            try {
                                if (OrganizationLocalServiceUtil.hasUserOrganization(
                                        getApprover().getUserId().longValue(), o.getOrganizationId())) {
                                    setUserLocation(1);
                                    getUserLocations().add(getUserLocation());
                                }
                            } catch (Exception e) {
                                System.out.print("portalData().init()-1 " + e);
                            }
                        }
                        if (o.getType().equals("location") && o.getName().equals("Satellite - LPC")) {
                            try {
                                if (OrganizationLocalServiceUtil.hasUserOrganization(
                                        getApprover().getUserId().longValue(), o.getOrganizationId())) {
                                    setUserLocation(2);
                                    getUserLocations().add(getUserLocation());
                                }
                            } catch (Exception e) {
                                System.out.print("portalData().init()-2 " + e);
                            }
                        }
                    }
                } catch (Exception e) {
                    System.out.print("portalData().init()-2 " + e);
                }
            } else {
                setMessage("Access denied.");
            }
        } catch (Exception e) {
            setMessage("Access denied.");
        }
    }
}

From source file:blade.servicebuilder.service.persistence.impl.FooPersistenceImpl.java

License:Open Source License

/**
 * Returns all the foos where uuid = &#63;.
 *
 * @param uuid the uuid/*w w  w.  j  a v  a 2s  .c  o m*/
 * @return the matching foos
 */
@Override
public List<Foo> findByUuid(String uuid) {
    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
}