001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.dynamicdatamapping.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.OrderByComparator;
029    import com.liferay.portal.kernel.util.SetUtil;
030    import com.liferay.portal.kernel.util.StringBundler;
031    import com.liferay.portal.kernel.util.StringPool;
032    import com.liferay.portal.kernel.util.Validator;
033    import com.liferay.portal.model.CacheModel;
034    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
035    
036    import com.liferay.portlet.dynamicdatamapping.NoSuchStructureVersionException;
037    import com.liferay.portlet.dynamicdatamapping.model.DDMStructureVersion;
038    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureVersionImpl;
039    import com.liferay.portlet.dynamicdatamapping.model.impl.DDMStructureVersionModelImpl;
040    import com.liferay.portlet.dynamicdatamapping.service.persistence.DDMStructureVersionPersistence;
041    
042    import java.io.Serializable;
043    
044    import java.util.Collections;
045    import java.util.HashMap;
046    import java.util.HashSet;
047    import java.util.Iterator;
048    import java.util.List;
049    import java.util.Map;
050    import java.util.Set;
051    
052    /**
053     * The persistence implementation for the d d m structure version service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see DDMStructureVersionPersistence
061     * @see com.liferay.portlet.dynamicdatamapping.service.persistence.DDMStructureVersionUtil
062     * @generated
063     */
064    @ProviderType
065    public class DDMStructureVersionPersistenceImpl extends BasePersistenceImpl<DDMStructureVersion>
066            implements DDMStructureVersionPersistence {
067            /*
068             * NOTE FOR DEVELOPERS:
069             *
070             * Never modify or reference this class directly. Always use {@link DDMStructureVersionUtil} to access the d d m structure version persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
071             */
072            public static final String FINDER_CLASS_NAME_ENTITY = DDMStructureVersionImpl.class.getName();
073            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List1";
075            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List2";
077            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
078                            DDMStructureVersionModelImpl.FINDER_CACHE_ENABLED,
079                            DDMStructureVersionImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
082                            DDMStructureVersionModelImpl.FINDER_CACHE_ENABLED,
083                            DDMStructureVersionImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
086                            DDMStructureVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID =
089                    new FinderPath(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
090                            DDMStructureVersionModelImpl.FINDER_CACHE_ENABLED,
091                            DDMStructureVersionImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByStructureId",
093                            new String[] {
094                                    Long.class.getName(),
095                                    
096                            Integer.class.getName(), Integer.class.getName(),
097                                    OrderByComparator.class.getName()
098                            });
099            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID =
100                    new FinderPath(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
101                            DDMStructureVersionModelImpl.FINDER_CACHE_ENABLED,
102                            DDMStructureVersionImpl.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByStructureId",
104                            new String[] { Long.class.getName() },
105                            DDMStructureVersionModelImpl.STRUCTUREID_COLUMN_BITMASK);
106            public static final FinderPath FINDER_PATH_COUNT_BY_STRUCTUREID = new FinderPath(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
107                            DDMStructureVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByStructureId",
109                            new String[] { Long.class.getName() });
110    
111            /**
112             * Returns all the d d m structure versions where structureId = &#63;.
113             *
114             * @param structureId the structure ID
115             * @return the matching d d m structure versions
116             */
117            @Override
118            public List<DDMStructureVersion> findByStructureId(long structureId) {
119                    return findByStructureId(structureId, QueryUtil.ALL_POS,
120                            QueryUtil.ALL_POS, null);
121            }
122    
123            /**
124             * Returns a range of all the d d m structure versions where structureId = &#63;.
125             *
126             * <p>
127             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DDMStructureVersionModelImpl}. 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.
128             * </p>
129             *
130             * @param structureId the structure ID
131             * @param start the lower bound of the range of d d m structure versions
132             * @param end the upper bound of the range of d d m structure versions (not inclusive)
133             * @return the range of matching d d m structure versions
134             */
135            @Override
136            public List<DDMStructureVersion> findByStructureId(long structureId,
137                    int start, int end) {
138                    return findByStructureId(structureId, start, end, null);
139            }
140    
141            /**
142             * Returns an ordered range of all the d d m structure versions where structureId = &#63;.
143             *
144             * <p>
145             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DDMStructureVersionModelImpl}. 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.
146             * </p>
147             *
148             * @param structureId the structure ID
149             * @param start the lower bound of the range of d d m structure versions
150             * @param end the upper bound of the range of d d m structure versions (not inclusive)
151             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
152             * @return the ordered range of matching d d m structure versions
153             */
154            @Override
155            public List<DDMStructureVersion> findByStructureId(long structureId,
156                    int start, int end,
157                    OrderByComparator<DDMStructureVersion> orderByComparator) {
158                    boolean pagination = true;
159                    FinderPath finderPath = null;
160                    Object[] finderArgs = null;
161    
162                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
163                                    (orderByComparator == null)) {
164                            pagination = false;
165                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID;
166                            finderArgs = new Object[] { structureId };
167                    }
168                    else {
169                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID;
170                            finderArgs = new Object[] { structureId, start, end, orderByComparator };
171                    }
172    
173                    List<DDMStructureVersion> list = (List<DDMStructureVersion>)FinderCacheUtil.getResult(finderPath,
174                                    finderArgs, this);
175    
176                    if ((list != null) && !list.isEmpty()) {
177                            for (DDMStructureVersion ddmStructureVersion : list) {
178                                    if ((structureId != ddmStructureVersion.getStructureId())) {
179                                            list = null;
180    
181                                            break;
182                                    }
183                            }
184                    }
185    
186                    if (list == null) {
187                            StringBundler query = null;
188    
189                            if (orderByComparator != null) {
190                                    query = new StringBundler(3 +
191                                                    (orderByComparator.getOrderByFields().length * 3));
192                            }
193                            else {
194                                    query = new StringBundler(3);
195                            }
196    
197                            query.append(_SQL_SELECT_DDMSTRUCTUREVERSION_WHERE);
198    
199                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
200    
201                            if (orderByComparator != null) {
202                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
203                                            orderByComparator);
204                            }
205                            else
206                             if (pagination) {
207                                    query.append(DDMStructureVersionModelImpl.ORDER_BY_JPQL);
208                            }
209    
210                            String sql = query.toString();
211    
212                            Session session = null;
213    
214                            try {
215                                    session = openSession();
216    
217                                    Query q = session.createQuery(sql);
218    
219                                    QueryPos qPos = QueryPos.getInstance(q);
220    
221                                    qPos.add(structureId);
222    
223                                    if (!pagination) {
224                                            list = (List<DDMStructureVersion>)QueryUtil.list(q,
225                                                            getDialect(), start, end, false);
226    
227                                            Collections.sort(list);
228    
229                                            list = Collections.unmodifiableList(list);
230                                    }
231                                    else {
232                                            list = (List<DDMStructureVersion>)QueryUtil.list(q,
233                                                            getDialect(), start, end);
234                                    }
235    
236                                    cacheResult(list);
237    
238                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
239                            }
240                            catch (Exception e) {
241                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
242    
243                                    throw processException(e);
244                            }
245                            finally {
246                                    closeSession(session);
247                            }
248                    }
249    
250                    return list;
251            }
252    
253            /**
254             * Returns the first d d m structure version in the ordered set where structureId = &#63;.
255             *
256             * @param structureId the structure ID
257             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
258             * @return the first matching d d m structure version
259             * @throws NoSuchStructureVersionException if a matching d d m structure version could not be found
260             */
261            @Override
262            public DDMStructureVersion findByStructureId_First(long structureId,
263                    OrderByComparator<DDMStructureVersion> orderByComparator)
264                    throws NoSuchStructureVersionException {
265                    DDMStructureVersion ddmStructureVersion = fetchByStructureId_First(structureId,
266                                    orderByComparator);
267    
268                    if (ddmStructureVersion != null) {
269                            return ddmStructureVersion;
270                    }
271    
272                    StringBundler msg = new StringBundler(4);
273    
274                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
275    
276                    msg.append("structureId=");
277                    msg.append(structureId);
278    
279                    msg.append(StringPool.CLOSE_CURLY_BRACE);
280    
281                    throw new NoSuchStructureVersionException(msg.toString());
282            }
283    
284            /**
285             * Returns the first d d m structure version in the ordered set where structureId = &#63;.
286             *
287             * @param structureId the structure ID
288             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
289             * @return the first matching d d m structure version, or <code>null</code> if a matching d d m structure version could not be found
290             */
291            @Override
292            public DDMStructureVersion fetchByStructureId_First(long structureId,
293                    OrderByComparator<DDMStructureVersion> orderByComparator) {
294                    List<DDMStructureVersion> list = findByStructureId(structureId, 0, 1,
295                                    orderByComparator);
296    
297                    if (!list.isEmpty()) {
298                            return list.get(0);
299                    }
300    
301                    return null;
302            }
303    
304            /**
305             * Returns the last d d m structure version in the ordered set where structureId = &#63;.
306             *
307             * @param structureId the structure ID
308             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
309             * @return the last matching d d m structure version
310             * @throws NoSuchStructureVersionException if a matching d d m structure version could not be found
311             */
312            @Override
313            public DDMStructureVersion findByStructureId_Last(long structureId,
314                    OrderByComparator<DDMStructureVersion> orderByComparator)
315                    throws NoSuchStructureVersionException {
316                    DDMStructureVersion ddmStructureVersion = fetchByStructureId_Last(structureId,
317                                    orderByComparator);
318    
319                    if (ddmStructureVersion != null) {
320                            return ddmStructureVersion;
321                    }
322    
323                    StringBundler msg = new StringBundler(4);
324    
325                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
326    
327                    msg.append("structureId=");
328                    msg.append(structureId);
329    
330                    msg.append(StringPool.CLOSE_CURLY_BRACE);
331    
332                    throw new NoSuchStructureVersionException(msg.toString());
333            }
334    
335            /**
336             * Returns the last d d m structure version in the ordered set where structureId = &#63;.
337             *
338             * @param structureId the structure ID
339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
340             * @return the last matching d d m structure version, or <code>null</code> if a matching d d m structure version could not be found
341             */
342            @Override
343            public DDMStructureVersion fetchByStructureId_Last(long structureId,
344                    OrderByComparator<DDMStructureVersion> orderByComparator) {
345                    int count = countByStructureId(structureId);
346    
347                    if (count == 0) {
348                            return null;
349                    }
350    
351                    List<DDMStructureVersion> list = findByStructureId(structureId,
352                                    count - 1, count, orderByComparator);
353    
354                    if (!list.isEmpty()) {
355                            return list.get(0);
356                    }
357    
358                    return null;
359            }
360    
361            /**
362             * Returns the d d m structure versions before and after the current d d m structure version in the ordered set where structureId = &#63;.
363             *
364             * @param structureVersionId the primary key of the current d d m structure version
365             * @param structureId the structure ID
366             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
367             * @return the previous, current, and next d d m structure version
368             * @throws NoSuchStructureVersionException if a d d m structure version with the primary key could not be found
369             */
370            @Override
371            public DDMStructureVersion[] findByStructureId_PrevAndNext(
372                    long structureVersionId, long structureId,
373                    OrderByComparator<DDMStructureVersion> orderByComparator)
374                    throws NoSuchStructureVersionException {
375                    DDMStructureVersion ddmStructureVersion = findByPrimaryKey(structureVersionId);
376    
377                    Session session = null;
378    
379                    try {
380                            session = openSession();
381    
382                            DDMStructureVersion[] array = new DDMStructureVersionImpl[3];
383    
384                            array[0] = getByStructureId_PrevAndNext(session,
385                                            ddmStructureVersion, structureId, orderByComparator, true);
386    
387                            array[1] = ddmStructureVersion;
388    
389                            array[2] = getByStructureId_PrevAndNext(session,
390                                            ddmStructureVersion, structureId, orderByComparator, false);
391    
392                            return array;
393                    }
394                    catch (Exception e) {
395                            throw processException(e);
396                    }
397                    finally {
398                            closeSession(session);
399                    }
400            }
401    
402            protected DDMStructureVersion getByStructureId_PrevAndNext(
403                    Session session, DDMStructureVersion ddmStructureVersion,
404                    long structureId,
405                    OrderByComparator<DDMStructureVersion> orderByComparator,
406                    boolean previous) {
407                    StringBundler query = null;
408    
409                    if (orderByComparator != null) {
410                            query = new StringBundler(6 +
411                                            (orderByComparator.getOrderByFields().length * 6));
412                    }
413                    else {
414                            query = new StringBundler(3);
415                    }
416    
417                    query.append(_SQL_SELECT_DDMSTRUCTUREVERSION_WHERE);
418    
419                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
420    
421                    if (orderByComparator != null) {
422                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
423    
424                            if (orderByConditionFields.length > 0) {
425                                    query.append(WHERE_AND);
426                            }
427    
428                            for (int i = 0; i < orderByConditionFields.length; i++) {
429                                    query.append(_ORDER_BY_ENTITY_ALIAS);
430                                    query.append(orderByConditionFields[i]);
431    
432                                    if ((i + 1) < orderByConditionFields.length) {
433                                            if (orderByComparator.isAscending() ^ previous) {
434                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
435                                            }
436                                            else {
437                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
438                                            }
439                                    }
440                                    else {
441                                            if (orderByComparator.isAscending() ^ previous) {
442                                                    query.append(WHERE_GREATER_THAN);
443                                            }
444                                            else {
445                                                    query.append(WHERE_LESSER_THAN);
446                                            }
447                                    }
448                            }
449    
450                            query.append(ORDER_BY_CLAUSE);
451    
452                            String[] orderByFields = orderByComparator.getOrderByFields();
453    
454                            for (int i = 0; i < orderByFields.length; i++) {
455                                    query.append(_ORDER_BY_ENTITY_ALIAS);
456                                    query.append(orderByFields[i]);
457    
458                                    if ((i + 1) < orderByFields.length) {
459                                            if (orderByComparator.isAscending() ^ previous) {
460                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
461                                            }
462                                            else {
463                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
464                                            }
465                                    }
466                                    else {
467                                            if (orderByComparator.isAscending() ^ previous) {
468                                                    query.append(ORDER_BY_ASC);
469                                            }
470                                            else {
471                                                    query.append(ORDER_BY_DESC);
472                                            }
473                                    }
474                            }
475                    }
476                    else {
477                            query.append(DDMStructureVersionModelImpl.ORDER_BY_JPQL);
478                    }
479    
480                    String sql = query.toString();
481    
482                    Query q = session.createQuery(sql);
483    
484                    q.setFirstResult(0);
485                    q.setMaxResults(2);
486    
487                    QueryPos qPos = QueryPos.getInstance(q);
488    
489                    qPos.add(structureId);
490    
491                    if (orderByComparator != null) {
492                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructureVersion);
493    
494                            for (Object value : values) {
495                                    qPos.add(value);
496                            }
497                    }
498    
499                    List<DDMStructureVersion> list = q.list();
500    
501                    if (list.size() == 2) {
502                            return list.get(1);
503                    }
504                    else {
505                            return null;
506                    }
507            }
508    
509            /**
510             * Removes all the d d m structure versions where structureId = &#63; from the database.
511             *
512             * @param structureId the structure ID
513             */
514            @Override
515            public void removeByStructureId(long structureId) {
516                    for (DDMStructureVersion ddmStructureVersion : findByStructureId(
517                                    structureId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
518                            remove(ddmStructureVersion);
519                    }
520            }
521    
522            /**
523             * Returns the number of d d m structure versions where structureId = &#63;.
524             *
525             * @param structureId the structure ID
526             * @return the number of matching d d m structure versions
527             */
528            @Override
529            public int countByStructureId(long structureId) {
530                    FinderPath finderPath = FINDER_PATH_COUNT_BY_STRUCTUREID;
531    
532                    Object[] finderArgs = new Object[] { structureId };
533    
534                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
535                                    this);
536    
537                    if (count == null) {
538                            StringBundler query = new StringBundler(2);
539    
540                            query.append(_SQL_COUNT_DDMSTRUCTUREVERSION_WHERE);
541    
542                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
543    
544                            String sql = query.toString();
545    
546                            Session session = null;
547    
548                            try {
549                                    session = openSession();
550    
551                                    Query q = session.createQuery(sql);
552    
553                                    QueryPos qPos = QueryPos.getInstance(q);
554    
555                                    qPos.add(structureId);
556    
557                                    count = (Long)q.uniqueResult();
558    
559                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
560                            }
561                            catch (Exception e) {
562                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
563    
564                                    throw processException(e);
565                            }
566                            finally {
567                                    closeSession(session);
568                            }
569                    }
570    
571                    return count.intValue();
572            }
573    
574            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2 = "ddmStructureVersion.structureId = ?";
575            public static final FinderPath FINDER_PATH_FETCH_BY_S_V = new FinderPath(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
576                            DDMStructureVersionModelImpl.FINDER_CACHE_ENABLED,
577                            DDMStructureVersionImpl.class, FINDER_CLASS_NAME_ENTITY,
578                            "fetchByS_V",
579                            new String[] { Long.class.getName(), String.class.getName() },
580                            DDMStructureVersionModelImpl.STRUCTUREID_COLUMN_BITMASK |
581                            DDMStructureVersionModelImpl.VERSION_COLUMN_BITMASK);
582            public static final FinderPath FINDER_PATH_COUNT_BY_S_V = new FinderPath(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
583                            DDMStructureVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
584                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByS_V",
585                            new String[] { Long.class.getName(), String.class.getName() });
586    
587            /**
588             * Returns the d d m structure version where structureId = &#63; and version = &#63; or throws a {@link NoSuchStructureVersionException} if it could not be found.
589             *
590             * @param structureId the structure ID
591             * @param version the version
592             * @return the matching d d m structure version
593             * @throws NoSuchStructureVersionException if a matching d d m structure version could not be found
594             */
595            @Override
596            public DDMStructureVersion findByS_V(long structureId, String version)
597                    throws NoSuchStructureVersionException {
598                    DDMStructureVersion ddmStructureVersion = fetchByS_V(structureId,
599                                    version);
600    
601                    if (ddmStructureVersion == null) {
602                            StringBundler msg = new StringBundler(6);
603    
604                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
605    
606                            msg.append("structureId=");
607                            msg.append(structureId);
608    
609                            msg.append(", version=");
610                            msg.append(version);
611    
612                            msg.append(StringPool.CLOSE_CURLY_BRACE);
613    
614                            if (_log.isWarnEnabled()) {
615                                    _log.warn(msg.toString());
616                            }
617    
618                            throw new NoSuchStructureVersionException(msg.toString());
619                    }
620    
621                    return ddmStructureVersion;
622            }
623    
624            /**
625             * Returns the d d m structure version where structureId = &#63; and version = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
626             *
627             * @param structureId the structure ID
628             * @param version the version
629             * @return the matching d d m structure version, or <code>null</code> if a matching d d m structure version could not be found
630             */
631            @Override
632            public DDMStructureVersion fetchByS_V(long structureId, String version) {
633                    return fetchByS_V(structureId, version, true);
634            }
635    
636            /**
637             * Returns the d d m structure version where structureId = &#63; and version = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
638             *
639             * @param structureId the structure ID
640             * @param version the version
641             * @param retrieveFromCache whether to use the finder cache
642             * @return the matching d d m structure version, or <code>null</code> if a matching d d m structure version could not be found
643             */
644            @Override
645            public DDMStructureVersion fetchByS_V(long structureId, String version,
646                    boolean retrieveFromCache) {
647                    Object[] finderArgs = new Object[] { structureId, version };
648    
649                    Object result = null;
650    
651                    if (retrieveFromCache) {
652                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_S_V,
653                                            finderArgs, this);
654                    }
655    
656                    if (result instanceof DDMStructureVersion) {
657                            DDMStructureVersion ddmStructureVersion = (DDMStructureVersion)result;
658    
659                            if ((structureId != ddmStructureVersion.getStructureId()) ||
660                                            !Validator.equals(version, ddmStructureVersion.getVersion())) {
661                                    result = null;
662                            }
663                    }
664    
665                    if (result == null) {
666                            StringBundler query = new StringBundler(4);
667    
668                            query.append(_SQL_SELECT_DDMSTRUCTUREVERSION_WHERE);
669    
670                            query.append(_FINDER_COLUMN_S_V_STRUCTUREID_2);
671    
672                            boolean bindVersion = false;
673    
674                            if (version == null) {
675                                    query.append(_FINDER_COLUMN_S_V_VERSION_1);
676                            }
677                            else if (version.equals(StringPool.BLANK)) {
678                                    query.append(_FINDER_COLUMN_S_V_VERSION_3);
679                            }
680                            else {
681                                    bindVersion = true;
682    
683                                    query.append(_FINDER_COLUMN_S_V_VERSION_2);
684                            }
685    
686                            String sql = query.toString();
687    
688                            Session session = null;
689    
690                            try {
691                                    session = openSession();
692    
693                                    Query q = session.createQuery(sql);
694    
695                                    QueryPos qPos = QueryPos.getInstance(q);
696    
697                                    qPos.add(structureId);
698    
699                                    if (bindVersion) {
700                                            qPos.add(version);
701                                    }
702    
703                                    List<DDMStructureVersion> list = q.list();
704    
705                                    if (list.isEmpty()) {
706                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_S_V,
707                                                    finderArgs, list);
708                                    }
709                                    else {
710                                            DDMStructureVersion ddmStructureVersion = list.get(0);
711    
712                                            result = ddmStructureVersion;
713    
714                                            cacheResult(ddmStructureVersion);
715    
716                                            if ((ddmStructureVersion.getStructureId() != structureId) ||
717                                                            (ddmStructureVersion.getVersion() == null) ||
718                                                            !ddmStructureVersion.getVersion().equals(version)) {
719                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_S_V,
720                                                            finderArgs, ddmStructureVersion);
721                                            }
722                                    }
723                            }
724                            catch (Exception e) {
725                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_S_V,
726                                            finderArgs);
727    
728                                    throw processException(e);
729                            }
730                            finally {
731                                    closeSession(session);
732                            }
733                    }
734    
735                    if (result instanceof List<?>) {
736                            return null;
737                    }
738                    else {
739                            return (DDMStructureVersion)result;
740                    }
741            }
742    
743            /**
744             * Removes the d d m structure version where structureId = &#63; and version = &#63; from the database.
745             *
746             * @param structureId the structure ID
747             * @param version the version
748             * @return the d d m structure version that was removed
749             */
750            @Override
751            public DDMStructureVersion removeByS_V(long structureId, String version)
752                    throws NoSuchStructureVersionException {
753                    DDMStructureVersion ddmStructureVersion = findByS_V(structureId, version);
754    
755                    return remove(ddmStructureVersion);
756            }
757    
758            /**
759             * Returns the number of d d m structure versions where structureId = &#63; and version = &#63;.
760             *
761             * @param structureId the structure ID
762             * @param version the version
763             * @return the number of matching d d m structure versions
764             */
765            @Override
766            public int countByS_V(long structureId, String version) {
767                    FinderPath finderPath = FINDER_PATH_COUNT_BY_S_V;
768    
769                    Object[] finderArgs = new Object[] { structureId, version };
770    
771                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
772                                    this);
773    
774                    if (count == null) {
775                            StringBundler query = new StringBundler(3);
776    
777                            query.append(_SQL_COUNT_DDMSTRUCTUREVERSION_WHERE);
778    
779                            query.append(_FINDER_COLUMN_S_V_STRUCTUREID_2);
780    
781                            boolean bindVersion = false;
782    
783                            if (version == null) {
784                                    query.append(_FINDER_COLUMN_S_V_VERSION_1);
785                            }
786                            else if (version.equals(StringPool.BLANK)) {
787                                    query.append(_FINDER_COLUMN_S_V_VERSION_3);
788                            }
789                            else {
790                                    bindVersion = true;
791    
792                                    query.append(_FINDER_COLUMN_S_V_VERSION_2);
793                            }
794    
795                            String sql = query.toString();
796    
797                            Session session = null;
798    
799                            try {
800                                    session = openSession();
801    
802                                    Query q = session.createQuery(sql);
803    
804                                    QueryPos qPos = QueryPos.getInstance(q);
805    
806                                    qPos.add(structureId);
807    
808                                    if (bindVersion) {
809                                            qPos.add(version);
810                                    }
811    
812                                    count = (Long)q.uniqueResult();
813    
814                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
815                            }
816                            catch (Exception e) {
817                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
818    
819                                    throw processException(e);
820                            }
821                            finally {
822                                    closeSession(session);
823                            }
824                    }
825    
826                    return count.intValue();
827            }
828    
829            private static final String _FINDER_COLUMN_S_V_STRUCTUREID_2 = "ddmStructureVersion.structureId = ? AND ";
830            private static final String _FINDER_COLUMN_S_V_VERSION_1 = "ddmStructureVersion.version IS NULL";
831            private static final String _FINDER_COLUMN_S_V_VERSION_2 = "ddmStructureVersion.version = ?";
832            private static final String _FINDER_COLUMN_S_V_VERSION_3 = "(ddmStructureVersion.version IS NULL OR ddmStructureVersion.version = '')";
833            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_S_S = new FinderPath(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
834                            DDMStructureVersionModelImpl.FINDER_CACHE_ENABLED,
835                            DDMStructureVersionImpl.class,
836                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByS_S",
837                            new String[] {
838                                    Long.class.getName(), Integer.class.getName(),
839                                    
840                            Integer.class.getName(), Integer.class.getName(),
841                                    OrderByComparator.class.getName()
842                            });
843            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_S = new FinderPath(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
844                            DDMStructureVersionModelImpl.FINDER_CACHE_ENABLED,
845                            DDMStructureVersionImpl.class,
846                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByS_S",
847                            new String[] { Long.class.getName(), Integer.class.getName() },
848                            DDMStructureVersionModelImpl.STRUCTUREID_COLUMN_BITMASK |
849                            DDMStructureVersionModelImpl.STATUS_COLUMN_BITMASK);
850            public static final FinderPath FINDER_PATH_COUNT_BY_S_S = new FinderPath(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
851                            DDMStructureVersionModelImpl.FINDER_CACHE_ENABLED, Long.class,
852                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByS_S",
853                            new String[] { Long.class.getName(), Integer.class.getName() });
854    
855            /**
856             * Returns all the d d m structure versions where structureId = &#63; and status = &#63;.
857             *
858             * @param structureId the structure ID
859             * @param status the status
860             * @return the matching d d m structure versions
861             */
862            @Override
863            public List<DDMStructureVersion> findByS_S(long structureId, int status) {
864                    return findByS_S(structureId, status, QueryUtil.ALL_POS,
865                            QueryUtil.ALL_POS, null);
866            }
867    
868            /**
869             * Returns a range of all the d d m structure versions where structureId = &#63; and status = &#63;.
870             *
871             * <p>
872             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DDMStructureVersionModelImpl}. 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.
873             * </p>
874             *
875             * @param structureId the structure ID
876             * @param status the status
877             * @param start the lower bound of the range of d d m structure versions
878             * @param end the upper bound of the range of d d m structure versions (not inclusive)
879             * @return the range of matching d d m structure versions
880             */
881            @Override
882            public List<DDMStructureVersion> findByS_S(long structureId, int status,
883                    int start, int end) {
884                    return findByS_S(structureId, status, start, end, null);
885            }
886    
887            /**
888             * Returns an ordered range of all the d d m structure versions where structureId = &#63; and status = &#63;.
889             *
890             * <p>
891             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DDMStructureVersionModelImpl}. 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.
892             * </p>
893             *
894             * @param structureId the structure ID
895             * @param status the status
896             * @param start the lower bound of the range of d d m structure versions
897             * @param end the upper bound of the range of d d m structure versions (not inclusive)
898             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
899             * @return the ordered range of matching d d m structure versions
900             */
901            @Override
902            public List<DDMStructureVersion> findByS_S(long structureId, int status,
903                    int start, int end,
904                    OrderByComparator<DDMStructureVersion> orderByComparator) {
905                    boolean pagination = true;
906                    FinderPath finderPath = null;
907                    Object[] finderArgs = null;
908    
909                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
910                                    (orderByComparator == null)) {
911                            pagination = false;
912                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_S;
913                            finderArgs = new Object[] { structureId, status };
914                    }
915                    else {
916                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_S_S;
917                            finderArgs = new Object[] {
918                                            structureId, status,
919                                            
920                                            start, end, orderByComparator
921                                    };
922                    }
923    
924                    List<DDMStructureVersion> list = (List<DDMStructureVersion>)FinderCacheUtil.getResult(finderPath,
925                                    finderArgs, this);
926    
927                    if ((list != null) && !list.isEmpty()) {
928                            for (DDMStructureVersion ddmStructureVersion : list) {
929                                    if ((structureId != ddmStructureVersion.getStructureId()) ||
930                                                    (status != ddmStructureVersion.getStatus())) {
931                                            list = null;
932    
933                                            break;
934                                    }
935                            }
936                    }
937    
938                    if (list == null) {
939                            StringBundler query = null;
940    
941                            if (orderByComparator != null) {
942                                    query = new StringBundler(4 +
943                                                    (orderByComparator.getOrderByFields().length * 3));
944                            }
945                            else {
946                                    query = new StringBundler(4);
947                            }
948    
949                            query.append(_SQL_SELECT_DDMSTRUCTUREVERSION_WHERE);
950    
951                            query.append(_FINDER_COLUMN_S_S_STRUCTUREID_2);
952    
953                            query.append(_FINDER_COLUMN_S_S_STATUS_2);
954    
955                            if (orderByComparator != null) {
956                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
957                                            orderByComparator);
958                            }
959                            else
960                             if (pagination) {
961                                    query.append(DDMStructureVersionModelImpl.ORDER_BY_JPQL);
962                            }
963    
964                            String sql = query.toString();
965    
966                            Session session = null;
967    
968                            try {
969                                    session = openSession();
970    
971                                    Query q = session.createQuery(sql);
972    
973                                    QueryPos qPos = QueryPos.getInstance(q);
974    
975                                    qPos.add(structureId);
976    
977                                    qPos.add(status);
978    
979                                    if (!pagination) {
980                                            list = (List<DDMStructureVersion>)QueryUtil.list(q,
981                                                            getDialect(), start, end, false);
982    
983                                            Collections.sort(list);
984    
985                                            list = Collections.unmodifiableList(list);
986                                    }
987                                    else {
988                                            list = (List<DDMStructureVersion>)QueryUtil.list(q,
989                                                            getDialect(), start, end);
990                                    }
991    
992                                    cacheResult(list);
993    
994                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
995                            }
996                            catch (Exception e) {
997                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
998    
999                                    throw processException(e);
1000                            }
1001                            finally {
1002                                    closeSession(session);
1003                            }
1004                    }
1005    
1006                    return list;
1007            }
1008    
1009            /**
1010             * Returns the first d d m structure version in the ordered set where structureId = &#63; and status = &#63;.
1011             *
1012             * @param structureId the structure ID
1013             * @param status the status
1014             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1015             * @return the first matching d d m structure version
1016             * @throws NoSuchStructureVersionException if a matching d d m structure version could not be found
1017             */
1018            @Override
1019            public DDMStructureVersion findByS_S_First(long structureId, int status,
1020                    OrderByComparator<DDMStructureVersion> orderByComparator)
1021                    throws NoSuchStructureVersionException {
1022                    DDMStructureVersion ddmStructureVersion = fetchByS_S_First(structureId,
1023                                    status, orderByComparator);
1024    
1025                    if (ddmStructureVersion != null) {
1026                            return ddmStructureVersion;
1027                    }
1028    
1029                    StringBundler msg = new StringBundler(6);
1030    
1031                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1032    
1033                    msg.append("structureId=");
1034                    msg.append(structureId);
1035    
1036                    msg.append(", status=");
1037                    msg.append(status);
1038    
1039                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1040    
1041                    throw new NoSuchStructureVersionException(msg.toString());
1042            }
1043    
1044            /**
1045             * Returns the first d d m structure version in the ordered set where structureId = &#63; and status = &#63;.
1046             *
1047             * @param structureId the structure ID
1048             * @param status the status
1049             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1050             * @return the first matching d d m structure version, or <code>null</code> if a matching d d m structure version could not be found
1051             */
1052            @Override
1053            public DDMStructureVersion fetchByS_S_First(long structureId, int status,
1054                    OrderByComparator<DDMStructureVersion> orderByComparator) {
1055                    List<DDMStructureVersion> list = findByS_S(structureId, status, 0, 1,
1056                                    orderByComparator);
1057    
1058                    if (!list.isEmpty()) {
1059                            return list.get(0);
1060                    }
1061    
1062                    return null;
1063            }
1064    
1065            /**
1066             * Returns the last d d m structure version in the ordered set where structureId = &#63; and status = &#63;.
1067             *
1068             * @param structureId the structure ID
1069             * @param status the status
1070             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1071             * @return the last matching d d m structure version
1072             * @throws NoSuchStructureVersionException if a matching d d m structure version could not be found
1073             */
1074            @Override
1075            public DDMStructureVersion findByS_S_Last(long structureId, int status,
1076                    OrderByComparator<DDMStructureVersion> orderByComparator)
1077                    throws NoSuchStructureVersionException {
1078                    DDMStructureVersion ddmStructureVersion = fetchByS_S_Last(structureId,
1079                                    status, orderByComparator);
1080    
1081                    if (ddmStructureVersion != null) {
1082                            return ddmStructureVersion;
1083                    }
1084    
1085                    StringBundler msg = new StringBundler(6);
1086    
1087                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1088    
1089                    msg.append("structureId=");
1090                    msg.append(structureId);
1091    
1092                    msg.append(", status=");
1093                    msg.append(status);
1094    
1095                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1096    
1097                    throw new NoSuchStructureVersionException(msg.toString());
1098            }
1099    
1100            /**
1101             * Returns the last d d m structure version in the ordered set where structureId = &#63; and status = &#63;.
1102             *
1103             * @param structureId the structure ID
1104             * @param status the status
1105             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1106             * @return the last matching d d m structure version, or <code>null</code> if a matching d d m structure version could not be found
1107             */
1108            @Override
1109            public DDMStructureVersion fetchByS_S_Last(long structureId, int status,
1110                    OrderByComparator<DDMStructureVersion> orderByComparator) {
1111                    int count = countByS_S(structureId, status);
1112    
1113                    if (count == 0) {
1114                            return null;
1115                    }
1116    
1117                    List<DDMStructureVersion> list = findByS_S(structureId, status,
1118                                    count - 1, count, orderByComparator);
1119    
1120                    if (!list.isEmpty()) {
1121                            return list.get(0);
1122                    }
1123    
1124                    return null;
1125            }
1126    
1127            /**
1128             * Returns the d d m structure versions before and after the current d d m structure version in the ordered set where structureId = &#63; and status = &#63;.
1129             *
1130             * @param structureVersionId the primary key of the current d d m structure version
1131             * @param structureId the structure ID
1132             * @param status the status
1133             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1134             * @return the previous, current, and next d d m structure version
1135             * @throws NoSuchStructureVersionException if a d d m structure version with the primary key could not be found
1136             */
1137            @Override
1138            public DDMStructureVersion[] findByS_S_PrevAndNext(
1139                    long structureVersionId, long structureId, int status,
1140                    OrderByComparator<DDMStructureVersion> orderByComparator)
1141                    throws NoSuchStructureVersionException {
1142                    DDMStructureVersion ddmStructureVersion = findByPrimaryKey(structureVersionId);
1143    
1144                    Session session = null;
1145    
1146                    try {
1147                            session = openSession();
1148    
1149                            DDMStructureVersion[] array = new DDMStructureVersionImpl[3];
1150    
1151                            array[0] = getByS_S_PrevAndNext(session, ddmStructureVersion,
1152                                            structureId, status, orderByComparator, true);
1153    
1154                            array[1] = ddmStructureVersion;
1155    
1156                            array[2] = getByS_S_PrevAndNext(session, ddmStructureVersion,
1157                                            structureId, status, orderByComparator, false);
1158    
1159                            return array;
1160                    }
1161                    catch (Exception e) {
1162                            throw processException(e);
1163                    }
1164                    finally {
1165                            closeSession(session);
1166                    }
1167            }
1168    
1169            protected DDMStructureVersion getByS_S_PrevAndNext(Session session,
1170                    DDMStructureVersion ddmStructureVersion, long structureId, int status,
1171                    OrderByComparator<DDMStructureVersion> orderByComparator,
1172                    boolean previous) {
1173                    StringBundler query = null;
1174    
1175                    if (orderByComparator != null) {
1176                            query = new StringBundler(6 +
1177                                            (orderByComparator.getOrderByFields().length * 6));
1178                    }
1179                    else {
1180                            query = new StringBundler(3);
1181                    }
1182    
1183                    query.append(_SQL_SELECT_DDMSTRUCTUREVERSION_WHERE);
1184    
1185                    query.append(_FINDER_COLUMN_S_S_STRUCTUREID_2);
1186    
1187                    query.append(_FINDER_COLUMN_S_S_STATUS_2);
1188    
1189                    if (orderByComparator != null) {
1190                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1191    
1192                            if (orderByConditionFields.length > 0) {
1193                                    query.append(WHERE_AND);
1194                            }
1195    
1196                            for (int i = 0; i < orderByConditionFields.length; i++) {
1197                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1198                                    query.append(orderByConditionFields[i]);
1199    
1200                                    if ((i + 1) < orderByConditionFields.length) {
1201                                            if (orderByComparator.isAscending() ^ previous) {
1202                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1203                                            }
1204                                            else {
1205                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1206                                            }
1207                                    }
1208                                    else {
1209                                            if (orderByComparator.isAscending() ^ previous) {
1210                                                    query.append(WHERE_GREATER_THAN);
1211                                            }
1212                                            else {
1213                                                    query.append(WHERE_LESSER_THAN);
1214                                            }
1215                                    }
1216                            }
1217    
1218                            query.append(ORDER_BY_CLAUSE);
1219    
1220                            String[] orderByFields = orderByComparator.getOrderByFields();
1221    
1222                            for (int i = 0; i < orderByFields.length; i++) {
1223                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1224                                    query.append(orderByFields[i]);
1225    
1226                                    if ((i + 1) < orderByFields.length) {
1227                                            if (orderByComparator.isAscending() ^ previous) {
1228                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1229                                            }
1230                                            else {
1231                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1232                                            }
1233                                    }
1234                                    else {
1235                                            if (orderByComparator.isAscending() ^ previous) {
1236                                                    query.append(ORDER_BY_ASC);
1237                                            }
1238                                            else {
1239                                                    query.append(ORDER_BY_DESC);
1240                                            }
1241                                    }
1242                            }
1243                    }
1244                    else {
1245                            query.append(DDMStructureVersionModelImpl.ORDER_BY_JPQL);
1246                    }
1247    
1248                    String sql = query.toString();
1249    
1250                    Query q = session.createQuery(sql);
1251    
1252                    q.setFirstResult(0);
1253                    q.setMaxResults(2);
1254    
1255                    QueryPos qPos = QueryPos.getInstance(q);
1256    
1257                    qPos.add(structureId);
1258    
1259                    qPos.add(status);
1260    
1261                    if (orderByComparator != null) {
1262                            Object[] values = orderByComparator.getOrderByConditionValues(ddmStructureVersion);
1263    
1264                            for (Object value : values) {
1265                                    qPos.add(value);
1266                            }
1267                    }
1268    
1269                    List<DDMStructureVersion> list = q.list();
1270    
1271                    if (list.size() == 2) {
1272                            return list.get(1);
1273                    }
1274                    else {
1275                            return null;
1276                    }
1277            }
1278    
1279            /**
1280             * Removes all the d d m structure versions where structureId = &#63; and status = &#63; from the database.
1281             *
1282             * @param structureId the structure ID
1283             * @param status the status
1284             */
1285            @Override
1286            public void removeByS_S(long structureId, int status) {
1287                    for (DDMStructureVersion ddmStructureVersion : findByS_S(structureId,
1288                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1289                            remove(ddmStructureVersion);
1290                    }
1291            }
1292    
1293            /**
1294             * Returns the number of d d m structure versions where structureId = &#63; and status = &#63;.
1295             *
1296             * @param structureId the structure ID
1297             * @param status the status
1298             * @return the number of matching d d m structure versions
1299             */
1300            @Override
1301            public int countByS_S(long structureId, int status) {
1302                    FinderPath finderPath = FINDER_PATH_COUNT_BY_S_S;
1303    
1304                    Object[] finderArgs = new Object[] { structureId, status };
1305    
1306                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1307                                    this);
1308    
1309                    if (count == null) {
1310                            StringBundler query = new StringBundler(3);
1311    
1312                            query.append(_SQL_COUNT_DDMSTRUCTUREVERSION_WHERE);
1313    
1314                            query.append(_FINDER_COLUMN_S_S_STRUCTUREID_2);
1315    
1316                            query.append(_FINDER_COLUMN_S_S_STATUS_2);
1317    
1318                            String sql = query.toString();
1319    
1320                            Session session = null;
1321    
1322                            try {
1323                                    session = openSession();
1324    
1325                                    Query q = session.createQuery(sql);
1326    
1327                                    QueryPos qPos = QueryPos.getInstance(q);
1328    
1329                                    qPos.add(structureId);
1330    
1331                                    qPos.add(status);
1332    
1333                                    count = (Long)q.uniqueResult();
1334    
1335                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1336                            }
1337                            catch (Exception e) {
1338                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1339    
1340                                    throw processException(e);
1341                            }
1342                            finally {
1343                                    closeSession(session);
1344                            }
1345                    }
1346    
1347                    return count.intValue();
1348            }
1349    
1350            private static final String _FINDER_COLUMN_S_S_STRUCTUREID_2 = "ddmStructureVersion.structureId = ? AND ";
1351            private static final String _FINDER_COLUMN_S_S_STATUS_2 = "ddmStructureVersion.status = ?";
1352    
1353            public DDMStructureVersionPersistenceImpl() {
1354                    setModelClass(DDMStructureVersion.class);
1355            }
1356    
1357            /**
1358             * Caches the d d m structure version in the entity cache if it is enabled.
1359             *
1360             * @param ddmStructureVersion the d d m structure version
1361             */
1362            @Override
1363            public void cacheResult(DDMStructureVersion ddmStructureVersion) {
1364                    EntityCacheUtil.putResult(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
1365                            DDMStructureVersionImpl.class, ddmStructureVersion.getPrimaryKey(),
1366                            ddmStructureVersion);
1367    
1368                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_S_V,
1369                            new Object[] {
1370                                    ddmStructureVersion.getStructureId(),
1371                                    ddmStructureVersion.getVersion()
1372                            }, ddmStructureVersion);
1373    
1374                    ddmStructureVersion.resetOriginalValues();
1375            }
1376    
1377            /**
1378             * Caches the d d m structure versions in the entity cache if it is enabled.
1379             *
1380             * @param ddmStructureVersions the d d m structure versions
1381             */
1382            @Override
1383            public void cacheResult(List<DDMStructureVersion> ddmStructureVersions) {
1384                    for (DDMStructureVersion ddmStructureVersion : ddmStructureVersions) {
1385                            if (EntityCacheUtil.getResult(
1386                                                    DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
1387                                                    DDMStructureVersionImpl.class,
1388                                                    ddmStructureVersion.getPrimaryKey()) == null) {
1389                                    cacheResult(ddmStructureVersion);
1390                            }
1391                            else {
1392                                    ddmStructureVersion.resetOriginalValues();
1393                            }
1394                    }
1395            }
1396    
1397            /**
1398             * Clears the cache for all d d m structure versions.
1399             *
1400             * <p>
1401             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1402             * </p>
1403             */
1404            @Override
1405            public void clearCache() {
1406                    EntityCacheUtil.clearCache(DDMStructureVersionImpl.class);
1407    
1408                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1409                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1410                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1411            }
1412    
1413            /**
1414             * Clears the cache for the d d m structure version.
1415             *
1416             * <p>
1417             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1418             * </p>
1419             */
1420            @Override
1421            public void clearCache(DDMStructureVersion ddmStructureVersion) {
1422                    EntityCacheUtil.removeResult(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
1423                            DDMStructureVersionImpl.class, ddmStructureVersion.getPrimaryKey());
1424    
1425                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1426                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1427    
1428                    clearUniqueFindersCache(ddmStructureVersion);
1429            }
1430    
1431            @Override
1432            public void clearCache(List<DDMStructureVersion> ddmStructureVersions) {
1433                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1434                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1435    
1436                    for (DDMStructureVersion ddmStructureVersion : ddmStructureVersions) {
1437                            EntityCacheUtil.removeResult(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
1438                                    DDMStructureVersionImpl.class,
1439                                    ddmStructureVersion.getPrimaryKey());
1440    
1441                            clearUniqueFindersCache(ddmStructureVersion);
1442                    }
1443            }
1444    
1445            protected void cacheUniqueFindersCache(
1446                    DDMStructureVersion ddmStructureVersion) {
1447                    if (ddmStructureVersion.isNew()) {
1448                            Object[] args = new Object[] {
1449                                            ddmStructureVersion.getStructureId(),
1450                                            ddmStructureVersion.getVersion()
1451                                    };
1452    
1453                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_S_V, args,
1454                                    Long.valueOf(1));
1455                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_S_V, args,
1456                                    ddmStructureVersion);
1457                    }
1458                    else {
1459                            DDMStructureVersionModelImpl ddmStructureVersionModelImpl = (DDMStructureVersionModelImpl)ddmStructureVersion;
1460    
1461                            if ((ddmStructureVersionModelImpl.getColumnBitmask() &
1462                                            FINDER_PATH_FETCH_BY_S_V.getColumnBitmask()) != 0) {
1463                                    Object[] args = new Object[] {
1464                                                    ddmStructureVersion.getStructureId(),
1465                                                    ddmStructureVersion.getVersion()
1466                                            };
1467    
1468                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_S_V, args,
1469                                            Long.valueOf(1));
1470                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_S_V, args,
1471                                            ddmStructureVersion);
1472                            }
1473                    }
1474            }
1475    
1476            protected void clearUniqueFindersCache(
1477                    DDMStructureVersion ddmStructureVersion) {
1478                    DDMStructureVersionModelImpl ddmStructureVersionModelImpl = (DDMStructureVersionModelImpl)ddmStructureVersion;
1479    
1480                    Object[] args = new Object[] {
1481                                    ddmStructureVersion.getStructureId(),
1482                                    ddmStructureVersion.getVersion()
1483                            };
1484    
1485                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_S_V, args);
1486                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_S_V, args);
1487    
1488                    if ((ddmStructureVersionModelImpl.getColumnBitmask() &
1489                                    FINDER_PATH_FETCH_BY_S_V.getColumnBitmask()) != 0) {
1490                            args = new Object[] {
1491                                            ddmStructureVersionModelImpl.getOriginalStructureId(),
1492                                            ddmStructureVersionModelImpl.getOriginalVersion()
1493                                    };
1494    
1495                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_S_V, args);
1496                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_S_V, args);
1497                    }
1498            }
1499    
1500            /**
1501             * Creates a new d d m structure version with the primary key. Does not add the d d m structure version to the database.
1502             *
1503             * @param structureVersionId the primary key for the new d d m structure version
1504             * @return the new d d m structure version
1505             */
1506            @Override
1507            public DDMStructureVersion create(long structureVersionId) {
1508                    DDMStructureVersion ddmStructureVersion = new DDMStructureVersionImpl();
1509    
1510                    ddmStructureVersion.setNew(true);
1511                    ddmStructureVersion.setPrimaryKey(structureVersionId);
1512    
1513                    return ddmStructureVersion;
1514            }
1515    
1516            /**
1517             * Removes the d d m structure version with the primary key from the database. Also notifies the appropriate model listeners.
1518             *
1519             * @param structureVersionId the primary key of the d d m structure version
1520             * @return the d d m structure version that was removed
1521             * @throws NoSuchStructureVersionException if a d d m structure version with the primary key could not be found
1522             */
1523            @Override
1524            public DDMStructureVersion remove(long structureVersionId)
1525                    throws NoSuchStructureVersionException {
1526                    return remove((Serializable)structureVersionId);
1527            }
1528    
1529            /**
1530             * Removes the d d m structure version with the primary key from the database. Also notifies the appropriate model listeners.
1531             *
1532             * @param primaryKey the primary key of the d d m structure version
1533             * @return the d d m structure version that was removed
1534             * @throws NoSuchStructureVersionException if a d d m structure version with the primary key could not be found
1535             */
1536            @Override
1537            public DDMStructureVersion remove(Serializable primaryKey)
1538                    throws NoSuchStructureVersionException {
1539                    Session session = null;
1540    
1541                    try {
1542                            session = openSession();
1543    
1544                            DDMStructureVersion ddmStructureVersion = (DDMStructureVersion)session.get(DDMStructureVersionImpl.class,
1545                                            primaryKey);
1546    
1547                            if (ddmStructureVersion == null) {
1548                                    if (_log.isWarnEnabled()) {
1549                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1550                                    }
1551    
1552                                    throw new NoSuchStructureVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1553                                            primaryKey);
1554                            }
1555    
1556                            return remove(ddmStructureVersion);
1557                    }
1558                    catch (NoSuchStructureVersionException nsee) {
1559                            throw nsee;
1560                    }
1561                    catch (Exception e) {
1562                            throw processException(e);
1563                    }
1564                    finally {
1565                            closeSession(session);
1566                    }
1567            }
1568    
1569            @Override
1570            protected DDMStructureVersion removeImpl(
1571                    DDMStructureVersion ddmStructureVersion) {
1572                    ddmStructureVersion = toUnwrappedModel(ddmStructureVersion);
1573    
1574                    Session session = null;
1575    
1576                    try {
1577                            session = openSession();
1578    
1579                            if (!session.contains(ddmStructureVersion)) {
1580                                    ddmStructureVersion = (DDMStructureVersion)session.get(DDMStructureVersionImpl.class,
1581                                                    ddmStructureVersion.getPrimaryKeyObj());
1582                            }
1583    
1584                            if (ddmStructureVersion != null) {
1585                                    session.delete(ddmStructureVersion);
1586                            }
1587                    }
1588                    catch (Exception e) {
1589                            throw processException(e);
1590                    }
1591                    finally {
1592                            closeSession(session);
1593                    }
1594    
1595                    if (ddmStructureVersion != null) {
1596                            clearCache(ddmStructureVersion);
1597                    }
1598    
1599                    return ddmStructureVersion;
1600            }
1601    
1602            @Override
1603            public DDMStructureVersion updateImpl(
1604                    DDMStructureVersion ddmStructureVersion) {
1605                    ddmStructureVersion = toUnwrappedModel(ddmStructureVersion);
1606    
1607                    boolean isNew = ddmStructureVersion.isNew();
1608    
1609                    DDMStructureVersionModelImpl ddmStructureVersionModelImpl = (DDMStructureVersionModelImpl)ddmStructureVersion;
1610    
1611                    Session session = null;
1612    
1613                    try {
1614                            session = openSession();
1615    
1616                            if (ddmStructureVersion.isNew()) {
1617                                    session.save(ddmStructureVersion);
1618    
1619                                    ddmStructureVersion.setNew(false);
1620                            }
1621                            else {
1622                                    session.merge(ddmStructureVersion);
1623                            }
1624                    }
1625                    catch (Exception e) {
1626                            throw processException(e);
1627                    }
1628                    finally {
1629                            closeSession(session);
1630                    }
1631    
1632                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1633    
1634                    if (isNew || !DDMStructureVersionModelImpl.COLUMN_BITMASK_ENABLED) {
1635                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1636                    }
1637    
1638                    else {
1639                            if ((ddmStructureVersionModelImpl.getColumnBitmask() &
1640                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID.getColumnBitmask()) != 0) {
1641                                    Object[] args = new Object[] {
1642                                                    ddmStructureVersionModelImpl.getOriginalStructureId()
1643                                            };
1644    
1645                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
1646                                            args);
1647                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
1648                                            args);
1649    
1650                                    args = new Object[] {
1651                                                    ddmStructureVersionModelImpl.getStructureId()
1652                                            };
1653    
1654                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
1655                                            args);
1656                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
1657                                            args);
1658                            }
1659    
1660                            if ((ddmStructureVersionModelImpl.getColumnBitmask() &
1661                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_S.getColumnBitmask()) != 0) {
1662                                    Object[] args = new Object[] {
1663                                                    ddmStructureVersionModelImpl.getOriginalStructureId(),
1664                                                    ddmStructureVersionModelImpl.getOriginalStatus()
1665                                            };
1666    
1667                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_S_S, args);
1668                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_S,
1669                                            args);
1670    
1671                                    args = new Object[] {
1672                                                    ddmStructureVersionModelImpl.getStructureId(),
1673                                                    ddmStructureVersionModelImpl.getStatus()
1674                                            };
1675    
1676                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_S_S, args);
1677                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_S_S,
1678                                            args);
1679                            }
1680                    }
1681    
1682                    EntityCacheUtil.putResult(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
1683                            DDMStructureVersionImpl.class, ddmStructureVersion.getPrimaryKey(),
1684                            ddmStructureVersion, false);
1685    
1686                    clearUniqueFindersCache(ddmStructureVersion);
1687                    cacheUniqueFindersCache(ddmStructureVersion);
1688    
1689                    ddmStructureVersion.resetOriginalValues();
1690    
1691                    return ddmStructureVersion;
1692            }
1693    
1694            protected DDMStructureVersion toUnwrappedModel(
1695                    DDMStructureVersion ddmStructureVersion) {
1696                    if (ddmStructureVersion instanceof DDMStructureVersionImpl) {
1697                            return ddmStructureVersion;
1698                    }
1699    
1700                    DDMStructureVersionImpl ddmStructureVersionImpl = new DDMStructureVersionImpl();
1701    
1702                    ddmStructureVersionImpl.setNew(ddmStructureVersion.isNew());
1703                    ddmStructureVersionImpl.setPrimaryKey(ddmStructureVersion.getPrimaryKey());
1704    
1705                    ddmStructureVersionImpl.setStructureVersionId(ddmStructureVersion.getStructureVersionId());
1706                    ddmStructureVersionImpl.setGroupId(ddmStructureVersion.getGroupId());
1707                    ddmStructureVersionImpl.setCompanyId(ddmStructureVersion.getCompanyId());
1708                    ddmStructureVersionImpl.setUserId(ddmStructureVersion.getUserId());
1709                    ddmStructureVersionImpl.setUserName(ddmStructureVersion.getUserName());
1710                    ddmStructureVersionImpl.setCreateDate(ddmStructureVersion.getCreateDate());
1711                    ddmStructureVersionImpl.setStructureId(ddmStructureVersion.getStructureId());
1712                    ddmStructureVersionImpl.setVersion(ddmStructureVersion.getVersion());
1713                    ddmStructureVersionImpl.setParentStructureId(ddmStructureVersion.getParentStructureId());
1714                    ddmStructureVersionImpl.setName(ddmStructureVersion.getName());
1715                    ddmStructureVersionImpl.setDescription(ddmStructureVersion.getDescription());
1716                    ddmStructureVersionImpl.setDefinition(ddmStructureVersion.getDefinition());
1717                    ddmStructureVersionImpl.setStorageType(ddmStructureVersion.getStorageType());
1718                    ddmStructureVersionImpl.setType(ddmStructureVersion.getType());
1719                    ddmStructureVersionImpl.setStatus(ddmStructureVersion.getStatus());
1720                    ddmStructureVersionImpl.setStatusByUserId(ddmStructureVersion.getStatusByUserId());
1721                    ddmStructureVersionImpl.setStatusByUserName(ddmStructureVersion.getStatusByUserName());
1722                    ddmStructureVersionImpl.setStatusDate(ddmStructureVersion.getStatusDate());
1723    
1724                    return ddmStructureVersionImpl;
1725            }
1726    
1727            /**
1728             * Returns the d d m structure version with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1729             *
1730             * @param primaryKey the primary key of the d d m structure version
1731             * @return the d d m structure version
1732             * @throws NoSuchStructureVersionException if a d d m structure version with the primary key could not be found
1733             */
1734            @Override
1735            public DDMStructureVersion findByPrimaryKey(Serializable primaryKey)
1736                    throws NoSuchStructureVersionException {
1737                    DDMStructureVersion ddmStructureVersion = fetchByPrimaryKey(primaryKey);
1738    
1739                    if (ddmStructureVersion == null) {
1740                            if (_log.isWarnEnabled()) {
1741                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1742                            }
1743    
1744                            throw new NoSuchStructureVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1745                                    primaryKey);
1746                    }
1747    
1748                    return ddmStructureVersion;
1749            }
1750    
1751            /**
1752             * Returns the d d m structure version with the primary key or throws a {@link NoSuchStructureVersionException} if it could not be found.
1753             *
1754             * @param structureVersionId the primary key of the d d m structure version
1755             * @return the d d m structure version
1756             * @throws NoSuchStructureVersionException if a d d m structure version with the primary key could not be found
1757             */
1758            @Override
1759            public DDMStructureVersion findByPrimaryKey(long structureVersionId)
1760                    throws NoSuchStructureVersionException {
1761                    return findByPrimaryKey((Serializable)structureVersionId);
1762            }
1763    
1764            /**
1765             * Returns the d d m structure version with the primary key or returns <code>null</code> if it could not be found.
1766             *
1767             * @param primaryKey the primary key of the d d m structure version
1768             * @return the d d m structure version, or <code>null</code> if a d d m structure version with the primary key could not be found
1769             */
1770            @Override
1771            public DDMStructureVersion fetchByPrimaryKey(Serializable primaryKey) {
1772                    DDMStructureVersion ddmStructureVersion = (DDMStructureVersion)EntityCacheUtil.getResult(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
1773                                    DDMStructureVersionImpl.class, primaryKey);
1774    
1775                    if (ddmStructureVersion == _nullDDMStructureVersion) {
1776                            return null;
1777                    }
1778    
1779                    if (ddmStructureVersion == null) {
1780                            Session session = null;
1781    
1782                            try {
1783                                    session = openSession();
1784    
1785                                    ddmStructureVersion = (DDMStructureVersion)session.get(DDMStructureVersionImpl.class,
1786                                                    primaryKey);
1787    
1788                                    if (ddmStructureVersion != null) {
1789                                            cacheResult(ddmStructureVersion);
1790                                    }
1791                                    else {
1792                                            EntityCacheUtil.putResult(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
1793                                                    DDMStructureVersionImpl.class, primaryKey,
1794                                                    _nullDDMStructureVersion);
1795                                    }
1796                            }
1797                            catch (Exception e) {
1798                                    EntityCacheUtil.removeResult(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
1799                                            DDMStructureVersionImpl.class, primaryKey);
1800    
1801                                    throw processException(e);
1802                            }
1803                            finally {
1804                                    closeSession(session);
1805                            }
1806                    }
1807    
1808                    return ddmStructureVersion;
1809            }
1810    
1811            /**
1812             * Returns the d d m structure version with the primary key or returns <code>null</code> if it could not be found.
1813             *
1814             * @param structureVersionId the primary key of the d d m structure version
1815             * @return the d d m structure version, or <code>null</code> if a d d m structure version with the primary key could not be found
1816             */
1817            @Override
1818            public DDMStructureVersion fetchByPrimaryKey(long structureVersionId) {
1819                    return fetchByPrimaryKey((Serializable)structureVersionId);
1820            }
1821    
1822            @Override
1823            public Map<Serializable, DDMStructureVersion> fetchByPrimaryKeys(
1824                    Set<Serializable> primaryKeys) {
1825                    if (primaryKeys.isEmpty()) {
1826                            return Collections.emptyMap();
1827                    }
1828    
1829                    Map<Serializable, DDMStructureVersion> map = new HashMap<Serializable, DDMStructureVersion>();
1830    
1831                    if (primaryKeys.size() == 1) {
1832                            Iterator<Serializable> iterator = primaryKeys.iterator();
1833    
1834                            Serializable primaryKey = iterator.next();
1835    
1836                            DDMStructureVersion ddmStructureVersion = fetchByPrimaryKey(primaryKey);
1837    
1838                            if (ddmStructureVersion != null) {
1839                                    map.put(primaryKey, ddmStructureVersion);
1840                            }
1841    
1842                            return map;
1843                    }
1844    
1845                    Set<Serializable> uncachedPrimaryKeys = null;
1846    
1847                    for (Serializable primaryKey : primaryKeys) {
1848                            DDMStructureVersion ddmStructureVersion = (DDMStructureVersion)EntityCacheUtil.getResult(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
1849                                            DDMStructureVersionImpl.class, primaryKey);
1850    
1851                            if (ddmStructureVersion == null) {
1852                                    if (uncachedPrimaryKeys == null) {
1853                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1854                                    }
1855    
1856                                    uncachedPrimaryKeys.add(primaryKey);
1857                            }
1858                            else {
1859                                    map.put(primaryKey, ddmStructureVersion);
1860                            }
1861                    }
1862    
1863                    if (uncachedPrimaryKeys == null) {
1864                            return map;
1865                    }
1866    
1867                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1868                                    1);
1869    
1870                    query.append(_SQL_SELECT_DDMSTRUCTUREVERSION_WHERE_PKS_IN);
1871    
1872                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1873                            query.append(String.valueOf(primaryKey));
1874    
1875                            query.append(StringPool.COMMA);
1876                    }
1877    
1878                    query.setIndex(query.index() - 1);
1879    
1880                    query.append(StringPool.CLOSE_PARENTHESIS);
1881    
1882                    String sql = query.toString();
1883    
1884                    Session session = null;
1885    
1886                    try {
1887                            session = openSession();
1888    
1889                            Query q = session.createQuery(sql);
1890    
1891                            for (DDMStructureVersion ddmStructureVersion : (List<DDMStructureVersion>)q.list()) {
1892                                    map.put(ddmStructureVersion.getPrimaryKeyObj(),
1893                                            ddmStructureVersion);
1894    
1895                                    cacheResult(ddmStructureVersion);
1896    
1897                                    uncachedPrimaryKeys.remove(ddmStructureVersion.getPrimaryKeyObj());
1898                            }
1899    
1900                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1901                                    EntityCacheUtil.putResult(DDMStructureVersionModelImpl.ENTITY_CACHE_ENABLED,
1902                                            DDMStructureVersionImpl.class, primaryKey,
1903                                            _nullDDMStructureVersion);
1904                            }
1905                    }
1906                    catch (Exception e) {
1907                            throw processException(e);
1908                    }
1909                    finally {
1910                            closeSession(session);
1911                    }
1912    
1913                    return map;
1914            }
1915    
1916            /**
1917             * Returns all the d d m structure versions.
1918             *
1919             * @return the d d m structure versions
1920             */
1921            @Override
1922            public List<DDMStructureVersion> findAll() {
1923                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1924            }
1925    
1926            /**
1927             * Returns a range of all the d d m structure versions.
1928             *
1929             * <p>
1930             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DDMStructureVersionModelImpl}. 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.
1931             * </p>
1932             *
1933             * @param start the lower bound of the range of d d m structure versions
1934             * @param end the upper bound of the range of d d m structure versions (not inclusive)
1935             * @return the range of d d m structure versions
1936             */
1937            @Override
1938            public List<DDMStructureVersion> findAll(int start, int end) {
1939                    return findAll(start, end, null);
1940            }
1941    
1942            /**
1943             * Returns an ordered range of all the d d m structure versions.
1944             *
1945             * <p>
1946             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link DDMStructureVersionModelImpl}. 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.
1947             * </p>
1948             *
1949             * @param start the lower bound of the range of d d m structure versions
1950             * @param end the upper bound of the range of d d m structure versions (not inclusive)
1951             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1952             * @return the ordered range of d d m structure versions
1953             */
1954            @Override
1955            public List<DDMStructureVersion> findAll(int start, int end,
1956                    OrderByComparator<DDMStructureVersion> orderByComparator) {
1957                    boolean pagination = true;
1958                    FinderPath finderPath = null;
1959                    Object[] finderArgs = null;
1960    
1961                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1962                                    (orderByComparator == null)) {
1963                            pagination = false;
1964                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1965                            finderArgs = FINDER_ARGS_EMPTY;
1966                    }
1967                    else {
1968                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1969                            finderArgs = new Object[] { start, end, orderByComparator };
1970                    }
1971    
1972                    List<DDMStructureVersion> list = (List<DDMStructureVersion>)FinderCacheUtil.getResult(finderPath,
1973                                    finderArgs, this);
1974    
1975                    if (list == null) {
1976                            StringBundler query = null;
1977                            String sql = null;
1978    
1979                            if (orderByComparator != null) {
1980                                    query = new StringBundler(2 +
1981                                                    (orderByComparator.getOrderByFields().length * 3));
1982    
1983                                    query.append(_SQL_SELECT_DDMSTRUCTUREVERSION);
1984    
1985                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1986                                            orderByComparator);
1987    
1988                                    sql = query.toString();
1989                            }
1990                            else {
1991                                    sql = _SQL_SELECT_DDMSTRUCTUREVERSION;
1992    
1993                                    if (pagination) {
1994                                            sql = sql.concat(DDMStructureVersionModelImpl.ORDER_BY_JPQL);
1995                                    }
1996                            }
1997    
1998                            Session session = null;
1999    
2000                            try {
2001                                    session = openSession();
2002    
2003                                    Query q = session.createQuery(sql);
2004    
2005                                    if (!pagination) {
2006                                            list = (List<DDMStructureVersion>)QueryUtil.list(q,
2007                                                            getDialect(), start, end, false);
2008    
2009                                            Collections.sort(list);
2010    
2011                                            list = Collections.unmodifiableList(list);
2012                                    }
2013                                    else {
2014                                            list = (List<DDMStructureVersion>)QueryUtil.list(q,
2015                                                            getDialect(), start, end);
2016                                    }
2017    
2018                                    cacheResult(list);
2019    
2020                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2021                            }
2022                            catch (Exception e) {
2023                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2024    
2025                                    throw processException(e);
2026                            }
2027                            finally {
2028                                    closeSession(session);
2029                            }
2030                    }
2031    
2032                    return list;
2033            }
2034    
2035            /**
2036             * Removes all the d d m structure versions from the database.
2037             *
2038             */
2039            @Override
2040            public void removeAll() {
2041                    for (DDMStructureVersion ddmStructureVersion : findAll()) {
2042                            remove(ddmStructureVersion);
2043                    }
2044            }
2045    
2046            /**
2047             * Returns the number of d d m structure versions.
2048             *
2049             * @return the number of d d m structure versions
2050             */
2051            @Override
2052            public int countAll() {
2053                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2054                                    FINDER_ARGS_EMPTY, this);
2055    
2056                    if (count == null) {
2057                            Session session = null;
2058    
2059                            try {
2060                                    session = openSession();
2061    
2062                                    Query q = session.createQuery(_SQL_COUNT_DDMSTRUCTUREVERSION);
2063    
2064                                    count = (Long)q.uniqueResult();
2065    
2066                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2067                                            FINDER_ARGS_EMPTY, count);
2068                            }
2069                            catch (Exception e) {
2070                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2071                                            FINDER_ARGS_EMPTY);
2072    
2073                                    throw processException(e);
2074                            }
2075                            finally {
2076                                    closeSession(session);
2077                            }
2078                    }
2079    
2080                    return count.intValue();
2081            }
2082    
2083            @Override
2084            protected Set<String> getBadColumnNames() {
2085                    return _badColumnNames;
2086            }
2087    
2088            /**
2089             * Initializes the d d m structure version persistence.
2090             */
2091            public void afterPropertiesSet() {
2092            }
2093    
2094            public void destroy() {
2095                    EntityCacheUtil.removeCache(DDMStructureVersionImpl.class.getName());
2096                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2097                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2098                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2099            }
2100    
2101            private static final String _SQL_SELECT_DDMSTRUCTUREVERSION = "SELECT ddmStructureVersion FROM DDMStructureVersion ddmStructureVersion";
2102            private static final String _SQL_SELECT_DDMSTRUCTUREVERSION_WHERE_PKS_IN = "SELECT ddmStructureVersion FROM DDMStructureVersion ddmStructureVersion WHERE structureVersionId IN (";
2103            private static final String _SQL_SELECT_DDMSTRUCTUREVERSION_WHERE = "SELECT ddmStructureVersion FROM DDMStructureVersion ddmStructureVersion WHERE ";
2104            private static final String _SQL_COUNT_DDMSTRUCTUREVERSION = "SELECT COUNT(ddmStructureVersion) FROM DDMStructureVersion ddmStructureVersion";
2105            private static final String _SQL_COUNT_DDMSTRUCTUREVERSION_WHERE = "SELECT COUNT(ddmStructureVersion) FROM DDMStructureVersion ddmStructureVersion WHERE ";
2106            private static final String _ORDER_BY_ENTITY_ALIAS = "ddmStructureVersion.";
2107            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DDMStructureVersion exists with the primary key ";
2108            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DDMStructureVersion exists with the key {";
2109            private static final Log _log = LogFactoryUtil.getLog(DDMStructureVersionPersistenceImpl.class);
2110            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2111                                    "type"
2112                            });
2113            private static final DDMStructureVersion _nullDDMStructureVersion = new DDMStructureVersionImpl() {
2114                            @Override
2115                            public Object clone() {
2116                                    return this;
2117                            }
2118    
2119                            @Override
2120                            public CacheModel<DDMStructureVersion> toCacheModel() {
2121                                    return _nullDDMStructureVersionCacheModel;
2122                            }
2123                    };
2124    
2125            private static final CacheModel<DDMStructureVersion> _nullDDMStructureVersionCacheModel =
2126                    new CacheModel<DDMStructureVersion>() {
2127                            @Override
2128                            public DDMStructureVersion toEntityModel() {
2129                                    return _nullDDMStructureVersion;
2130                            }
2131                    };
2132    }