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