001    /**
002     * Copyright (c) 2000-2010 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.expando.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.ModelListener;
037    import com.liferay.portal.service.persistence.BatchSessionUtil;
038    import com.liferay.portal.service.persistence.ResourcePersistence;
039    import com.liferay.portal.service.persistence.UserPersistence;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    
042    import com.liferay.portlet.expando.NoSuchValueException;
043    import com.liferay.portlet.expando.model.ExpandoValue;
044    import com.liferay.portlet.expando.model.impl.ExpandoValueImpl;
045    import com.liferay.portlet.expando.model.impl.ExpandoValueModelImpl;
046    
047    import java.io.Serializable;
048    
049    import java.util.ArrayList;
050    import java.util.Collections;
051    import java.util.List;
052    
053    /**
054     * @author    Brian Wing Shun Chan
055     * @see       ExpandoValuePersistence
056     * @see       ExpandoValueUtil
057     * @generated
058     */
059    public class ExpandoValuePersistenceImpl extends BasePersistenceImpl<ExpandoValue>
060            implements ExpandoValuePersistence {
061            public static final String FINDER_CLASS_NAME_ENTITY = ExpandoValueImpl.class.getName();
062            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
063                    ".List";
064            public static final FinderPath FINDER_PATH_FIND_BY_TABLEID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
065                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
066                            "findByTableId",
067                            new String[] {
068                                    Long.class.getName(),
069                                    
070                            "java.lang.Integer", "java.lang.Integer",
071                                    "com.liferay.portal.kernel.util.OrderByComparator"
072                            });
073            public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
074                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
075                            "countByTableId", new String[] { Long.class.getName() });
076            public static final FinderPath FINDER_PATH_FIND_BY_COLUMNID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
077                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
078                            "findByColumnId",
079                            new String[] {
080                                    Long.class.getName(),
081                                    
082                            "java.lang.Integer", "java.lang.Integer",
083                                    "com.liferay.portal.kernel.util.OrderByComparator"
084                            });
085            public static final FinderPath FINDER_PATH_COUNT_BY_COLUMNID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
086                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
087                            "countByColumnId", new String[] { Long.class.getName() });
088            public static final FinderPath FINDER_PATH_FIND_BY_ROWID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
089                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
090                            "findByRowId",
091                            new String[] {
092                                    Long.class.getName(),
093                                    
094                            "java.lang.Integer", "java.lang.Integer",
095                                    "com.liferay.portal.kernel.util.OrderByComparator"
096                            });
097            public static final FinderPath FINDER_PATH_COUNT_BY_ROWID = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
098                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
099                            "countByRowId", new String[] { Long.class.getName() });
100            public static final FinderPath FINDER_PATH_FIND_BY_T_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
101                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102                            "findByT_C",
103                            new String[] {
104                                    Long.class.getName(), Long.class.getName(),
105                                    
106                            "java.lang.Integer", "java.lang.Integer",
107                                    "com.liferay.portal.kernel.util.OrderByComparator"
108                            });
109            public static final FinderPath FINDER_PATH_COUNT_BY_T_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
110                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111                            "countByT_C",
112                            new String[] { Long.class.getName(), Long.class.getName() });
113            public static final FinderPath FINDER_PATH_FIND_BY_T_CPK = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
114                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
115                            "findByT_CPK",
116                            new String[] {
117                                    Long.class.getName(), Long.class.getName(),
118                                    
119                            "java.lang.Integer", "java.lang.Integer",
120                                    "com.liferay.portal.kernel.util.OrderByComparator"
121                            });
122            public static final FinderPath FINDER_PATH_COUNT_BY_T_CPK = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
123                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
124                            "countByT_CPK",
125                            new String[] { Long.class.getName(), Long.class.getName() });
126            public static final FinderPath FINDER_PATH_FIND_BY_T_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
127                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
128                            "findByT_R",
129                            new String[] {
130                                    Long.class.getName(), Long.class.getName(),
131                                    
132                            "java.lang.Integer", "java.lang.Integer",
133                                    "com.liferay.portal.kernel.util.OrderByComparator"
134                            });
135            public static final FinderPath FINDER_PATH_COUNT_BY_T_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
136                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
137                            "countByT_R",
138                            new String[] { Long.class.getName(), Long.class.getName() });
139            public static final FinderPath FINDER_PATH_FETCH_BY_C_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
140                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED,
141                            FINDER_CLASS_NAME_ENTITY, "fetchByC_R",
142                            new String[] { Long.class.getName(), Long.class.getName() });
143            public static final FinderPath FINDER_PATH_COUNT_BY_C_R = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
144                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
145                            "countByC_R",
146                            new String[] { Long.class.getName(), Long.class.getName() });
147            public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
148                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
149                            "findByC_C",
150                            new String[] {
151                                    Long.class.getName(), Long.class.getName(),
152                                    
153                            "java.lang.Integer", "java.lang.Integer",
154                                    "com.liferay.portal.kernel.util.OrderByComparator"
155                            });
156            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
157                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
158                            "countByC_C",
159                            new String[] { Long.class.getName(), Long.class.getName() });
160            public static final FinderPath FINDER_PATH_FETCH_BY_T_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
161                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED,
162                            FINDER_CLASS_NAME_ENTITY, "fetchByT_C_C",
163                            new String[] {
164                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
165                            });
166            public static final FinderPath FINDER_PATH_COUNT_BY_T_C_C = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
167                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
168                            "countByT_C_C",
169                            new String[] {
170                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
171                            });
172            public static final FinderPath FINDER_PATH_FIND_BY_T_C_D = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
173                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
174                            "findByT_C_D",
175                            new String[] {
176                                    Long.class.getName(), Long.class.getName(),
177                                    String.class.getName(),
178                                    
179                            "java.lang.Integer", "java.lang.Integer",
180                                    "com.liferay.portal.kernel.util.OrderByComparator"
181                            });
182            public static final FinderPath FINDER_PATH_COUNT_BY_T_C_D = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
183                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
184                            "countByT_C_D",
185                            new String[] {
186                                    Long.class.getName(), Long.class.getName(),
187                                    String.class.getName()
188                            });
189            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
190                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
191                            "findAll", new String[0]);
192            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
193                            ExpandoValueModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
194                            "countAll", new String[0]);
195    
196            public void cacheResult(ExpandoValue expandoValue) {
197                    EntityCacheUtil.putResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
198                            ExpandoValueImpl.class, expandoValue.getPrimaryKey(), expandoValue);
199    
200                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
201                            new Object[] {
202                                    new Long(expandoValue.getColumnId()),
203                                    new Long(expandoValue.getRowId())
204                            }, expandoValue);
205    
206                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
207                            new Object[] {
208                                    new Long(expandoValue.getTableId()),
209                                    new Long(expandoValue.getColumnId()),
210                                    new Long(expandoValue.getClassPK())
211                            }, expandoValue);
212            }
213    
214            public void cacheResult(List<ExpandoValue> expandoValues) {
215                    for (ExpandoValue expandoValue : expandoValues) {
216                            if (EntityCacheUtil.getResult(
217                                                    ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
218                                                    ExpandoValueImpl.class, expandoValue.getPrimaryKey(),
219                                                    this) == null) {
220                                    cacheResult(expandoValue);
221                            }
222                    }
223            }
224    
225            public void clearCache() {
226                    CacheRegistryUtil.clear(ExpandoValueImpl.class.getName());
227                    EntityCacheUtil.clearCache(ExpandoValueImpl.class.getName());
228                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
229                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
230            }
231    
232            public void clearCache(ExpandoValue expandoValue) {
233                    EntityCacheUtil.removeResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
234                            ExpandoValueImpl.class, expandoValue.getPrimaryKey());
235    
236                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R,
237                            new Object[] {
238                                    new Long(expandoValue.getColumnId()),
239                                    new Long(expandoValue.getRowId())
240                            });
241    
242                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C_C,
243                            new Object[] {
244                                    new Long(expandoValue.getTableId()),
245                                    new Long(expandoValue.getColumnId()),
246                                    new Long(expandoValue.getClassPK())
247                            });
248            }
249    
250            public ExpandoValue create(long valueId) {
251                    ExpandoValue expandoValue = new ExpandoValueImpl();
252    
253                    expandoValue.setNew(true);
254                    expandoValue.setPrimaryKey(valueId);
255    
256                    return expandoValue;
257            }
258    
259            public ExpandoValue remove(Serializable primaryKey)
260                    throws NoSuchModelException, SystemException {
261                    return remove(((Long)primaryKey).longValue());
262            }
263    
264            public ExpandoValue remove(long valueId)
265                    throws NoSuchValueException, SystemException {
266                    Session session = null;
267    
268                    try {
269                            session = openSession();
270    
271                            ExpandoValue expandoValue = (ExpandoValue)session.get(ExpandoValueImpl.class,
272                                            new Long(valueId));
273    
274                            if (expandoValue == null) {
275                                    if (_log.isWarnEnabled()) {
276                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + valueId);
277                                    }
278    
279                                    throw new NoSuchValueException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
280                                            valueId);
281                            }
282    
283                            return remove(expandoValue);
284                    }
285                    catch (NoSuchValueException nsee) {
286                            throw nsee;
287                    }
288                    catch (Exception e) {
289                            throw processException(e);
290                    }
291                    finally {
292                            closeSession(session);
293                    }
294            }
295    
296            protected ExpandoValue removeImpl(ExpandoValue expandoValue)
297                    throws SystemException {
298                    expandoValue = toUnwrappedModel(expandoValue);
299    
300                    Session session = null;
301    
302                    try {
303                            session = openSession();
304    
305                            if (expandoValue.isCachedModel() || BatchSessionUtil.isEnabled()) {
306                                    Object staleObject = session.get(ExpandoValueImpl.class,
307                                                    expandoValue.getPrimaryKeyObj());
308    
309                                    if (staleObject != null) {
310                                            session.evict(staleObject);
311                                    }
312                            }
313    
314                            session.delete(expandoValue);
315    
316                            session.flush();
317                    }
318                    catch (Exception e) {
319                            throw processException(e);
320                    }
321                    finally {
322                            closeSession(session);
323                    }
324    
325                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
326    
327                    ExpandoValueModelImpl expandoValueModelImpl = (ExpandoValueModelImpl)expandoValue;
328    
329                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R,
330                            new Object[] {
331                                    new Long(expandoValueModelImpl.getOriginalColumnId()),
332                                    new Long(expandoValueModelImpl.getOriginalRowId())
333                            });
334    
335                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C_C,
336                            new Object[] {
337                                    new Long(expandoValueModelImpl.getOriginalTableId()),
338                                    new Long(expandoValueModelImpl.getOriginalColumnId()),
339                                    new Long(expandoValueModelImpl.getOriginalClassPK())
340                            });
341    
342                    EntityCacheUtil.removeResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
343                            ExpandoValueImpl.class, expandoValue.getPrimaryKey());
344    
345                    return expandoValue;
346            }
347    
348            public ExpandoValue updateImpl(
349                    com.liferay.portlet.expando.model.ExpandoValue expandoValue,
350                    boolean merge) throws SystemException {
351                    expandoValue = toUnwrappedModel(expandoValue);
352    
353                    boolean isNew = expandoValue.isNew();
354    
355                    ExpandoValueModelImpl expandoValueModelImpl = (ExpandoValueModelImpl)expandoValue;
356    
357                    Session session = null;
358    
359                    try {
360                            session = openSession();
361    
362                            BatchSessionUtil.update(session, expandoValue, merge);
363    
364                            expandoValue.setNew(false);
365                    }
366                    catch (Exception e) {
367                            throw processException(e);
368                    }
369                    finally {
370                            closeSession(session);
371                    }
372    
373                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
374    
375                    EntityCacheUtil.putResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
376                            ExpandoValueImpl.class, expandoValue.getPrimaryKey(), expandoValue);
377    
378                    if (!isNew &&
379                                    ((expandoValue.getColumnId() != expandoValueModelImpl.getOriginalColumnId()) ||
380                                    (expandoValue.getRowId() != expandoValueModelImpl.getOriginalRowId()))) {
381                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_R,
382                                    new Object[] {
383                                            new Long(expandoValueModelImpl.getOriginalColumnId()),
384                                            new Long(expandoValueModelImpl.getOriginalRowId())
385                                    });
386                    }
387    
388                    if (isNew ||
389                                    ((expandoValue.getColumnId() != expandoValueModelImpl.getOriginalColumnId()) ||
390                                    (expandoValue.getRowId() != expandoValueModelImpl.getOriginalRowId()))) {
391                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
392                                    new Object[] {
393                                            new Long(expandoValue.getColumnId()),
394                                            new Long(expandoValue.getRowId())
395                                    }, expandoValue);
396                    }
397    
398                    if (!isNew &&
399                                    ((expandoValue.getTableId() != expandoValueModelImpl.getOriginalTableId()) ||
400                                    (expandoValue.getColumnId() != expandoValueModelImpl.getOriginalColumnId()) ||
401                                    (expandoValue.getClassPK() != expandoValueModelImpl.getOriginalClassPK()))) {
402                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_C_C,
403                                    new Object[] {
404                                            new Long(expandoValueModelImpl.getOriginalTableId()),
405                                            new Long(expandoValueModelImpl.getOriginalColumnId()),
406                                            new Long(expandoValueModelImpl.getOriginalClassPK())
407                                    });
408                    }
409    
410                    if (isNew ||
411                                    ((expandoValue.getTableId() != expandoValueModelImpl.getOriginalTableId()) ||
412                                    (expandoValue.getColumnId() != expandoValueModelImpl.getOriginalColumnId()) ||
413                                    (expandoValue.getClassPK() != expandoValueModelImpl.getOriginalClassPK()))) {
414                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
415                                    new Object[] {
416                                            new Long(expandoValue.getTableId()),
417                                            new Long(expandoValue.getColumnId()),
418                                            new Long(expandoValue.getClassPK())
419                                    }, expandoValue);
420                    }
421    
422                    return expandoValue;
423            }
424    
425            protected ExpandoValue toUnwrappedModel(ExpandoValue expandoValue) {
426                    if (expandoValue instanceof ExpandoValueImpl) {
427                            return expandoValue;
428                    }
429    
430                    ExpandoValueImpl expandoValueImpl = new ExpandoValueImpl();
431    
432                    expandoValueImpl.setNew(expandoValue.isNew());
433                    expandoValueImpl.setPrimaryKey(expandoValue.getPrimaryKey());
434    
435                    expandoValueImpl.setValueId(expandoValue.getValueId());
436                    expandoValueImpl.setCompanyId(expandoValue.getCompanyId());
437                    expandoValueImpl.setTableId(expandoValue.getTableId());
438                    expandoValueImpl.setColumnId(expandoValue.getColumnId());
439                    expandoValueImpl.setRowId(expandoValue.getRowId());
440                    expandoValueImpl.setClassNameId(expandoValue.getClassNameId());
441                    expandoValueImpl.setClassPK(expandoValue.getClassPK());
442                    expandoValueImpl.setData(expandoValue.getData());
443    
444                    return expandoValueImpl;
445            }
446    
447            public ExpandoValue findByPrimaryKey(Serializable primaryKey)
448                    throws NoSuchModelException, SystemException {
449                    return findByPrimaryKey(((Long)primaryKey).longValue());
450            }
451    
452            public ExpandoValue findByPrimaryKey(long valueId)
453                    throws NoSuchValueException, SystemException {
454                    ExpandoValue expandoValue = fetchByPrimaryKey(valueId);
455    
456                    if (expandoValue == null) {
457                            if (_log.isWarnEnabled()) {
458                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + valueId);
459                            }
460    
461                            throw new NoSuchValueException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
462                                    valueId);
463                    }
464    
465                    return expandoValue;
466            }
467    
468            public ExpandoValue fetchByPrimaryKey(Serializable primaryKey)
469                    throws SystemException {
470                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
471            }
472    
473            public ExpandoValue fetchByPrimaryKey(long valueId)
474                    throws SystemException {
475                    ExpandoValue expandoValue = (ExpandoValue)EntityCacheUtil.getResult(ExpandoValueModelImpl.ENTITY_CACHE_ENABLED,
476                                    ExpandoValueImpl.class, valueId, this);
477    
478                    if (expandoValue == null) {
479                            Session session = null;
480    
481                            try {
482                                    session = openSession();
483    
484                                    expandoValue = (ExpandoValue)session.get(ExpandoValueImpl.class,
485                                                    new Long(valueId));
486                            }
487                            catch (Exception e) {
488                                    throw processException(e);
489                            }
490                            finally {
491                                    if (expandoValue != null) {
492                                            cacheResult(expandoValue);
493                                    }
494    
495                                    closeSession(session);
496                            }
497                    }
498    
499                    return expandoValue;
500            }
501    
502            public List<ExpandoValue> findByTableId(long tableId)
503                    throws SystemException {
504                    return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
505            }
506    
507            public List<ExpandoValue> findByTableId(long tableId, int start, int end)
508                    throws SystemException {
509                    return findByTableId(tableId, start, end, null);
510            }
511    
512            public List<ExpandoValue> findByTableId(long tableId, int start, int end,
513                    OrderByComparator orderByComparator) throws SystemException {
514                    Object[] finderArgs = new Object[] {
515                                    tableId,
516                                    
517                                    String.valueOf(start), String.valueOf(end),
518                                    String.valueOf(orderByComparator)
519                            };
520    
521                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TABLEID,
522                                    finderArgs, this);
523    
524                    if (list == null) {
525                            Session session = null;
526    
527                            try {
528                                    session = openSession();
529    
530                                    StringBundler query = null;
531    
532                                    if (orderByComparator != null) {
533                                            query = new StringBundler(3 +
534                                                            (orderByComparator.getOrderByFields().length * 3));
535                                    }
536                                    else {
537                                            query = new StringBundler(3);
538                                    }
539    
540                                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
541    
542                                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
543    
544                                    if (orderByComparator != null) {
545                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
546                                                    orderByComparator);
547                                    }
548    
549                                    else {
550                                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
551                                    }
552    
553                                    String sql = query.toString();
554    
555                                    Query q = session.createQuery(sql);
556    
557                                    QueryPos qPos = QueryPos.getInstance(q);
558    
559                                    qPos.add(tableId);
560    
561                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
562                                                    start, end);
563                            }
564                            catch (Exception e) {
565                                    throw processException(e);
566                            }
567                            finally {
568                                    if (list == null) {
569                                            list = new ArrayList<ExpandoValue>();
570                                    }
571    
572                                    cacheResult(list);
573    
574                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TABLEID,
575                                            finderArgs, list);
576    
577                                    closeSession(session);
578                            }
579                    }
580    
581                    return list;
582            }
583    
584            public ExpandoValue findByTableId_First(long tableId,
585                    OrderByComparator orderByComparator)
586                    throws NoSuchValueException, SystemException {
587                    List<ExpandoValue> list = findByTableId(tableId, 0, 1, orderByComparator);
588    
589                    if (list.isEmpty()) {
590                            StringBundler msg = new StringBundler(4);
591    
592                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
593    
594                            msg.append("tableId=");
595                            msg.append(tableId);
596    
597                            msg.append(StringPool.CLOSE_CURLY_BRACE);
598    
599                            throw new NoSuchValueException(msg.toString());
600                    }
601                    else {
602                            return list.get(0);
603                    }
604            }
605    
606            public ExpandoValue findByTableId_Last(long tableId,
607                    OrderByComparator orderByComparator)
608                    throws NoSuchValueException, SystemException {
609                    int count = countByTableId(tableId);
610    
611                    List<ExpandoValue> list = findByTableId(tableId, count - 1, count,
612                                    orderByComparator);
613    
614                    if (list.isEmpty()) {
615                            StringBundler msg = new StringBundler(4);
616    
617                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
618    
619                            msg.append("tableId=");
620                            msg.append(tableId);
621    
622                            msg.append(StringPool.CLOSE_CURLY_BRACE);
623    
624                            throw new NoSuchValueException(msg.toString());
625                    }
626                    else {
627                            return list.get(0);
628                    }
629            }
630    
631            public ExpandoValue[] findByTableId_PrevAndNext(long valueId, long tableId,
632                    OrderByComparator orderByComparator)
633                    throws NoSuchValueException, SystemException {
634                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
635    
636                    Session session = null;
637    
638                    try {
639                            session = openSession();
640    
641                            ExpandoValue[] array = new ExpandoValueImpl[3];
642    
643                            array[0] = getByTableId_PrevAndNext(session, expandoValue, tableId,
644                                            orderByComparator, true);
645    
646                            array[1] = expandoValue;
647    
648                            array[2] = getByTableId_PrevAndNext(session, expandoValue, tableId,
649                                            orderByComparator, false);
650    
651                            return array;
652                    }
653                    catch (Exception e) {
654                            throw processException(e);
655                    }
656                    finally {
657                            closeSession(session);
658                    }
659            }
660    
661            protected ExpandoValue getByTableId_PrevAndNext(Session session,
662                    ExpandoValue expandoValue, long tableId,
663                    OrderByComparator orderByComparator, boolean previous) {
664                    StringBundler query = null;
665    
666                    if (orderByComparator != null) {
667                            query = new StringBundler(6 +
668                                            (orderByComparator.getOrderByFields().length * 6));
669                    }
670                    else {
671                            query = new StringBundler(3);
672                    }
673    
674                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
675    
676                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
677    
678                    if (orderByComparator != null) {
679                            String[] orderByFields = orderByComparator.getOrderByFields();
680    
681                            if (orderByFields.length > 0) {
682                                    query.append(WHERE_AND);
683                            }
684    
685                            for (int i = 0; i < orderByFields.length; i++) {
686                                    query.append(_ORDER_BY_ENTITY_ALIAS);
687                                    query.append(orderByFields[i]);
688    
689                                    if ((i + 1) < orderByFields.length) {
690                                            if (orderByComparator.isAscending() ^ previous) {
691                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
692                                            }
693                                            else {
694                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
695                                            }
696                                    }
697                                    else {
698                                            if (orderByComparator.isAscending() ^ previous) {
699                                                    query.append(WHERE_GREATER_THAN);
700                                            }
701                                            else {
702                                                    query.append(WHERE_LESSER_THAN);
703                                            }
704                                    }
705                            }
706    
707                            query.append(ORDER_BY_CLAUSE);
708    
709                            for (int i = 0; i < orderByFields.length; i++) {
710                                    query.append(_ORDER_BY_ENTITY_ALIAS);
711                                    query.append(orderByFields[i]);
712    
713                                    if ((i + 1) < orderByFields.length) {
714                                            if (orderByComparator.isAscending() ^ previous) {
715                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
716                                            }
717                                            else {
718                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
719                                            }
720                                    }
721                                    else {
722                                            if (orderByComparator.isAscending() ^ previous) {
723                                                    query.append(ORDER_BY_ASC);
724                                            }
725                                            else {
726                                                    query.append(ORDER_BY_DESC);
727                                            }
728                                    }
729                            }
730                    }
731    
732                    else {
733                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
734                    }
735    
736                    String sql = query.toString();
737    
738                    Query q = session.createQuery(sql);
739    
740                    q.setFirstResult(0);
741                    q.setMaxResults(2);
742    
743                    QueryPos qPos = QueryPos.getInstance(q);
744    
745                    qPos.add(tableId);
746    
747                    if (orderByComparator != null) {
748                            Object[] values = orderByComparator.getOrderByValues(expandoValue);
749    
750                            for (Object value : values) {
751                                    qPos.add(value);
752                            }
753                    }
754    
755                    List<ExpandoValue> list = q.list();
756    
757                    if (list.size() == 2) {
758                            return list.get(1);
759                    }
760                    else {
761                            return null;
762                    }
763            }
764    
765            public List<ExpandoValue> findByColumnId(long columnId)
766                    throws SystemException {
767                    return findByColumnId(columnId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
768                            null);
769            }
770    
771            public List<ExpandoValue> findByColumnId(long columnId, int start, int end)
772                    throws SystemException {
773                    return findByColumnId(columnId, start, end, null);
774            }
775    
776            public List<ExpandoValue> findByColumnId(long columnId, int start, int end,
777                    OrderByComparator orderByComparator) throws SystemException {
778                    Object[] finderArgs = new Object[] {
779                                    columnId,
780                                    
781                                    String.valueOf(start), String.valueOf(end),
782                                    String.valueOf(orderByComparator)
783                            };
784    
785                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COLUMNID,
786                                    finderArgs, this);
787    
788                    if (list == null) {
789                            Session session = null;
790    
791                            try {
792                                    session = openSession();
793    
794                                    StringBundler query = null;
795    
796                                    if (orderByComparator != null) {
797                                            query = new StringBundler(3 +
798                                                            (orderByComparator.getOrderByFields().length * 3));
799                                    }
800                                    else {
801                                            query = new StringBundler(3);
802                                    }
803    
804                                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
805    
806                                    query.append(_FINDER_COLUMN_COLUMNID_COLUMNID_2);
807    
808                                    if (orderByComparator != null) {
809                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
810                                                    orderByComparator);
811                                    }
812    
813                                    else {
814                                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
815                                    }
816    
817                                    String sql = query.toString();
818    
819                                    Query q = session.createQuery(sql);
820    
821                                    QueryPos qPos = QueryPos.getInstance(q);
822    
823                                    qPos.add(columnId);
824    
825                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
826                                                    start, end);
827                            }
828                            catch (Exception e) {
829                                    throw processException(e);
830                            }
831                            finally {
832                                    if (list == null) {
833                                            list = new ArrayList<ExpandoValue>();
834                                    }
835    
836                                    cacheResult(list);
837    
838                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COLUMNID,
839                                            finderArgs, list);
840    
841                                    closeSession(session);
842                            }
843                    }
844    
845                    return list;
846            }
847    
848            public ExpandoValue findByColumnId_First(long columnId,
849                    OrderByComparator orderByComparator)
850                    throws NoSuchValueException, SystemException {
851                    List<ExpandoValue> list = findByColumnId(columnId, 0, 1,
852                                    orderByComparator);
853    
854                    if (list.isEmpty()) {
855                            StringBundler msg = new StringBundler(4);
856    
857                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
858    
859                            msg.append("columnId=");
860                            msg.append(columnId);
861    
862                            msg.append(StringPool.CLOSE_CURLY_BRACE);
863    
864                            throw new NoSuchValueException(msg.toString());
865                    }
866                    else {
867                            return list.get(0);
868                    }
869            }
870    
871            public ExpandoValue findByColumnId_Last(long columnId,
872                    OrderByComparator orderByComparator)
873                    throws NoSuchValueException, SystemException {
874                    int count = countByColumnId(columnId);
875    
876                    List<ExpandoValue> list = findByColumnId(columnId, count - 1, count,
877                                    orderByComparator);
878    
879                    if (list.isEmpty()) {
880                            StringBundler msg = new StringBundler(4);
881    
882                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
883    
884                            msg.append("columnId=");
885                            msg.append(columnId);
886    
887                            msg.append(StringPool.CLOSE_CURLY_BRACE);
888    
889                            throw new NoSuchValueException(msg.toString());
890                    }
891                    else {
892                            return list.get(0);
893                    }
894            }
895    
896            public ExpandoValue[] findByColumnId_PrevAndNext(long valueId,
897                    long columnId, OrderByComparator orderByComparator)
898                    throws NoSuchValueException, SystemException {
899                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
900    
901                    Session session = null;
902    
903                    try {
904                            session = openSession();
905    
906                            ExpandoValue[] array = new ExpandoValueImpl[3];
907    
908                            array[0] = getByColumnId_PrevAndNext(session, expandoValue,
909                                            columnId, orderByComparator, true);
910    
911                            array[1] = expandoValue;
912    
913                            array[2] = getByColumnId_PrevAndNext(session, expandoValue,
914                                            columnId, orderByComparator, false);
915    
916                            return array;
917                    }
918                    catch (Exception e) {
919                            throw processException(e);
920                    }
921                    finally {
922                            closeSession(session);
923                    }
924            }
925    
926            protected ExpandoValue getByColumnId_PrevAndNext(Session session,
927                    ExpandoValue expandoValue, long columnId,
928                    OrderByComparator orderByComparator, boolean previous) {
929                    StringBundler query = null;
930    
931                    if (orderByComparator != null) {
932                            query = new StringBundler(6 +
933                                            (orderByComparator.getOrderByFields().length * 6));
934                    }
935                    else {
936                            query = new StringBundler(3);
937                    }
938    
939                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
940    
941                    query.append(_FINDER_COLUMN_COLUMNID_COLUMNID_2);
942    
943                    if (orderByComparator != null) {
944                            String[] orderByFields = orderByComparator.getOrderByFields();
945    
946                            if (orderByFields.length > 0) {
947                                    query.append(WHERE_AND);
948                            }
949    
950                            for (int i = 0; i < orderByFields.length; i++) {
951                                    query.append(_ORDER_BY_ENTITY_ALIAS);
952                                    query.append(orderByFields[i]);
953    
954                                    if ((i + 1) < orderByFields.length) {
955                                            if (orderByComparator.isAscending() ^ previous) {
956                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
957                                            }
958                                            else {
959                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
960                                            }
961                                    }
962                                    else {
963                                            if (orderByComparator.isAscending() ^ previous) {
964                                                    query.append(WHERE_GREATER_THAN);
965                                            }
966                                            else {
967                                                    query.append(WHERE_LESSER_THAN);
968                                            }
969                                    }
970                            }
971    
972                            query.append(ORDER_BY_CLAUSE);
973    
974                            for (int i = 0; i < orderByFields.length; i++) {
975                                    query.append(_ORDER_BY_ENTITY_ALIAS);
976                                    query.append(orderByFields[i]);
977    
978                                    if ((i + 1) < orderByFields.length) {
979                                            if (orderByComparator.isAscending() ^ previous) {
980                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
981                                            }
982                                            else {
983                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
984                                            }
985                                    }
986                                    else {
987                                            if (orderByComparator.isAscending() ^ previous) {
988                                                    query.append(ORDER_BY_ASC);
989                                            }
990                                            else {
991                                                    query.append(ORDER_BY_DESC);
992                                            }
993                                    }
994                            }
995                    }
996    
997                    else {
998                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
999                    }
1000    
1001                    String sql = query.toString();
1002    
1003                    Query q = session.createQuery(sql);
1004    
1005                    q.setFirstResult(0);
1006                    q.setMaxResults(2);
1007    
1008                    QueryPos qPos = QueryPos.getInstance(q);
1009    
1010                    qPos.add(columnId);
1011    
1012                    if (orderByComparator != null) {
1013                            Object[] values = orderByComparator.getOrderByValues(expandoValue);
1014    
1015                            for (Object value : values) {
1016                                    qPos.add(value);
1017                            }
1018                    }
1019    
1020                    List<ExpandoValue> list = q.list();
1021    
1022                    if (list.size() == 2) {
1023                            return list.get(1);
1024                    }
1025                    else {
1026                            return null;
1027                    }
1028            }
1029    
1030            public List<ExpandoValue> findByRowId(long rowId) throws SystemException {
1031                    return findByRowId(rowId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1032            }
1033    
1034            public List<ExpandoValue> findByRowId(long rowId, int start, int end)
1035                    throws SystemException {
1036                    return findByRowId(rowId, start, end, null);
1037            }
1038    
1039            public List<ExpandoValue> findByRowId(long rowId, int start, int end,
1040                    OrderByComparator orderByComparator) throws SystemException {
1041                    Object[] finderArgs = new Object[] {
1042                                    rowId,
1043                                    
1044                                    String.valueOf(start), String.valueOf(end),
1045                                    String.valueOf(orderByComparator)
1046                            };
1047    
1048                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ROWID,
1049                                    finderArgs, this);
1050    
1051                    if (list == null) {
1052                            Session session = null;
1053    
1054                            try {
1055                                    session = openSession();
1056    
1057                                    StringBundler query = null;
1058    
1059                                    if (orderByComparator != null) {
1060                                            query = new StringBundler(3 +
1061                                                            (orderByComparator.getOrderByFields().length * 3));
1062                                    }
1063                                    else {
1064                                            query = new StringBundler(3);
1065                                    }
1066    
1067                                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1068    
1069                                    query.append(_FINDER_COLUMN_ROWID_ROWID_2);
1070    
1071                                    if (orderByComparator != null) {
1072                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1073                                                    orderByComparator);
1074                                    }
1075    
1076                                    else {
1077                                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1078                                    }
1079    
1080                                    String sql = query.toString();
1081    
1082                                    Query q = session.createQuery(sql);
1083    
1084                                    QueryPos qPos = QueryPos.getInstance(q);
1085    
1086                                    qPos.add(rowId);
1087    
1088                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1089                                                    start, end);
1090                            }
1091                            catch (Exception e) {
1092                                    throw processException(e);
1093                            }
1094                            finally {
1095                                    if (list == null) {
1096                                            list = new ArrayList<ExpandoValue>();
1097                                    }
1098    
1099                                    cacheResult(list);
1100    
1101                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ROWID,
1102                                            finderArgs, list);
1103    
1104                                    closeSession(session);
1105                            }
1106                    }
1107    
1108                    return list;
1109            }
1110    
1111            public ExpandoValue findByRowId_First(long rowId,
1112                    OrderByComparator orderByComparator)
1113                    throws NoSuchValueException, SystemException {
1114                    List<ExpandoValue> list = findByRowId(rowId, 0, 1, orderByComparator);
1115    
1116                    if (list.isEmpty()) {
1117                            StringBundler msg = new StringBundler(4);
1118    
1119                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1120    
1121                            msg.append("rowId=");
1122                            msg.append(rowId);
1123    
1124                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1125    
1126                            throw new NoSuchValueException(msg.toString());
1127                    }
1128                    else {
1129                            return list.get(0);
1130                    }
1131            }
1132    
1133            public ExpandoValue findByRowId_Last(long rowId,
1134                    OrderByComparator orderByComparator)
1135                    throws NoSuchValueException, SystemException {
1136                    int count = countByRowId(rowId);
1137    
1138                    List<ExpandoValue> list = findByRowId(rowId, count - 1, count,
1139                                    orderByComparator);
1140    
1141                    if (list.isEmpty()) {
1142                            StringBundler msg = new StringBundler(4);
1143    
1144                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1145    
1146                            msg.append("rowId=");
1147                            msg.append(rowId);
1148    
1149                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1150    
1151                            throw new NoSuchValueException(msg.toString());
1152                    }
1153                    else {
1154                            return list.get(0);
1155                    }
1156            }
1157    
1158            public ExpandoValue[] findByRowId_PrevAndNext(long valueId, long rowId,
1159                    OrderByComparator orderByComparator)
1160                    throws NoSuchValueException, SystemException {
1161                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
1162    
1163                    Session session = null;
1164    
1165                    try {
1166                            session = openSession();
1167    
1168                            ExpandoValue[] array = new ExpandoValueImpl[3];
1169    
1170                            array[0] = getByRowId_PrevAndNext(session, expandoValue, rowId,
1171                                            orderByComparator, true);
1172    
1173                            array[1] = expandoValue;
1174    
1175                            array[2] = getByRowId_PrevAndNext(session, expandoValue, rowId,
1176                                            orderByComparator, false);
1177    
1178                            return array;
1179                    }
1180                    catch (Exception e) {
1181                            throw processException(e);
1182                    }
1183                    finally {
1184                            closeSession(session);
1185                    }
1186            }
1187    
1188            protected ExpandoValue getByRowId_PrevAndNext(Session session,
1189                    ExpandoValue expandoValue, long rowId,
1190                    OrderByComparator orderByComparator, boolean previous) {
1191                    StringBundler query = null;
1192    
1193                    if (orderByComparator != null) {
1194                            query = new StringBundler(6 +
1195                                            (orderByComparator.getOrderByFields().length * 6));
1196                    }
1197                    else {
1198                            query = new StringBundler(3);
1199                    }
1200    
1201                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1202    
1203                    query.append(_FINDER_COLUMN_ROWID_ROWID_2);
1204    
1205                    if (orderByComparator != null) {
1206                            String[] orderByFields = orderByComparator.getOrderByFields();
1207    
1208                            if (orderByFields.length > 0) {
1209                                    query.append(WHERE_AND);
1210                            }
1211    
1212                            for (int i = 0; i < orderByFields.length; i++) {
1213                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1214                                    query.append(orderByFields[i]);
1215    
1216                                    if ((i + 1) < orderByFields.length) {
1217                                            if (orderByComparator.isAscending() ^ previous) {
1218                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1219                                            }
1220                                            else {
1221                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1222                                            }
1223                                    }
1224                                    else {
1225                                            if (orderByComparator.isAscending() ^ previous) {
1226                                                    query.append(WHERE_GREATER_THAN);
1227                                            }
1228                                            else {
1229                                                    query.append(WHERE_LESSER_THAN);
1230                                            }
1231                                    }
1232                            }
1233    
1234                            query.append(ORDER_BY_CLAUSE);
1235    
1236                            for (int i = 0; i < orderByFields.length; i++) {
1237                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1238                                    query.append(orderByFields[i]);
1239    
1240                                    if ((i + 1) < orderByFields.length) {
1241                                            if (orderByComparator.isAscending() ^ previous) {
1242                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1243                                            }
1244                                            else {
1245                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1246                                            }
1247                                    }
1248                                    else {
1249                                            if (orderByComparator.isAscending() ^ previous) {
1250                                                    query.append(ORDER_BY_ASC);
1251                                            }
1252                                            else {
1253                                                    query.append(ORDER_BY_DESC);
1254                                            }
1255                                    }
1256                            }
1257                    }
1258    
1259                    else {
1260                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1261                    }
1262    
1263                    String sql = query.toString();
1264    
1265                    Query q = session.createQuery(sql);
1266    
1267                    q.setFirstResult(0);
1268                    q.setMaxResults(2);
1269    
1270                    QueryPos qPos = QueryPos.getInstance(q);
1271    
1272                    qPos.add(rowId);
1273    
1274                    if (orderByComparator != null) {
1275                            Object[] values = orderByComparator.getOrderByValues(expandoValue);
1276    
1277                            for (Object value : values) {
1278                                    qPos.add(value);
1279                            }
1280                    }
1281    
1282                    List<ExpandoValue> list = q.list();
1283    
1284                    if (list.size() == 2) {
1285                            return list.get(1);
1286                    }
1287                    else {
1288                            return null;
1289                    }
1290            }
1291    
1292            public List<ExpandoValue> findByT_C(long tableId, long columnId)
1293                    throws SystemException {
1294                    return findByT_C(tableId, columnId, QueryUtil.ALL_POS,
1295                            QueryUtil.ALL_POS, null);
1296            }
1297    
1298            public List<ExpandoValue> findByT_C(long tableId, long columnId, int start,
1299                    int end) throws SystemException {
1300                    return findByT_C(tableId, columnId, start, end, null);
1301            }
1302    
1303            public List<ExpandoValue> findByT_C(long tableId, long columnId, int start,
1304                    int end, OrderByComparator orderByComparator) throws SystemException {
1305                    Object[] finderArgs = new Object[] {
1306                                    tableId, columnId,
1307                                    
1308                                    String.valueOf(start), String.valueOf(end),
1309                                    String.valueOf(orderByComparator)
1310                            };
1311    
1312                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_C,
1313                                    finderArgs, this);
1314    
1315                    if (list == null) {
1316                            Session session = null;
1317    
1318                            try {
1319                                    session = openSession();
1320    
1321                                    StringBundler query = null;
1322    
1323                                    if (orderByComparator != null) {
1324                                            query = new StringBundler(4 +
1325                                                            (orderByComparator.getOrderByFields().length * 3));
1326                                    }
1327                                    else {
1328                                            query = new StringBundler(4);
1329                                    }
1330    
1331                                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1332    
1333                                    query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1334    
1335                                    query.append(_FINDER_COLUMN_T_C_COLUMNID_2);
1336    
1337                                    if (orderByComparator != null) {
1338                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1339                                                    orderByComparator);
1340                                    }
1341    
1342                                    else {
1343                                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1344                                    }
1345    
1346                                    String sql = query.toString();
1347    
1348                                    Query q = session.createQuery(sql);
1349    
1350                                    QueryPos qPos = QueryPos.getInstance(q);
1351    
1352                                    qPos.add(tableId);
1353    
1354                                    qPos.add(columnId);
1355    
1356                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1357                                                    start, end);
1358                            }
1359                            catch (Exception e) {
1360                                    throw processException(e);
1361                            }
1362                            finally {
1363                                    if (list == null) {
1364                                            list = new ArrayList<ExpandoValue>();
1365                                    }
1366    
1367                                    cacheResult(list);
1368    
1369                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_C, finderArgs,
1370                                            list);
1371    
1372                                    closeSession(session);
1373                            }
1374                    }
1375    
1376                    return list;
1377            }
1378    
1379            public ExpandoValue findByT_C_First(long tableId, long columnId,
1380                    OrderByComparator orderByComparator)
1381                    throws NoSuchValueException, SystemException {
1382                    List<ExpandoValue> list = findByT_C(tableId, columnId, 0, 1,
1383                                    orderByComparator);
1384    
1385                    if (list.isEmpty()) {
1386                            StringBundler msg = new StringBundler(6);
1387    
1388                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1389    
1390                            msg.append("tableId=");
1391                            msg.append(tableId);
1392    
1393                            msg.append(", columnId=");
1394                            msg.append(columnId);
1395    
1396                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1397    
1398                            throw new NoSuchValueException(msg.toString());
1399                    }
1400                    else {
1401                            return list.get(0);
1402                    }
1403            }
1404    
1405            public ExpandoValue findByT_C_Last(long tableId, long columnId,
1406                    OrderByComparator orderByComparator)
1407                    throws NoSuchValueException, SystemException {
1408                    int count = countByT_C(tableId, columnId);
1409    
1410                    List<ExpandoValue> list = findByT_C(tableId, columnId, count - 1,
1411                                    count, orderByComparator);
1412    
1413                    if (list.isEmpty()) {
1414                            StringBundler msg = new StringBundler(6);
1415    
1416                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1417    
1418                            msg.append("tableId=");
1419                            msg.append(tableId);
1420    
1421                            msg.append(", columnId=");
1422                            msg.append(columnId);
1423    
1424                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1425    
1426                            throw new NoSuchValueException(msg.toString());
1427                    }
1428                    else {
1429                            return list.get(0);
1430                    }
1431            }
1432    
1433            public ExpandoValue[] findByT_C_PrevAndNext(long valueId, long tableId,
1434                    long columnId, OrderByComparator orderByComparator)
1435                    throws NoSuchValueException, SystemException {
1436                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
1437    
1438                    Session session = null;
1439    
1440                    try {
1441                            session = openSession();
1442    
1443                            ExpandoValue[] array = new ExpandoValueImpl[3];
1444    
1445                            array[0] = getByT_C_PrevAndNext(session, expandoValue, tableId,
1446                                            columnId, orderByComparator, true);
1447    
1448                            array[1] = expandoValue;
1449    
1450                            array[2] = getByT_C_PrevAndNext(session, expandoValue, tableId,
1451                                            columnId, orderByComparator, false);
1452    
1453                            return array;
1454                    }
1455                    catch (Exception e) {
1456                            throw processException(e);
1457                    }
1458                    finally {
1459                            closeSession(session);
1460                    }
1461            }
1462    
1463            protected ExpandoValue getByT_C_PrevAndNext(Session session,
1464                    ExpandoValue expandoValue, long tableId, long columnId,
1465                    OrderByComparator orderByComparator, boolean previous) {
1466                    StringBundler query = null;
1467    
1468                    if (orderByComparator != null) {
1469                            query = new StringBundler(6 +
1470                                            (orderByComparator.getOrderByFields().length * 6));
1471                    }
1472                    else {
1473                            query = new StringBundler(3);
1474                    }
1475    
1476                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1477    
1478                    query.append(_FINDER_COLUMN_T_C_TABLEID_2);
1479    
1480                    query.append(_FINDER_COLUMN_T_C_COLUMNID_2);
1481    
1482                    if (orderByComparator != null) {
1483                            String[] orderByFields = orderByComparator.getOrderByFields();
1484    
1485                            if (orderByFields.length > 0) {
1486                                    query.append(WHERE_AND);
1487                            }
1488    
1489                            for (int i = 0; i < orderByFields.length; i++) {
1490                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1491                                    query.append(orderByFields[i]);
1492    
1493                                    if ((i + 1) < orderByFields.length) {
1494                                            if (orderByComparator.isAscending() ^ previous) {
1495                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1496                                            }
1497                                            else {
1498                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1499                                            }
1500                                    }
1501                                    else {
1502                                            if (orderByComparator.isAscending() ^ previous) {
1503                                                    query.append(WHERE_GREATER_THAN);
1504                                            }
1505                                            else {
1506                                                    query.append(WHERE_LESSER_THAN);
1507                                            }
1508                                    }
1509                            }
1510    
1511                            query.append(ORDER_BY_CLAUSE);
1512    
1513                            for (int i = 0; i < orderByFields.length; i++) {
1514                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1515                                    query.append(orderByFields[i]);
1516    
1517                                    if ((i + 1) < orderByFields.length) {
1518                                            if (orderByComparator.isAscending() ^ previous) {
1519                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1520                                            }
1521                                            else {
1522                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1523                                            }
1524                                    }
1525                                    else {
1526                                            if (orderByComparator.isAscending() ^ previous) {
1527                                                    query.append(ORDER_BY_ASC);
1528                                            }
1529                                            else {
1530                                                    query.append(ORDER_BY_DESC);
1531                                            }
1532                                    }
1533                            }
1534                    }
1535    
1536                    else {
1537                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1538                    }
1539    
1540                    String sql = query.toString();
1541    
1542                    Query q = session.createQuery(sql);
1543    
1544                    q.setFirstResult(0);
1545                    q.setMaxResults(2);
1546    
1547                    QueryPos qPos = QueryPos.getInstance(q);
1548    
1549                    qPos.add(tableId);
1550    
1551                    qPos.add(columnId);
1552    
1553                    if (orderByComparator != null) {
1554                            Object[] values = orderByComparator.getOrderByValues(expandoValue);
1555    
1556                            for (Object value : values) {
1557                                    qPos.add(value);
1558                            }
1559                    }
1560    
1561                    List<ExpandoValue> list = q.list();
1562    
1563                    if (list.size() == 2) {
1564                            return list.get(1);
1565                    }
1566                    else {
1567                            return null;
1568                    }
1569            }
1570    
1571            public List<ExpandoValue> findByT_CPK(long tableId, long classPK)
1572                    throws SystemException {
1573                    return findByT_CPK(tableId, classPK, QueryUtil.ALL_POS,
1574                            QueryUtil.ALL_POS, null);
1575            }
1576    
1577            public List<ExpandoValue> findByT_CPK(long tableId, long classPK,
1578                    int start, int end) throws SystemException {
1579                    return findByT_CPK(tableId, classPK, start, end, null);
1580            }
1581    
1582            public List<ExpandoValue> findByT_CPK(long tableId, long classPK,
1583                    int start, int end, OrderByComparator orderByComparator)
1584                    throws SystemException {
1585                    Object[] finderArgs = new Object[] {
1586                                    tableId, classPK,
1587                                    
1588                                    String.valueOf(start), String.valueOf(end),
1589                                    String.valueOf(orderByComparator)
1590                            };
1591    
1592                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_CPK,
1593                                    finderArgs, this);
1594    
1595                    if (list == null) {
1596                            Session session = null;
1597    
1598                            try {
1599                                    session = openSession();
1600    
1601                                    StringBundler query = null;
1602    
1603                                    if (orderByComparator != null) {
1604                                            query = new StringBundler(4 +
1605                                                            (orderByComparator.getOrderByFields().length * 3));
1606                                    }
1607                                    else {
1608                                            query = new StringBundler(4);
1609                                    }
1610    
1611                                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1612    
1613                                    query.append(_FINDER_COLUMN_T_CPK_TABLEID_2);
1614    
1615                                    query.append(_FINDER_COLUMN_T_CPK_CLASSPK_2);
1616    
1617                                    if (orderByComparator != null) {
1618                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1619                                                    orderByComparator);
1620                                    }
1621    
1622                                    else {
1623                                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1624                                    }
1625    
1626                                    String sql = query.toString();
1627    
1628                                    Query q = session.createQuery(sql);
1629    
1630                                    QueryPos qPos = QueryPos.getInstance(q);
1631    
1632                                    qPos.add(tableId);
1633    
1634                                    qPos.add(classPK);
1635    
1636                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1637                                                    start, end);
1638                            }
1639                            catch (Exception e) {
1640                                    throw processException(e);
1641                            }
1642                            finally {
1643                                    if (list == null) {
1644                                            list = new ArrayList<ExpandoValue>();
1645                                    }
1646    
1647                                    cacheResult(list);
1648    
1649                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_CPK,
1650                                            finderArgs, list);
1651    
1652                                    closeSession(session);
1653                            }
1654                    }
1655    
1656                    return list;
1657            }
1658    
1659            public ExpandoValue findByT_CPK_First(long tableId, long classPK,
1660                    OrderByComparator orderByComparator)
1661                    throws NoSuchValueException, SystemException {
1662                    List<ExpandoValue> list = findByT_CPK(tableId, classPK, 0, 1,
1663                                    orderByComparator);
1664    
1665                    if (list.isEmpty()) {
1666                            StringBundler msg = new StringBundler(6);
1667    
1668                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1669    
1670                            msg.append("tableId=");
1671                            msg.append(tableId);
1672    
1673                            msg.append(", classPK=");
1674                            msg.append(classPK);
1675    
1676                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1677    
1678                            throw new NoSuchValueException(msg.toString());
1679                    }
1680                    else {
1681                            return list.get(0);
1682                    }
1683            }
1684    
1685            public ExpandoValue findByT_CPK_Last(long tableId, long classPK,
1686                    OrderByComparator orderByComparator)
1687                    throws NoSuchValueException, SystemException {
1688                    int count = countByT_CPK(tableId, classPK);
1689    
1690                    List<ExpandoValue> list = findByT_CPK(tableId, classPK, count - 1,
1691                                    count, orderByComparator);
1692    
1693                    if (list.isEmpty()) {
1694                            StringBundler msg = new StringBundler(6);
1695    
1696                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1697    
1698                            msg.append("tableId=");
1699                            msg.append(tableId);
1700    
1701                            msg.append(", classPK=");
1702                            msg.append(classPK);
1703    
1704                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1705    
1706                            throw new NoSuchValueException(msg.toString());
1707                    }
1708                    else {
1709                            return list.get(0);
1710                    }
1711            }
1712    
1713            public ExpandoValue[] findByT_CPK_PrevAndNext(long valueId, long tableId,
1714                    long classPK, OrderByComparator orderByComparator)
1715                    throws NoSuchValueException, SystemException {
1716                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
1717    
1718                    Session session = null;
1719    
1720                    try {
1721                            session = openSession();
1722    
1723                            ExpandoValue[] array = new ExpandoValueImpl[3];
1724    
1725                            array[0] = getByT_CPK_PrevAndNext(session, expandoValue, tableId,
1726                                            classPK, orderByComparator, true);
1727    
1728                            array[1] = expandoValue;
1729    
1730                            array[2] = getByT_CPK_PrevAndNext(session, expandoValue, tableId,
1731                                            classPK, orderByComparator, false);
1732    
1733                            return array;
1734                    }
1735                    catch (Exception e) {
1736                            throw processException(e);
1737                    }
1738                    finally {
1739                            closeSession(session);
1740                    }
1741            }
1742    
1743            protected ExpandoValue getByT_CPK_PrevAndNext(Session session,
1744                    ExpandoValue expandoValue, long tableId, long classPK,
1745                    OrderByComparator orderByComparator, boolean previous) {
1746                    StringBundler query = null;
1747    
1748                    if (orderByComparator != null) {
1749                            query = new StringBundler(6 +
1750                                            (orderByComparator.getOrderByFields().length * 6));
1751                    }
1752                    else {
1753                            query = new StringBundler(3);
1754                    }
1755    
1756                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1757    
1758                    query.append(_FINDER_COLUMN_T_CPK_TABLEID_2);
1759    
1760                    query.append(_FINDER_COLUMN_T_CPK_CLASSPK_2);
1761    
1762                    if (orderByComparator != null) {
1763                            String[] orderByFields = orderByComparator.getOrderByFields();
1764    
1765                            if (orderByFields.length > 0) {
1766                                    query.append(WHERE_AND);
1767                            }
1768    
1769                            for (int i = 0; i < orderByFields.length; i++) {
1770                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1771                                    query.append(orderByFields[i]);
1772    
1773                                    if ((i + 1) < orderByFields.length) {
1774                                            if (orderByComparator.isAscending() ^ previous) {
1775                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1776                                            }
1777                                            else {
1778                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1779                                            }
1780                                    }
1781                                    else {
1782                                            if (orderByComparator.isAscending() ^ previous) {
1783                                                    query.append(WHERE_GREATER_THAN);
1784                                            }
1785                                            else {
1786                                                    query.append(WHERE_LESSER_THAN);
1787                                            }
1788                                    }
1789                            }
1790    
1791                            query.append(ORDER_BY_CLAUSE);
1792    
1793                            for (int i = 0; i < orderByFields.length; i++) {
1794                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1795                                    query.append(orderByFields[i]);
1796    
1797                                    if ((i + 1) < orderByFields.length) {
1798                                            if (orderByComparator.isAscending() ^ previous) {
1799                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1800                                            }
1801                                            else {
1802                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1803                                            }
1804                                    }
1805                                    else {
1806                                            if (orderByComparator.isAscending() ^ previous) {
1807                                                    query.append(ORDER_BY_ASC);
1808                                            }
1809                                            else {
1810                                                    query.append(ORDER_BY_DESC);
1811                                            }
1812                                    }
1813                            }
1814                    }
1815    
1816                    else {
1817                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1818                    }
1819    
1820                    String sql = query.toString();
1821    
1822                    Query q = session.createQuery(sql);
1823    
1824                    q.setFirstResult(0);
1825                    q.setMaxResults(2);
1826    
1827                    QueryPos qPos = QueryPos.getInstance(q);
1828    
1829                    qPos.add(tableId);
1830    
1831                    qPos.add(classPK);
1832    
1833                    if (orderByComparator != null) {
1834                            Object[] values = orderByComparator.getOrderByValues(expandoValue);
1835    
1836                            for (Object value : values) {
1837                                    qPos.add(value);
1838                            }
1839                    }
1840    
1841                    List<ExpandoValue> list = q.list();
1842    
1843                    if (list.size() == 2) {
1844                            return list.get(1);
1845                    }
1846                    else {
1847                            return null;
1848                    }
1849            }
1850    
1851            public List<ExpandoValue> findByT_R(long tableId, long rowId)
1852                    throws SystemException {
1853                    return findByT_R(tableId, rowId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1854                            null);
1855            }
1856    
1857            public List<ExpandoValue> findByT_R(long tableId, long rowId, int start,
1858                    int end) throws SystemException {
1859                    return findByT_R(tableId, rowId, start, end, null);
1860            }
1861    
1862            public List<ExpandoValue> findByT_R(long tableId, long rowId, int start,
1863                    int end, OrderByComparator orderByComparator) throws SystemException {
1864                    Object[] finderArgs = new Object[] {
1865                                    tableId, rowId,
1866                                    
1867                                    String.valueOf(start), String.valueOf(end),
1868                                    String.valueOf(orderByComparator)
1869                            };
1870    
1871                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_R,
1872                                    finderArgs, this);
1873    
1874                    if (list == null) {
1875                            Session session = null;
1876    
1877                            try {
1878                                    session = openSession();
1879    
1880                                    StringBundler query = null;
1881    
1882                                    if (orderByComparator != null) {
1883                                            query = new StringBundler(4 +
1884                                                            (orderByComparator.getOrderByFields().length * 3));
1885                                    }
1886                                    else {
1887                                            query = new StringBundler(4);
1888                                    }
1889    
1890                                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
1891    
1892                                    query.append(_FINDER_COLUMN_T_R_TABLEID_2);
1893    
1894                                    query.append(_FINDER_COLUMN_T_R_ROWID_2);
1895    
1896                                    if (orderByComparator != null) {
1897                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1898                                                    orderByComparator);
1899                                    }
1900    
1901                                    else {
1902                                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
1903                                    }
1904    
1905                                    String sql = query.toString();
1906    
1907                                    Query q = session.createQuery(sql);
1908    
1909                                    QueryPos qPos = QueryPos.getInstance(q);
1910    
1911                                    qPos.add(tableId);
1912    
1913                                    qPos.add(rowId);
1914    
1915                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
1916                                                    start, end);
1917                            }
1918                            catch (Exception e) {
1919                                    throw processException(e);
1920                            }
1921                            finally {
1922                                    if (list == null) {
1923                                            list = new ArrayList<ExpandoValue>();
1924                                    }
1925    
1926                                    cacheResult(list);
1927    
1928                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_R, finderArgs,
1929                                            list);
1930    
1931                                    closeSession(session);
1932                            }
1933                    }
1934    
1935                    return list;
1936            }
1937    
1938            public ExpandoValue findByT_R_First(long tableId, long rowId,
1939                    OrderByComparator orderByComparator)
1940                    throws NoSuchValueException, SystemException {
1941                    List<ExpandoValue> list = findByT_R(tableId, rowId, 0, 1,
1942                                    orderByComparator);
1943    
1944                    if (list.isEmpty()) {
1945                            StringBundler msg = new StringBundler(6);
1946    
1947                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1948    
1949                            msg.append("tableId=");
1950                            msg.append(tableId);
1951    
1952                            msg.append(", rowId=");
1953                            msg.append(rowId);
1954    
1955                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1956    
1957                            throw new NoSuchValueException(msg.toString());
1958                    }
1959                    else {
1960                            return list.get(0);
1961                    }
1962            }
1963    
1964            public ExpandoValue findByT_R_Last(long tableId, long rowId,
1965                    OrderByComparator orderByComparator)
1966                    throws NoSuchValueException, SystemException {
1967                    int count = countByT_R(tableId, rowId);
1968    
1969                    List<ExpandoValue> list = findByT_R(tableId, rowId, count - 1, count,
1970                                    orderByComparator);
1971    
1972                    if (list.isEmpty()) {
1973                            StringBundler msg = new StringBundler(6);
1974    
1975                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1976    
1977                            msg.append("tableId=");
1978                            msg.append(tableId);
1979    
1980                            msg.append(", rowId=");
1981                            msg.append(rowId);
1982    
1983                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1984    
1985                            throw new NoSuchValueException(msg.toString());
1986                    }
1987                    else {
1988                            return list.get(0);
1989                    }
1990            }
1991    
1992            public ExpandoValue[] findByT_R_PrevAndNext(long valueId, long tableId,
1993                    long rowId, OrderByComparator orderByComparator)
1994                    throws NoSuchValueException, SystemException {
1995                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
1996    
1997                    Session session = null;
1998    
1999                    try {
2000                            session = openSession();
2001    
2002                            ExpandoValue[] array = new ExpandoValueImpl[3];
2003    
2004                            array[0] = getByT_R_PrevAndNext(session, expandoValue, tableId,
2005                                            rowId, orderByComparator, true);
2006    
2007                            array[1] = expandoValue;
2008    
2009                            array[2] = getByT_R_PrevAndNext(session, expandoValue, tableId,
2010                                            rowId, orderByComparator, false);
2011    
2012                            return array;
2013                    }
2014                    catch (Exception e) {
2015                            throw processException(e);
2016                    }
2017                    finally {
2018                            closeSession(session);
2019                    }
2020            }
2021    
2022            protected ExpandoValue getByT_R_PrevAndNext(Session session,
2023                    ExpandoValue expandoValue, long tableId, long rowId,
2024                    OrderByComparator orderByComparator, boolean previous) {
2025                    StringBundler query = null;
2026    
2027                    if (orderByComparator != null) {
2028                            query = new StringBundler(6 +
2029                                            (orderByComparator.getOrderByFields().length * 6));
2030                    }
2031                    else {
2032                            query = new StringBundler(3);
2033                    }
2034    
2035                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2036    
2037                    query.append(_FINDER_COLUMN_T_R_TABLEID_2);
2038    
2039                    query.append(_FINDER_COLUMN_T_R_ROWID_2);
2040    
2041                    if (orderByComparator != null) {
2042                            String[] orderByFields = orderByComparator.getOrderByFields();
2043    
2044                            if (orderByFields.length > 0) {
2045                                    query.append(WHERE_AND);
2046                            }
2047    
2048                            for (int i = 0; i < orderByFields.length; i++) {
2049                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2050                                    query.append(orderByFields[i]);
2051    
2052                                    if ((i + 1) < orderByFields.length) {
2053                                            if (orderByComparator.isAscending() ^ previous) {
2054                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2055                                            }
2056                                            else {
2057                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2058                                            }
2059                                    }
2060                                    else {
2061                                            if (orderByComparator.isAscending() ^ previous) {
2062                                                    query.append(WHERE_GREATER_THAN);
2063                                            }
2064                                            else {
2065                                                    query.append(WHERE_LESSER_THAN);
2066                                            }
2067                                    }
2068                            }
2069    
2070                            query.append(ORDER_BY_CLAUSE);
2071    
2072                            for (int i = 0; i < orderByFields.length; i++) {
2073                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2074                                    query.append(orderByFields[i]);
2075    
2076                                    if ((i + 1) < orderByFields.length) {
2077                                            if (orderByComparator.isAscending() ^ previous) {
2078                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2079                                            }
2080                                            else {
2081                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2082                                            }
2083                                    }
2084                                    else {
2085                                            if (orderByComparator.isAscending() ^ previous) {
2086                                                    query.append(ORDER_BY_ASC);
2087                                            }
2088                                            else {
2089                                                    query.append(ORDER_BY_DESC);
2090                                            }
2091                                    }
2092                            }
2093                    }
2094    
2095                    else {
2096                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2097                    }
2098    
2099                    String sql = query.toString();
2100    
2101                    Query q = session.createQuery(sql);
2102    
2103                    q.setFirstResult(0);
2104                    q.setMaxResults(2);
2105    
2106                    QueryPos qPos = QueryPos.getInstance(q);
2107    
2108                    qPos.add(tableId);
2109    
2110                    qPos.add(rowId);
2111    
2112                    if (orderByComparator != null) {
2113                            Object[] values = orderByComparator.getOrderByValues(expandoValue);
2114    
2115                            for (Object value : values) {
2116                                    qPos.add(value);
2117                            }
2118                    }
2119    
2120                    List<ExpandoValue> list = q.list();
2121    
2122                    if (list.size() == 2) {
2123                            return list.get(1);
2124                    }
2125                    else {
2126                            return null;
2127                    }
2128            }
2129    
2130            public ExpandoValue findByC_R(long columnId, long rowId)
2131                    throws NoSuchValueException, SystemException {
2132                    ExpandoValue expandoValue = fetchByC_R(columnId, rowId);
2133    
2134                    if (expandoValue == null) {
2135                            StringBundler msg = new StringBundler(6);
2136    
2137                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2138    
2139                            msg.append("columnId=");
2140                            msg.append(columnId);
2141    
2142                            msg.append(", rowId=");
2143                            msg.append(rowId);
2144    
2145                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2146    
2147                            if (_log.isWarnEnabled()) {
2148                                    _log.warn(msg.toString());
2149                            }
2150    
2151                            throw new NoSuchValueException(msg.toString());
2152                    }
2153    
2154                    return expandoValue;
2155            }
2156    
2157            public ExpandoValue fetchByC_R(long columnId, long rowId)
2158                    throws SystemException {
2159                    return fetchByC_R(columnId, rowId, true);
2160            }
2161    
2162            public ExpandoValue fetchByC_R(long columnId, long rowId,
2163                    boolean retrieveFromCache) throws SystemException {
2164                    Object[] finderArgs = new Object[] { columnId, rowId };
2165    
2166                    Object result = null;
2167    
2168                    if (retrieveFromCache) {
2169                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_R,
2170                                            finderArgs, this);
2171                    }
2172    
2173                    if (result == null) {
2174                            Session session = null;
2175    
2176                            try {
2177                                    session = openSession();
2178    
2179                                    StringBundler query = new StringBundler(4);
2180    
2181                                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2182    
2183                                    query.append(_FINDER_COLUMN_C_R_COLUMNID_2);
2184    
2185                                    query.append(_FINDER_COLUMN_C_R_ROWID_2);
2186    
2187                                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2188    
2189                                    String sql = query.toString();
2190    
2191                                    Query q = session.createQuery(sql);
2192    
2193                                    QueryPos qPos = QueryPos.getInstance(q);
2194    
2195                                    qPos.add(columnId);
2196    
2197                                    qPos.add(rowId);
2198    
2199                                    List<ExpandoValue> list = q.list();
2200    
2201                                    result = list;
2202    
2203                                    ExpandoValue expandoValue = null;
2204    
2205                                    if (list.isEmpty()) {
2206                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
2207                                                    finderArgs, list);
2208                                    }
2209                                    else {
2210                                            expandoValue = list.get(0);
2211    
2212                                            cacheResult(expandoValue);
2213    
2214                                            if ((expandoValue.getColumnId() != columnId) ||
2215                                                            (expandoValue.getRowId() != rowId)) {
2216                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
2217                                                            finderArgs, expandoValue);
2218                                            }
2219                                    }
2220    
2221                                    return expandoValue;
2222                            }
2223                            catch (Exception e) {
2224                                    throw processException(e);
2225                            }
2226                            finally {
2227                                    if (result == null) {
2228                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_R,
2229                                                    finderArgs, new ArrayList<ExpandoValue>());
2230                                    }
2231    
2232                                    closeSession(session);
2233                            }
2234                    }
2235                    else {
2236                            if (result instanceof List<?>) {
2237                                    return null;
2238                            }
2239                            else {
2240                                    return (ExpandoValue)result;
2241                            }
2242                    }
2243            }
2244    
2245            public List<ExpandoValue> findByC_C(long classNameId, long classPK)
2246                    throws SystemException {
2247                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
2248                            QueryUtil.ALL_POS, null);
2249            }
2250    
2251            public List<ExpandoValue> findByC_C(long classNameId, long classPK,
2252                    int start, int end) throws SystemException {
2253                    return findByC_C(classNameId, classPK, start, end, null);
2254            }
2255    
2256            public List<ExpandoValue> findByC_C(long classNameId, long classPK,
2257                    int start, int end, OrderByComparator orderByComparator)
2258                    throws SystemException {
2259                    Object[] finderArgs = new Object[] {
2260                                    classNameId, classPK,
2261                                    
2262                                    String.valueOf(start), String.valueOf(end),
2263                                    String.valueOf(orderByComparator)
2264                            };
2265    
2266                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
2267                                    finderArgs, this);
2268    
2269                    if (list == null) {
2270                            Session session = null;
2271    
2272                            try {
2273                                    session = openSession();
2274    
2275                                    StringBundler query = null;
2276    
2277                                    if (orderByComparator != null) {
2278                                            query = new StringBundler(4 +
2279                                                            (orderByComparator.getOrderByFields().length * 3));
2280                                    }
2281                                    else {
2282                                            query = new StringBundler(4);
2283                                    }
2284    
2285                                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2286    
2287                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2288    
2289                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2290    
2291                                    if (orderByComparator != null) {
2292                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2293                                                    orderByComparator);
2294                                    }
2295    
2296                                    else {
2297                                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2298                                    }
2299    
2300                                    String sql = query.toString();
2301    
2302                                    Query q = session.createQuery(sql);
2303    
2304                                    QueryPos qPos = QueryPos.getInstance(q);
2305    
2306                                    qPos.add(classNameId);
2307    
2308                                    qPos.add(classPK);
2309    
2310                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
2311                                                    start, end);
2312                            }
2313                            catch (Exception e) {
2314                                    throw processException(e);
2315                            }
2316                            finally {
2317                                    if (list == null) {
2318                                            list = new ArrayList<ExpandoValue>();
2319                                    }
2320    
2321                                    cacheResult(list);
2322    
2323                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
2324                                            list);
2325    
2326                                    closeSession(session);
2327                            }
2328                    }
2329    
2330                    return list;
2331            }
2332    
2333            public ExpandoValue findByC_C_First(long classNameId, long classPK,
2334                    OrderByComparator orderByComparator)
2335                    throws NoSuchValueException, SystemException {
2336                    List<ExpandoValue> list = findByC_C(classNameId, classPK, 0, 1,
2337                                    orderByComparator);
2338    
2339                    if (list.isEmpty()) {
2340                            StringBundler msg = new StringBundler(6);
2341    
2342                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2343    
2344                            msg.append("classNameId=");
2345                            msg.append(classNameId);
2346    
2347                            msg.append(", classPK=");
2348                            msg.append(classPK);
2349    
2350                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2351    
2352                            throw new NoSuchValueException(msg.toString());
2353                    }
2354                    else {
2355                            return list.get(0);
2356                    }
2357            }
2358    
2359            public ExpandoValue findByC_C_Last(long classNameId, long classPK,
2360                    OrderByComparator orderByComparator)
2361                    throws NoSuchValueException, SystemException {
2362                    int count = countByC_C(classNameId, classPK);
2363    
2364                    List<ExpandoValue> list = findByC_C(classNameId, classPK, count - 1,
2365                                    count, orderByComparator);
2366    
2367                    if (list.isEmpty()) {
2368                            StringBundler msg = new StringBundler(6);
2369    
2370                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2371    
2372                            msg.append("classNameId=");
2373                            msg.append(classNameId);
2374    
2375                            msg.append(", classPK=");
2376                            msg.append(classPK);
2377    
2378                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2379    
2380                            throw new NoSuchValueException(msg.toString());
2381                    }
2382                    else {
2383                            return list.get(0);
2384                    }
2385            }
2386    
2387            public ExpandoValue[] findByC_C_PrevAndNext(long valueId, long classNameId,
2388                    long classPK, OrderByComparator orderByComparator)
2389                    throws NoSuchValueException, SystemException {
2390                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
2391    
2392                    Session session = null;
2393    
2394                    try {
2395                            session = openSession();
2396    
2397                            ExpandoValue[] array = new ExpandoValueImpl[3];
2398    
2399                            array[0] = getByC_C_PrevAndNext(session, expandoValue, classNameId,
2400                                            classPK, orderByComparator, true);
2401    
2402                            array[1] = expandoValue;
2403    
2404                            array[2] = getByC_C_PrevAndNext(session, expandoValue, classNameId,
2405                                            classPK, orderByComparator, false);
2406    
2407                            return array;
2408                    }
2409                    catch (Exception e) {
2410                            throw processException(e);
2411                    }
2412                    finally {
2413                            closeSession(session);
2414                    }
2415            }
2416    
2417            protected ExpandoValue getByC_C_PrevAndNext(Session session,
2418                    ExpandoValue expandoValue, long classNameId, long classPK,
2419                    OrderByComparator orderByComparator, boolean previous) {
2420                    StringBundler query = null;
2421    
2422                    if (orderByComparator != null) {
2423                            query = new StringBundler(6 +
2424                                            (orderByComparator.getOrderByFields().length * 6));
2425                    }
2426                    else {
2427                            query = new StringBundler(3);
2428                    }
2429    
2430                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2431    
2432                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2433    
2434                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2435    
2436                    if (orderByComparator != null) {
2437                            String[] orderByFields = orderByComparator.getOrderByFields();
2438    
2439                            if (orderByFields.length > 0) {
2440                                    query.append(WHERE_AND);
2441                            }
2442    
2443                            for (int i = 0; i < orderByFields.length; i++) {
2444                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2445                                    query.append(orderByFields[i]);
2446    
2447                                    if ((i + 1) < orderByFields.length) {
2448                                            if (orderByComparator.isAscending() ^ previous) {
2449                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2450                                            }
2451                                            else {
2452                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2453                                            }
2454                                    }
2455                                    else {
2456                                            if (orderByComparator.isAscending() ^ previous) {
2457                                                    query.append(WHERE_GREATER_THAN);
2458                                            }
2459                                            else {
2460                                                    query.append(WHERE_LESSER_THAN);
2461                                            }
2462                                    }
2463                            }
2464    
2465                            query.append(ORDER_BY_CLAUSE);
2466    
2467                            for (int i = 0; i < orderByFields.length; i++) {
2468                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2469                                    query.append(orderByFields[i]);
2470    
2471                                    if ((i + 1) < orderByFields.length) {
2472                                            if (orderByComparator.isAscending() ^ previous) {
2473                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2474                                            }
2475                                            else {
2476                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2477                                            }
2478                                    }
2479                                    else {
2480                                            if (orderByComparator.isAscending() ^ previous) {
2481                                                    query.append(ORDER_BY_ASC);
2482                                            }
2483                                            else {
2484                                                    query.append(ORDER_BY_DESC);
2485                                            }
2486                                    }
2487                            }
2488                    }
2489    
2490                    else {
2491                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2492                    }
2493    
2494                    String sql = query.toString();
2495    
2496                    Query q = session.createQuery(sql);
2497    
2498                    q.setFirstResult(0);
2499                    q.setMaxResults(2);
2500    
2501                    QueryPos qPos = QueryPos.getInstance(q);
2502    
2503                    qPos.add(classNameId);
2504    
2505                    qPos.add(classPK);
2506    
2507                    if (orderByComparator != null) {
2508                            Object[] values = orderByComparator.getOrderByValues(expandoValue);
2509    
2510                            for (Object value : values) {
2511                                    qPos.add(value);
2512                            }
2513                    }
2514    
2515                    List<ExpandoValue> list = q.list();
2516    
2517                    if (list.size() == 2) {
2518                            return list.get(1);
2519                    }
2520                    else {
2521                            return null;
2522                    }
2523            }
2524    
2525            public ExpandoValue findByT_C_C(long tableId, long columnId, long classPK)
2526                    throws NoSuchValueException, SystemException {
2527                    ExpandoValue expandoValue = fetchByT_C_C(tableId, columnId, classPK);
2528    
2529                    if (expandoValue == null) {
2530                            StringBundler msg = new StringBundler(8);
2531    
2532                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2533    
2534                            msg.append("tableId=");
2535                            msg.append(tableId);
2536    
2537                            msg.append(", columnId=");
2538                            msg.append(columnId);
2539    
2540                            msg.append(", classPK=");
2541                            msg.append(classPK);
2542    
2543                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2544    
2545                            if (_log.isWarnEnabled()) {
2546                                    _log.warn(msg.toString());
2547                            }
2548    
2549                            throw new NoSuchValueException(msg.toString());
2550                    }
2551    
2552                    return expandoValue;
2553            }
2554    
2555            public ExpandoValue fetchByT_C_C(long tableId, long columnId, long classPK)
2556                    throws SystemException {
2557                    return fetchByT_C_C(tableId, columnId, classPK, true);
2558            }
2559    
2560            public ExpandoValue fetchByT_C_C(long tableId, long columnId, long classPK,
2561                    boolean retrieveFromCache) throws SystemException {
2562                    Object[] finderArgs = new Object[] { tableId, columnId, classPK };
2563    
2564                    Object result = null;
2565    
2566                    if (retrieveFromCache) {
2567                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_C_C,
2568                                            finderArgs, this);
2569                    }
2570    
2571                    if (result == null) {
2572                            Session session = null;
2573    
2574                            try {
2575                                    session = openSession();
2576    
2577                                    StringBundler query = new StringBundler(5);
2578    
2579                                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2580    
2581                                    query.append(_FINDER_COLUMN_T_C_C_TABLEID_2);
2582    
2583                                    query.append(_FINDER_COLUMN_T_C_C_COLUMNID_2);
2584    
2585                                    query.append(_FINDER_COLUMN_T_C_C_CLASSPK_2);
2586    
2587                                    query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2588    
2589                                    String sql = query.toString();
2590    
2591                                    Query q = session.createQuery(sql);
2592    
2593                                    QueryPos qPos = QueryPos.getInstance(q);
2594    
2595                                    qPos.add(tableId);
2596    
2597                                    qPos.add(columnId);
2598    
2599                                    qPos.add(classPK);
2600    
2601                                    List<ExpandoValue> list = q.list();
2602    
2603                                    result = list;
2604    
2605                                    ExpandoValue expandoValue = null;
2606    
2607                                    if (list.isEmpty()) {
2608                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
2609                                                    finderArgs, list);
2610                                    }
2611                                    else {
2612                                            expandoValue = list.get(0);
2613    
2614                                            cacheResult(expandoValue);
2615    
2616                                            if ((expandoValue.getTableId() != tableId) ||
2617                                                            (expandoValue.getColumnId() != columnId) ||
2618                                                            (expandoValue.getClassPK() != classPK)) {
2619                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
2620                                                            finderArgs, expandoValue);
2621                                            }
2622                                    }
2623    
2624                                    return expandoValue;
2625                            }
2626                            catch (Exception e) {
2627                                    throw processException(e);
2628                            }
2629                            finally {
2630                                    if (result == null) {
2631                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_C_C,
2632                                                    finderArgs, new ArrayList<ExpandoValue>());
2633                                    }
2634    
2635                                    closeSession(session);
2636                            }
2637                    }
2638                    else {
2639                            if (result instanceof List<?>) {
2640                                    return null;
2641                            }
2642                            else {
2643                                    return (ExpandoValue)result;
2644                            }
2645                    }
2646            }
2647    
2648            public List<ExpandoValue> findByT_C_D(long tableId, long columnId,
2649                    String data) throws SystemException {
2650                    return findByT_C_D(tableId, columnId, data, QueryUtil.ALL_POS,
2651                            QueryUtil.ALL_POS, null);
2652            }
2653    
2654            public List<ExpandoValue> findByT_C_D(long tableId, long columnId,
2655                    String data, int start, int end) throws SystemException {
2656                    return findByT_C_D(tableId, columnId, data, start, end, null);
2657            }
2658    
2659            public List<ExpandoValue> findByT_C_D(long tableId, long columnId,
2660                    String data, int start, int end, OrderByComparator orderByComparator)
2661                    throws SystemException {
2662                    Object[] finderArgs = new Object[] {
2663                                    tableId, columnId, data,
2664                                    
2665                                    String.valueOf(start), String.valueOf(end),
2666                                    String.valueOf(orderByComparator)
2667                            };
2668    
2669                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_C_D,
2670                                    finderArgs, this);
2671    
2672                    if (list == null) {
2673                            Session session = null;
2674    
2675                            try {
2676                                    session = openSession();
2677    
2678                                    StringBundler query = null;
2679    
2680                                    if (orderByComparator != null) {
2681                                            query = new StringBundler(5 +
2682                                                            (orderByComparator.getOrderByFields().length * 3));
2683                                    }
2684                                    else {
2685                                            query = new StringBundler(5);
2686                                    }
2687    
2688                                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2689    
2690                                    query.append(_FINDER_COLUMN_T_C_D_TABLEID_2);
2691    
2692                                    query.append(_FINDER_COLUMN_T_C_D_COLUMNID_2);
2693    
2694                                    if (data == null) {
2695                                            query.append(_FINDER_COLUMN_T_C_D_DATA_1);
2696                                    }
2697                                    else {
2698                                            if (data.equals(StringPool.BLANK)) {
2699                                                    query.append(_FINDER_COLUMN_T_C_D_DATA_3);
2700                                            }
2701                                            else {
2702                                                    query.append(_FINDER_COLUMN_T_C_D_DATA_2);
2703                                            }
2704                                    }
2705    
2706                                    if (orderByComparator != null) {
2707                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2708                                                    orderByComparator);
2709                                    }
2710    
2711                                    else {
2712                                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2713                                    }
2714    
2715                                    String sql = query.toString();
2716    
2717                                    Query q = session.createQuery(sql);
2718    
2719                                    QueryPos qPos = QueryPos.getInstance(q);
2720    
2721                                    qPos.add(tableId);
2722    
2723                                    qPos.add(columnId);
2724    
2725                                    if (data != null) {
2726                                            qPos.add(data);
2727                                    }
2728    
2729                                    list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
2730                                                    start, end);
2731                            }
2732                            catch (Exception e) {
2733                                    throw processException(e);
2734                            }
2735                            finally {
2736                                    if (list == null) {
2737                                            list = new ArrayList<ExpandoValue>();
2738                                    }
2739    
2740                                    cacheResult(list);
2741    
2742                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_C_D,
2743                                            finderArgs, list);
2744    
2745                                    closeSession(session);
2746                            }
2747                    }
2748    
2749                    return list;
2750            }
2751    
2752            public ExpandoValue findByT_C_D_First(long tableId, long columnId,
2753                    String data, OrderByComparator orderByComparator)
2754                    throws NoSuchValueException, SystemException {
2755                    List<ExpandoValue> list = findByT_C_D(tableId, columnId, data, 0, 1,
2756                                    orderByComparator);
2757    
2758                    if (list.isEmpty()) {
2759                            StringBundler msg = new StringBundler(8);
2760    
2761                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2762    
2763                            msg.append("tableId=");
2764                            msg.append(tableId);
2765    
2766                            msg.append(", columnId=");
2767                            msg.append(columnId);
2768    
2769                            msg.append(", data=");
2770                            msg.append(data);
2771    
2772                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2773    
2774                            throw new NoSuchValueException(msg.toString());
2775                    }
2776                    else {
2777                            return list.get(0);
2778                    }
2779            }
2780    
2781            public ExpandoValue findByT_C_D_Last(long tableId, long columnId,
2782                    String data, OrderByComparator orderByComparator)
2783                    throws NoSuchValueException, SystemException {
2784                    int count = countByT_C_D(tableId, columnId, data);
2785    
2786                    List<ExpandoValue> list = findByT_C_D(tableId, columnId, data,
2787                                    count - 1, count, orderByComparator);
2788    
2789                    if (list.isEmpty()) {
2790                            StringBundler msg = new StringBundler(8);
2791    
2792                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2793    
2794                            msg.append("tableId=");
2795                            msg.append(tableId);
2796    
2797                            msg.append(", columnId=");
2798                            msg.append(columnId);
2799    
2800                            msg.append(", data=");
2801                            msg.append(data);
2802    
2803                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2804    
2805                            throw new NoSuchValueException(msg.toString());
2806                    }
2807                    else {
2808                            return list.get(0);
2809                    }
2810            }
2811    
2812            public ExpandoValue[] findByT_C_D_PrevAndNext(long valueId, long tableId,
2813                    long columnId, String data, OrderByComparator orderByComparator)
2814                    throws NoSuchValueException, SystemException {
2815                    ExpandoValue expandoValue = findByPrimaryKey(valueId);
2816    
2817                    Session session = null;
2818    
2819                    try {
2820                            session = openSession();
2821    
2822                            ExpandoValue[] array = new ExpandoValueImpl[3];
2823    
2824                            array[0] = getByT_C_D_PrevAndNext(session, expandoValue, tableId,
2825                                            columnId, data, orderByComparator, true);
2826    
2827                            array[1] = expandoValue;
2828    
2829                            array[2] = getByT_C_D_PrevAndNext(session, expandoValue, tableId,
2830                                            columnId, data, orderByComparator, false);
2831    
2832                            return array;
2833                    }
2834                    catch (Exception e) {
2835                            throw processException(e);
2836                    }
2837                    finally {
2838                            closeSession(session);
2839                    }
2840            }
2841    
2842            protected ExpandoValue getByT_C_D_PrevAndNext(Session session,
2843                    ExpandoValue expandoValue, long tableId, long columnId, String data,
2844                    OrderByComparator orderByComparator, boolean previous) {
2845                    StringBundler query = null;
2846    
2847                    if (orderByComparator != null) {
2848                            query = new StringBundler(6 +
2849                                            (orderByComparator.getOrderByFields().length * 6));
2850                    }
2851                    else {
2852                            query = new StringBundler(3);
2853                    }
2854    
2855                    query.append(_SQL_SELECT_EXPANDOVALUE_WHERE);
2856    
2857                    query.append(_FINDER_COLUMN_T_C_D_TABLEID_2);
2858    
2859                    query.append(_FINDER_COLUMN_T_C_D_COLUMNID_2);
2860    
2861                    if (data == null) {
2862                            query.append(_FINDER_COLUMN_T_C_D_DATA_1);
2863                    }
2864                    else {
2865                            if (data.equals(StringPool.BLANK)) {
2866                                    query.append(_FINDER_COLUMN_T_C_D_DATA_3);
2867                            }
2868                            else {
2869                                    query.append(_FINDER_COLUMN_T_C_D_DATA_2);
2870                            }
2871                    }
2872    
2873                    if (orderByComparator != null) {
2874                            String[] orderByFields = orderByComparator.getOrderByFields();
2875    
2876                            if (orderByFields.length > 0) {
2877                                    query.append(WHERE_AND);
2878                            }
2879    
2880                            for (int i = 0; i < orderByFields.length; i++) {
2881                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2882                                    query.append(orderByFields[i]);
2883    
2884                                    if ((i + 1) < orderByFields.length) {
2885                                            if (orderByComparator.isAscending() ^ previous) {
2886                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2887                                            }
2888                                            else {
2889                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2890                                            }
2891                                    }
2892                                    else {
2893                                            if (orderByComparator.isAscending() ^ previous) {
2894                                                    query.append(WHERE_GREATER_THAN);
2895                                            }
2896                                            else {
2897                                                    query.append(WHERE_LESSER_THAN);
2898                                            }
2899                                    }
2900                            }
2901    
2902                            query.append(ORDER_BY_CLAUSE);
2903    
2904                            for (int i = 0; i < orderByFields.length; i++) {
2905                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2906                                    query.append(orderByFields[i]);
2907    
2908                                    if ((i + 1) < orderByFields.length) {
2909                                            if (orderByComparator.isAscending() ^ previous) {
2910                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2911                                            }
2912                                            else {
2913                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2914                                            }
2915                                    }
2916                                    else {
2917                                            if (orderByComparator.isAscending() ^ previous) {
2918                                                    query.append(ORDER_BY_ASC);
2919                                            }
2920                                            else {
2921                                                    query.append(ORDER_BY_DESC);
2922                                            }
2923                                    }
2924                            }
2925                    }
2926    
2927                    else {
2928                            query.append(ExpandoValueModelImpl.ORDER_BY_JPQL);
2929                    }
2930    
2931                    String sql = query.toString();
2932    
2933                    Query q = session.createQuery(sql);
2934    
2935                    q.setFirstResult(0);
2936                    q.setMaxResults(2);
2937    
2938                    QueryPos qPos = QueryPos.getInstance(q);
2939    
2940                    qPos.add(tableId);
2941    
2942                    qPos.add(columnId);
2943    
2944                    if (data != null) {
2945                            qPos.add(data);
2946                    }
2947    
2948                    if (orderByComparator != null) {
2949                            Object[] values = orderByComparator.getOrderByValues(expandoValue);
2950    
2951                            for (Object value : values) {
2952                                    qPos.add(value);
2953                            }
2954                    }
2955    
2956                    List<ExpandoValue> list = q.list();
2957    
2958                    if (list.size() == 2) {
2959                            return list.get(1);
2960                    }
2961                    else {
2962                            return null;
2963                    }
2964            }
2965    
2966            public List<ExpandoValue> findAll() throws SystemException {
2967                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2968            }
2969    
2970            public List<ExpandoValue> findAll(int start, int end)
2971                    throws SystemException {
2972                    return findAll(start, end, null);
2973            }
2974    
2975            public List<ExpandoValue> findAll(int start, int end,
2976                    OrderByComparator orderByComparator) throws SystemException {
2977                    Object[] finderArgs = new Object[] {
2978                                    String.valueOf(start), String.valueOf(end),
2979                                    String.valueOf(orderByComparator)
2980                            };
2981    
2982                    List<ExpandoValue> list = (List<ExpandoValue>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2983                                    finderArgs, this);
2984    
2985                    if (list == null) {
2986                            Session session = null;
2987    
2988                            try {
2989                                    session = openSession();
2990    
2991                                    StringBundler query = null;
2992                                    String sql = null;
2993    
2994                                    if (orderByComparator != null) {
2995                                            query = new StringBundler(2 +
2996                                                            (orderByComparator.getOrderByFields().length * 3));
2997    
2998                                            query.append(_SQL_SELECT_EXPANDOVALUE);
2999    
3000                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3001                                                    orderByComparator);
3002    
3003                                            sql = query.toString();
3004                                    }
3005                                    else {
3006                                            sql = _SQL_SELECT_EXPANDOVALUE.concat(ExpandoValueModelImpl.ORDER_BY_JPQL);
3007                                    }
3008    
3009                                    Query q = session.createQuery(sql);
3010    
3011                                    if (orderByComparator == null) {
3012                                            list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
3013                                                            start, end, false);
3014    
3015                                            Collections.sort(list);
3016                                    }
3017                                    else {
3018                                            list = (List<ExpandoValue>)QueryUtil.list(q, getDialect(),
3019                                                            start, end);
3020                                    }
3021                            }
3022                            catch (Exception e) {
3023                                    throw processException(e);
3024                            }
3025                            finally {
3026                                    if (list == null) {
3027                                            list = new ArrayList<ExpandoValue>();
3028                                    }
3029    
3030                                    cacheResult(list);
3031    
3032                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
3033    
3034                                    closeSession(session);
3035                            }
3036                    }
3037    
3038                    return list;
3039            }
3040    
3041            public void removeByTableId(long tableId) throws SystemException {
3042                    for (ExpandoValue expandoValue : findByTableId(tableId)) {
3043                            remove(expandoValue);
3044                    }
3045            }
3046    
3047            public void removeByColumnId(long columnId) throws SystemException {
3048                    for (ExpandoValue expandoValue : findByColumnId(columnId)) {
3049                            remove(expandoValue);
3050                    }
3051            }
3052    
3053            public void removeByRowId(long rowId) throws SystemException {
3054                    for (ExpandoValue expandoValue : findByRowId(rowId)) {
3055                            remove(expandoValue);
3056                    }
3057            }
3058    
3059            public void removeByT_C(long tableId, long columnId)
3060                    throws SystemException {
3061                    for (ExpandoValue expandoValue : findByT_C(tableId, columnId)) {
3062                            remove(expandoValue);
3063                    }
3064            }
3065    
3066            public void removeByT_CPK(long tableId, long classPK)
3067                    throws SystemException {
3068                    for (ExpandoValue expandoValue : findByT_CPK(tableId, classPK)) {
3069                            remove(expandoValue);
3070                    }
3071            }
3072    
3073            public void removeByT_R(long tableId, long rowId) throws SystemException {
3074                    for (ExpandoValue expandoValue : findByT_R(tableId, rowId)) {
3075                            remove(expandoValue);
3076                    }
3077            }
3078    
3079            public void removeByC_R(long columnId, long rowId)
3080                    throws NoSuchValueException, SystemException {
3081                    ExpandoValue expandoValue = findByC_R(columnId, rowId);
3082    
3083                    remove(expandoValue);
3084            }
3085    
3086            public void removeByC_C(long classNameId, long classPK)
3087                    throws SystemException {
3088                    for (ExpandoValue expandoValue : findByC_C(classNameId, classPK)) {
3089                            remove(expandoValue);
3090                    }
3091            }
3092    
3093            public void removeByT_C_C(long tableId, long columnId, long classPK)
3094                    throws NoSuchValueException, SystemException {
3095                    ExpandoValue expandoValue = findByT_C_C(tableId, columnId, classPK);
3096    
3097                    remove(expandoValue);
3098            }
3099    
3100            public void removeByT_C_D(long tableId, long columnId, String data)
3101                    throws SystemException {
3102                    for (ExpandoValue expandoValue : findByT_C_D(tableId, columnId, data)) {
3103                            remove(expandoValue);
3104                    }
3105            }
3106    
3107            public void removeAll() throws SystemException {
3108                    for (ExpandoValue expandoValue : findAll()) {
3109                            remove(expandoValue);
3110                    }
3111            }
3112    
3113            public int countByTableId(long tableId) throws SystemException {
3114                    Object[] finderArgs = new Object[] { tableId };
3115    
3116                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
3117                                    finderArgs, this);
3118    
3119                    if (count == null) {
3120                            Session session = null;
3121    
3122                            try {
3123                                    session = openSession();
3124    
3125                                    StringBundler query = new StringBundler(2);
3126    
3127                                    query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3128    
3129                                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
3130    
3131                                    String sql = query.toString();
3132    
3133                                    Query q = session.createQuery(sql);
3134    
3135                                    QueryPos qPos = QueryPos.getInstance(q);
3136    
3137                                    qPos.add(tableId);
3138    
3139                                    count = (Long)q.uniqueResult();
3140                            }
3141                            catch (Exception e) {
3142                                    throw processException(e);
3143                            }
3144                            finally {
3145                                    if (count == null) {
3146                                            count = Long.valueOf(0);
3147                                    }
3148    
3149                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
3150                                            finderArgs, count);
3151    
3152                                    closeSession(session);
3153                            }
3154                    }
3155    
3156                    return count.intValue();
3157            }
3158    
3159            public int countByColumnId(long columnId) throws SystemException {
3160                    Object[] finderArgs = new Object[] { columnId };
3161    
3162                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COLUMNID,
3163                                    finderArgs, this);
3164    
3165                    if (count == null) {
3166                            Session session = null;
3167    
3168                            try {
3169                                    session = openSession();
3170    
3171                                    StringBundler query = new StringBundler(2);
3172    
3173                                    query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3174    
3175                                    query.append(_FINDER_COLUMN_COLUMNID_COLUMNID_2);
3176    
3177                                    String sql = query.toString();
3178    
3179                                    Query q = session.createQuery(sql);
3180    
3181                                    QueryPos qPos = QueryPos.getInstance(q);
3182    
3183                                    qPos.add(columnId);
3184    
3185                                    count = (Long)q.uniqueResult();
3186                            }
3187                            catch (Exception e) {
3188                                    throw processException(e);
3189                            }
3190                            finally {
3191                                    if (count == null) {
3192                                            count = Long.valueOf(0);
3193                                    }
3194    
3195                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COLUMNID,
3196                                            finderArgs, count);
3197    
3198                                    closeSession(session);
3199                            }
3200                    }
3201    
3202                    return count.intValue();
3203            }
3204    
3205            public int countByRowId(long rowId) throws SystemException {
3206                    Object[] finderArgs = new Object[] { rowId };
3207    
3208                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROWID,
3209                                    finderArgs, this);
3210    
3211                    if (count == null) {
3212                            Session session = null;
3213    
3214                            try {
3215                                    session = openSession();
3216    
3217                                    StringBundler query = new StringBundler(2);
3218    
3219                                    query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3220    
3221                                    query.append(_FINDER_COLUMN_ROWID_ROWID_2);
3222    
3223                                    String sql = query.toString();
3224    
3225                                    Query q = session.createQuery(sql);
3226    
3227                                    QueryPos qPos = QueryPos.getInstance(q);
3228    
3229                                    qPos.add(rowId);
3230    
3231                                    count = (Long)q.uniqueResult();
3232                            }
3233                            catch (Exception e) {
3234                                    throw processException(e);
3235                            }
3236                            finally {
3237                                    if (count == null) {
3238                                            count = Long.valueOf(0);
3239                                    }
3240    
3241                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROWID,
3242                                            finderArgs, count);
3243    
3244                                    closeSession(session);
3245                            }
3246                    }
3247    
3248                    return count.intValue();
3249            }
3250    
3251            public int countByT_C(long tableId, long columnId)
3252                    throws SystemException {
3253                    Object[] finderArgs = new Object[] { tableId, columnId };
3254    
3255                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C,
3256                                    finderArgs, this);
3257    
3258                    if (count == null) {
3259                            Session session = null;
3260    
3261                            try {
3262                                    session = openSession();
3263    
3264                                    StringBundler query = new StringBundler(3);
3265    
3266                                    query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3267    
3268                                    query.append(_FINDER_COLUMN_T_C_TABLEID_2);
3269    
3270                                    query.append(_FINDER_COLUMN_T_C_COLUMNID_2);
3271    
3272                                    String sql = query.toString();
3273    
3274                                    Query q = session.createQuery(sql);
3275    
3276                                    QueryPos qPos = QueryPos.getInstance(q);
3277    
3278                                    qPos.add(tableId);
3279    
3280                                    qPos.add(columnId);
3281    
3282                                    count = (Long)q.uniqueResult();
3283                            }
3284                            catch (Exception e) {
3285                                    throw processException(e);
3286                            }
3287                            finally {
3288                                    if (count == null) {
3289                                            count = Long.valueOf(0);
3290                                    }
3291    
3292                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C, finderArgs,
3293                                            count);
3294    
3295                                    closeSession(session);
3296                            }
3297                    }
3298    
3299                    return count.intValue();
3300            }
3301    
3302            public int countByT_CPK(long tableId, long classPK)
3303                    throws SystemException {
3304                    Object[] finderArgs = new Object[] { tableId, classPK };
3305    
3306                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_CPK,
3307                                    finderArgs, this);
3308    
3309                    if (count == null) {
3310                            Session session = null;
3311    
3312                            try {
3313                                    session = openSession();
3314    
3315                                    StringBundler query = new StringBundler(3);
3316    
3317                                    query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3318    
3319                                    query.append(_FINDER_COLUMN_T_CPK_TABLEID_2);
3320    
3321                                    query.append(_FINDER_COLUMN_T_CPK_CLASSPK_2);
3322    
3323                                    String sql = query.toString();
3324    
3325                                    Query q = session.createQuery(sql);
3326    
3327                                    QueryPos qPos = QueryPos.getInstance(q);
3328    
3329                                    qPos.add(tableId);
3330    
3331                                    qPos.add(classPK);
3332    
3333                                    count = (Long)q.uniqueResult();
3334                            }
3335                            catch (Exception e) {
3336                                    throw processException(e);
3337                            }
3338                            finally {
3339                                    if (count == null) {
3340                                            count = Long.valueOf(0);
3341                                    }
3342    
3343                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_CPK,
3344                                            finderArgs, count);
3345    
3346                                    closeSession(session);
3347                            }
3348                    }
3349    
3350                    return count.intValue();
3351            }
3352    
3353            public int countByT_R(long tableId, long rowId) throws SystemException {
3354                    Object[] finderArgs = new Object[] { tableId, rowId };
3355    
3356                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_R,
3357                                    finderArgs, this);
3358    
3359                    if (count == null) {
3360                            Session session = null;
3361    
3362                            try {
3363                                    session = openSession();
3364    
3365                                    StringBundler query = new StringBundler(3);
3366    
3367                                    query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3368    
3369                                    query.append(_FINDER_COLUMN_T_R_TABLEID_2);
3370    
3371                                    query.append(_FINDER_COLUMN_T_R_ROWID_2);
3372    
3373                                    String sql = query.toString();
3374    
3375                                    Query q = session.createQuery(sql);
3376    
3377                                    QueryPos qPos = QueryPos.getInstance(q);
3378    
3379                                    qPos.add(tableId);
3380    
3381                                    qPos.add(rowId);
3382    
3383                                    count = (Long)q.uniqueResult();
3384                            }
3385                            catch (Exception e) {
3386                                    throw processException(e);
3387                            }
3388                            finally {
3389                                    if (count == null) {
3390                                            count = Long.valueOf(0);
3391                                    }
3392    
3393                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_R, finderArgs,
3394                                            count);
3395    
3396                                    closeSession(session);
3397                            }
3398                    }
3399    
3400                    return count.intValue();
3401            }
3402    
3403            public int countByC_R(long columnId, long rowId) throws SystemException {
3404                    Object[] finderArgs = new Object[] { columnId, rowId };
3405    
3406                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_R,
3407                                    finderArgs, this);
3408    
3409                    if (count == null) {
3410                            Session session = null;
3411    
3412                            try {
3413                                    session = openSession();
3414    
3415                                    StringBundler query = new StringBundler(3);
3416    
3417                                    query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3418    
3419                                    query.append(_FINDER_COLUMN_C_R_COLUMNID_2);
3420    
3421                                    query.append(_FINDER_COLUMN_C_R_ROWID_2);
3422    
3423                                    String sql = query.toString();
3424    
3425                                    Query q = session.createQuery(sql);
3426    
3427                                    QueryPos qPos = QueryPos.getInstance(q);
3428    
3429                                    qPos.add(columnId);
3430    
3431                                    qPos.add(rowId);
3432    
3433                                    count = (Long)q.uniqueResult();
3434                            }
3435                            catch (Exception e) {
3436                                    throw processException(e);
3437                            }
3438                            finally {
3439                                    if (count == null) {
3440                                            count = Long.valueOf(0);
3441                                    }
3442    
3443                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_R, finderArgs,
3444                                            count);
3445    
3446                                    closeSession(session);
3447                            }
3448                    }
3449    
3450                    return count.intValue();
3451            }
3452    
3453            public int countByC_C(long classNameId, long classPK)
3454                    throws SystemException {
3455                    Object[] finderArgs = new Object[] { classNameId, classPK };
3456    
3457                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
3458                                    finderArgs, this);
3459    
3460                    if (count == null) {
3461                            Session session = null;
3462    
3463                            try {
3464                                    session = openSession();
3465    
3466                                    StringBundler query = new StringBundler(3);
3467    
3468                                    query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3469    
3470                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3471    
3472                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3473    
3474                                    String sql = query.toString();
3475    
3476                                    Query q = session.createQuery(sql);
3477    
3478                                    QueryPos qPos = QueryPos.getInstance(q);
3479    
3480                                    qPos.add(classNameId);
3481    
3482                                    qPos.add(classPK);
3483    
3484                                    count = (Long)q.uniqueResult();
3485                            }
3486                            catch (Exception e) {
3487                                    throw processException(e);
3488                            }
3489                            finally {
3490                                    if (count == null) {
3491                                            count = Long.valueOf(0);
3492                                    }
3493    
3494                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
3495                                            count);
3496    
3497                                    closeSession(session);
3498                            }
3499                    }
3500    
3501                    return count.intValue();
3502            }
3503    
3504            public int countByT_C_C(long tableId, long columnId, long classPK)
3505                    throws SystemException {
3506                    Object[] finderArgs = new Object[] { tableId, columnId, classPK };
3507    
3508                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C_C,
3509                                    finderArgs, this);
3510    
3511                    if (count == null) {
3512                            Session session = null;
3513    
3514                            try {
3515                                    session = openSession();
3516    
3517                                    StringBundler query = new StringBundler(4);
3518    
3519                                    query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3520    
3521                                    query.append(_FINDER_COLUMN_T_C_C_TABLEID_2);
3522    
3523                                    query.append(_FINDER_COLUMN_T_C_C_COLUMNID_2);
3524    
3525                                    query.append(_FINDER_COLUMN_T_C_C_CLASSPK_2);
3526    
3527                                    String sql = query.toString();
3528    
3529                                    Query q = session.createQuery(sql);
3530    
3531                                    QueryPos qPos = QueryPos.getInstance(q);
3532    
3533                                    qPos.add(tableId);
3534    
3535                                    qPos.add(columnId);
3536    
3537                                    qPos.add(classPK);
3538    
3539                                    count = (Long)q.uniqueResult();
3540                            }
3541                            catch (Exception e) {
3542                                    throw processException(e);
3543                            }
3544                            finally {
3545                                    if (count == null) {
3546                                            count = Long.valueOf(0);
3547                                    }
3548    
3549                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C_C,
3550                                            finderArgs, count);
3551    
3552                                    closeSession(session);
3553                            }
3554                    }
3555    
3556                    return count.intValue();
3557            }
3558    
3559            public int countByT_C_D(long tableId, long columnId, String data)
3560                    throws SystemException {
3561                    Object[] finderArgs = new Object[] { tableId, columnId, data };
3562    
3563                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_C_D,
3564                                    finderArgs, this);
3565    
3566                    if (count == null) {
3567                            Session session = null;
3568    
3569                            try {
3570                                    session = openSession();
3571    
3572                                    StringBundler query = new StringBundler(4);
3573    
3574                                    query.append(_SQL_COUNT_EXPANDOVALUE_WHERE);
3575    
3576                                    query.append(_FINDER_COLUMN_T_C_D_TABLEID_2);
3577    
3578                                    query.append(_FINDER_COLUMN_T_C_D_COLUMNID_2);
3579    
3580                                    if (data == null) {
3581                                            query.append(_FINDER_COLUMN_T_C_D_DATA_1);
3582                                    }
3583                                    else {
3584                                            if (data.equals(StringPool.BLANK)) {
3585                                                    query.append(_FINDER_COLUMN_T_C_D_DATA_3);
3586                                            }
3587                                            else {
3588                                                    query.append(_FINDER_COLUMN_T_C_D_DATA_2);
3589                                            }
3590                                    }
3591    
3592                                    String sql = query.toString();
3593    
3594                                    Query q = session.createQuery(sql);
3595    
3596                                    QueryPos qPos = QueryPos.getInstance(q);
3597    
3598                                    qPos.add(tableId);
3599    
3600                                    qPos.add(columnId);
3601    
3602                                    if (data != null) {
3603                                            qPos.add(data);
3604                                    }
3605    
3606                                    count = (Long)q.uniqueResult();
3607                            }
3608                            catch (Exception e) {
3609                                    throw processException(e);
3610                            }
3611                            finally {
3612                                    if (count == null) {
3613                                            count = Long.valueOf(0);
3614                                    }
3615    
3616                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_C_D,
3617                                            finderArgs, count);
3618    
3619                                    closeSession(session);
3620                            }
3621                    }
3622    
3623                    return count.intValue();
3624            }
3625    
3626            public int countAll() throws SystemException {
3627                    Object[] finderArgs = new Object[0];
3628    
3629                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3630                                    finderArgs, this);
3631    
3632                    if (count == null) {
3633                            Session session = null;
3634    
3635                            try {
3636                                    session = openSession();
3637    
3638                                    Query q = session.createQuery(_SQL_COUNT_EXPANDOVALUE);
3639    
3640                                    count = (Long)q.uniqueResult();
3641                            }
3642                            catch (Exception e) {
3643                                    throw processException(e);
3644                            }
3645                            finally {
3646                                    if (count == null) {
3647                                            count = Long.valueOf(0);
3648                                    }
3649    
3650                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3651                                            count);
3652    
3653                                    closeSession(session);
3654                            }
3655                    }
3656    
3657                    return count.intValue();
3658            }
3659    
3660            public void afterPropertiesSet() {
3661                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3662                                            com.liferay.portal.util.PropsUtil.get(
3663                                                    "value.object.listener.com.liferay.portlet.expando.model.ExpandoValue")));
3664    
3665                    if (listenerClassNames.length > 0) {
3666                            try {
3667                                    List<ModelListener<ExpandoValue>> listenersList = new ArrayList<ModelListener<ExpandoValue>>();
3668    
3669                                    for (String listenerClassName : listenerClassNames) {
3670                                            listenersList.add((ModelListener<ExpandoValue>)InstanceFactory.newInstance(
3671                                                            listenerClassName));
3672                                    }
3673    
3674                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3675                            }
3676                            catch (Exception e) {
3677                                    _log.error(e);
3678                            }
3679                    }
3680            }
3681    
3682            @BeanReference(type = ExpandoColumnPersistence.class)
3683            protected ExpandoColumnPersistence expandoColumnPersistence;
3684            @BeanReference(type = ExpandoRowPersistence.class)
3685            protected ExpandoRowPersistence expandoRowPersistence;
3686            @BeanReference(type = ExpandoTablePersistence.class)
3687            protected ExpandoTablePersistence expandoTablePersistence;
3688            @BeanReference(type = ExpandoValuePersistence.class)
3689            protected ExpandoValuePersistence expandoValuePersistence;
3690            @BeanReference(type = ResourcePersistence.class)
3691            protected ResourcePersistence resourcePersistence;
3692            @BeanReference(type = UserPersistence.class)
3693            protected UserPersistence userPersistence;
3694            private static final String _SQL_SELECT_EXPANDOVALUE = "SELECT expandoValue FROM ExpandoValue expandoValue";
3695            private static final String _SQL_SELECT_EXPANDOVALUE_WHERE = "SELECT expandoValue FROM ExpandoValue expandoValue WHERE ";
3696            private static final String _SQL_COUNT_EXPANDOVALUE = "SELECT COUNT(expandoValue) FROM ExpandoValue expandoValue";
3697            private static final String _SQL_COUNT_EXPANDOVALUE_WHERE = "SELECT COUNT(expandoValue) FROM ExpandoValue expandoValue WHERE ";
3698            private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoValue.tableId = ?";
3699            private static final String _FINDER_COLUMN_COLUMNID_COLUMNID_2 = "expandoValue.columnId = ?";
3700            private static final String _FINDER_COLUMN_ROWID_ROWID_2 = "expandoValue.rowId = ?";
3701            private static final String _FINDER_COLUMN_T_C_TABLEID_2 = "expandoValue.tableId = ? AND ";
3702            private static final String _FINDER_COLUMN_T_C_COLUMNID_2 = "expandoValue.columnId = ?";
3703            private static final String _FINDER_COLUMN_T_CPK_TABLEID_2 = "expandoValue.tableId = ? AND ";
3704            private static final String _FINDER_COLUMN_T_CPK_CLASSPK_2 = "expandoValue.classPK = ?";
3705            private static final String _FINDER_COLUMN_T_R_TABLEID_2 = "expandoValue.tableId = ? AND ";
3706            private static final String _FINDER_COLUMN_T_R_ROWID_2 = "expandoValue.rowId = ?";
3707            private static final String _FINDER_COLUMN_C_R_COLUMNID_2 = "expandoValue.columnId = ? AND ";
3708            private static final String _FINDER_COLUMN_C_R_ROWID_2 = "expandoValue.rowId = ?";
3709            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoValue.classNameId = ? AND ";
3710            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "expandoValue.classPK = ?";
3711            private static final String _FINDER_COLUMN_T_C_C_TABLEID_2 = "expandoValue.tableId = ? AND ";
3712            private static final String _FINDER_COLUMN_T_C_C_COLUMNID_2 = "expandoValue.columnId = ? AND ";
3713            private static final String _FINDER_COLUMN_T_C_C_CLASSPK_2 = "expandoValue.classPK = ?";
3714            private static final String _FINDER_COLUMN_T_C_D_TABLEID_2 = "expandoValue.tableId = ? AND ";
3715            private static final String _FINDER_COLUMN_T_C_D_COLUMNID_2 = "expandoValue.columnId = ? AND ";
3716            private static final String _FINDER_COLUMN_T_C_D_DATA_1 = "expandoValue.data IS NULL";
3717            private static final String _FINDER_COLUMN_T_C_D_DATA_2 = "expandoValue.data = ?";
3718            private static final String _FINDER_COLUMN_T_C_D_DATA_3 = "(expandoValue.data IS NULL OR expandoValue.data = ?)";
3719            private static final String _ORDER_BY_ENTITY_ALIAS = "expandoValue.";
3720            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoValue exists with the primary key ";
3721            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoValue exists with the key {";
3722            private static Log _log = LogFactoryUtil.getLog(ExpandoValuePersistenceImpl.class);
3723    }