Example usage for com.liferay.portal.kernel.util StringPool BLANK

List of usage examples for com.liferay.portal.kernel.util StringPool BLANK

Introduction

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

Prototype

String BLANK

To view the source code for com.liferay.portal.kernel.util StringPool BLANK.

Click Source Link

Usage

From source file:at.graz.hmmc.liferay.portlet.puch.service.persistence.FahrzeugPersistenceImpl.java

License:Open Source License

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

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

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

    if ((list != null) && !list.isEmpty()) {
        for (Fahrzeug fahrzeug : list) {
            if (!Validator.equals(typ, fahrzeug.getTyp())) {
                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_FAHRZEUG_WHERE);

        boolean bindTyp = false;

        if (typ == null) {
            query.append(_FINDER_COLUMN_TYP_TYP_1);
        } else if (typ.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_TYP_TYP_3);
        } else {
            bindTyp = true;

            query.append(_FINDER_COLUMN_TYP_TYP_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindTyp) {
                qPos.add(typ);
            }

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:at.graz.hmmc.liferay.portlet.puch.service.persistence.FahrzeugPersistenceImpl.java

License:Open Source License

protected Fahrzeug getByTyp_PrevAndNext(Session session, Fahrzeug fahrzeug, String typ,
        OrderByComparator orderByComparator, boolean previous) {
    StringBundler query = null;/*w  w w . ja v a  2  s  . co m*/

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

    query.append(_SQL_SELECT_FAHRZEUG_WHERE);

    boolean bindTyp = false;

    if (typ == null) {
        query.append(_FINDER_COLUMN_TYP_TYP_1);
    } else if (typ.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_TYP_TYP_3);
    } else {
        bindTyp = true;

        query.append(_FINDER_COLUMN_TYP_TYP_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(FahrzeugModelImpl.ORDER_BY_JPQL);
    }

    String sql = query.toString();

    Query q = session.createQuery(sql);

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

    QueryPos qPos = QueryPos.getInstance(q);

    if (bindTyp) {
        qPos.add(typ);
    }

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

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

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

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

From source file:at.graz.hmmc.liferay.portlet.puch.service.persistence.FahrzeugPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of fahrzeugs where typ = &#63;.
 *
 * @param typ the typ/*  w  ww . j av  a  2  s  . com*/
 * @return the number of matching fahrzeugs
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByTyp(String typ) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_TYP;

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

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

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

        query.append(_SQL_COUNT_FAHRZEUG_WHERE);

        boolean bindTyp = false;

        if (typ == null) {
            query.append(_FINDER_COLUMN_TYP_TYP_1);
        } else if (typ.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_TYP_TYP_3);
        } else {
            bindTyp = true;

            query.append(_FINDER_COLUMN_TYP_TYP_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindTyp) {
                qPos.add(typ);
            }

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}

From source file:at.graz.hmmc.liferay.portlet.puch.service.persistence.ObjectDataPersistenceImpl.java

License:Open Source License

/**
 * Returns the object data where puchmuseumsobjectId = &#63; and objectkey = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param puchmuseumsobjectId the puchmuseumsobject ID
 * @param objectkey the objectkey/* w w w . ja v  a 2s.c  o  m*/
 * @param retrieveFromCache whether to use the finder cache
 * @return the matching object data, or <code>null</code> if a matching object data could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public ObjectData fetchByDataByOntology(long puchmuseumsobjectId, String objectkey, boolean retrieveFromCache)
        throws SystemException {
    Object[] finderArgs = new Object[] { puchmuseumsobjectId, objectkey };

    Object result = null;

    if (retrieveFromCache) {
        result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_DATABYONTOLOGY, finderArgs, this);
    }

    if (result instanceof ObjectData) {
        ObjectData objectData = (ObjectData) result;

        if ((puchmuseumsobjectId != objectData.getPuchmuseumsobjectId())
                || !Validator.equals(objectkey, objectData.getObjectkey())) {
            result = null;
        }
    }

    if (result == null) {
        StringBundler query = new StringBundler(4);

        query.append(_SQL_SELECT_OBJECTDATA_WHERE);

        query.append(_FINDER_COLUMN_DATABYONTOLOGY_PUCHMUSEUMSOBJECTID_2);

        boolean bindObjectkey = false;

        if (objectkey == null) {
            query.append(_FINDER_COLUMN_DATABYONTOLOGY_OBJECTKEY_1);
        } else if (objectkey.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_DATABYONTOLOGY_OBJECTKEY_3);
        } else {
            bindObjectkey = true;

            query.append(_FINDER_COLUMN_DATABYONTOLOGY_OBJECTKEY_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(puchmuseumsobjectId);

            if (bindObjectkey) {
                qPos.add(objectkey);
            }

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

            if (list.isEmpty()) {
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DATABYONTOLOGY, finderArgs, list);
            } else {
                if ((list.size() > 1) && _log.isWarnEnabled()) {
                    _log.warn(
                            "ObjectDataPersistenceImpl.fetchByDataByOntology(long, String, boolean) with parameters ("
                                    + StringUtil.merge(finderArgs)
                                    + ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
                }

                ObjectData objectData = list.get(0);

                result = objectData;

                cacheResult(objectData);

                if ((objectData.getPuchmuseumsobjectId() != puchmuseumsobjectId)
                        || (objectData.getObjectkey() == null)
                        || !objectData.getObjectkey().equals(objectkey)) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DATABYONTOLOGY, finderArgs, objectData);
                }
            }
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DATABYONTOLOGY, finderArgs);

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

    if (result instanceof List<?>) {
        return null;
    } else {
        return (ObjectData) result;
    }
}

From source file:at.graz.hmmc.liferay.portlet.puch.service.persistence.ObjectDataPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of object datas where puchmuseumsobjectId = &#63; and objectkey = &#63;.
 *
 * @param puchmuseumsobjectId the puchmuseumsobject ID
 * @param objectkey the objectkey/*from www. j ava  2  s .c  om*/
 * @return the number of matching object datas
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByDataByOntology(long puchmuseumsobjectId, String objectkey) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_DATABYONTOLOGY;

    Object[] finderArgs = new Object[] { puchmuseumsobjectId, objectkey };

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

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

        query.append(_SQL_COUNT_OBJECTDATA_WHERE);

        query.append(_FINDER_COLUMN_DATABYONTOLOGY_PUCHMUSEUMSOBJECTID_2);

        boolean bindObjectkey = false;

        if (objectkey == null) {
            query.append(_FINDER_COLUMN_DATABYONTOLOGY_OBJECTKEY_1);
        } else if (objectkey.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_DATABYONTOLOGY_OBJECTKEY_3);
        } else {
            bindObjectkey = true;

            query.append(_FINDER_COLUMN_DATABYONTOLOGY_OBJECTKEY_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(puchmuseumsobjectId);

            if (bindObjectkey) {
                qPos.add(objectkey);
            }

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}

From source file:at.graz.hmmc.liferay.portlet.puch.service.persistence.PersonPersistenceImpl.java

License:Open Source License

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

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

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

    if ((list != null) && !list.isEmpty()) {
        for (Person person : list) {
            if (!Validator.equals(vorname, person.getVorname())) {
                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_PERSON_WHERE);

        boolean bindVorname = false;

        if (vorname == null) {
            query.append(_FINDER_COLUMN_VORNAME_VORNAME_1);
        } else if (vorname.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_VORNAME_VORNAME_3);
        } else {
            bindVorname = true;

            query.append(_FINDER_COLUMN_VORNAME_VORNAME_2);
        }

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

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindVorname) {
                qPos.add(vorname);
            }

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

                Collections.sort(list);

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

            cacheResult(list);

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

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

    return list;
}

From source file:at.graz.hmmc.liferay.portlet.puch.service.persistence.PersonPersistenceImpl.java

License:Open Source License

protected Person getByVorname_PrevAndNext(Session session, Person person, String vorname,
        OrderByComparator orderByComparator, boolean previous) {
    StringBundler query = null;//from   w  ww . java  2 s  . co m

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

    query.append(_SQL_SELECT_PERSON_WHERE);

    boolean bindVorname = false;

    if (vorname == null) {
        query.append(_FINDER_COLUMN_VORNAME_VORNAME_1);
    } else if (vorname.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_VORNAME_VORNAME_3);
    } else {
        bindVorname = true;

        query.append(_FINDER_COLUMN_VORNAME_VORNAME_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(PersonModelImpl.ORDER_BY_JPQL);
    }

    String sql = query.toString();

    Query q = session.createQuery(sql);

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

    QueryPos qPos = QueryPos.getInstance(q);

    if (bindVorname) {
        qPos.add(vorname);
    }

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

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

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

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

From source file:at.graz.hmmc.liferay.portlet.puch.service.persistence.PersonPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of persons where vorname = &#63;.
 *
 * @param vorname the vorname/* w  w w  .j av a  2  s.c  o  m*/
 * @return the number of matching persons
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByVorname(String vorname) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_VORNAME;

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

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

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

        query.append(_SQL_COUNT_PERSON_WHERE);

        boolean bindVorname = false;

        if (vorname == null) {
            query.append(_FINDER_COLUMN_VORNAME_VORNAME_1);
        } else if (vorname.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_VORNAME_VORNAME_3);
        } else {
            bindVorname = true;

            query.append(_FINDER_COLUMN_VORNAME_VORNAME_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            if (bindVorname) {
                qPos.add(vorname);
            }

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}

From source file:at.graz.hmmc.liferay.portlet.puch.service.persistence.TransaktionDataPersistenceImpl.java

License:Open Source License

/**
 * Returns the transaktion data where transaktionId = &#63; and objectkey = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param transaktionId the transaktion ID
 * @param objectkey the objectkey/*from w ww  .  ja v  a 2 s. c  o  m*/
 * @param retrieveFromCache whether to use the finder cache
 * @return the matching transaktion data, or <code>null</code> if a matching transaktion data could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public TransaktionData fetchByDataByOntology(long transaktionId, String objectkey, boolean retrieveFromCache)
        throws SystemException {
    Object[] finderArgs = new Object[] { transaktionId, objectkey };

    Object result = null;

    if (retrieveFromCache) {
        result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_DATABYONTOLOGY, finderArgs, this);
    }

    if (result instanceof TransaktionData) {
        TransaktionData transaktionData = (TransaktionData) result;

        if ((transaktionId != transaktionData.getTransaktionId())
                || !Validator.equals(objectkey, transaktionData.getObjectkey())) {
            result = null;
        }
    }

    if (result == null) {
        StringBundler query = new StringBundler(4);

        query.append(_SQL_SELECT_TRANSAKTIONDATA_WHERE);

        query.append(_FINDER_COLUMN_DATABYONTOLOGY_TRANSAKTIONID_2);

        boolean bindObjectkey = false;

        if (objectkey == null) {
            query.append(_FINDER_COLUMN_DATABYONTOLOGY_OBJECTKEY_1);
        } else if (objectkey.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_DATABYONTOLOGY_OBJECTKEY_3);
        } else {
            bindObjectkey = true;

            query.append(_FINDER_COLUMN_DATABYONTOLOGY_OBJECTKEY_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(transaktionId);

            if (bindObjectkey) {
                qPos.add(objectkey);
            }

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

            if (list.isEmpty()) {
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DATABYONTOLOGY, finderArgs, list);
            } else {
                if ((list.size() > 1) && _log.isWarnEnabled()) {
                    _log.warn(
                            "TransaktionDataPersistenceImpl.fetchByDataByOntology(long, String, boolean) with parameters ("
                                    + StringUtil.merge(finderArgs)
                                    + ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
                }

                TransaktionData transaktionData = list.get(0);

                result = transaktionData;

                cacheResult(transaktionData);

                if ((transaktionData.getTransaktionId() != transaktionId)
                        || (transaktionData.getObjectkey() == null)
                        || !transaktionData.getObjectkey().equals(objectkey)) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DATABYONTOLOGY, finderArgs, transaktionData);
                }
            }
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DATABYONTOLOGY, finderArgs);

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

    if (result instanceof List<?>) {
        return null;
    } else {
        return (TransaktionData) result;
    }
}

From source file:at.graz.hmmc.liferay.portlet.puch.service.persistence.TransaktionDataPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of transaktion datas where transaktionId = &#63; and objectkey = &#63;.
 *
 * @param transaktionId the transaktion ID
 * @param objectkey the objectkey/*  w ww . ja v a2 s  .  com*/
 * @return the number of matching transaktion datas
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByDataByOntology(long transaktionId, String objectkey) throws SystemException {
    FinderPath finderPath = FINDER_PATH_COUNT_BY_DATABYONTOLOGY;

    Object[] finderArgs = new Object[] { transaktionId, objectkey };

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

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

        query.append(_SQL_COUNT_TRANSAKTIONDATA_WHERE);

        query.append(_FINDER_COLUMN_DATABYONTOLOGY_TRANSAKTIONID_2);

        boolean bindObjectkey = false;

        if (objectkey == null) {
            query.append(_FINDER_COLUMN_DATABYONTOLOGY_OBJECTKEY_1);
        } else if (objectkey.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_DATABYONTOLOGY_OBJECTKEY_3);
        } else {
            bindObjectkey = true;

            query.append(_FINDER_COLUMN_DATABYONTOLOGY_OBJECTKEY_2);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(transaktionId);

            if (bindObjectkey) {
                qPos.add(objectkey);
            }

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}