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