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