001    /**
002     * Copyright (c) 2000-2012 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.bean.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.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
040    import com.liferay.portal.service.persistence.BatchSessionUtil;
041    import com.liferay.portal.service.persistence.ResourcePersistence;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.expando.NoSuchColumnException;
046    import com.liferay.portlet.expando.model.ExpandoColumn;
047    import com.liferay.portlet.expando.model.impl.ExpandoColumnImpl;
048    import com.liferay.portlet.expando.model.impl.ExpandoColumnModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the expando column service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see ExpandoColumnPersistence
065     * @see ExpandoColumnUtil
066     * @generated
067     */
068    public class ExpandoColumnPersistenceImpl extends BasePersistenceImpl<ExpandoColumn>
069            implements ExpandoColumnPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * Never modify or reference this class directly. Always use {@link ExpandoColumnUtil} to access the expando column persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = ExpandoColumnImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
081                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
082                            ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
083                            "findByTableId",
084                            new String[] {
085                                    Long.class.getName(),
086                                    
087                            "java.lang.Integer", "java.lang.Integer",
088                                    "com.liferay.portal.kernel.util.OrderByComparator"
089                            });
090            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID =
091                    new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
092                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
093                            ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
094                            "findByTableId", new String[] { Long.class.getName() },
095                            ExpandoColumnModelImpl.TABLEID_COLUMN_BITMASK);
096            public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
097                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTableId",
099                            new String[] { Long.class.getName() });
100            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
101                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
102                            ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
103                            "findByT_N",
104                            new String[] {
105                                    Long.class.getName(), String.class.getName(),
106                                    
107                            "java.lang.Integer", "java.lang.Integer",
108                                    "com.liferay.portal.kernel.util.OrderByComparator"
109                            });
110            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
111                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
112                            ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
113                            "findByT_N",
114                            new String[] { Long.class.getName(), String.class.getName() },
115                            ExpandoColumnModelImpl.TABLEID_COLUMN_BITMASK |
116                            ExpandoColumnModelImpl.NAME_COLUMN_BITMASK);
117            public static final FinderPath FINDER_PATH_COUNT_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
118                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
119                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_N",
120                            new String[] { Long.class.getName(), String.class.getName() });
121            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
122                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
123                            ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
124                            "findAll", new String[0]);
125            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
126                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
127                            ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
128                            "findAll", new String[0]);
129            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
130                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
131                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
132    
133            /**
134             * Caches the expando column in the entity cache if it is enabled.
135             *
136             * @param expandoColumn the expando column
137             */
138            public void cacheResult(ExpandoColumn expandoColumn) {
139                    EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
140                            ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
141                            expandoColumn);
142    
143                    expandoColumn.resetOriginalValues();
144            }
145    
146            /**
147             * Caches the expando columns in the entity cache if it is enabled.
148             *
149             * @param expandoColumns the expando columns
150             */
151            public void cacheResult(List<ExpandoColumn> expandoColumns) {
152                    for (ExpandoColumn expandoColumn : expandoColumns) {
153                            if (EntityCacheUtil.getResult(
154                                                    ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
155                                                    ExpandoColumnImpl.class, expandoColumn.getPrimaryKey()) == null) {
156                                    cacheResult(expandoColumn);
157                            }
158                            else {
159                                    expandoColumn.resetOriginalValues();
160                            }
161                    }
162            }
163    
164            /**
165             * Clears the cache for all expando columns.
166             *
167             * <p>
168             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
169             * </p>
170             */
171            @Override
172            public void clearCache() {
173                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
174                            CacheRegistryUtil.clear(ExpandoColumnImpl.class.getName());
175                    }
176    
177                    EntityCacheUtil.clearCache(ExpandoColumnImpl.class.getName());
178    
179                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
180                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
181                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
182            }
183    
184            /**
185             * Clears the cache for the expando column.
186             *
187             * <p>
188             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
189             * </p>
190             */
191            @Override
192            public void clearCache(ExpandoColumn expandoColumn) {
193                    EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
194                            ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
195    
196                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
197                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
198            }
199    
200            @Override
201            public void clearCache(List<ExpandoColumn> expandoColumns) {
202                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
203                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
204    
205                    for (ExpandoColumn expandoColumn : expandoColumns) {
206                            EntityCacheUtil.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
207                                    ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
208                    }
209            }
210    
211            /**
212             * Creates a new expando column with the primary key. Does not add the expando column to the database.
213             *
214             * @param columnId the primary key for the new expando column
215             * @return the new expando column
216             */
217            public ExpandoColumn create(long columnId) {
218                    ExpandoColumn expandoColumn = new ExpandoColumnImpl();
219    
220                    expandoColumn.setNew(true);
221                    expandoColumn.setPrimaryKey(columnId);
222    
223                    return expandoColumn;
224            }
225    
226            /**
227             * Removes the expando column with the primary key from the database. Also notifies the appropriate model listeners.
228             *
229             * @param columnId the primary key of the expando column
230             * @return the expando column that was removed
231             * @throws com.liferay.portlet.expando.NoSuchColumnException if a expando column with the primary key could not be found
232             * @throws SystemException if a system exception occurred
233             */
234            public ExpandoColumn remove(long columnId)
235                    throws NoSuchColumnException, SystemException {
236                    return remove(Long.valueOf(columnId));
237            }
238    
239            /**
240             * Removes the expando column with the primary key from the database. Also notifies the appropriate model listeners.
241             *
242             * @param primaryKey the primary key of the expando column
243             * @return the expando column that was removed
244             * @throws com.liferay.portlet.expando.NoSuchColumnException if a expando column with the primary key could not be found
245             * @throws SystemException if a system exception occurred
246             */
247            @Override
248            public ExpandoColumn remove(Serializable primaryKey)
249                    throws NoSuchColumnException, SystemException {
250                    Session session = null;
251    
252                    try {
253                            session = openSession();
254    
255                            ExpandoColumn expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
256                                            primaryKey);
257    
258                            if (expandoColumn == null) {
259                                    if (_log.isWarnEnabled()) {
260                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
261                                    }
262    
263                                    throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
264                                            primaryKey);
265                            }
266    
267                            return remove(expandoColumn);
268                    }
269                    catch (NoSuchColumnException nsee) {
270                            throw nsee;
271                    }
272                    catch (Exception e) {
273                            throw processException(e);
274                    }
275                    finally {
276                            closeSession(session);
277                    }
278            }
279    
280            @Override
281            protected ExpandoColumn removeImpl(ExpandoColumn expandoColumn)
282                    throws SystemException {
283                    expandoColumn = toUnwrappedModel(expandoColumn);
284    
285                    Session session = null;
286    
287                    try {
288                            session = openSession();
289    
290                            BatchSessionUtil.delete(session, expandoColumn);
291                    }
292                    catch (Exception e) {
293                            throw processException(e);
294                    }
295                    finally {
296                            closeSession(session);
297                    }
298    
299                    clearCache(expandoColumn);
300    
301                    return expandoColumn;
302            }
303    
304            @Override
305            public ExpandoColumn updateImpl(
306                    com.liferay.portlet.expando.model.ExpandoColumn expandoColumn,
307                    boolean merge) throws SystemException {
308                    expandoColumn = toUnwrappedModel(expandoColumn);
309    
310                    boolean isNew = expandoColumn.isNew();
311    
312                    ExpandoColumnModelImpl expandoColumnModelImpl = (ExpandoColumnModelImpl)expandoColumn;
313    
314                    Session session = null;
315    
316                    try {
317                            session = openSession();
318    
319                            BatchSessionUtil.update(session, expandoColumn, merge);
320    
321                            expandoColumn.setNew(false);
322                    }
323                    catch (Exception e) {
324                            throw processException(e);
325                    }
326                    finally {
327                            closeSession(session);
328                    }
329    
330                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
331    
332                    if (isNew || !ExpandoColumnModelImpl.COLUMN_BITMASK_ENABLED) {
333                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
334                    }
335    
336                    else {
337                            if ((expandoColumnModelImpl.getColumnBitmask() &
338                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
339                                    Object[] args = new Object[] {
340                                                    Long.valueOf(expandoColumnModelImpl.getOriginalTableId())
341                                            };
342    
343                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
344                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
345                                            args);
346    
347                                    args = new Object[] {
348                                                    Long.valueOf(expandoColumnModelImpl.getTableId())
349                                            };
350    
351                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
352                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
353                                            args);
354                            }
355    
356                            if ((expandoColumnModelImpl.getColumnBitmask() &
357                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N.getColumnBitmask()) != 0) {
358                                    Object[] args = new Object[] {
359                                                    Long.valueOf(expandoColumnModelImpl.getOriginalTableId()),
360                                                    
361                                                    expandoColumnModelImpl.getOriginalName()
362                                            };
363    
364                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
365                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N,
366                                            args);
367    
368                                    args = new Object[] {
369                                                    Long.valueOf(expandoColumnModelImpl.getTableId()),
370                                                    
371                                                    expandoColumnModelImpl.getName()
372                                            };
373    
374                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
375                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N,
376                                            args);
377                            }
378                    }
379    
380                    EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
381                            ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
382                            expandoColumn);
383    
384                    return expandoColumn;
385            }
386    
387            protected ExpandoColumn toUnwrappedModel(ExpandoColumn expandoColumn) {
388                    if (expandoColumn instanceof ExpandoColumnImpl) {
389                            return expandoColumn;
390                    }
391    
392                    ExpandoColumnImpl expandoColumnImpl = new ExpandoColumnImpl();
393    
394                    expandoColumnImpl.setNew(expandoColumn.isNew());
395                    expandoColumnImpl.setPrimaryKey(expandoColumn.getPrimaryKey());
396    
397                    expandoColumnImpl.setColumnId(expandoColumn.getColumnId());
398                    expandoColumnImpl.setCompanyId(expandoColumn.getCompanyId());
399                    expandoColumnImpl.setTableId(expandoColumn.getTableId());
400                    expandoColumnImpl.setName(expandoColumn.getName());
401                    expandoColumnImpl.setType(expandoColumn.getType());
402                    expandoColumnImpl.setDefaultData(expandoColumn.getDefaultData());
403                    expandoColumnImpl.setTypeSettings(expandoColumn.getTypeSettings());
404    
405                    return expandoColumnImpl;
406            }
407    
408            /**
409             * Returns the expando column with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
410             *
411             * @param primaryKey the primary key of the expando column
412             * @return the expando column
413             * @throws com.liferay.portal.NoSuchModelException if a expando column with the primary key could not be found
414             * @throws SystemException if a system exception occurred
415             */
416            @Override
417            public ExpandoColumn findByPrimaryKey(Serializable primaryKey)
418                    throws NoSuchModelException, SystemException {
419                    return findByPrimaryKey(((Long)primaryKey).longValue());
420            }
421    
422            /**
423             * Returns the expando column with the primary key or throws a {@link com.liferay.portlet.expando.NoSuchColumnException} if it could not be found.
424             *
425             * @param columnId the primary key of the expando column
426             * @return the expando column
427             * @throws com.liferay.portlet.expando.NoSuchColumnException if a expando column with the primary key could not be found
428             * @throws SystemException if a system exception occurred
429             */
430            public ExpandoColumn findByPrimaryKey(long columnId)
431                    throws NoSuchColumnException, SystemException {
432                    ExpandoColumn expandoColumn = fetchByPrimaryKey(columnId);
433    
434                    if (expandoColumn == null) {
435                            if (_log.isWarnEnabled()) {
436                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + columnId);
437                            }
438    
439                            throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
440                                    columnId);
441                    }
442    
443                    return expandoColumn;
444            }
445    
446            /**
447             * Returns the expando column with the primary key or returns <code>null</code> if it could not be found.
448             *
449             * @param primaryKey the primary key of the expando column
450             * @return the expando column, or <code>null</code> if a expando column with the primary key could not be found
451             * @throws SystemException if a system exception occurred
452             */
453            @Override
454            public ExpandoColumn fetchByPrimaryKey(Serializable primaryKey)
455                    throws SystemException {
456                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
457            }
458    
459            /**
460             * Returns the expando column with the primary key or returns <code>null</code> if it could not be found.
461             *
462             * @param columnId the primary key of the expando column
463             * @return the expando column, or <code>null</code> if a expando column with the primary key could not be found
464             * @throws SystemException if a system exception occurred
465             */
466            public ExpandoColumn fetchByPrimaryKey(long columnId)
467                    throws SystemException {
468                    ExpandoColumn expandoColumn = (ExpandoColumn)EntityCacheUtil.getResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
469                                    ExpandoColumnImpl.class, columnId);
470    
471                    if (expandoColumn == _nullExpandoColumn) {
472                            return null;
473                    }
474    
475                    if (expandoColumn == null) {
476                            Session session = null;
477    
478                            boolean hasException = false;
479    
480                            try {
481                                    session = openSession();
482    
483                                    expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
484                                                    Long.valueOf(columnId));
485                            }
486                            catch (Exception e) {
487                                    hasException = true;
488    
489                                    throw processException(e);
490                            }
491                            finally {
492                                    if (expandoColumn != null) {
493                                            cacheResult(expandoColumn);
494                                    }
495                                    else if (!hasException) {
496                                            EntityCacheUtil.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
497                                                    ExpandoColumnImpl.class, columnId, _nullExpandoColumn);
498                                    }
499    
500                                    closeSession(session);
501                            }
502                    }
503    
504                    return expandoColumn;
505            }
506    
507            /**
508             * Returns all the expando columns where tableId = &#63;.
509             *
510             * @param tableId the table ID
511             * @return the matching expando columns
512             * @throws SystemException if a system exception occurred
513             */
514            public List<ExpandoColumn> findByTableId(long tableId)
515                    throws SystemException {
516                    return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
517            }
518    
519            /**
520             * Returns a range of all the expando columns where tableId = &#63;.
521             *
522             * <p>
523             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
524             * </p>
525             *
526             * @param tableId the table ID
527             * @param start the lower bound of the range of expando columns
528             * @param end the upper bound of the range of expando columns (not inclusive)
529             * @return the range of matching expando columns
530             * @throws SystemException if a system exception occurred
531             */
532            public List<ExpandoColumn> findByTableId(long tableId, int start, int end)
533                    throws SystemException {
534                    return findByTableId(tableId, start, end, null);
535            }
536    
537            /**
538             * Returns an ordered range of all the expando columns where tableId = &#63;.
539             *
540             * <p>
541             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
542             * </p>
543             *
544             * @param tableId the table ID
545             * @param start the lower bound of the range of expando columns
546             * @param end the upper bound of the range of expando columns (not inclusive)
547             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
548             * @return the ordered range of matching expando columns
549             * @throws SystemException if a system exception occurred
550             */
551            public List<ExpandoColumn> findByTableId(long tableId, int start, int end,
552                    OrderByComparator orderByComparator) throws SystemException {
553                    FinderPath finderPath = null;
554                    Object[] finderArgs = null;
555    
556                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
557                                    (orderByComparator == null)) {
558                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
559                            finderArgs = new Object[] { tableId };
560                    }
561                    else {
562                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
563                            finderArgs = new Object[] { tableId, start, end, orderByComparator };
564                    }
565    
566                    List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
567                                    finderArgs, this);
568    
569                    if (list == null) {
570                            StringBundler query = null;
571    
572                            if (orderByComparator != null) {
573                                    query = new StringBundler(3 +
574                                                    (orderByComparator.getOrderByFields().length * 3));
575                            }
576                            else {
577                                    query = new StringBundler(3);
578                            }
579    
580                            query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
581    
582                            query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
583    
584                            if (orderByComparator != null) {
585                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
586                                            orderByComparator);
587                            }
588    
589                            else {
590                                    query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
591                            }
592    
593                            String sql = query.toString();
594    
595                            Session session = null;
596    
597                            try {
598                                    session = openSession();
599    
600                                    Query q = session.createQuery(sql);
601    
602                                    QueryPos qPos = QueryPos.getInstance(q);
603    
604                                    qPos.add(tableId);
605    
606                                    list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
607                                                    start, end);
608                            }
609                            catch (Exception e) {
610                                    throw processException(e);
611                            }
612                            finally {
613                                    if (list == null) {
614                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
615                                    }
616                                    else {
617                                            cacheResult(list);
618    
619                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
620                                    }
621    
622                                    closeSession(session);
623                            }
624                    }
625    
626                    return list;
627            }
628    
629            /**
630             * Returns the first expando column in the ordered set where tableId = &#63;.
631             *
632             * <p>
633             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
634             * </p>
635             *
636             * @param tableId the table ID
637             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
638             * @return the first matching expando column
639             * @throws com.liferay.portlet.expando.NoSuchColumnException if a matching expando column could not be found
640             * @throws SystemException if a system exception occurred
641             */
642            public ExpandoColumn findByTableId_First(long tableId,
643                    OrderByComparator orderByComparator)
644                    throws NoSuchColumnException, SystemException {
645                    List<ExpandoColumn> list = findByTableId(tableId, 0, 1,
646                                    orderByComparator);
647    
648                    if (list.isEmpty()) {
649                            StringBundler msg = new StringBundler(4);
650    
651                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
652    
653                            msg.append("tableId=");
654                            msg.append(tableId);
655    
656                            msg.append(StringPool.CLOSE_CURLY_BRACE);
657    
658                            throw new NoSuchColumnException(msg.toString());
659                    }
660                    else {
661                            return list.get(0);
662                    }
663            }
664    
665            /**
666             * Returns the last expando column in the ordered set where tableId = &#63;.
667             *
668             * <p>
669             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
670             * </p>
671             *
672             * @param tableId the table ID
673             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
674             * @return the last matching expando column
675             * @throws com.liferay.portlet.expando.NoSuchColumnException if a matching expando column could not be found
676             * @throws SystemException if a system exception occurred
677             */
678            public ExpandoColumn findByTableId_Last(long tableId,
679                    OrderByComparator orderByComparator)
680                    throws NoSuchColumnException, SystemException {
681                    int count = countByTableId(tableId);
682    
683                    List<ExpandoColumn> list = findByTableId(tableId, count - 1, count,
684                                    orderByComparator);
685    
686                    if (list.isEmpty()) {
687                            StringBundler msg = new StringBundler(4);
688    
689                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
690    
691                            msg.append("tableId=");
692                            msg.append(tableId);
693    
694                            msg.append(StringPool.CLOSE_CURLY_BRACE);
695    
696                            throw new NoSuchColumnException(msg.toString());
697                    }
698                    else {
699                            return list.get(0);
700                    }
701            }
702    
703            /**
704             * Returns the expando columns before and after the current expando column in the ordered set where tableId = &#63;.
705             *
706             * <p>
707             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
708             * </p>
709             *
710             * @param columnId the primary key of the current expando column
711             * @param tableId the table ID
712             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
713             * @return the previous, current, and next expando column
714             * @throws com.liferay.portlet.expando.NoSuchColumnException if a expando column with the primary key could not be found
715             * @throws SystemException if a system exception occurred
716             */
717            public ExpandoColumn[] findByTableId_PrevAndNext(long columnId,
718                    long tableId, OrderByComparator orderByComparator)
719                    throws NoSuchColumnException, SystemException {
720                    ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
721    
722                    Session session = null;
723    
724                    try {
725                            session = openSession();
726    
727                            ExpandoColumn[] array = new ExpandoColumnImpl[3];
728    
729                            array[0] = getByTableId_PrevAndNext(session, expandoColumn,
730                                            tableId, orderByComparator, true);
731    
732                            array[1] = expandoColumn;
733    
734                            array[2] = getByTableId_PrevAndNext(session, expandoColumn,
735                                            tableId, orderByComparator, false);
736    
737                            return array;
738                    }
739                    catch (Exception e) {
740                            throw processException(e);
741                    }
742                    finally {
743                            closeSession(session);
744                    }
745            }
746    
747            protected ExpandoColumn getByTableId_PrevAndNext(Session session,
748                    ExpandoColumn expandoColumn, long tableId,
749                    OrderByComparator orderByComparator, boolean previous) {
750                    StringBundler query = null;
751    
752                    if (orderByComparator != null) {
753                            query = new StringBundler(6 +
754                                            (orderByComparator.getOrderByFields().length * 6));
755                    }
756                    else {
757                            query = new StringBundler(3);
758                    }
759    
760                    query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
761    
762                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
763    
764                    if (orderByComparator != null) {
765                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
766    
767                            if (orderByConditionFields.length > 0) {
768                                    query.append(WHERE_AND);
769                            }
770    
771                            for (int i = 0; i < orderByConditionFields.length; i++) {
772                                    query.append(_ORDER_BY_ENTITY_ALIAS);
773                                    query.append(orderByConditionFields[i]);
774    
775                                    if ((i + 1) < orderByConditionFields.length) {
776                                            if (orderByComparator.isAscending() ^ previous) {
777                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
778                                            }
779                                            else {
780                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
781                                            }
782                                    }
783                                    else {
784                                            if (orderByComparator.isAscending() ^ previous) {
785                                                    query.append(WHERE_GREATER_THAN);
786                                            }
787                                            else {
788                                                    query.append(WHERE_LESSER_THAN);
789                                            }
790                                    }
791                            }
792    
793                            query.append(ORDER_BY_CLAUSE);
794    
795                            String[] orderByFields = orderByComparator.getOrderByFields();
796    
797                            for (int i = 0; i < orderByFields.length; i++) {
798                                    query.append(_ORDER_BY_ENTITY_ALIAS);
799                                    query.append(orderByFields[i]);
800    
801                                    if ((i + 1) < orderByFields.length) {
802                                            if (orderByComparator.isAscending() ^ previous) {
803                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
804                                            }
805                                            else {
806                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
807                                            }
808                                    }
809                                    else {
810                                            if (orderByComparator.isAscending() ^ previous) {
811                                                    query.append(ORDER_BY_ASC);
812                                            }
813                                            else {
814                                                    query.append(ORDER_BY_DESC);
815                                            }
816                                    }
817                            }
818                    }
819    
820                    else {
821                            query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
822                    }
823    
824                    String sql = query.toString();
825    
826                    Query q = session.createQuery(sql);
827    
828                    q.setFirstResult(0);
829                    q.setMaxResults(2);
830    
831                    QueryPos qPos = QueryPos.getInstance(q);
832    
833                    qPos.add(tableId);
834    
835                    if (orderByComparator != null) {
836                            Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
837    
838                            for (Object value : values) {
839                                    qPos.add(value);
840                            }
841                    }
842    
843                    List<ExpandoColumn> list = q.list();
844    
845                    if (list.size() == 2) {
846                            return list.get(1);
847                    }
848                    else {
849                            return null;
850                    }
851            }
852    
853            /**
854             * Returns all the expando columns that the user has permission to view where tableId = &#63;.
855             *
856             * @param tableId the table ID
857             * @return the matching expando columns that the user has permission to view
858             * @throws SystemException if a system exception occurred
859             */
860            public List<ExpandoColumn> filterFindByTableId(long tableId)
861                    throws SystemException {
862                    return filterFindByTableId(tableId, QueryUtil.ALL_POS,
863                            QueryUtil.ALL_POS, null);
864            }
865    
866            /**
867             * Returns a range of all the expando columns that the user has permission to view where tableId = &#63;.
868             *
869             * <p>
870             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
871             * </p>
872             *
873             * @param tableId the table ID
874             * @param start the lower bound of the range of expando columns
875             * @param end the upper bound of the range of expando columns (not inclusive)
876             * @return the range of matching expando columns that the user has permission to view
877             * @throws SystemException if a system exception occurred
878             */
879            public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
880                    int end) throws SystemException {
881                    return filterFindByTableId(tableId, start, end, null);
882            }
883    
884            /**
885             * Returns an ordered range of all the expando columns that the user has permissions to view where tableId = &#63;.
886             *
887             * <p>
888             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
889             * </p>
890             *
891             * @param tableId the table ID
892             * @param start the lower bound of the range of expando columns
893             * @param end the upper bound of the range of expando columns (not inclusive)
894             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
895             * @return the ordered range of matching expando columns that the user has permission to view
896             * @throws SystemException if a system exception occurred
897             */
898            public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
899                    int end, OrderByComparator orderByComparator) throws SystemException {
900                    if (!InlineSQLHelperUtil.isEnabled()) {
901                            return findByTableId(tableId, start, end, orderByComparator);
902                    }
903    
904                    StringBundler query = null;
905    
906                    if (orderByComparator != null) {
907                            query = new StringBundler(3 +
908                                            (orderByComparator.getOrderByFields().length * 3));
909                    }
910                    else {
911                            query = new StringBundler(3);
912                    }
913    
914                    if (getDB().isSupportsInlineDistinct()) {
915                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
916                    }
917                    else {
918                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
919                    }
920    
921                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
922    
923                    if (!getDB().isSupportsInlineDistinct()) {
924                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
925                    }
926    
927                    if (orderByComparator != null) {
928                            if (getDB().isSupportsInlineDistinct()) {
929                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
930                                            orderByComparator);
931                            }
932                            else {
933                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
934                                            orderByComparator);
935                            }
936                    }
937    
938                    else {
939                            if (getDB().isSupportsInlineDistinct()) {
940                                    query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
941                            }
942                            else {
943                                    query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
944                            }
945                    }
946    
947                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
948                                    ExpandoColumn.class.getName(),
949                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
950    
951                    Session session = null;
952    
953                    try {
954                            session = openSession();
955    
956                            SQLQuery q = session.createSQLQuery(sql);
957    
958                            if (getDB().isSupportsInlineDistinct()) {
959                                    q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
960                            }
961                            else {
962                                    q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
963                            }
964    
965                            QueryPos qPos = QueryPos.getInstance(q);
966    
967                            qPos.add(tableId);
968    
969                            return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
970                                    end);
971                    }
972                    catch (Exception e) {
973                            throw processException(e);
974                    }
975                    finally {
976                            closeSession(session);
977                    }
978            }
979    
980            /**
981             * Returns the expando columns before and after the current expando column in the ordered set of expando columns that the user has permission to view where tableId = &#63;.
982             *
983             * @param columnId the primary key of the current expando column
984             * @param tableId the table ID
985             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
986             * @return the previous, current, and next expando column
987             * @throws com.liferay.portlet.expando.NoSuchColumnException if a expando column with the primary key could not be found
988             * @throws SystemException if a system exception occurred
989             */
990            public ExpandoColumn[] filterFindByTableId_PrevAndNext(long columnId,
991                    long tableId, OrderByComparator orderByComparator)
992                    throws NoSuchColumnException, SystemException {
993                    if (!InlineSQLHelperUtil.isEnabled()) {
994                            return findByTableId_PrevAndNext(columnId, tableId,
995                                    orderByComparator);
996                    }
997    
998                    ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
999    
1000                    Session session = null;
1001    
1002                    try {
1003                            session = openSession();
1004    
1005                            ExpandoColumn[] array = new ExpandoColumnImpl[3];
1006    
1007                            array[0] = filterGetByTableId_PrevAndNext(session, expandoColumn,
1008                                            tableId, orderByComparator, true);
1009    
1010                            array[1] = expandoColumn;
1011    
1012                            array[2] = filterGetByTableId_PrevAndNext(session, expandoColumn,
1013                                            tableId, orderByComparator, false);
1014    
1015                            return array;
1016                    }
1017                    catch (Exception e) {
1018                            throw processException(e);
1019                    }
1020                    finally {
1021                            closeSession(session);
1022                    }
1023            }
1024    
1025            protected ExpandoColumn filterGetByTableId_PrevAndNext(Session session,
1026                    ExpandoColumn expandoColumn, long tableId,
1027                    OrderByComparator orderByComparator, boolean previous) {
1028                    StringBundler query = null;
1029    
1030                    if (orderByComparator != null) {
1031                            query = new StringBundler(6 +
1032                                            (orderByComparator.getOrderByFields().length * 6));
1033                    }
1034                    else {
1035                            query = new StringBundler(3);
1036                    }
1037    
1038                    if (getDB().isSupportsInlineDistinct()) {
1039                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1040                    }
1041                    else {
1042                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
1043                    }
1044    
1045                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
1046    
1047                    if (!getDB().isSupportsInlineDistinct()) {
1048                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
1049                    }
1050    
1051                    if (orderByComparator != null) {
1052                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1053    
1054                            if (orderByConditionFields.length > 0) {
1055                                    query.append(WHERE_AND);
1056                            }
1057    
1058                            for (int i = 0; i < orderByConditionFields.length; i++) {
1059                                    if (getDB().isSupportsInlineDistinct()) {
1060                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1061                                    }
1062                                    else {
1063                                            query.append(_ORDER_BY_ENTITY_TABLE);
1064                                    }
1065    
1066                                    query.append(orderByConditionFields[i]);
1067    
1068                                    if ((i + 1) < orderByConditionFields.length) {
1069                                            if (orderByComparator.isAscending() ^ previous) {
1070                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1071                                            }
1072                                            else {
1073                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1074                                            }
1075                                    }
1076                                    else {
1077                                            if (orderByComparator.isAscending() ^ previous) {
1078                                                    query.append(WHERE_GREATER_THAN);
1079                                            }
1080                                            else {
1081                                                    query.append(WHERE_LESSER_THAN);
1082                                            }
1083                                    }
1084                            }
1085    
1086                            query.append(ORDER_BY_CLAUSE);
1087    
1088                            String[] orderByFields = orderByComparator.getOrderByFields();
1089    
1090                            for (int i = 0; i < orderByFields.length; i++) {
1091                                    if (getDB().isSupportsInlineDistinct()) {
1092                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1093                                    }
1094                                    else {
1095                                            query.append(_ORDER_BY_ENTITY_TABLE);
1096                                    }
1097    
1098                                    query.append(orderByFields[i]);
1099    
1100                                    if ((i + 1) < orderByFields.length) {
1101                                            if (orderByComparator.isAscending() ^ previous) {
1102                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1103                                            }
1104                                            else {
1105                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1106                                            }
1107                                    }
1108                                    else {
1109                                            if (orderByComparator.isAscending() ^ previous) {
1110                                                    query.append(ORDER_BY_ASC);
1111                                            }
1112                                            else {
1113                                                    query.append(ORDER_BY_DESC);
1114                                            }
1115                                    }
1116                            }
1117                    }
1118    
1119                    else {
1120                            if (getDB().isSupportsInlineDistinct()) {
1121                                    query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1122                            }
1123                            else {
1124                                    query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
1125                            }
1126                    }
1127    
1128                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1129                                    ExpandoColumn.class.getName(),
1130                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1131    
1132                    SQLQuery q = session.createSQLQuery(sql);
1133    
1134                    q.setFirstResult(0);
1135                    q.setMaxResults(2);
1136    
1137                    if (getDB().isSupportsInlineDistinct()) {
1138                            q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
1139                    }
1140                    else {
1141                            q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
1142                    }
1143    
1144                    QueryPos qPos = QueryPos.getInstance(q);
1145    
1146                    qPos.add(tableId);
1147    
1148                    if (orderByComparator != null) {
1149                            Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
1150    
1151                            for (Object value : values) {
1152                                    qPos.add(value);
1153                            }
1154                    }
1155    
1156                    List<ExpandoColumn> list = q.list();
1157    
1158                    if (list.size() == 2) {
1159                            return list.get(1);
1160                    }
1161                    else {
1162                            return null;
1163                    }
1164            }
1165    
1166            /**
1167             * Returns all the expando columns where tableId = &#63; and name = &#63;.
1168             *
1169             * @param tableId the table ID
1170             * @param name the name
1171             * @return the matching expando columns
1172             * @throws SystemException if a system exception occurred
1173             */
1174            public List<ExpandoColumn> findByT_N(long tableId, String name)
1175                    throws SystemException {
1176                    return findByT_N(tableId, name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1177                            null);
1178            }
1179    
1180            /**
1181             * Returns a range of all the expando columns where tableId = &#63; and name = &#63;.
1182             *
1183             * <p>
1184             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1185             * </p>
1186             *
1187             * @param tableId the table ID
1188             * @param name the name
1189             * @param start the lower bound of the range of expando columns
1190             * @param end the upper bound of the range of expando columns (not inclusive)
1191             * @return the range of matching expando columns
1192             * @throws SystemException if a system exception occurred
1193             */
1194            public List<ExpandoColumn> findByT_N(long tableId, String name, int start,
1195                    int end) throws SystemException {
1196                    return findByT_N(tableId, name, start, end, null);
1197            }
1198    
1199            /**
1200             * Returns an ordered range of all the expando columns where tableId = &#63; and name = &#63;.
1201             *
1202             * <p>
1203             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1204             * </p>
1205             *
1206             * @param tableId the table ID
1207             * @param name the name
1208             * @param start the lower bound of the range of expando columns
1209             * @param end the upper bound of the range of expando columns (not inclusive)
1210             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1211             * @return the ordered range of matching expando columns
1212             * @throws SystemException if a system exception occurred
1213             */
1214            public List<ExpandoColumn> findByT_N(long tableId, String name, int start,
1215                    int end, OrderByComparator orderByComparator) throws SystemException {
1216                    FinderPath finderPath = null;
1217                    Object[] finderArgs = null;
1218    
1219                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1220                                    (orderByComparator == null)) {
1221                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N;
1222                            finderArgs = new Object[] { tableId, name };
1223                    }
1224                    else {
1225                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N;
1226                            finderArgs = new Object[] {
1227                                            tableId, name,
1228                                            
1229                                            start, end, orderByComparator
1230                                    };
1231                    }
1232    
1233                    List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
1234                                    finderArgs, this);
1235    
1236                    if (list == null) {
1237                            StringBundler query = null;
1238    
1239                            if (orderByComparator != null) {
1240                                    query = new StringBundler(4 +
1241                                                    (orderByComparator.getOrderByFields().length * 3));
1242                            }
1243                            else {
1244                                    query = new StringBundler(4);
1245                            }
1246    
1247                            query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1248    
1249                            query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1250    
1251                            if (name == null) {
1252                                    query.append(_FINDER_COLUMN_T_N_NAME_1);
1253                            }
1254                            else {
1255                                    if (name.equals(StringPool.BLANK)) {
1256                                            query.append(_FINDER_COLUMN_T_N_NAME_3);
1257                                    }
1258                                    else {
1259                                            query.append(_FINDER_COLUMN_T_N_NAME_2);
1260                                    }
1261                            }
1262    
1263                            if (orderByComparator != null) {
1264                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1265                                            orderByComparator);
1266                            }
1267    
1268                            else {
1269                                    query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1270                            }
1271    
1272                            String sql = query.toString();
1273    
1274                            Session session = null;
1275    
1276                            try {
1277                                    session = openSession();
1278    
1279                                    Query q = session.createQuery(sql);
1280    
1281                                    QueryPos qPos = QueryPos.getInstance(q);
1282    
1283                                    qPos.add(tableId);
1284    
1285                                    if (name != null) {
1286                                            qPos.add(name);
1287                                    }
1288    
1289                                    list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1290                                                    start, end);
1291                            }
1292                            catch (Exception e) {
1293                                    throw processException(e);
1294                            }
1295                            finally {
1296                                    if (list == null) {
1297                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1298                                    }
1299                                    else {
1300                                            cacheResult(list);
1301    
1302                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1303                                    }
1304    
1305                                    closeSession(session);
1306                            }
1307                    }
1308    
1309                    return list;
1310            }
1311    
1312            /**
1313             * Returns the first expando column in the ordered set where tableId = &#63; and name = &#63;.
1314             *
1315             * <p>
1316             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1317             * </p>
1318             *
1319             * @param tableId the table ID
1320             * @param name the name
1321             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1322             * @return the first matching expando column
1323             * @throws com.liferay.portlet.expando.NoSuchColumnException if a matching expando column could not be found
1324             * @throws SystemException if a system exception occurred
1325             */
1326            public ExpandoColumn findByT_N_First(long tableId, String name,
1327                    OrderByComparator orderByComparator)
1328                    throws NoSuchColumnException, SystemException {
1329                    List<ExpandoColumn> list = findByT_N(tableId, name, 0, 1,
1330                                    orderByComparator);
1331    
1332                    if (list.isEmpty()) {
1333                            StringBundler msg = new StringBundler(6);
1334    
1335                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1336    
1337                            msg.append("tableId=");
1338                            msg.append(tableId);
1339    
1340                            msg.append(", name=");
1341                            msg.append(name);
1342    
1343                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1344    
1345                            throw new NoSuchColumnException(msg.toString());
1346                    }
1347                    else {
1348                            return list.get(0);
1349                    }
1350            }
1351    
1352            /**
1353             * Returns the last expando column in the ordered set where tableId = &#63; and name = &#63;.
1354             *
1355             * <p>
1356             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1357             * </p>
1358             *
1359             * @param tableId the table ID
1360             * @param name the name
1361             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1362             * @return the last matching expando column
1363             * @throws com.liferay.portlet.expando.NoSuchColumnException if a matching expando column could not be found
1364             * @throws SystemException if a system exception occurred
1365             */
1366            public ExpandoColumn findByT_N_Last(long tableId, String name,
1367                    OrderByComparator orderByComparator)
1368                    throws NoSuchColumnException, SystemException {
1369                    int count = countByT_N(tableId, name);
1370    
1371                    List<ExpandoColumn> list = findByT_N(tableId, name, count - 1, count,
1372                                    orderByComparator);
1373    
1374                    if (list.isEmpty()) {
1375                            StringBundler msg = new StringBundler(6);
1376    
1377                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1378    
1379                            msg.append("tableId=");
1380                            msg.append(tableId);
1381    
1382                            msg.append(", name=");
1383                            msg.append(name);
1384    
1385                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1386    
1387                            throw new NoSuchColumnException(msg.toString());
1388                    }
1389                    else {
1390                            return list.get(0);
1391                    }
1392            }
1393    
1394            /**
1395             * Returns the expando columns before and after the current expando column in the ordered set where tableId = &#63; and name = &#63;.
1396             *
1397             * <p>
1398             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1399             * </p>
1400             *
1401             * @param columnId the primary key of the current expando column
1402             * @param tableId the table ID
1403             * @param name the name
1404             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1405             * @return the previous, current, and next expando column
1406             * @throws com.liferay.portlet.expando.NoSuchColumnException if a expando column with the primary key could not be found
1407             * @throws SystemException if a system exception occurred
1408             */
1409            public ExpandoColumn[] findByT_N_PrevAndNext(long columnId, long tableId,
1410                    String name, OrderByComparator orderByComparator)
1411                    throws NoSuchColumnException, SystemException {
1412                    ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1413    
1414                    Session session = null;
1415    
1416                    try {
1417                            session = openSession();
1418    
1419                            ExpandoColumn[] array = new ExpandoColumnImpl[3];
1420    
1421                            array[0] = getByT_N_PrevAndNext(session, expandoColumn, tableId,
1422                                            name, orderByComparator, true);
1423    
1424                            array[1] = expandoColumn;
1425    
1426                            array[2] = getByT_N_PrevAndNext(session, expandoColumn, tableId,
1427                                            name, orderByComparator, false);
1428    
1429                            return array;
1430                    }
1431                    catch (Exception e) {
1432                            throw processException(e);
1433                    }
1434                    finally {
1435                            closeSession(session);
1436                    }
1437            }
1438    
1439            protected ExpandoColumn getByT_N_PrevAndNext(Session session,
1440                    ExpandoColumn expandoColumn, long tableId, String name,
1441                    OrderByComparator orderByComparator, boolean previous) {
1442                    StringBundler query = null;
1443    
1444                    if (orderByComparator != null) {
1445                            query = new StringBundler(6 +
1446                                            (orderByComparator.getOrderByFields().length * 6));
1447                    }
1448                    else {
1449                            query = new StringBundler(3);
1450                    }
1451    
1452                    query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1453    
1454                    query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1455    
1456                    if (name == null) {
1457                            query.append(_FINDER_COLUMN_T_N_NAME_1);
1458                    }
1459                    else {
1460                            if (name.equals(StringPool.BLANK)) {
1461                                    query.append(_FINDER_COLUMN_T_N_NAME_3);
1462                            }
1463                            else {
1464                                    query.append(_FINDER_COLUMN_T_N_NAME_2);
1465                            }
1466                    }
1467    
1468                    if (orderByComparator != null) {
1469                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1470    
1471                            if (orderByConditionFields.length > 0) {
1472                                    query.append(WHERE_AND);
1473                            }
1474    
1475                            for (int i = 0; i < orderByConditionFields.length; i++) {
1476                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1477                                    query.append(orderByConditionFields[i]);
1478    
1479                                    if ((i + 1) < orderByConditionFields.length) {
1480                                            if (orderByComparator.isAscending() ^ previous) {
1481                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1482                                            }
1483                                            else {
1484                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1485                                            }
1486                                    }
1487                                    else {
1488                                            if (orderByComparator.isAscending() ^ previous) {
1489                                                    query.append(WHERE_GREATER_THAN);
1490                                            }
1491                                            else {
1492                                                    query.append(WHERE_LESSER_THAN);
1493                                            }
1494                                    }
1495                            }
1496    
1497                            query.append(ORDER_BY_CLAUSE);
1498    
1499                            String[] orderByFields = orderByComparator.getOrderByFields();
1500    
1501                            for (int i = 0; i < orderByFields.length; i++) {
1502                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1503                                    query.append(orderByFields[i]);
1504    
1505                                    if ((i + 1) < orderByFields.length) {
1506                                            if (orderByComparator.isAscending() ^ previous) {
1507                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1508                                            }
1509                                            else {
1510                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1511                                            }
1512                                    }
1513                                    else {
1514                                            if (orderByComparator.isAscending() ^ previous) {
1515                                                    query.append(ORDER_BY_ASC);
1516                                            }
1517                                            else {
1518                                                    query.append(ORDER_BY_DESC);
1519                                            }
1520                                    }
1521                            }
1522                    }
1523    
1524                    else {
1525                            query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1526                    }
1527    
1528                    String sql = query.toString();
1529    
1530                    Query q = session.createQuery(sql);
1531    
1532                    q.setFirstResult(0);
1533                    q.setMaxResults(2);
1534    
1535                    QueryPos qPos = QueryPos.getInstance(q);
1536    
1537                    qPos.add(tableId);
1538    
1539                    if (name != null) {
1540                            qPos.add(name);
1541                    }
1542    
1543                    if (orderByComparator != null) {
1544                            Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
1545    
1546                            for (Object value : values) {
1547                                    qPos.add(value);
1548                            }
1549                    }
1550    
1551                    List<ExpandoColumn> list = q.list();
1552    
1553                    if (list.size() == 2) {
1554                            return list.get(1);
1555                    }
1556                    else {
1557                            return null;
1558                    }
1559            }
1560    
1561            /**
1562             * Returns all the expando columns where tableId = &#63; and name = any &#63;.
1563             *
1564             * <p>
1565             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1566             * </p>
1567             *
1568             * @param tableId the table ID
1569             * @param names the names
1570             * @return the matching expando columns
1571             * @throws SystemException if a system exception occurred
1572             */
1573            public List<ExpandoColumn> findByT_N(long tableId, String[] names)
1574                    throws SystemException {
1575                    return findByT_N(tableId, names, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1576                            null);
1577            }
1578    
1579            /**
1580             * Returns a range of all the expando columns where tableId = &#63; and name = any &#63;.
1581             *
1582             * <p>
1583             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1584             * </p>
1585             *
1586             * @param tableId the table ID
1587             * @param names the names
1588             * @param start the lower bound of the range of expando columns
1589             * @param end the upper bound of the range of expando columns (not inclusive)
1590             * @return the range of matching expando columns
1591             * @throws SystemException if a system exception occurred
1592             */
1593            public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1594                    int start, int end) throws SystemException {
1595                    return findByT_N(tableId, names, start, end, null);
1596            }
1597    
1598            /**
1599             * Returns an ordered range of all the expando columns where tableId = &#63; and name = any &#63;.
1600             *
1601             * <p>
1602             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1603             * </p>
1604             *
1605             * @param tableId the table ID
1606             * @param names the names
1607             * @param start the lower bound of the range of expando columns
1608             * @param end the upper bound of the range of expando columns (not inclusive)
1609             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1610             * @return the ordered range of matching expando columns
1611             * @throws SystemException if a system exception occurred
1612             */
1613            public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1614                    int start, int end, OrderByComparator orderByComparator)
1615                    throws SystemException {
1616                    FinderPath finderPath = null;
1617                    Object[] finderArgs = null;
1618    
1619                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1620                                    (orderByComparator == null)) {
1621                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N;
1622                            finderArgs = new Object[] { tableId, StringUtil.merge(names) };
1623                    }
1624                    else {
1625                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N;
1626                            finderArgs = new Object[] {
1627                                            tableId, StringUtil.merge(names),
1628                                            
1629                                            start, end, orderByComparator
1630                                    };
1631                    }
1632    
1633                    List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
1634                                    finderArgs, this);
1635    
1636                    if (list == null) {
1637                            StringBundler query = new StringBundler();
1638    
1639                            query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1640    
1641                            boolean conjunctionable = false;
1642    
1643                            if (conjunctionable) {
1644                                    query.append(WHERE_AND);
1645                            }
1646    
1647                            query.append(_FINDER_COLUMN_T_N_TABLEID_5);
1648    
1649                            conjunctionable = true;
1650    
1651                            if ((names == null) || (names.length > 0)) {
1652                                    if (conjunctionable) {
1653                                            query.append(WHERE_AND);
1654                                    }
1655    
1656                                    query.append(StringPool.OPEN_PARENTHESIS);
1657    
1658                                    for (int i = 0; i < names.length; i++) {
1659                                            String name = names[i];
1660    
1661                                            if (name == null) {
1662                                                    query.append(_FINDER_COLUMN_T_N_NAME_4);
1663                                            }
1664                                            else {
1665                                                    if (name.equals(StringPool.BLANK)) {
1666                                                            query.append(_FINDER_COLUMN_T_N_NAME_6);
1667                                                    }
1668                                                    else {
1669                                                            query.append(_FINDER_COLUMN_T_N_NAME_5);
1670                                                    }
1671                                            }
1672    
1673                                            if ((i + 1) < names.length) {
1674                                                    query.append(WHERE_OR);
1675                                            }
1676                                    }
1677    
1678                                    query.append(StringPool.CLOSE_PARENTHESIS);
1679    
1680                                    conjunctionable = true;
1681                            }
1682    
1683                            if (orderByComparator != null) {
1684                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1685                                            orderByComparator);
1686                            }
1687    
1688                            else {
1689                                    query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1690                            }
1691    
1692                            String sql = query.toString();
1693    
1694                            Session session = null;
1695    
1696                            try {
1697                                    session = openSession();
1698    
1699                                    Query q = session.createQuery(sql);
1700    
1701                                    QueryPos qPos = QueryPos.getInstance(q);
1702    
1703                                    qPos.add(tableId);
1704    
1705                                    if (names != null) {
1706                                            qPos.add(names);
1707                                    }
1708    
1709                                    list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1710                                                    start, end);
1711                            }
1712                            catch (Exception e) {
1713                                    throw processException(e);
1714                            }
1715                            finally {
1716                                    if (list == null) {
1717                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1718                                    }
1719                                    else {
1720                                            cacheResult(list);
1721    
1722                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1723                                    }
1724    
1725                                    closeSession(session);
1726                            }
1727                    }
1728    
1729                    return list;
1730            }
1731    
1732            /**
1733             * Returns all the expando columns that the user has permission to view where tableId = &#63; and name = &#63;.
1734             *
1735             * @param tableId the table ID
1736             * @param name the name
1737             * @return the matching expando columns that the user has permission to view
1738             * @throws SystemException if a system exception occurred
1739             */
1740            public List<ExpandoColumn> filterFindByT_N(long tableId, String name)
1741                    throws SystemException {
1742                    return filterFindByT_N(tableId, name, QueryUtil.ALL_POS,
1743                            QueryUtil.ALL_POS, null);
1744            }
1745    
1746            /**
1747             * Returns a range of all the expando columns that the user has permission to view where tableId = &#63; and name = &#63;.
1748             *
1749             * <p>
1750             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1751             * </p>
1752             *
1753             * @param tableId the table ID
1754             * @param name the name
1755             * @param start the lower bound of the range of expando columns
1756             * @param end the upper bound of the range of expando columns (not inclusive)
1757             * @return the range of matching expando columns that the user has permission to view
1758             * @throws SystemException if a system exception occurred
1759             */
1760            public List<ExpandoColumn> filterFindByT_N(long tableId, String name,
1761                    int start, int end) throws SystemException {
1762                    return filterFindByT_N(tableId, name, start, end, null);
1763            }
1764    
1765            /**
1766             * Returns an ordered range of all the expando columns that the user has permissions to view where tableId = &#63; and name = &#63;.
1767             *
1768             * <p>
1769             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1770             * </p>
1771             *
1772             * @param tableId the table ID
1773             * @param name the name
1774             * @param start the lower bound of the range of expando columns
1775             * @param end the upper bound of the range of expando columns (not inclusive)
1776             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1777             * @return the ordered range of matching expando columns that the user has permission to view
1778             * @throws SystemException if a system exception occurred
1779             */
1780            public List<ExpandoColumn> filterFindByT_N(long tableId, String name,
1781                    int start, int end, OrderByComparator orderByComparator)
1782                    throws SystemException {
1783                    if (!InlineSQLHelperUtil.isEnabled()) {
1784                            return findByT_N(tableId, name, start, end, orderByComparator);
1785                    }
1786    
1787                    StringBundler query = null;
1788    
1789                    if (orderByComparator != null) {
1790                            query = new StringBundler(4 +
1791                                            (orderByComparator.getOrderByFields().length * 3));
1792                    }
1793                    else {
1794                            query = new StringBundler(4);
1795                    }
1796    
1797                    if (getDB().isSupportsInlineDistinct()) {
1798                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1799                    }
1800                    else {
1801                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
1802                    }
1803    
1804                    query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1805    
1806                    if (name == null) {
1807                            query.append(_FINDER_COLUMN_T_N_NAME_1);
1808                    }
1809                    else {
1810                            if (name.equals(StringPool.BLANK)) {
1811                                    query.append(_FINDER_COLUMN_T_N_NAME_3);
1812                            }
1813                            else {
1814                                    query.append(_FINDER_COLUMN_T_N_NAME_2);
1815                            }
1816                    }
1817    
1818                    if (!getDB().isSupportsInlineDistinct()) {
1819                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
1820                    }
1821    
1822                    if (orderByComparator != null) {
1823                            if (getDB().isSupportsInlineDistinct()) {
1824                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1825                                            orderByComparator);
1826                            }
1827                            else {
1828                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1829                                            orderByComparator);
1830                            }
1831                    }
1832    
1833                    else {
1834                            if (getDB().isSupportsInlineDistinct()) {
1835                                    query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1836                            }
1837                            else {
1838                                    query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
1839                            }
1840                    }
1841    
1842                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1843                                    ExpandoColumn.class.getName(),
1844                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1845    
1846                    Session session = null;
1847    
1848                    try {
1849                            session = openSession();
1850    
1851                            SQLQuery q = session.createSQLQuery(sql);
1852    
1853                            if (getDB().isSupportsInlineDistinct()) {
1854                                    q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
1855                            }
1856                            else {
1857                                    q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
1858                            }
1859    
1860                            QueryPos qPos = QueryPos.getInstance(q);
1861    
1862                            qPos.add(tableId);
1863    
1864                            if (name != null) {
1865                                    qPos.add(name);
1866                            }
1867    
1868                            return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
1869                                    end);
1870                    }
1871                    catch (Exception e) {
1872                            throw processException(e);
1873                    }
1874                    finally {
1875                            closeSession(session);
1876                    }
1877            }
1878    
1879            /**
1880             * Returns the expando columns before and after the current expando column in the ordered set of expando columns that the user has permission to view where tableId = &#63; and name = &#63;.
1881             *
1882             * @param columnId the primary key of the current expando column
1883             * @param tableId the table ID
1884             * @param name the name
1885             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1886             * @return the previous, current, and next expando column
1887             * @throws com.liferay.portlet.expando.NoSuchColumnException if a expando column with the primary key could not be found
1888             * @throws SystemException if a system exception occurred
1889             */
1890            public ExpandoColumn[] filterFindByT_N_PrevAndNext(long columnId,
1891                    long tableId, String name, OrderByComparator orderByComparator)
1892                    throws NoSuchColumnException, SystemException {
1893                    if (!InlineSQLHelperUtil.isEnabled()) {
1894                            return findByT_N_PrevAndNext(columnId, tableId, name,
1895                                    orderByComparator);
1896                    }
1897    
1898                    ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
1899    
1900                    Session session = null;
1901    
1902                    try {
1903                            session = openSession();
1904    
1905                            ExpandoColumn[] array = new ExpandoColumnImpl[3];
1906    
1907                            array[0] = filterGetByT_N_PrevAndNext(session, expandoColumn,
1908                                            tableId, name, orderByComparator, true);
1909    
1910                            array[1] = expandoColumn;
1911    
1912                            array[2] = filterGetByT_N_PrevAndNext(session, expandoColumn,
1913                                            tableId, name, orderByComparator, false);
1914    
1915                            return array;
1916                    }
1917                    catch (Exception e) {
1918                            throw processException(e);
1919                    }
1920                    finally {
1921                            closeSession(session);
1922                    }
1923            }
1924    
1925            protected ExpandoColumn filterGetByT_N_PrevAndNext(Session session,
1926                    ExpandoColumn expandoColumn, long tableId, String name,
1927                    OrderByComparator orderByComparator, boolean previous) {
1928                    StringBundler query = null;
1929    
1930                    if (orderByComparator != null) {
1931                            query = new StringBundler(6 +
1932                                            (orderByComparator.getOrderByFields().length * 6));
1933                    }
1934                    else {
1935                            query = new StringBundler(3);
1936                    }
1937    
1938                    if (getDB().isSupportsInlineDistinct()) {
1939                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1940                    }
1941                    else {
1942                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
1943                    }
1944    
1945                    query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1946    
1947                    if (name == null) {
1948                            query.append(_FINDER_COLUMN_T_N_NAME_1);
1949                    }
1950                    else {
1951                            if (name.equals(StringPool.BLANK)) {
1952                                    query.append(_FINDER_COLUMN_T_N_NAME_3);
1953                            }
1954                            else {
1955                                    query.append(_FINDER_COLUMN_T_N_NAME_2);
1956                            }
1957                    }
1958    
1959                    if (!getDB().isSupportsInlineDistinct()) {
1960                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
1961                    }
1962    
1963                    if (orderByComparator != null) {
1964                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1965    
1966                            if (orderByConditionFields.length > 0) {
1967                                    query.append(WHERE_AND);
1968                            }
1969    
1970                            for (int i = 0; i < orderByConditionFields.length; i++) {
1971                                    if (getDB().isSupportsInlineDistinct()) {
1972                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1973                                    }
1974                                    else {
1975                                            query.append(_ORDER_BY_ENTITY_TABLE);
1976                                    }
1977    
1978                                    query.append(orderByConditionFields[i]);
1979    
1980                                    if ((i + 1) < orderByConditionFields.length) {
1981                                            if (orderByComparator.isAscending() ^ previous) {
1982                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1983                                            }
1984                                            else {
1985                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1986                                            }
1987                                    }
1988                                    else {
1989                                            if (orderByComparator.isAscending() ^ previous) {
1990                                                    query.append(WHERE_GREATER_THAN);
1991                                            }
1992                                            else {
1993                                                    query.append(WHERE_LESSER_THAN);
1994                                            }
1995                                    }
1996                            }
1997    
1998                            query.append(ORDER_BY_CLAUSE);
1999    
2000                            String[] orderByFields = orderByComparator.getOrderByFields();
2001    
2002                            for (int i = 0; i < orderByFields.length; i++) {
2003                                    if (getDB().isSupportsInlineDistinct()) {
2004                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2005                                    }
2006                                    else {
2007                                            query.append(_ORDER_BY_ENTITY_TABLE);
2008                                    }
2009    
2010                                    query.append(orderByFields[i]);
2011    
2012                                    if ((i + 1) < orderByFields.length) {
2013                                            if (orderByComparator.isAscending() ^ previous) {
2014                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2015                                            }
2016                                            else {
2017                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2018                                            }
2019                                    }
2020                                    else {
2021                                            if (orderByComparator.isAscending() ^ previous) {
2022                                                    query.append(ORDER_BY_ASC);
2023                                            }
2024                                            else {
2025                                                    query.append(ORDER_BY_DESC);
2026                                            }
2027                                    }
2028                            }
2029                    }
2030    
2031                    else {
2032                            if (getDB().isSupportsInlineDistinct()) {
2033                                    query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2034                            }
2035                            else {
2036                                    query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
2037                            }
2038                    }
2039    
2040                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2041                                    ExpandoColumn.class.getName(),
2042                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2043    
2044                    SQLQuery q = session.createSQLQuery(sql);
2045    
2046                    q.setFirstResult(0);
2047                    q.setMaxResults(2);
2048    
2049                    if (getDB().isSupportsInlineDistinct()) {
2050                            q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
2051                    }
2052                    else {
2053                            q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
2054                    }
2055    
2056                    QueryPos qPos = QueryPos.getInstance(q);
2057    
2058                    qPos.add(tableId);
2059    
2060                    if (name != null) {
2061                            qPos.add(name);
2062                    }
2063    
2064                    if (orderByComparator != null) {
2065                            Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
2066    
2067                            for (Object value : values) {
2068                                    qPos.add(value);
2069                            }
2070                    }
2071    
2072                    List<ExpandoColumn> list = q.list();
2073    
2074                    if (list.size() == 2) {
2075                            return list.get(1);
2076                    }
2077                    else {
2078                            return null;
2079                    }
2080            }
2081    
2082            /**
2083             * Returns all the expando columns that the user has permission to view where tableId = &#63; and name = any &#63;.
2084             *
2085             * @param tableId the table ID
2086             * @param names the names
2087             * @return the matching expando columns that the user has permission to view
2088             * @throws SystemException if a system exception occurred
2089             */
2090            public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names)
2091                    throws SystemException {
2092                    return filterFindByT_N(tableId, names, QueryUtil.ALL_POS,
2093                            QueryUtil.ALL_POS, null);
2094            }
2095    
2096            /**
2097             * Returns a range of all the expando columns that the user has permission to view where tableId = &#63; and name = any &#63;.
2098             *
2099             * <p>
2100             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2101             * </p>
2102             *
2103             * @param tableId the table ID
2104             * @param names the names
2105             * @param start the lower bound of the range of expando columns
2106             * @param end the upper bound of the range of expando columns (not inclusive)
2107             * @return the range of matching expando columns that the user has permission to view
2108             * @throws SystemException if a system exception occurred
2109             */
2110            public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names,
2111                    int start, int end) throws SystemException {
2112                    return filterFindByT_N(tableId, names, start, end, null);
2113            }
2114    
2115            /**
2116             * Returns an ordered range of all the expando columns that the user has permission to view where tableId = &#63; and name = any &#63;.
2117             *
2118             * <p>
2119             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2120             * </p>
2121             *
2122             * @param tableId the table ID
2123             * @param names the names
2124             * @param start the lower bound of the range of expando columns
2125             * @param end the upper bound of the range of expando columns (not inclusive)
2126             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2127             * @return the ordered range of matching expando columns that the user has permission to view
2128             * @throws SystemException if a system exception occurred
2129             */
2130            public List<ExpandoColumn> filterFindByT_N(long tableId, String[] names,
2131                    int start, int end, OrderByComparator orderByComparator)
2132                    throws SystemException {
2133                    if (!InlineSQLHelperUtil.isEnabled()) {
2134                            return findByT_N(tableId, names, start, end, orderByComparator);
2135                    }
2136    
2137                    StringBundler query = new StringBundler();
2138    
2139                    if (getDB().isSupportsInlineDistinct()) {
2140                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
2141                    }
2142                    else {
2143                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
2144                    }
2145    
2146                    boolean conjunctionable = false;
2147    
2148                    if (conjunctionable) {
2149                            query.append(WHERE_AND);
2150                    }
2151    
2152                    query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2153    
2154                    conjunctionable = true;
2155    
2156                    if ((names == null) || (names.length > 0)) {
2157                            if (conjunctionable) {
2158                                    query.append(WHERE_AND);
2159                            }
2160    
2161                            query.append(StringPool.OPEN_PARENTHESIS);
2162    
2163                            for (int i = 0; i < names.length; i++) {
2164                                    String name = names[i];
2165    
2166                                    if (name == null) {
2167                                            query.append(_FINDER_COLUMN_T_N_NAME_4);
2168                                    }
2169                                    else {
2170                                            if (name.equals(StringPool.BLANK)) {
2171                                                    query.append(_FINDER_COLUMN_T_N_NAME_6);
2172                                            }
2173                                            else {
2174                                                    query.append(_FINDER_COLUMN_T_N_NAME_5);
2175                                            }
2176                                    }
2177    
2178                                    if ((i + 1) < names.length) {
2179                                            query.append(WHERE_OR);
2180                                    }
2181                            }
2182    
2183                            query.append(StringPool.CLOSE_PARENTHESIS);
2184    
2185                            conjunctionable = true;
2186                    }
2187    
2188                    if (!getDB().isSupportsInlineDistinct()) {
2189                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
2190                    }
2191    
2192                    if (orderByComparator != null) {
2193                            if (getDB().isSupportsInlineDistinct()) {
2194                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2195                                            orderByComparator);
2196                            }
2197                            else {
2198                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2199                                            orderByComparator);
2200                            }
2201                    }
2202    
2203                    else {
2204                            if (getDB().isSupportsInlineDistinct()) {
2205                                    query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2206                            }
2207                            else {
2208                                    query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
2209                            }
2210                    }
2211    
2212                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2213                                    ExpandoColumn.class.getName(),
2214                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2215    
2216                    Session session = null;
2217    
2218                    try {
2219                            session = openSession();
2220    
2221                            SQLQuery q = session.createSQLQuery(sql);
2222    
2223                            if (getDB().isSupportsInlineDistinct()) {
2224                                    q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
2225                            }
2226                            else {
2227                                    q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
2228                            }
2229    
2230                            QueryPos qPos = QueryPos.getInstance(q);
2231    
2232                            qPos.add(tableId);
2233    
2234                            if (names != null) {
2235                                    qPos.add(names);
2236                            }
2237    
2238                            return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
2239                                    end);
2240                    }
2241                    catch (Exception e) {
2242                            throw processException(e);
2243                    }
2244                    finally {
2245                            closeSession(session);
2246                    }
2247            }
2248    
2249            /**
2250             * Returns all the expando columns.
2251             *
2252             * @return the expando columns
2253             * @throws SystemException if a system exception occurred
2254             */
2255            public List<ExpandoColumn> findAll() throws SystemException {
2256                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2257            }
2258    
2259            /**
2260             * Returns a range of all the expando columns.
2261             *
2262             * <p>
2263             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2264             * </p>
2265             *
2266             * @param start the lower bound of the range of expando columns
2267             * @param end the upper bound of the range of expando columns (not inclusive)
2268             * @return the range of expando columns
2269             * @throws SystemException if a system exception occurred
2270             */
2271            public List<ExpandoColumn> findAll(int start, int end)
2272                    throws SystemException {
2273                    return findAll(start, end, null);
2274            }
2275    
2276            /**
2277             * Returns an ordered range of all the expando columns.
2278             *
2279             * <p>
2280             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2281             * </p>
2282             *
2283             * @param start the lower bound of the range of expando columns
2284             * @param end the upper bound of the range of expando columns (not inclusive)
2285             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2286             * @return the ordered range of expando columns
2287             * @throws SystemException if a system exception occurred
2288             */
2289            public List<ExpandoColumn> findAll(int start, int end,
2290                    OrderByComparator orderByComparator) throws SystemException {
2291                    FinderPath finderPath = null;
2292                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2293    
2294                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2295                                    (orderByComparator == null)) {
2296                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2297                            finderArgs = FINDER_ARGS_EMPTY;
2298                    }
2299                    else {
2300                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2301                            finderArgs = new Object[] { start, end, orderByComparator };
2302                    }
2303    
2304                    List<ExpandoColumn> list = (List<ExpandoColumn>)FinderCacheUtil.getResult(finderPath,
2305                                    finderArgs, this);
2306    
2307                    if (list == null) {
2308                            StringBundler query = null;
2309                            String sql = null;
2310    
2311                            if (orderByComparator != null) {
2312                                    query = new StringBundler(2 +
2313                                                    (orderByComparator.getOrderByFields().length * 3));
2314    
2315                                    query.append(_SQL_SELECT_EXPANDOCOLUMN);
2316    
2317                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2318                                            orderByComparator);
2319    
2320                                    sql = query.toString();
2321                            }
2322                            else {
2323                                    sql = _SQL_SELECT_EXPANDOCOLUMN.concat(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2324                            }
2325    
2326                            Session session = null;
2327    
2328                            try {
2329                                    session = openSession();
2330    
2331                                    Query q = session.createQuery(sql);
2332    
2333                                    if (orderByComparator == null) {
2334                                            list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2335                                                            start, end, false);
2336    
2337                                            Collections.sort(list);
2338                                    }
2339                                    else {
2340                                            list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2341                                                            start, end);
2342                                    }
2343                            }
2344                            catch (Exception e) {
2345                                    throw processException(e);
2346                            }
2347                            finally {
2348                                    if (list == null) {
2349                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2350                                    }
2351                                    else {
2352                                            cacheResult(list);
2353    
2354                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2355                                    }
2356    
2357                                    closeSession(session);
2358                            }
2359                    }
2360    
2361                    return list;
2362            }
2363    
2364            /**
2365             * Removes all the expando columns where tableId = &#63; from the database.
2366             *
2367             * @param tableId the table ID
2368             * @throws SystemException if a system exception occurred
2369             */
2370            public void removeByTableId(long tableId) throws SystemException {
2371                    for (ExpandoColumn expandoColumn : findByTableId(tableId)) {
2372                            remove(expandoColumn);
2373                    }
2374            }
2375    
2376            /**
2377             * Removes all the expando columns where tableId = &#63; and name = &#63; from the database.
2378             *
2379             * @param tableId the table ID
2380             * @param name the name
2381             * @throws SystemException if a system exception occurred
2382             */
2383            public void removeByT_N(long tableId, String name)
2384                    throws SystemException {
2385                    for (ExpandoColumn expandoColumn : findByT_N(tableId, name)) {
2386                            remove(expandoColumn);
2387                    }
2388            }
2389    
2390            /**
2391             * Removes all the expando columns from the database.
2392             *
2393             * @throws SystemException if a system exception occurred
2394             */
2395            public void removeAll() throws SystemException {
2396                    for (ExpandoColumn expandoColumn : findAll()) {
2397                            remove(expandoColumn);
2398                    }
2399            }
2400    
2401            /**
2402             * Returns the number of expando columns where tableId = &#63;.
2403             *
2404             * @param tableId the table ID
2405             * @return the number of matching expando columns
2406             * @throws SystemException if a system exception occurred
2407             */
2408            public int countByTableId(long tableId) throws SystemException {
2409                    Object[] finderArgs = new Object[] { tableId };
2410    
2411                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TABLEID,
2412                                    finderArgs, this);
2413    
2414                    if (count == null) {
2415                            StringBundler query = new StringBundler(2);
2416    
2417                            query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2418    
2419                            query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
2420    
2421                            String sql = query.toString();
2422    
2423                            Session session = null;
2424    
2425                            try {
2426                                    session = openSession();
2427    
2428                                    Query q = session.createQuery(sql);
2429    
2430                                    QueryPos qPos = QueryPos.getInstance(q);
2431    
2432                                    qPos.add(tableId);
2433    
2434                                    count = (Long)q.uniqueResult();
2435                            }
2436                            catch (Exception e) {
2437                                    throw processException(e);
2438                            }
2439                            finally {
2440                                    if (count == null) {
2441                                            count = Long.valueOf(0);
2442                                    }
2443    
2444                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TABLEID,
2445                                            finderArgs, count);
2446    
2447                                    closeSession(session);
2448                            }
2449                    }
2450    
2451                    return count.intValue();
2452            }
2453    
2454            /**
2455             * Returns the number of expando columns that the user has permission to view where tableId = &#63;.
2456             *
2457             * @param tableId the table ID
2458             * @return the number of matching expando columns that the user has permission to view
2459             * @throws SystemException if a system exception occurred
2460             */
2461            public int filterCountByTableId(long tableId) throws SystemException {
2462                    if (!InlineSQLHelperUtil.isEnabled()) {
2463                            return countByTableId(tableId);
2464                    }
2465    
2466                    StringBundler query = new StringBundler(2);
2467    
2468                    query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2469    
2470                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
2471    
2472                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2473                                    ExpandoColumn.class.getName(),
2474                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2475    
2476                    Session session = null;
2477    
2478                    try {
2479                            session = openSession();
2480    
2481                            SQLQuery q = session.createSQLQuery(sql);
2482    
2483                            q.addScalar(COUNT_COLUMN_NAME,
2484                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2485    
2486                            QueryPos qPos = QueryPos.getInstance(q);
2487    
2488                            qPos.add(tableId);
2489    
2490                            Long count = (Long)q.uniqueResult();
2491    
2492                            return count.intValue();
2493                    }
2494                    catch (Exception e) {
2495                            throw processException(e);
2496                    }
2497                    finally {
2498                            closeSession(session);
2499                    }
2500            }
2501    
2502            /**
2503             * Returns the number of expando columns where tableId = &#63; and name = &#63;.
2504             *
2505             * @param tableId the table ID
2506             * @param name the name
2507             * @return the number of matching expando columns
2508             * @throws SystemException if a system exception occurred
2509             */
2510            public int countByT_N(long tableId, String name) throws SystemException {
2511                    Object[] finderArgs = new Object[] { tableId, name };
2512    
2513                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_N,
2514                                    finderArgs, this);
2515    
2516                    if (count == null) {
2517                            StringBundler query = new StringBundler(3);
2518    
2519                            query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2520    
2521                            query.append(_FINDER_COLUMN_T_N_TABLEID_2);
2522    
2523                            if (name == null) {
2524                                    query.append(_FINDER_COLUMN_T_N_NAME_1);
2525                            }
2526                            else {
2527                                    if (name.equals(StringPool.BLANK)) {
2528                                            query.append(_FINDER_COLUMN_T_N_NAME_3);
2529                                    }
2530                                    else {
2531                                            query.append(_FINDER_COLUMN_T_N_NAME_2);
2532                                    }
2533                            }
2534    
2535                            String sql = query.toString();
2536    
2537                            Session session = null;
2538    
2539                            try {
2540                                    session = openSession();
2541    
2542                                    Query q = session.createQuery(sql);
2543    
2544                                    QueryPos qPos = QueryPos.getInstance(q);
2545    
2546                                    qPos.add(tableId);
2547    
2548                                    if (name != null) {
2549                                            qPos.add(name);
2550                                    }
2551    
2552                                    count = (Long)q.uniqueResult();
2553                            }
2554                            catch (Exception e) {
2555                                    throw processException(e);
2556                            }
2557                            finally {
2558                                    if (count == null) {
2559                                            count = Long.valueOf(0);
2560                                    }
2561    
2562                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_N, finderArgs,
2563                                            count);
2564    
2565                                    closeSession(session);
2566                            }
2567                    }
2568    
2569                    return count.intValue();
2570            }
2571    
2572            /**
2573             * Returns the number of expando columns where tableId = &#63; and name = any &#63;.
2574             *
2575             * @param tableId the table ID
2576             * @param names the names
2577             * @return the number of matching expando columns
2578             * @throws SystemException if a system exception occurred
2579             */
2580            public int countByT_N(long tableId, String[] names)
2581                    throws SystemException {
2582                    Object[] finderArgs = new Object[] { tableId, StringUtil.merge(names) };
2583    
2584                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_N,
2585                                    finderArgs, this);
2586    
2587                    if (count == null) {
2588                            StringBundler query = new StringBundler();
2589    
2590                            query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2591    
2592                            boolean conjunctionable = false;
2593    
2594                            if (conjunctionable) {
2595                                    query.append(WHERE_AND);
2596                            }
2597    
2598                            query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2599    
2600                            conjunctionable = true;
2601    
2602                            if ((names == null) || (names.length > 0)) {
2603                                    if (conjunctionable) {
2604                                            query.append(WHERE_AND);
2605                                    }
2606    
2607                                    query.append(StringPool.OPEN_PARENTHESIS);
2608    
2609                                    for (int i = 0; i < names.length; i++) {
2610                                            String name = names[i];
2611    
2612                                            if (name == null) {
2613                                                    query.append(_FINDER_COLUMN_T_N_NAME_4);
2614                                            }
2615                                            else {
2616                                                    if (name.equals(StringPool.BLANK)) {
2617                                                            query.append(_FINDER_COLUMN_T_N_NAME_6);
2618                                                    }
2619                                                    else {
2620                                                            query.append(_FINDER_COLUMN_T_N_NAME_5);
2621                                                    }
2622                                            }
2623    
2624                                            if ((i + 1) < names.length) {
2625                                                    query.append(WHERE_OR);
2626                                            }
2627                                    }
2628    
2629                                    query.append(StringPool.CLOSE_PARENTHESIS);
2630    
2631                                    conjunctionable = true;
2632                            }
2633    
2634                            String sql = query.toString();
2635    
2636                            Session session = null;
2637    
2638                            try {
2639                                    session = openSession();
2640    
2641                                    Query q = session.createQuery(sql);
2642    
2643                                    QueryPos qPos = QueryPos.getInstance(q);
2644    
2645                                    qPos.add(tableId);
2646    
2647                                    if (names != null) {
2648                                            qPos.add(names);
2649                                    }
2650    
2651                                    count = (Long)q.uniqueResult();
2652                            }
2653                            catch (Exception e) {
2654                                    throw processException(e);
2655                            }
2656                            finally {
2657                                    if (count == null) {
2658                                            count = Long.valueOf(0);
2659                                    }
2660    
2661                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_N, finderArgs,
2662                                            count);
2663    
2664                                    closeSession(session);
2665                            }
2666                    }
2667    
2668                    return count.intValue();
2669            }
2670    
2671            /**
2672             * Returns the number of expando columns that the user has permission to view where tableId = &#63; and name = &#63;.
2673             *
2674             * @param tableId the table ID
2675             * @param name the name
2676             * @return the number of matching expando columns that the user has permission to view
2677             * @throws SystemException if a system exception occurred
2678             */
2679            public int filterCountByT_N(long tableId, String name)
2680                    throws SystemException {
2681                    if (!InlineSQLHelperUtil.isEnabled()) {
2682                            return countByT_N(tableId, name);
2683                    }
2684    
2685                    StringBundler query = new StringBundler(3);
2686    
2687                    query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2688    
2689                    query.append(_FINDER_COLUMN_T_N_TABLEID_2);
2690    
2691                    if (name == null) {
2692                            query.append(_FINDER_COLUMN_T_N_NAME_1);
2693                    }
2694                    else {
2695                            if (name.equals(StringPool.BLANK)) {
2696                                    query.append(_FINDER_COLUMN_T_N_NAME_3);
2697                            }
2698                            else {
2699                                    query.append(_FINDER_COLUMN_T_N_NAME_2);
2700                            }
2701                    }
2702    
2703                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2704                                    ExpandoColumn.class.getName(),
2705                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2706    
2707                    Session session = null;
2708    
2709                    try {
2710                            session = openSession();
2711    
2712                            SQLQuery q = session.createSQLQuery(sql);
2713    
2714                            q.addScalar(COUNT_COLUMN_NAME,
2715                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2716    
2717                            QueryPos qPos = QueryPos.getInstance(q);
2718    
2719                            qPos.add(tableId);
2720    
2721                            if (name != null) {
2722                                    qPos.add(name);
2723                            }
2724    
2725                            Long count = (Long)q.uniqueResult();
2726    
2727                            return count.intValue();
2728                    }
2729                    catch (Exception e) {
2730                            throw processException(e);
2731                    }
2732                    finally {
2733                            closeSession(session);
2734                    }
2735            }
2736    
2737            /**
2738             * Returns the number of expando columns that the user has permission to view where tableId = &#63; and name = any &#63;.
2739             *
2740             * @param tableId the table ID
2741             * @param names the names
2742             * @return the number of matching expando columns that the user has permission to view
2743             * @throws SystemException if a system exception occurred
2744             */
2745            public int filterCountByT_N(long tableId, String[] names)
2746                    throws SystemException {
2747                    if (!InlineSQLHelperUtil.isEnabled()) {
2748                            return countByT_N(tableId, names);
2749                    }
2750    
2751                    StringBundler query = new StringBundler();
2752    
2753                    query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
2754    
2755                    boolean conjunctionable = false;
2756    
2757                    if (conjunctionable) {
2758                            query.append(WHERE_AND);
2759                    }
2760    
2761                    query.append(_FINDER_COLUMN_T_N_TABLEID_5);
2762    
2763                    conjunctionable = true;
2764    
2765                    if ((names == null) || (names.length > 0)) {
2766                            if (conjunctionable) {
2767                                    query.append(WHERE_AND);
2768                            }
2769    
2770                            query.append(StringPool.OPEN_PARENTHESIS);
2771    
2772                            for (int i = 0; i < names.length; i++) {
2773                                    String name = names[i];
2774    
2775                                    if (name == null) {
2776                                            query.append(_FINDER_COLUMN_T_N_NAME_4);
2777                                    }
2778                                    else {
2779                                            if (name.equals(StringPool.BLANK)) {
2780                                                    query.append(_FINDER_COLUMN_T_N_NAME_6);
2781                                            }
2782                                            else {
2783                                                    query.append(_FINDER_COLUMN_T_N_NAME_5);
2784                                            }
2785                                    }
2786    
2787                                    if ((i + 1) < names.length) {
2788                                            query.append(WHERE_OR);
2789                                    }
2790                            }
2791    
2792                            query.append(StringPool.CLOSE_PARENTHESIS);
2793    
2794                            conjunctionable = true;
2795                    }
2796    
2797                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2798                                    ExpandoColumn.class.getName(),
2799                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2800    
2801                    Session session = null;
2802    
2803                    try {
2804                            session = openSession();
2805    
2806                            SQLQuery q = session.createSQLQuery(sql);
2807    
2808                            q.addScalar(COUNT_COLUMN_NAME,
2809                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2810    
2811                            QueryPos qPos = QueryPos.getInstance(q);
2812    
2813                            qPos.add(tableId);
2814    
2815                            if (names != null) {
2816                                    qPos.add(names);
2817                            }
2818    
2819                            Long count = (Long)q.uniqueResult();
2820    
2821                            return count.intValue();
2822                    }
2823                    catch (Exception e) {
2824                            throw processException(e);
2825                    }
2826                    finally {
2827                            closeSession(session);
2828                    }
2829            }
2830    
2831            /**
2832             * Returns the number of expando columns.
2833             *
2834             * @return the number of expando columns
2835             * @throws SystemException if a system exception occurred
2836             */
2837            public int countAll() throws SystemException {
2838                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2839                                    FINDER_ARGS_EMPTY, this);
2840    
2841                    if (count == null) {
2842                            Session session = null;
2843    
2844                            try {
2845                                    session = openSession();
2846    
2847                                    Query q = session.createQuery(_SQL_COUNT_EXPANDOCOLUMN);
2848    
2849                                    count = (Long)q.uniqueResult();
2850                            }
2851                            catch (Exception e) {
2852                                    throw processException(e);
2853                            }
2854                            finally {
2855                                    if (count == null) {
2856                                            count = Long.valueOf(0);
2857                                    }
2858    
2859                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2860                                            FINDER_ARGS_EMPTY, count);
2861    
2862                                    closeSession(session);
2863                            }
2864                    }
2865    
2866                    return count.intValue();
2867            }
2868    
2869            /**
2870             * Initializes the expando column persistence.
2871             */
2872            public void afterPropertiesSet() {
2873                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2874                                            com.liferay.portal.util.PropsUtil.get(
2875                                                    "value.object.listener.com.liferay.portlet.expando.model.ExpandoColumn")));
2876    
2877                    if (listenerClassNames.length > 0) {
2878                            try {
2879                                    List<ModelListener<ExpandoColumn>> listenersList = new ArrayList<ModelListener<ExpandoColumn>>();
2880    
2881                                    for (String listenerClassName : listenerClassNames) {
2882                                            listenersList.add((ModelListener<ExpandoColumn>)InstanceFactory.newInstance(
2883                                                            listenerClassName));
2884                                    }
2885    
2886                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2887                            }
2888                            catch (Exception e) {
2889                                    _log.error(e);
2890                            }
2891                    }
2892            }
2893    
2894            public void destroy() {
2895                    EntityCacheUtil.removeCache(ExpandoColumnImpl.class.getName());
2896                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2897                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2898            }
2899    
2900            @BeanReference(type = ExpandoColumnPersistence.class)
2901            protected ExpandoColumnPersistence expandoColumnPersistence;
2902            @BeanReference(type = ExpandoRowPersistence.class)
2903            protected ExpandoRowPersistence expandoRowPersistence;
2904            @BeanReference(type = ExpandoTablePersistence.class)
2905            protected ExpandoTablePersistence expandoTablePersistence;
2906            @BeanReference(type = ExpandoValuePersistence.class)
2907            protected ExpandoValuePersistence expandoValuePersistence;
2908            @BeanReference(type = ResourcePersistence.class)
2909            protected ResourcePersistence resourcePersistence;
2910            @BeanReference(type = UserPersistence.class)
2911            protected UserPersistence userPersistence;
2912            private static final String _SQL_SELECT_EXPANDOCOLUMN = "SELECT expandoColumn FROM ExpandoColumn expandoColumn";
2913            private static final String _SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT expandoColumn FROM ExpandoColumn expandoColumn WHERE ";
2914            private static final String _SQL_COUNT_EXPANDOCOLUMN = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn";
2915            private static final String _SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn WHERE ";
2916            private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoColumn.tableId = ?";
2917            private static final String _FINDER_COLUMN_T_N_TABLEID_2 = "expandoColumn.tableId = ? AND ";
2918            private static final String _FINDER_COLUMN_T_N_TABLEID_5 = "(" +
2919                    _removeConjunction(_FINDER_COLUMN_T_N_TABLEID_2) + ")";
2920            private static final String _FINDER_COLUMN_T_N_NAME_1 = "expandoColumn.name IS NULL";
2921            private static final String _FINDER_COLUMN_T_N_NAME_2 = "expandoColumn.name = ?";
2922            private static final String _FINDER_COLUMN_T_N_NAME_3 = "(expandoColumn.name IS NULL OR expandoColumn.name = ?)";
2923            private static final String _FINDER_COLUMN_T_N_NAME_4 = "(" +
2924                    _removeConjunction(_FINDER_COLUMN_T_N_NAME_1) + ")";
2925            private static final String _FINDER_COLUMN_T_N_NAME_5 = "(" +
2926                    _removeConjunction(_FINDER_COLUMN_T_N_NAME_2) + ")";
2927            private static final String _FINDER_COLUMN_T_N_NAME_6 = "(" +
2928                    _removeConjunction(_FINDER_COLUMN_T_N_NAME_3) + ")";
2929    
2930            private static String _removeConjunction(String sql) {
2931                    int pos = sql.indexOf(" AND ");
2932    
2933                    if (pos != -1) {
2934                            sql = sql.substring(0, pos);
2935                    }
2936    
2937                    return sql;
2938            }
2939    
2940            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "expandoColumn.columnId";
2941            private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT DISTINCT {expandoColumn.*} FROM ExpandoColumn expandoColumn WHERE ";
2942            private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1 =
2943                    "SELECT {ExpandoColumn.*} FROM (SELECT DISTINCT expandoColumn.columnId FROM ExpandoColumn expandoColumn WHERE ";
2944            private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2 =
2945                    ") TEMP_TABLE INNER JOIN ExpandoColumn ON TEMP_TABLE.columnId = ExpandoColumn.columnId";
2946            private static final String _FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(DISTINCT expandoColumn.columnId) AS COUNT_VALUE FROM ExpandoColumn expandoColumn WHERE ";
2947            private static final String _FILTER_ENTITY_ALIAS = "expandoColumn";
2948            private static final String _FILTER_ENTITY_TABLE = "ExpandoColumn";
2949            private static final String _ORDER_BY_ENTITY_ALIAS = "expandoColumn.";
2950            private static final String _ORDER_BY_ENTITY_TABLE = "ExpandoColumn.";
2951            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoColumn exists with the primary key ";
2952            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoColumn exists with the key {";
2953            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2954            private static Log _log = LogFactoryUtil.getLog(ExpandoColumnPersistenceImpl.class);
2955            private static ExpandoColumn _nullExpandoColumn = new ExpandoColumnImpl() {
2956                            @Override
2957                            public Object clone() {
2958                                    return this;
2959                            }
2960    
2961                            @Override
2962                            public CacheModel<ExpandoColumn> toCacheModel() {
2963                                    return _nullExpandoColumnCacheModel;
2964                            }
2965                    };
2966    
2967            private static CacheModel<ExpandoColumn> _nullExpandoColumnCacheModel = new CacheModel<ExpandoColumn>() {
2968                            public ExpandoColumn toEntityModel() {
2969                                    return _nullExpandoColumn;
2970                            }
2971                    };
2972    }