com.appuntivari.esempio.service.persistence.RelazioniSistemiPersistenceImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.appuntivari.esempio.service.persistence.RelazioniSistemiPersistenceImpl.java

Source

/**
 * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.appuntivari.esempio.service.persistence;

import com.appuntivari.esempio.NoSuchRelazioniSistemiException;
import com.appuntivari.esempio.model.RelazioniSistemi;
import com.appuntivari.esempio.model.impl.RelazioniSistemiImpl;
import com.appuntivari.esempio.model.impl.RelazioniSistemiModelImpl;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.security.permission.InlineSQLHelperUtil;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the relazioni sistemi service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author Pasturenzi Francesco
 * @see RelazioniSistemiPersistence
 * @see RelazioniSistemiUtil
 * @generated
 */
public class RelazioniSistemiPersistenceImpl extends BasePersistenceImpl<RelazioniSistemi>
        implements RelazioniSistemiPersistence {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never modify or reference this class directly. Always use {@link RelazioniSistemiUtil} to access the relazioni sistemi persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
     */
    public static final String FINDER_CLASS_NAME_ENTITY = RelazioniSistemiImpl.class.getName();
    public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY + ".List1";
    public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY + ".List2";
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SISTEMAFROM = new FinderPath(
            RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiModelImpl.FINDER_CACHE_ENABLED,
            RelazioniSistemiImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySistemaFrom",
            new String[] { String.class.getName(),

                    "java.lang.Integer", "java.lang.Integer", "com.liferay.portal.kernel.util.OrderByComparator" });
    public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SISTEMAFROM = new FinderPath(
            RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiModelImpl.FINDER_CACHE_ENABLED,
            RelazioniSistemiImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySistemaFrom",
            new String[] { String.class.getName() }, RelazioniSistemiModelImpl.SISTEMAFROM_COLUMN_BITMASK);
    public static final FinderPath FINDER_PATH_COUNT_BY_SISTEMAFROM = new FinderPath(
            RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiModelImpl.FINDER_CACHE_ENABLED,
            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySistemaFrom",
            new String[] { String.class.getName() });
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SISTEMATO = new FinderPath(
            RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiModelImpl.FINDER_CACHE_ENABLED,
            RelazioniSistemiImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySistemaTo",
            new String[] { String.class.getName(),

                    "java.lang.Integer", "java.lang.Integer", "com.liferay.portal.kernel.util.OrderByComparator" });
    public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SISTEMATO = new FinderPath(
            RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiModelImpl.FINDER_CACHE_ENABLED,
            RelazioniSistemiImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySistemaTo",
            new String[] { String.class.getName() }, RelazioniSistemiModelImpl.SISTEMATO_COLUMN_BITMASK);
    public static final FinderPath FINDER_PATH_COUNT_BY_SISTEMATO = new FinderPath(
            RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiModelImpl.FINDER_CACHE_ENABLED,
            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySistemaTo",
            new String[] { String.class.getName() });
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(
            RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiModelImpl.FINDER_CACHE_ENABLED,
            RelazioniSistemiImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
    public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(
            RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiModelImpl.FINDER_CACHE_ENABLED,
            RelazioniSistemiImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
    public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(
            RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiModelImpl.FINDER_CACHE_ENABLED,
            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);

    /**
     * Caches the relazioni sistemi in the entity cache if it is enabled.
     *
     * @param relazioniSistemi the relazioni sistemi
     */
    public void cacheResult(RelazioniSistemi relazioniSistemi) {
        EntityCacheUtil.putResult(RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiImpl.class,
                relazioniSistemi.getPrimaryKey(), relazioniSistemi);

        relazioniSistemi.resetOriginalValues();
    }

    /**
     * Caches the relazioni sistemis in the entity cache if it is enabled.
     *
     * @param relazioniSistemis the relazioni sistemis
     */
    public void cacheResult(List<RelazioniSistemi> relazioniSistemis) {
        for (RelazioniSistemi relazioniSistemi : relazioniSistemis) {
            if (EntityCacheUtil.getResult(RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED,
                    RelazioniSistemiImpl.class, relazioniSistemi.getPrimaryKey()) == null) {
                cacheResult(relazioniSistemi);
            } else {
                relazioniSistemi.resetOriginalValues();
            }
        }
    }

    /**
     * Clears the cache for all relazioni sistemis.
     *
     * <p>
     * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
     * </p>
     */
    @Override
    public void clearCache() {
        if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
            CacheRegistryUtil.clear(RelazioniSistemiImpl.class.getName());
        }

        EntityCacheUtil.clearCache(RelazioniSistemiImpl.class.getName());

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    /**
     * Clears the cache for the relazioni sistemi.
     *
     * <p>
     * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
     * </p>
     */
    @Override
    public void clearCache(RelazioniSistemi relazioniSistemi) {
        EntityCacheUtil.removeResult(RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiImpl.class,
                relazioniSistemi.getPrimaryKey());

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    @Override
    public void clearCache(List<RelazioniSistemi> relazioniSistemis) {
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

        for (RelazioniSistemi relazioniSistemi : relazioniSistemis) {
            EntityCacheUtil.removeResult(RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiImpl.class,
                    relazioniSistemi.getPrimaryKey());
        }
    }

    /**
     * Creates a new relazioni sistemi with the primary key. Does not add the relazioni sistemi to the database.
     *
     * @param relazioneSistemaid the primary key for the new relazioni sistemi
     * @return the new relazioni sistemi
     */
    public RelazioniSistemi create(long relazioneSistemaid) {
        RelazioniSistemi relazioniSistemi = new RelazioniSistemiImpl();

        relazioniSistemi.setNew(true);
        relazioniSistemi.setPrimaryKey(relazioneSistemaid);

        return relazioniSistemi;
    }

    /**
     * Removes the relazioni sistemi with the primary key from the database. Also notifies the appropriate model listeners.
     *
     * @param relazioneSistemaid the primary key of the relazioni sistemi
     * @return the relazioni sistemi that was removed
     * @throws com.appuntivari.esempio.NoSuchRelazioniSistemiException if a relazioni sistemi with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi remove(long relazioneSistemaid)
            throws NoSuchRelazioniSistemiException, SystemException {
        return remove(Long.valueOf(relazioneSistemaid));
    }

    /**
     * Removes the relazioni sistemi with the primary key from the database. Also notifies the appropriate model listeners.
     *
     * @param primaryKey the primary key of the relazioni sistemi
     * @return the relazioni sistemi that was removed
     * @throws com.appuntivari.esempio.NoSuchRelazioniSistemiException if a relazioni sistemi with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public RelazioniSistemi remove(Serializable primaryKey)
            throws NoSuchRelazioniSistemiException, SystemException {
        Session session = null;

        try {
            session = openSession();

            RelazioniSistemi relazioniSistemi = (RelazioniSistemi) session.get(RelazioniSistemiImpl.class,
                    primaryKey);

            if (relazioniSistemi == null) {
                if (_log.isWarnEnabled()) {
                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
                }

                throw new NoSuchRelazioniSistemiException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
            }

            return remove(relazioniSistemi);
        } catch (NoSuchRelazioniSistemiException nsee) {
            throw nsee;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    @Override
    protected RelazioniSistemi removeImpl(RelazioniSistemi relazioniSistemi) throws SystemException {
        relazioniSistemi = toUnwrappedModel(relazioniSistemi);

        Session session = null;

        try {
            session = openSession();

            BatchSessionUtil.delete(session, relazioniSistemi);
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }

        clearCache(relazioniSistemi);

        return relazioniSistemi;
    }

    @Override
    public RelazioniSistemi updateImpl(com.appuntivari.esempio.model.RelazioniSistemi relazioniSistemi,
            boolean merge) throws SystemException {
        relazioniSistemi = toUnwrappedModel(relazioniSistemi);

        boolean isNew = relazioniSistemi.isNew();

        RelazioniSistemiModelImpl relazioniSistemiModelImpl = (RelazioniSistemiModelImpl) relazioniSistemi;

        Session session = null;

        try {
            session = openSession();

            BatchSessionUtil.update(session, relazioniSistemi, merge);

            relazioniSistemi.setNew(false);
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

        if (isNew || !RelazioniSistemiModelImpl.COLUMN_BITMASK_ENABLED) {
            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
        }

        else {
            if ((relazioniSistemiModelImpl.getColumnBitmask()
                    & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SISTEMAFROM.getColumnBitmask()) != 0) {
                Object[] args = new Object[] { relazioniSistemiModelImpl.getOriginalSistemaFrom() };

                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SISTEMAFROM, args);
                FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SISTEMAFROM, args);

                args = new Object[] { relazioniSistemiModelImpl.getSistemaFrom() };

                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SISTEMAFROM, args);
                FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SISTEMAFROM, args);
            }

            if ((relazioniSistemiModelImpl.getColumnBitmask()
                    & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SISTEMATO.getColumnBitmask()) != 0) {
                Object[] args = new Object[] { relazioniSistemiModelImpl.getOriginalSistemaTo() };

                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SISTEMATO, args);
                FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SISTEMATO, args);

                args = new Object[] { relazioniSistemiModelImpl.getSistemaTo() };

                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SISTEMATO, args);
                FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SISTEMATO, args);
            }
        }

        EntityCacheUtil.putResult(RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiImpl.class,
                relazioniSistemi.getPrimaryKey(), relazioniSistemi);

        return relazioniSistemi;
    }

    protected RelazioniSistemi toUnwrappedModel(RelazioniSistemi relazioniSistemi) {
        if (relazioniSistemi instanceof RelazioniSistemiImpl) {
            return relazioniSistemi;
        }

        RelazioniSistemiImpl relazioniSistemiImpl = new RelazioniSistemiImpl();

        relazioniSistemiImpl.setNew(relazioniSistemi.isNew());
        relazioniSistemiImpl.setPrimaryKey(relazioniSistemi.getPrimaryKey());

        relazioniSistemiImpl.setRelazioneSistemaid(relazioniSistemi.getRelazioneSistemaid());
        relazioniSistemiImpl.setDescrizione(relazioniSistemi.getDescrizione());
        relazioniSistemiImpl.setSistemaFrom(relazioniSistemi.getSistemaFrom());
        relazioniSistemiImpl.setSistemaTo(relazioniSistemi.getSistemaTo());

        return relazioniSistemiImpl;
    }

    /**
     * Returns the relazioni sistemi with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
     *
     * @param primaryKey the primary key of the relazioni sistemi
     * @return the relazioni sistemi
     * @throws com.liferay.portal.NoSuchModelException if a relazioni sistemi with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public RelazioniSistemi findByPrimaryKey(Serializable primaryKey) throws NoSuchModelException, SystemException {
        return findByPrimaryKey(((Long) primaryKey).longValue());
    }

    /**
     * Returns the relazioni sistemi with the primary key or throws a {@link com.appuntivari.esempio.NoSuchRelazioniSistemiException} if it could not be found.
     *
     * @param relazioneSistemaid the primary key of the relazioni sistemi
     * @return the relazioni sistemi
     * @throws com.appuntivari.esempio.NoSuchRelazioniSistemiException if a relazioni sistemi with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi findByPrimaryKey(long relazioneSistemaid)
            throws NoSuchRelazioniSistemiException, SystemException {
        RelazioniSistemi relazioniSistemi = fetchByPrimaryKey(relazioneSistemaid);

        if (relazioniSistemi == null) {
            if (_log.isWarnEnabled()) {
                _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relazioneSistemaid);
            }

            throw new NoSuchRelazioniSistemiException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + relazioneSistemaid);
        }

        return relazioniSistemi;
    }

    /**
     * Returns the relazioni sistemi with the primary key or returns <code>null</code> if it could not be found.
     *
     * @param primaryKey the primary key of the relazioni sistemi
     * @return the relazioni sistemi, or <code>null</code> if a relazioni sistemi with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public RelazioniSistemi fetchByPrimaryKey(Serializable primaryKey) throws SystemException {
        return fetchByPrimaryKey(((Long) primaryKey).longValue());
    }

    /**
     * Returns the relazioni sistemi with the primary key or returns <code>null</code> if it could not be found.
     *
     * @param relazioneSistemaid the primary key of the relazioni sistemi
     * @return the relazioni sistemi, or <code>null</code> if a relazioni sistemi with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi fetchByPrimaryKey(long relazioneSistemaid) throws SystemException {
        RelazioniSistemi relazioniSistemi = (RelazioniSistemi) EntityCacheUtil.getResult(
                RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED, RelazioniSistemiImpl.class, relazioneSistemaid);

        if (relazioniSistemi == _nullRelazioniSistemi) {
            return null;
        }

        if (relazioniSistemi == null) {
            Session session = null;

            boolean hasException = false;

            try {
                session = openSession();

                relazioniSistemi = (RelazioniSistemi) session.get(RelazioniSistemiImpl.class,
                        Long.valueOf(relazioneSistemaid));
            } catch (Exception e) {
                hasException = true;

                throw processException(e);
            } finally {
                if (relazioniSistemi != null) {
                    cacheResult(relazioniSistemi);
                } else if (!hasException) {
                    EntityCacheUtil.putResult(RelazioniSistemiModelImpl.ENTITY_CACHE_ENABLED,
                            RelazioniSistemiImpl.class, relazioneSistemaid, _nullRelazioniSistemi);
                }

                closeSession(session);
            }
        }

        return relazioniSistemi;
    }

    /**
     * Returns all the relazioni sistemis where sistemaFrom = &#63;.
     *
     * @param sistemaFrom the sistema from
     * @return the matching relazioni sistemis
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> findBySistemaFrom(String sistemaFrom) throws SystemException {
        return findBySistemaFrom(sistemaFrom, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the relazioni sistemis where sistemaFrom = &#63;.
     *
     * <p>
     * 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.
     * </p>
     *
     * @param sistemaFrom the sistema from
     * @param start the lower bound of the range of relazioni sistemis
     * @param end the upper bound of the range of relazioni sistemis (not inclusive)
     * @return the range of matching relazioni sistemis
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> findBySistemaFrom(String sistemaFrom, int start, int end) throws SystemException {
        return findBySistemaFrom(sistemaFrom, start, end, null);
    }

    /**
     * Returns an ordered range of all the relazioni sistemis where sistemaFrom = &#63;.
     *
     * <p>
     * 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.
     * </p>
     *
     * @param sistemaFrom the sistema from
     * @param start the lower bound of the range of relazioni sistemis
     * @param end the upper bound of the range of relazioni sistemis (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of matching relazioni sistemis
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> findBySistemaFrom(String sistemaFrom, int start, int end,
            OrderByComparator orderByComparator) throws SystemException {
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SISTEMAFROM;
            finderArgs = new Object[] { sistemaFrom };
        } else {
            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SISTEMAFROM;
            finderArgs = new Object[] { sistemaFrom, start, end, orderByComparator };
        }

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

        if ((list != null) && !list.isEmpty()) {
            for (RelazioniSistemi relazioniSistemi : list) {
                if (!Validator.equals(sistemaFrom, relazioniSistemi.getSistemaFrom())) {
                    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_RELAZIONISISTEMI_WHERE);

            if (sistemaFrom == null) {
                query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_1);
            } else {
                if (sistemaFrom.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_3);
                } else {
                    query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_2);
                }
            }

            if (orderByComparator != null) {
                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
            }

            else {
                query.append(RelazioniSistemiModelImpl.ORDER_BY_JPQL);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (sistemaFrom != null) {
                    qPos.add(sistemaFrom);
                }

                list = (List<RelazioniSistemi>) QueryUtil.list(q, getDialect(), start, end);
            } catch (Exception e) {
                throw processException(e);
            } finally {
                if (list == null) {
                    FinderCacheUtil.removeResult(finderPath, finderArgs);
                } else {
                    cacheResult(list);

                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
                }

                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Returns the first relazioni sistemi in the ordered set where sistemaFrom = &#63;.
     *
     * @param sistemaFrom the sistema from
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching relazioni sistemi
     * @throws com.appuntivari.esempio.NoSuchRelazioniSistemiException if a matching relazioni sistemi could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi findBySistemaFrom_First(String sistemaFrom, OrderByComparator orderByComparator)
            throws NoSuchRelazioniSistemiException, SystemException {
        RelazioniSistemi relazioniSistemi = fetchBySistemaFrom_First(sistemaFrom, orderByComparator);

        if (relazioniSistemi != null) {
            return relazioniSistemi;
        }

        StringBundler msg = new StringBundler(4);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("sistemaFrom=");
        msg.append(sistemaFrom);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchRelazioniSistemiException(msg.toString());
    }

    /**
     * Returns the first relazioni sistemi in the ordered set where sistemaFrom = &#63;.
     *
     * @param sistemaFrom the sistema from
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching relazioni sistemi, or <code>null</code> if a matching relazioni sistemi could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi fetchBySistemaFrom_First(String sistemaFrom, OrderByComparator orderByComparator)
            throws SystemException {
        List<RelazioniSistemi> list = findBySistemaFrom(sistemaFrom, 0, 1, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the last relazioni sistemi in the ordered set where sistemaFrom = &#63;.
     *
     * @param sistemaFrom the sistema from
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching relazioni sistemi
     * @throws com.appuntivari.esempio.NoSuchRelazioniSistemiException if a matching relazioni sistemi could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi findBySistemaFrom_Last(String sistemaFrom, OrderByComparator orderByComparator)
            throws NoSuchRelazioniSistemiException, SystemException {
        RelazioniSistemi relazioniSistemi = fetchBySistemaFrom_Last(sistemaFrom, orderByComparator);

        if (relazioniSistemi != null) {
            return relazioniSistemi;
        }

        StringBundler msg = new StringBundler(4);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("sistemaFrom=");
        msg.append(sistemaFrom);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchRelazioniSistemiException(msg.toString());
    }

    /**
     * Returns the last relazioni sistemi in the ordered set where sistemaFrom = &#63;.
     *
     * @param sistemaFrom the sistema from
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching relazioni sistemi, or <code>null</code> if a matching relazioni sistemi could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi fetchBySistemaFrom_Last(String sistemaFrom, OrderByComparator orderByComparator)
            throws SystemException {
        int count = countBySistemaFrom(sistemaFrom);

        List<RelazioniSistemi> list = findBySistemaFrom(sistemaFrom, count - 1, count, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the relazioni sistemis before and after the current relazioni sistemi in the ordered set where sistemaFrom = &#63;.
     *
     * @param relazioneSistemaid the primary key of the current relazioni sistemi
     * @param sistemaFrom the sistema from
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the previous, current, and next relazioni sistemi
     * @throws com.appuntivari.esempio.NoSuchRelazioniSistemiException if a relazioni sistemi with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi[] findBySistemaFrom_PrevAndNext(long relazioneSistemaid, String sistemaFrom,
            OrderByComparator orderByComparator) throws NoSuchRelazioniSistemiException, SystemException {
        RelazioniSistemi relazioniSistemi = findByPrimaryKey(relazioneSistemaid);

        Session session = null;

        try {
            session = openSession();

            RelazioniSistemi[] array = new RelazioniSistemiImpl[3];

            array[0] = getBySistemaFrom_PrevAndNext(session, relazioniSistemi, sistemaFrom, orderByComparator,
                    true);

            array[1] = relazioniSistemi;

            array[2] = getBySistemaFrom_PrevAndNext(session, relazioniSistemi, sistemaFrom, orderByComparator,
                    false);

            return array;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    protected RelazioniSistemi getBySistemaFrom_PrevAndNext(Session session, RelazioniSistemi relazioniSistemi,
            String sistemaFrom, OrderByComparator orderByComparator, boolean previous) {
        StringBundler query = null;

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

        query.append(_SQL_SELECT_RELAZIONISISTEMI_WHERE);

        if (sistemaFrom == null) {
            query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_1);
        } else {
            if (sistemaFrom.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_3);
            } else {
                query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_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(RelazioniSistemiModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Query q = session.createQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        if (sistemaFrom != null) {
            qPos.add(sistemaFrom);
        }

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

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

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

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

    /**
     * Returns all the relazioni sistemis that the user has permission to view where sistemaFrom = &#63;.
     *
     * @param sistemaFrom the sistema from
     * @return the matching relazioni sistemis that the user has permission to view
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> filterFindBySistemaFrom(String sistemaFrom) throws SystemException {
        return filterFindBySistemaFrom(sistemaFrom, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the relazioni sistemis that the user has permission to view where sistemaFrom = &#63;.
     *
     * <p>
     * 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.
     * </p>
     *
     * @param sistemaFrom the sistema from
     * @param start the lower bound of the range of relazioni sistemis
     * @param end the upper bound of the range of relazioni sistemis (not inclusive)
     * @return the range of matching relazioni sistemis that the user has permission to view
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> filterFindBySistemaFrom(String sistemaFrom, int start, int end)
            throws SystemException {
        return filterFindBySistemaFrom(sistemaFrom, start, end, null);
    }

    /**
     * Returns an ordered range of all the relazioni sistemis that the user has permissions to view where sistemaFrom = &#63;.
     *
     * <p>
     * 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.
     * </p>
     *
     * @param sistemaFrom the sistema from
     * @param start the lower bound of the range of relazioni sistemis
     * @param end the upper bound of the range of relazioni sistemis (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of matching relazioni sistemis that the user has permission to view
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> filterFindBySistemaFrom(String sistemaFrom, int start, int end,
            OrderByComparator orderByComparator) throws SystemException {
        if (!InlineSQLHelperUtil.isEnabled()) {
            return findBySistemaFrom(sistemaFrom, start, end, orderByComparator);
        }

        StringBundler query = null;

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

        if (getDB().isSupportsInlineDistinct()) {
            query.append(_FILTER_SQL_SELECT_RELAZIONISISTEMI_WHERE);
        } else {
            query.append(_FILTER_SQL_SELECT_RELAZIONISISTEMI_NO_INLINE_DISTINCT_WHERE_1);
        }

        if (sistemaFrom == null) {
            query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_1);
        } else {
            if (sistemaFrom.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_3);
            } else {
                query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_2);
            }
        }

        if (!getDB().isSupportsInlineDistinct()) {
            query.append(_FILTER_SQL_SELECT_RELAZIONISISTEMI_NO_INLINE_DISTINCT_WHERE_2);
        }

        if (orderByComparator != null) {
            if (getDB().isSupportsInlineDistinct()) {
                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
            } else {
                appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator);
            }
        }

        else {
            if (getDB().isSupportsInlineDistinct()) {
                query.append(RelazioniSistemiModelImpl.ORDER_BY_JPQL);
            } else {
                query.append(RelazioniSistemiModelImpl.ORDER_BY_SQL);
            }
        }

        String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), RelazioniSistemi.class.getName(),
                _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);

        Session session = null;

        try {
            session = openSession();

            SQLQuery q = session.createSQLQuery(sql);

            if (getDB().isSupportsInlineDistinct()) {
                q.addEntity(_FILTER_ENTITY_ALIAS, RelazioniSistemiImpl.class);
            } else {
                q.addEntity(_FILTER_ENTITY_TABLE, RelazioniSistemiImpl.class);
            }

            QueryPos qPos = QueryPos.getInstance(q);

            if (sistemaFrom != null) {
                qPos.add(sistemaFrom);
            }

            return (List<RelazioniSistemi>) QueryUtil.list(q, getDialect(), start, end);
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    /**
     * Returns the relazioni sistemis before and after the current relazioni sistemi in the ordered set of relazioni sistemis that the user has permission to view where sistemaFrom = &#63;.
     *
     * @param relazioneSistemaid the primary key of the current relazioni sistemi
     * @param sistemaFrom the sistema from
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the previous, current, and next relazioni sistemi
     * @throws com.appuntivari.esempio.NoSuchRelazioniSistemiException if a relazioni sistemi with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi[] filterFindBySistemaFrom_PrevAndNext(long relazioneSistemaid, String sistemaFrom,
            OrderByComparator orderByComparator) throws NoSuchRelazioniSistemiException, SystemException {
        if (!InlineSQLHelperUtil.isEnabled()) {
            return findBySistemaFrom_PrevAndNext(relazioneSistemaid, sistemaFrom, orderByComparator);
        }

        RelazioniSistemi relazioniSistemi = findByPrimaryKey(relazioneSistemaid);

        Session session = null;

        try {
            session = openSession();

            RelazioniSistemi[] array = new RelazioniSistemiImpl[3];

            array[0] = filterGetBySistemaFrom_PrevAndNext(session, relazioniSistemi, sistemaFrom, orderByComparator,
                    true);

            array[1] = relazioniSistemi;

            array[2] = filterGetBySistemaFrom_PrevAndNext(session, relazioniSistemi, sistemaFrom, orderByComparator,
                    false);

            return array;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    protected RelazioniSistemi filterGetBySistemaFrom_PrevAndNext(Session session,
            RelazioniSistemi relazioniSistemi, String sistemaFrom, OrderByComparator orderByComparator,
            boolean previous) {
        StringBundler query = null;

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

        if (getDB().isSupportsInlineDistinct()) {
            query.append(_FILTER_SQL_SELECT_RELAZIONISISTEMI_WHERE);
        } else {
            query.append(_FILTER_SQL_SELECT_RELAZIONISISTEMI_NO_INLINE_DISTINCT_WHERE_1);
        }

        if (sistemaFrom == null) {
            query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_1);
        } else {
            if (sistemaFrom.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_3);
            } else {
                query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_2);
            }
        }

        if (!getDB().isSupportsInlineDistinct()) {
            query.append(_FILTER_SQL_SELECT_RELAZIONISISTEMI_NO_INLINE_DISTINCT_WHERE_2);
        }

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

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

            for (int i = 0; i < orderByConditionFields.length; i++) {
                if (getDB().isSupportsInlineDistinct()) {
                    query.append(_ORDER_BY_ENTITY_ALIAS);
                } else {
                    query.append(_ORDER_BY_ENTITY_TABLE);
                }

                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++) {
                if (getDB().isSupportsInlineDistinct()) {
                    query.append(_ORDER_BY_ENTITY_ALIAS);
                } else {
                    query.append(_ORDER_BY_ENTITY_TABLE);
                }

                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 {
            if (getDB().isSupportsInlineDistinct()) {
                query.append(RelazioniSistemiModelImpl.ORDER_BY_JPQL);
            } else {
                query.append(RelazioniSistemiModelImpl.ORDER_BY_SQL);
            }
        }

        String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), RelazioniSistemi.class.getName(),
                _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);

        SQLQuery q = session.createSQLQuery(sql);

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

        if (getDB().isSupportsInlineDistinct()) {
            q.addEntity(_FILTER_ENTITY_ALIAS, RelazioniSistemiImpl.class);
        } else {
            q.addEntity(_FILTER_ENTITY_TABLE, RelazioniSistemiImpl.class);
        }

        QueryPos qPos = QueryPos.getInstance(q);

        if (sistemaFrom != null) {
            qPos.add(sistemaFrom);
        }

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

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

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

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

    /**
     * Returns all the relazioni sistemis where sistemaTo = &#63;.
     *
     * @param sistemaTo the sistema to
     * @return the matching relazioni sistemis
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> findBySistemaTo(String sistemaTo) throws SystemException {
        return findBySistemaTo(sistemaTo, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the relazioni sistemis where sistemaTo = &#63;.
     *
     * <p>
     * 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.
     * </p>
     *
     * @param sistemaTo the sistema to
     * @param start the lower bound of the range of relazioni sistemis
     * @param end the upper bound of the range of relazioni sistemis (not inclusive)
     * @return the range of matching relazioni sistemis
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> findBySistemaTo(String sistemaTo, int start, int end) throws SystemException {
        return findBySistemaTo(sistemaTo, start, end, null);
    }

    /**
     * Returns an ordered range of all the relazioni sistemis where sistemaTo = &#63;.
     *
     * <p>
     * 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.
     * </p>
     *
     * @param sistemaTo the sistema to
     * @param start the lower bound of the range of relazioni sistemis
     * @param end the upper bound of the range of relazioni sistemis (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of matching relazioni sistemis
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> findBySistemaTo(String sistemaTo, int start, int end,
            OrderByComparator orderByComparator) throws SystemException {
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SISTEMATO;
            finderArgs = new Object[] { sistemaTo };
        } else {
            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SISTEMATO;
            finderArgs = new Object[] { sistemaTo, start, end, orderByComparator };
        }

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

        if ((list != null) && !list.isEmpty()) {
            for (RelazioniSistemi relazioniSistemi : list) {
                if (!Validator.equals(sistemaTo, relazioniSistemi.getSistemaTo())) {
                    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_RELAZIONISISTEMI_WHERE);

            if (sistemaTo == null) {
                query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_1);
            } else {
                if (sistemaTo.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_3);
                } else {
                    query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_2);
                }
            }

            if (orderByComparator != null) {
                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
            }

            else {
                query.append(RelazioniSistemiModelImpl.ORDER_BY_JPQL);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (sistemaTo != null) {
                    qPos.add(sistemaTo);
                }

                list = (List<RelazioniSistemi>) QueryUtil.list(q, getDialect(), start, end);
            } catch (Exception e) {
                throw processException(e);
            } finally {
                if (list == null) {
                    FinderCacheUtil.removeResult(finderPath, finderArgs);
                } else {
                    cacheResult(list);

                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
                }

                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Returns the first relazioni sistemi in the ordered set where sistemaTo = &#63;.
     *
     * @param sistemaTo the sistema to
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching relazioni sistemi
     * @throws com.appuntivari.esempio.NoSuchRelazioniSistemiException if a matching relazioni sistemi could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi findBySistemaTo_First(String sistemaTo, OrderByComparator orderByComparator)
            throws NoSuchRelazioniSistemiException, SystemException {
        RelazioniSistemi relazioniSistemi = fetchBySistemaTo_First(sistemaTo, orderByComparator);

        if (relazioniSistemi != null) {
            return relazioniSistemi;
        }

        StringBundler msg = new StringBundler(4);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("sistemaTo=");
        msg.append(sistemaTo);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchRelazioniSistemiException(msg.toString());
    }

    /**
     * Returns the first relazioni sistemi in the ordered set where sistemaTo = &#63;.
     *
     * @param sistemaTo the sistema to
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching relazioni sistemi, or <code>null</code> if a matching relazioni sistemi could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi fetchBySistemaTo_First(String sistemaTo, OrderByComparator orderByComparator)
            throws SystemException {
        List<RelazioniSistemi> list = findBySistemaTo(sistemaTo, 0, 1, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the last relazioni sistemi in the ordered set where sistemaTo = &#63;.
     *
     * @param sistemaTo the sistema to
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching relazioni sistemi
     * @throws com.appuntivari.esempio.NoSuchRelazioniSistemiException if a matching relazioni sistemi could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi findBySistemaTo_Last(String sistemaTo, OrderByComparator orderByComparator)
            throws NoSuchRelazioniSistemiException, SystemException {
        RelazioniSistemi relazioniSistemi = fetchBySistemaTo_Last(sistemaTo, orderByComparator);

        if (relazioniSistemi != null) {
            return relazioniSistemi;
        }

        StringBundler msg = new StringBundler(4);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("sistemaTo=");
        msg.append(sistemaTo);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchRelazioniSistemiException(msg.toString());
    }

    /**
     * Returns the last relazioni sistemi in the ordered set where sistemaTo = &#63;.
     *
     * @param sistemaTo the sistema to
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching relazioni sistemi, or <code>null</code> if a matching relazioni sistemi could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi fetchBySistemaTo_Last(String sistemaTo, OrderByComparator orderByComparator)
            throws SystemException {
        int count = countBySistemaTo(sistemaTo);

        List<RelazioniSistemi> list = findBySistemaTo(sistemaTo, count - 1, count, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the relazioni sistemis before and after the current relazioni sistemi in the ordered set where sistemaTo = &#63;.
     *
     * @param relazioneSistemaid the primary key of the current relazioni sistemi
     * @param sistemaTo the sistema to
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the previous, current, and next relazioni sistemi
     * @throws com.appuntivari.esempio.NoSuchRelazioniSistemiException if a relazioni sistemi with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi[] findBySistemaTo_PrevAndNext(long relazioneSistemaid, String sistemaTo,
            OrderByComparator orderByComparator) throws NoSuchRelazioniSistemiException, SystemException {
        RelazioniSistemi relazioniSistemi = findByPrimaryKey(relazioneSistemaid);

        Session session = null;

        try {
            session = openSession();

            RelazioniSistemi[] array = new RelazioniSistemiImpl[3];

            array[0] = getBySistemaTo_PrevAndNext(session, relazioniSistemi, sistemaTo, orderByComparator, true);

            array[1] = relazioniSistemi;

            array[2] = getBySistemaTo_PrevAndNext(session, relazioniSistemi, sistemaTo, orderByComparator, false);

            return array;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    protected RelazioniSistemi getBySistemaTo_PrevAndNext(Session session, RelazioniSistemi relazioniSistemi,
            String sistemaTo, OrderByComparator orderByComparator, boolean previous) {
        StringBundler query = null;

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

        query.append(_SQL_SELECT_RELAZIONISISTEMI_WHERE);

        if (sistemaTo == null) {
            query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_1);
        } else {
            if (sistemaTo.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_3);
            } else {
                query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_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(RelazioniSistemiModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Query q = session.createQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        if (sistemaTo != null) {
            qPos.add(sistemaTo);
        }

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

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

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

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

    /**
     * Returns all the relazioni sistemis that the user has permission to view where sistemaTo = &#63;.
     *
     * @param sistemaTo the sistema to
     * @return the matching relazioni sistemis that the user has permission to view
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> filterFindBySistemaTo(String sistemaTo) throws SystemException {
        return filterFindBySistemaTo(sistemaTo, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the relazioni sistemis that the user has permission to view where sistemaTo = &#63;.
     *
     * <p>
     * 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.
     * </p>
     *
     * @param sistemaTo the sistema to
     * @param start the lower bound of the range of relazioni sistemis
     * @param end the upper bound of the range of relazioni sistemis (not inclusive)
     * @return the range of matching relazioni sistemis that the user has permission to view
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> filterFindBySistemaTo(String sistemaTo, int start, int end)
            throws SystemException {
        return filterFindBySistemaTo(sistemaTo, start, end, null);
    }

    /**
     * Returns an ordered range of all the relazioni sistemis that the user has permissions to view where sistemaTo = &#63;.
     *
     * <p>
     * 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.
     * </p>
     *
     * @param sistemaTo the sistema to
     * @param start the lower bound of the range of relazioni sistemis
     * @param end the upper bound of the range of relazioni sistemis (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of matching relazioni sistemis that the user has permission to view
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> filterFindBySistemaTo(String sistemaTo, int start, int end,
            OrderByComparator orderByComparator) throws SystemException {
        if (!InlineSQLHelperUtil.isEnabled()) {
            return findBySistemaTo(sistemaTo, start, end, orderByComparator);
        }

        StringBundler query = null;

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

        if (getDB().isSupportsInlineDistinct()) {
            query.append(_FILTER_SQL_SELECT_RELAZIONISISTEMI_WHERE);
        } else {
            query.append(_FILTER_SQL_SELECT_RELAZIONISISTEMI_NO_INLINE_DISTINCT_WHERE_1);
        }

        if (sistemaTo == null) {
            query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_1);
        } else {
            if (sistemaTo.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_3);
            } else {
                query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_2);
            }
        }

        if (!getDB().isSupportsInlineDistinct()) {
            query.append(_FILTER_SQL_SELECT_RELAZIONISISTEMI_NO_INLINE_DISTINCT_WHERE_2);
        }

        if (orderByComparator != null) {
            if (getDB().isSupportsInlineDistinct()) {
                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
            } else {
                appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator);
            }
        }

        else {
            if (getDB().isSupportsInlineDistinct()) {
                query.append(RelazioniSistemiModelImpl.ORDER_BY_JPQL);
            } else {
                query.append(RelazioniSistemiModelImpl.ORDER_BY_SQL);
            }
        }

        String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), RelazioniSistemi.class.getName(),
                _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);

        Session session = null;

        try {
            session = openSession();

            SQLQuery q = session.createSQLQuery(sql);

            if (getDB().isSupportsInlineDistinct()) {
                q.addEntity(_FILTER_ENTITY_ALIAS, RelazioniSistemiImpl.class);
            } else {
                q.addEntity(_FILTER_ENTITY_TABLE, RelazioniSistemiImpl.class);
            }

            QueryPos qPos = QueryPos.getInstance(q);

            if (sistemaTo != null) {
                qPos.add(sistemaTo);
            }

            return (List<RelazioniSistemi>) QueryUtil.list(q, getDialect(), start, end);
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    /**
     * Returns the relazioni sistemis before and after the current relazioni sistemi in the ordered set of relazioni sistemis that the user has permission to view where sistemaTo = &#63;.
     *
     * @param relazioneSistemaid the primary key of the current relazioni sistemi
     * @param sistemaTo the sistema to
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the previous, current, and next relazioni sistemi
     * @throws com.appuntivari.esempio.NoSuchRelazioniSistemiException if a relazioni sistemi with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    public RelazioniSistemi[] filterFindBySistemaTo_PrevAndNext(long relazioneSistemaid, String sistemaTo,
            OrderByComparator orderByComparator) throws NoSuchRelazioniSistemiException, SystemException {
        if (!InlineSQLHelperUtil.isEnabled()) {
            return findBySistemaTo_PrevAndNext(relazioneSistemaid, sistemaTo, orderByComparator);
        }

        RelazioniSistemi relazioniSistemi = findByPrimaryKey(relazioneSistemaid);

        Session session = null;

        try {
            session = openSession();

            RelazioniSistemi[] array = new RelazioniSistemiImpl[3];

            array[0] = filterGetBySistemaTo_PrevAndNext(session, relazioniSistemi, sistemaTo, orderByComparator,
                    true);

            array[1] = relazioniSistemi;

            array[2] = filterGetBySistemaTo_PrevAndNext(session, relazioniSistemi, sistemaTo, orderByComparator,
                    false);

            return array;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    protected RelazioniSistemi filterGetBySistemaTo_PrevAndNext(Session session, RelazioniSistemi relazioniSistemi,
            String sistemaTo, OrderByComparator orderByComparator, boolean previous) {
        StringBundler query = null;

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

        if (getDB().isSupportsInlineDistinct()) {
            query.append(_FILTER_SQL_SELECT_RELAZIONISISTEMI_WHERE);
        } else {
            query.append(_FILTER_SQL_SELECT_RELAZIONISISTEMI_NO_INLINE_DISTINCT_WHERE_1);
        }

        if (sistemaTo == null) {
            query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_1);
        } else {
            if (sistemaTo.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_3);
            } else {
                query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_2);
            }
        }

        if (!getDB().isSupportsInlineDistinct()) {
            query.append(_FILTER_SQL_SELECT_RELAZIONISISTEMI_NO_INLINE_DISTINCT_WHERE_2);
        }

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

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

            for (int i = 0; i < orderByConditionFields.length; i++) {
                if (getDB().isSupportsInlineDistinct()) {
                    query.append(_ORDER_BY_ENTITY_ALIAS);
                } else {
                    query.append(_ORDER_BY_ENTITY_TABLE);
                }

                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++) {
                if (getDB().isSupportsInlineDistinct()) {
                    query.append(_ORDER_BY_ENTITY_ALIAS);
                } else {
                    query.append(_ORDER_BY_ENTITY_TABLE);
                }

                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 {
            if (getDB().isSupportsInlineDistinct()) {
                query.append(RelazioniSistemiModelImpl.ORDER_BY_JPQL);
            } else {
                query.append(RelazioniSistemiModelImpl.ORDER_BY_SQL);
            }
        }

        String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), RelazioniSistemi.class.getName(),
                _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);

        SQLQuery q = session.createSQLQuery(sql);

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

        if (getDB().isSupportsInlineDistinct()) {
            q.addEntity(_FILTER_ENTITY_ALIAS, RelazioniSistemiImpl.class);
        } else {
            q.addEntity(_FILTER_ENTITY_TABLE, RelazioniSistemiImpl.class);
        }

        QueryPos qPos = QueryPos.getInstance(q);

        if (sistemaTo != null) {
            qPos.add(sistemaTo);
        }

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

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

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

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

    /**
     * Returns all the relazioni sistemis.
     *
     * @return the relazioni sistemis
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> findAll() throws SystemException {
        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the relazioni sistemis.
     *
     * <p>
     * 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.
     * </p>
     *
     * @param start the lower bound of the range of relazioni sistemis
     * @param end the upper bound of the range of relazioni sistemis (not inclusive)
     * @return the range of relazioni sistemis
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> findAll(int start, int end) throws SystemException {
        return findAll(start, end, null);
    }

    /**
     * Returns an ordered range of all the relazioni sistemis.
     *
     * <p>
     * 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.
     * </p>
     *
     * @param start the lower bound of the range of relazioni sistemis
     * @param end the upper bound of the range of relazioni sistemis (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of relazioni sistemis
     * @throws SystemException if a system exception occurred
     */
    public List<RelazioniSistemi> findAll(int start, int end, OrderByComparator orderByComparator)
            throws SystemException {
        FinderPath finderPath = null;
        Object[] finderArgs = new Object[] { start, end, orderByComparator };

        if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
            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<RelazioniSistemi> list = (List<RelazioniSistemi>) 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_RELAZIONISISTEMI);

                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);

                sql = query.toString();
            } else {
                sql = _SQL_SELECT_RELAZIONISISTEMI.concat(RelazioniSistemiModelImpl.ORDER_BY_JPQL);
            }

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                if (orderByComparator == null) {
                    list = (List<RelazioniSistemi>) QueryUtil.list(q, getDialect(), start, end, false);

                    Collections.sort(list);
                } else {
                    list = (List<RelazioniSistemi>) QueryUtil.list(q, getDialect(), start, end);
                }
            } catch (Exception e) {
                throw processException(e);
            } finally {
                if (list == null) {
                    FinderCacheUtil.removeResult(finderPath, finderArgs);
                } else {
                    cacheResult(list);

                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
                }

                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Removes all the relazioni sistemis where sistemaFrom = &#63; from the database.
     *
     * @param sistemaFrom the sistema from
     * @throws SystemException if a system exception occurred
     */
    public void removeBySistemaFrom(String sistemaFrom) throws SystemException {
        for (RelazioniSistemi relazioniSistemi : findBySistemaFrom(sistemaFrom)) {
            remove(relazioniSistemi);
        }
    }

    /**
     * Removes all the relazioni sistemis where sistemaTo = &#63; from the database.
     *
     * @param sistemaTo the sistema to
     * @throws SystemException if a system exception occurred
     */
    public void removeBySistemaTo(String sistemaTo) throws SystemException {
        for (RelazioniSistemi relazioniSistemi : findBySistemaTo(sistemaTo)) {
            remove(relazioniSistemi);
        }
    }

    /**
     * Removes all the relazioni sistemis from the database.
     *
     * @throws SystemException if a system exception occurred
     */
    public void removeAll() throws SystemException {
        for (RelazioniSistemi relazioniSistemi : findAll()) {
            remove(relazioniSistemi);
        }
    }

    /**
     * Returns the number of relazioni sistemis where sistemaFrom = &#63;.
     *
     * @param sistemaFrom the sistema from
     * @return the number of matching relazioni sistemis
     * @throws SystemException if a system exception occurred
     */
    public int countBySistemaFrom(String sistemaFrom) throws SystemException {
        Object[] finderArgs = new Object[] { sistemaFrom };

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

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

            query.append(_SQL_COUNT_RELAZIONISISTEMI_WHERE);

            if (sistemaFrom == null) {
                query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_1);
            } else {
                if (sistemaFrom.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_3);
                } else {
                    query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_2);
                }
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (sistemaFrom != null) {
                    qPos.add(sistemaFrom);
                }

                count = (Long) q.uniqueResult();
            } catch (Exception e) {
                throw processException(e);
            } finally {
                if (count == null) {
                    count = Long.valueOf(0);
                }

                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SISTEMAFROM, finderArgs, count);

                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Returns the number of relazioni sistemis that the user has permission to view where sistemaFrom = &#63;.
     *
     * @param sistemaFrom the sistema from
     * @return the number of matching relazioni sistemis that the user has permission to view
     * @throws SystemException if a system exception occurred
     */
    public int filterCountBySistemaFrom(String sistemaFrom) throws SystemException {
        if (!InlineSQLHelperUtil.isEnabled()) {
            return countBySistemaFrom(sistemaFrom);
        }

        StringBundler query = new StringBundler(2);

        query.append(_FILTER_SQL_COUNT_RELAZIONISISTEMI_WHERE);

        if (sistemaFrom == null) {
            query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_1);
        } else {
            if (sistemaFrom.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_3);
            } else {
                query.append(_FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_2);
            }
        }

        String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), RelazioniSistemi.class.getName(),
                _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);

        Session session = null;

        try {
            session = openSession();

            SQLQuery q = session.createSQLQuery(sql);

            q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG);

            QueryPos qPos = QueryPos.getInstance(q);

            if (sistemaFrom != null) {
                qPos.add(sistemaFrom);
            }

            Long count = (Long) q.uniqueResult();

            return count.intValue();
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    /**
     * Returns the number of relazioni sistemis where sistemaTo = &#63;.
     *
     * @param sistemaTo the sistema to
     * @return the number of matching relazioni sistemis
     * @throws SystemException if a system exception occurred
     */
    public int countBySistemaTo(String sistemaTo) throws SystemException {
        Object[] finderArgs = new Object[] { sistemaTo };

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

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

            query.append(_SQL_COUNT_RELAZIONISISTEMI_WHERE);

            if (sistemaTo == null) {
                query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_1);
            } else {
                if (sistemaTo.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_3);
                } else {
                    query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_2);
                }
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (sistemaTo != null) {
                    qPos.add(sistemaTo);
                }

                count = (Long) q.uniqueResult();
            } catch (Exception e) {
                throw processException(e);
            } finally {
                if (count == null) {
                    count = Long.valueOf(0);
                }

                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SISTEMATO, finderArgs, count);

                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Returns the number of relazioni sistemis that the user has permission to view where sistemaTo = &#63;.
     *
     * @param sistemaTo the sistema to
     * @return the number of matching relazioni sistemis that the user has permission to view
     * @throws SystemException if a system exception occurred
     */
    public int filterCountBySistemaTo(String sistemaTo) throws SystemException {
        if (!InlineSQLHelperUtil.isEnabled()) {
            return countBySistemaTo(sistemaTo);
        }

        StringBundler query = new StringBundler(2);

        query.append(_FILTER_SQL_COUNT_RELAZIONISISTEMI_WHERE);

        if (sistemaTo == null) {
            query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_1);
        } else {
            if (sistemaTo.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_3);
            } else {
                query.append(_FINDER_COLUMN_SISTEMATO_SISTEMATO_2);
            }
        }

        String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), RelazioniSistemi.class.getName(),
                _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);

        Session session = null;

        try {
            session = openSession();

            SQLQuery q = session.createSQLQuery(sql);

            q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG);

            QueryPos qPos = QueryPos.getInstance(q);

            if (sistemaTo != null) {
                qPos.add(sistemaTo);
            }

            Long count = (Long) q.uniqueResult();

            return count.intValue();
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    /**
     * Returns the number of relazioni sistemis.
     *
     * @return the number of relazioni sistemis
     * @throws SystemException if a system exception occurred
     */
    public int countAll() throws SystemException {
        Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY, this);

        if (count == null) {
            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(_SQL_COUNT_RELAZIONISISTEMI);

                count = (Long) q.uniqueResult();
            } catch (Exception e) {
                throw processException(e);
            } finally {
                if (count == null) {
                    count = Long.valueOf(0);
                }

                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY, count);

                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Initializes the relazioni sistemi persistence.
     */
    public void afterPropertiesSet() {
        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(com.liferay.util.service.ServiceProps
                .get("value.object.listener.com.appuntivari.esempio.model.RelazioniSistemi")));

        if (listenerClassNames.length > 0) {
            try {
                List<ModelListener<RelazioniSistemi>> listenersList = new ArrayList<ModelListener<RelazioniSistemi>>();

                for (String listenerClassName : listenerClassNames) {
                    Class<?> clazz = getClass();

                    listenersList.add((ModelListener<RelazioniSistemi>) InstanceFactory
                            .newInstance(clazz.getClassLoader(), listenerClassName));
                }

                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
            } catch (Exception e) {
                _log.error(e);
            }
        }
    }

    public void destroy() {
        EntityCacheUtil.removeCache(RelazioniSistemiImpl.class.getName());
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    @BeanReference(type = ExternalUsersPersistence.class)
    protected ExternalUsersPersistence externalUsersPersistence;
    @BeanReference(type = RelazioniSistemiPersistence.class)
    protected RelazioniSistemiPersistence relazioniSistemiPersistence;
    @BeanReference(type = SistemiPersistence.class)
    protected SistemiPersistence sistemiPersistence;
    @BeanReference(type = ResourcePersistence.class)
    protected ResourcePersistence resourcePersistence;
    @BeanReference(type = UserPersistence.class)
    protected UserPersistence userPersistence;
    private static final String _SQL_SELECT_RELAZIONISISTEMI = "SELECT relazioniSistemi FROM RelazioniSistemi relazioniSistemi";
    private static final String _SQL_SELECT_RELAZIONISISTEMI_WHERE = "SELECT relazioniSistemi FROM RelazioniSistemi relazioniSistemi WHERE ";
    private static final String _SQL_COUNT_RELAZIONISISTEMI = "SELECT COUNT(relazioniSistemi) FROM RelazioniSistemi relazioniSistemi";
    private static final String _SQL_COUNT_RELAZIONISISTEMI_WHERE = "SELECT COUNT(relazioniSistemi) FROM RelazioniSistemi relazioniSistemi WHERE ";
    private static final String _FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_1 = "relazioniSistemi.sistemaFrom IS NULL";
    private static final String _FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_2 = "relazioniSistemi.sistemaFrom = ?";
    private static final String _FINDER_COLUMN_SISTEMAFROM_SISTEMAFROM_3 = "(relazioniSistemi.sistemaFrom IS NULL OR relazioniSistemi.sistemaFrom = ?)";
    private static final String _FINDER_COLUMN_SISTEMATO_SISTEMATO_1 = "relazioniSistemi.sistemaTo IS NULL";
    private static final String _FINDER_COLUMN_SISTEMATO_SISTEMATO_2 = "relazioniSistemi.sistemaTo = ?";
    private static final String _FINDER_COLUMN_SISTEMATO_SISTEMATO_3 = "(relazioniSistemi.sistemaTo IS NULL OR relazioniSistemi.sistemaTo = ?)";
    private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "relazioniSistemi.relazioneSistemaid";
    private static final String _FILTER_SQL_SELECT_RELAZIONISISTEMI_WHERE = "SELECT DISTINCT {relazioniSistemi.*} FROM AV_RelazioniSistemi relazioniSistemi WHERE ";
    private static final String _FILTER_SQL_SELECT_RELAZIONISISTEMI_NO_INLINE_DISTINCT_WHERE_1 = "SELECT {AV_RelazioniSistemi.*} FROM (SELECT DISTINCT relazioniSistemi.relazioneSistemaid FROM AV_RelazioniSistemi relazioniSistemi WHERE ";
    private static final String _FILTER_SQL_SELECT_RELAZIONISISTEMI_NO_INLINE_DISTINCT_WHERE_2 = ") TEMP_TABLE INNER JOIN AV_RelazioniSistemi ON TEMP_TABLE.relazioneSistemaid = AV_RelazioniSistemi.relazioneSistemaid";
    private static final String _FILTER_SQL_COUNT_RELAZIONISISTEMI_WHERE = "SELECT COUNT(DISTINCT relazioniSistemi.relazioneSistemaid) AS COUNT_VALUE FROM AV_RelazioniSistemi relazioniSistemi WHERE ";
    private static final String _FILTER_ENTITY_ALIAS = "relazioniSistemi";
    private static final String _FILTER_ENTITY_TABLE = "AV_RelazioniSistemi";
    private static final String _ORDER_BY_ENTITY_ALIAS = "relazioniSistemi.";
    private static final String _ORDER_BY_ENTITY_TABLE = "AV_RelazioniSistemi.";
    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RelazioniSistemi exists with the primary key ";
    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RelazioniSistemi exists with the key {";
    private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil
            .getBoolean(PropsUtil.get(PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
    private static Log _log = LogFactoryUtil.getLog(RelazioniSistemiPersistenceImpl.class);
    private static RelazioniSistemi _nullRelazioniSistemi = new RelazioniSistemiImpl() {
        @Override
        public Object clone() {
            return this;
        }

        @Override
        public CacheModel<RelazioniSistemi> toCacheModel() {
            return _nullRelazioniSistemiCacheModel;
        }
    };

    private static CacheModel<RelazioniSistemi> _nullRelazioniSistemiCacheModel = new CacheModel<RelazioniSistemi>() {
        public RelazioniSistemi toEntityModel() {
            return _nullRelazioniSistemi;
        }
    };
}